- 浏览: 335685 次
- 性别:
- 来自: 天津
-
文章分类
最新评论
-
xing0029:
这样配置的话 事物不成功啊 还有什么地方需要注意的么 可以加我 ...
JTA集成JOTM或Atomikos配置分布式事务(Tomcat应用服务器) -
mengqingyu:
liuxiaolu 写道jotm的我的没有成功,楼主能否帮助一 ...
JTA集成JOTM或Atomikos配置分布式事务(Tomcat应用服务器) -
liuxiaolu:
jotm的我的没有成功,楼主能否帮助一下
JTA集成JOTM或Atomikos配置分布式事务(Tomcat应用服务器) -
aptech406328627:
求解救,没弄好QQ:1053942353
Spring邮件发送(可带附件,模板,群发,异步发送等功能) -
ghpaas:
web可视化自定义表单推荐使用GForms开发平台(http: ...
在线表单设计器设计原理
import java.util.List; import java.util.Map; import net.sf.json.JSONObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.mina.core.service.IoHandlerAdapter; import org.apache.mina.core.session.IdleStatus; import org.apache.mina.core.session.IoSession; import org.webframe.web.util.WebFrameUtils; import com.berheley.bi.grp.nio.messageUtil.IProcessor; import com.berheley.bi.grp.nio.messageUtil.IWebMessageHelper; import com.berheley.bi.grp.nio.messageUtil.SocketManager; /** * * 类功能描述:消息推送核心类 * * @author <a href="mailto:qingyu.meng21@gmail.com">mengqingyu </a> * @version $Id: codetemplates.xml,v 1.1 2009/03/06 01:13:01 mengqingyu Exp $ * Create: 2013-7-30 下午03:35:40 */ public class ServerHandler extends IoHandlerAdapter { private Log log = LogFactory.getLog(ServerHandler.class); private IWebMessageHelper webMessageHelper; public IWebMessageHelper getWebMessageHelper() { return webMessageHelper; } public void setWebMessageHelper(IWebMessageHelper webMessageHelper) { this.webMessageHelper = webMessageHelper; } /** * 接受消息,登陆时执行此方法 */ @Override public void messageReceived(IoSession session, Object message) throws Exception { String msg = message.toString().trim(); if (msg.startsWith("{")) { String username = JSONObject.fromObject(msg).getString("sd").toString(); SocketManager.getInstance().addUserToOnlineMap(username, session); List<Map<String,Object>> userList = webMessageHelper.findUserByBinding(username); if(userList.size()>0){ String jsonMessage = webMessageHelper.changeListToJSONArray(webMessageHelper.findMobileByBinding()).toString(); webMessageHelper.sendMessage(username, jsonMessage, (IProcessor) WebFrameUtils.getBean("webMessage")); } } log.info("<-------------------- Received Message: " + msg + "--------------------->"); } @Override public void sessionCreated(IoSession session) throws Exception { super.sessionCreated(session); log.info("<--------------------MINA Server Connection Created--------------------->"); } @Override public void sessionOpened(IoSession session) throws Exception { super.sessionOpened(session); session.getConfig().setIdleTime(IdleStatus.BOTH_IDLE, 1800); //读写 通道均在1800 秒内无任何操作就进入空闲状态 log.info("<--------------------MINA Server Connection Opened--------------------->"); } @Override public void sessionClosed(IoSession session) throws Exception { this.removeUserBySessionId(session); session.close(true); log.info("<--------------------MINA Server Connection Closed--------------------->"); } @Override public void exceptionCaught(IoSession session, Throwable cause) throws Exception { this.removeUserBySessionId(session); session.close(true); log.info("Session Id: " + session.getId() + "" + cause.getMessage()); log.error(cause); } /** * 超出空闲时间执行 */ @Override public void sessionIdle(IoSession session, IdleStatus status) throws Exception { this.removeUserBySessionId(session); session.close(true); log.info("<--------------------Session Idle--------------------->"); } /** * * @function:移除在线列表,关闭session * @param session * @author: mengqingyu 2013-7-30 下午03:35:22 */ private void removeUserBySessionId(IoSession session) { SocketManager.getInstance().removeUserBySessionId(session.getId()); } } import java.beans.PropertyEditorSupport; import java.nio.charset.Charset; /** * * 类功能描述:中文编码 * * @author <a href="mailto:qingyu.meng21@gmail.com">mengqingyu </a> * @version $Id: codetemplates.xml,v 1.1 2009/03/06 01:13:01 mengqingyu Exp $ * Create: 2014-1-15 下午01:42:30 */ public class CharsetEditor extends PropertyEditorSupport { private Object value; @Override public void setAsText(String text) throws IllegalArgumentException { if (text != null) this.value = Charset.forName(text); else this.value = Charset.forName("UTF-8"); } @Override public Object getValue() { return value; } } import org.apache.mina.transport.socket.nio.NioSocketAcceptor; import org.webframe.web.util.WebFrameUtils; /** * * 类功能描述:获取端口号 * * @author <a href="mailto:qingyu.meng21@gmail.com">mengqingyu </a> * @version $Id: codetemplates.xml,v 1.1 2009/03/06 01:13:01 mengqingyu Exp $ * Create: 2013-7-30 下午03:42:04 */ public class MinaHelper { private static final NioSocketAcceptor acc = (NioSocketAcceptor) WebFrameUtils.getBean("ioAcceptor"); public static int getMinaPort() { return acc.getDefaultLocalAddress().getPort(); } } import net.sf.json.JSONObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.mina.core.session.IoSession; import com.berheley.bi.grp.nio.mina.ServerHandler; /** * * 类功能描述:消息处理器抽象类 * * @author <a href="mailto:qingyu.meng21@gmail.com">mengqingyu </a> * @version $Id: codetemplates.xml,v 1.1 2009/03/06 01:13:01 mengqingyu Exp $ * Create: 2013-7-30 下午03:52:59 */ public abstract class AbstractProcessor implements IProcessor { protected Log log = LogFactory.getLog(ServerHandler.class); protected SocketManager manager = SocketManager.getInstance(); public abstract void process(JSONObject jsonMessage, IoSession session); } import net.sf.json.JSONObject; import org.apache.mina.core.session.IoSession; /** * * 类功能描述:统一消息处理接口 * * @author <a href="mailto:qingyu.meng21@gmail.com">mengqingyu </a> * @version $Id: codetemplates.xml,v 1.1 2009/03/06 01:13:01 mengqingyu Exp $ * Create: 2014-1-15 下午01:42:02 */ public interface IProcessor { /** * * @function:统一消息处理接口 * @param jsonMessage * @param session * @author: mengqingyu 2013-7-30 下午03:56:10 */ public void process(JSONObject jsonMessage, IoSession session); } import net.sf.json.JSONObject; import org.apache.mina.core.session.IoSession; import org.springframework.stereotype.Component; /** * * 类功能描述:消息提醒处理器 * * @author <a href="mailto:qingyu.meng21@gmail.com">mengqingyu </a> * @version $Id: codetemplates.xml,v 1.1 2009/03/06 01:13:01 mengqingyu Exp $ * Create: 2013-7-3 下午04:04:50 */ @Component("webMessage") public class WebMessageProcessor extends AbstractProcessor { @Override public void process(JSONObject jsonMessage, IoSession session) { if (jsonMessage != null) { IoSession userSession = manager.getUserSession(jsonMessage.getString("sender")); if (userSession != null) { userSession.write(jsonMessage); log.info("***********************【页面提醒】:" + jsonMessage); } } } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"> <util:properties id="mina" location="classpath:mina.properties"/> <bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor" init-method="bind" destroy-method="unbind"> <property name="defaultLocalAddress" value="#{mina['mina.server.port']}" /> <property name="handler" ref="serverHandler" /> <property name="filterChainBuilder" ref="minaFilterChainBuilder" /> </bean> <!-- NIO处理器 --> <bean id="serverHandler" class="com.berheley.bi.grp.nio.mina.ServerHandler"> <property name="webMessageHelper" ref="webMessageHelper" /> </bean> <!-- 构造过滤器链--> <bean id="minaFilterChainBuilder" class="org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder"> <property name="filters"> <map> <entry key="minaloggingFilter" value-ref="minaloggingFilter" /> <entry key="minaProtocolCodecFilter" value-ref="minaProtocolCodecFilter" /> </map> </property> </bean> <!-- 保证TCP协议所有的包发送方的写操作与接受方的读操作一一对应 --> <bean id="minaProtocolCodecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter"> <constructor-arg> <bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory"> <constructor-arg index="0" type="java.nio.charset.Charset"> <value>UTF-8</value> </constructor-arg> <property name="encoderMaxLineLength" ref="maxValue"></property> <property name="decoderMaxLineLength" ref="maxValue"></property> </bean> </constructor-arg> </bean> <util:constant id="maxValue" static-field="java.lang.Integer.MAX_VALUE"/> <!-- 构造日志过滤器 --> <bean id="minaloggingFilter" class="org.apache.mina.filter.logging.LoggingFilter" /> <!-- 构造属性编辑器 --> <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <property name="customEditors"> <map> <entry key="java.net.SocketAddress"> <bean class="org.apache.mina.integration.beans.InetSocketAddressEditor" /> </entry> <entry key="java.nio.charset.Charset"> <bean class="com.berheley.bi.grp.nio.mina.CharsetEditor" /> </entry> </map> </property> </bean> </beans>
mina.properties文件内容
mina.server.port=9094 mina.flex.port=840
- 消息推送核心代码.rar (838 KB)
- 下载次数: 20
发表评论
-
基于Mybatis封装的增删改查实现通用自动化sql
2014-12-07 20:59 41981.基于map或javaBean的增删改查可实现不写dao接口 ... -
S2SH读取XML扩展点
2014-07-27 01:39 757由于struts2、hibernate通过默认配置文件不支持通 ... -
导出Word、Excel、PPT通用功能设计思路
2014-03-07 16:25 1865工作中经常 ... -
HttpClient抓取解析网站支持多种验证方式
2014-03-06 10:10 1450工作中遇到了抓取多个项目数据并且有多种验证方式包括Http标准 ... -
Tomcat架构分析及性能调优
2014-02-16 17:59 3243一.Tomcat容器层级结构 分为四个等级,由四个子容器组成 ... -
(转载)拦截器与过滤器的区别
2013-05-10 15:36 1047拦截器与过滤器的区别 : 1.拦截器是基于java的反射机制 ... -
(转载)Struts中默认的拦截器栈
2013-05-10 13:19 5095Struts中默认的拦截器栈 ... -
Java并发模式
2013-04-02 12:58 2298在公司做培训时用到,顺便在这里做个总结。 1.生产者消费者模式 ... -
海量数据、高并发优化方案
2013-03-16 18:53 8591一.应用服务器负载均衡 1.链路负载均衡 通过DNS解析域 ... -
Lucene 详解
2013-03-01 11:10 15571.什么是全文检索 对于搜索,按被搜索的资源类 ... -
Spring JDBC批量操作
2013-01-20 02:51 271、使用JdbcTemplate进行批 ... -
集成JBPM3,实现流程流转
2012-11-29 16:48 2217集成JBPM到OA系统,并实现JbpmFacade接口 - ... -
Spring MVC 文件上传
2010-03-23 16:45 1124MultipartHttpServletRequest mul ... -
导出Excel(jxl)
2009-08-05 09:15 526Action代码: import java.io.IOExce ... -
Hibernate笔记(常用技术)
2009-07-21 17:13 2172一.对象关系映射基础 1.hibernate对象属性映射 ...
相关推荐
python学习资源
jfinal-undertow 用于开发、部署由 jfinal 开发的 web 项目
基于Andorid的音乐播放器项目设计(国外开源)实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。
python学习资源
python学习资源
python学习一些项目和资源
【毕业设计】java-springboot+vue家具销售平台实现源码(完整前后端+mysql+说明文档+LunW).zip
HTML+CSS+JavaScarip开发的前端网页源代码
python学习资源
【毕业设计】java-springboot-vue健身房信息管理系统源码(完整前后端+mysql+说明文档+LunW).zip
成绩管理系统C/Go。大学生期末小作业,指针实现,C语言版本(ANSI C)和Go语言版本
1_基于大数据的智能菜品个性化推荐与点餐系统的设计与实现.docx
【毕业设计】java-springboot-vue交流互动平台实现源码(完整前后端+mysql+说明文档+LunW).zip
内容概要:本文主要探讨了在高并发情况下如何设计并优化火车票秒杀系统,确保系统的高性能与稳定性。通过对比分析三种库存管理模式(下单减库存、支付减库存、预扣库存),强调了预扣库存结合本地缓存及远程Redis统一库存的优势,同时介绍了如何利用Nginx的加权轮询策略、MQ消息队列异步处理等方式降低系统压力,保障交易完整性和数据一致性,防止超卖现象。 适用人群:具有一定互联网应用开发经验的研发人员和技术管理人员。 使用场景及目标:适用于电商、票务等行业需要处理大量瞬时并发请求的业务场景。其目标在于通过合理的架构规划,实现在高峰期保持平台的稳定运行,保证用户体验的同时最大化销售额。 其他说明:文中提及的技术细节如Epoll I/O多路复用模型以及分布式系统中的容错措施等内容,对于深入理解大规模并发系统的构建有着重要指导意义。
基于 OpenCV 和 PyTorch 的深度车牌识别
【毕业设计-java】springboot-vue教学资料管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
此数据集包含有关出租车行程的详细信息,包括乘客人数、行程距离、付款类型、车费金额和行程时长。它可用于各种数据分析和机器学习应用程序,例如票价预测和乘车模式分析。
把代码放到Word中,通过开发工具——Visual Basic——插入模块,粘贴在里在,把在硅基流动中申请的API放到VBA代码中。在Word中,选择一个问题,运行这个DeepSeekV3的宏就可以实现在线问答
【毕业设计】java-springboot+vue机动车号牌管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
【毕业设计】java-springboot-vue交通管理在线服务系统的开发源码(完整前后端+mysql+说明文档+LunW).zip