当前位置: 首页>>代码示例>>Java>>正文


Java ThreadMsgManager类代码示例

本文整理汇总了Java中org.grain.threadmsg.ThreadMsgManager的典型用法代码示例。如果您正苦于以下问题:Java ThreadMsgManager类的具体用法?Java ThreadMsgManager怎么用?Java ThreadMsgManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ThreadMsgManager类属于org.grain.threadmsg包,在下文中一共展示了ThreadMsgManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: messageReceived

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
	super.messageReceived(session, message);
	if (MinaConfig.log != null) {
		MinaConfig.log.info("minaserver messageReceived");
	}
	TcpPacket pt = (TcpPacket) message;
	// 如果是获取锁,需要汇集到一个线程
	if (pt.gettOpCode() == DistributedlockTCode.DISTRIBUTED_LOCK_C1) {
		ThreadMsgManager.dispatchThreadMsg(DistributedlockMsg.MERGE_TCPPACKET, message, null);
	} else {
		// 其他情况不需要
		ThreadTcpManager.dispatchTcp(pt);
	}

}
 
开发者ID:dianbaer,项目名称:grain,代码行数:17,代码来源:DistributedlockServerHandler.java

示例2: onRemove

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
@Override
public void onRemove() throws Exception {
	// 离开场景时xxx
	// 发布离线消息
	UserOffline.Builder builder = UserOffline.newBuilder();
	builder.setUserId(getUserId());
	ThreadMsgManager.dispatchThreadMsg(MsgOpCodeChat.USER_OFFLINE, builder.build(), this);
}
 
开发者ID:dianbaer,项目名称:anychat,代码行数:9,代码来源:OnlineUser.java

示例3: onOpen

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
@OnOpen
public void onOpen(Session session) {

	try {
		ThreadMsgManager.dispatchThreadMsg(WSMsg.WEBSOCKET_CLIENT_CREATE_CONNECT, null, session);
	} catch (Exception e) {
		if (WSManager.log != null) {
			WSManager.log.error("MsgManager.dispatchMsg error", e);
		}
	}
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:12,代码来源:WebSocketServer.java

示例4: onClose

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
@OnClose
public void onClose(Session session, CloseReason closeReason) {
	try {
		ThreadMsgManager.dispatchThreadMsg(WSMsg.WEBSOCKET_CLIENT_DISCONNECT, null, session);
	} catch (Exception e) {
		if (WSManager.log != null) {
			WSManager.log.error("MsgManager.dispatchMsg error", e);
		}
	}
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:11,代码来源:WebSocketServer.java

示例5: sessionClosed

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
@Override
public void sessionClosed(IoSession session) throws Exception {
	super.sessionClosed(session);
	if (MinaConfig.log != null) {
		MinaConfig.log.warn("minaserver sessionClosed");
	}
	ThreadMsgManager.dispatchThreadMsg(TcpMsg.MINA_CLIENT_DISCONNECT, null, session);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:9,代码来源:ThreadMinaServerHandler.java

示例6: sessionCreated

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
@Override
public void sessionCreated(IoSession session) throws Exception {
	super.sessionCreated(session);
	if (MinaConfig.log != null) {
		MinaConfig.log.info("minaserver sessionCreated");
	}
	ThreadMsgManager.dispatchThreadMsg(TcpMsg.MINA_CLIENT_CREATE_CONNECT, null, session);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:9,代码来源:ThreadMinaServerHandler.java

示例7: sessionClosed

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
@Override
public void sessionClosed(IoSession session) throws Exception {
	super.sessionClosed(session);
	if (MinaConfig.log != null) {
		MinaConfig.log.warn("minaclient sessionClosed");
	}
	// 设置链接已断开,断线过会儿会断线重连
	MinaClient.getInstance().ioConnectorStateMap.put(ioConnector, false);
	// 发布与服务器断开的消息
	ThreadMsgManager.dispatchThreadMsg(TcpMsg.MINA_SERVER_DISCONNECT, this.name, session);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:12,代码来源:ThreadMinaClientHandler.java

示例8: sessionCreated

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
@Override
public void sessionCreated(IoSession session) throws Exception {
	super.sessionCreated(session);
	if (MinaConfig.log != null) {
		MinaConfig.log.info("minaclient sessionCreated");
	}
	// 发布与服务器链接成功的消息
	ThreadMsgManager.dispatchThreadMsg(TcpMsg.MINA_SERVER_CONNECTED, this.name, session);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:10,代码来源:ThreadMinaClientHandler.java

示例9: main

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	GrainLog grainLog = new GrainLog(LoggerFactory.getLogger("minaLog"));
	GrainLog grainLog1 = new GrainLog(LoggerFactory.getLogger("msgLog"));
	// 初始化线程消息(需要锁定两条线程第一条唤醒用的,第二条获取锁信息汇集用的)
	AsyncThreadManager.init(100, 10, 3, 2, grainLog1);
	AsyncThreadManager.start();
	MsgManager.init(true, grainLog1);
	// 设置消息归属线程,不设置则随机分配
	ThreadMsgManager.addMapping(TcpMsg.MINA_CLIENT_CREATE_CONNECT, new int[] { 1, 1 });
	ThreadMsgManager.addMapping(TcpMsg.MINA_CLIENT_DISCONNECT, new int[] { 1, 1 });
	// 第二条用于汇集用
	int[] threadPriority = AsyncThreadManager.getLockThreadPriority(2);
	ThreadMsgManager.addMapping(DistributedlockMsg.MERGE_TCPPACKET, threadPriority);
	// 注册关注的消息
	MergeTCPService mergeTCPService = new MergeTCPService();
	MsgManager.addMsgListener(mergeTCPService);

	WaitLockManager.init(120000);
	ThreadTcpManager.init();
	// 初始化分布式锁服务器
	ArrayList<String> types = new ArrayList<>();
	types.add("user");
	types.add("group");
	DistributedLockServer.init(types, grainLog1);
	// 注册tcp回调函数
	DistributedLockService distributedLockService = new DistributedLockService();
	TcpManager.addTcpListener(distributedLockService);
	// 创建TCP服务器
	MinaServer.init("0.0.0.0", 7005, DistributedlockServerHandler.class, true, grainLog);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:31,代码来源:DistributedlockServerTest.java

示例10: main

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	GrainLog grainLog = new GrainLog(LoggerFactory.getLogger("minaLog"));
	GrainLog grainLog1 = new GrainLog(LoggerFactory.getLogger("msgLog"));

	// 初始化线程消息
	AsyncThreadManager.init(100, 10, 3, 1, grainLog1);
	AsyncThreadManager.start();
	MsgManager.init(true, grainLog1);
	// 设置消息归属线程,不设置则随机分配
	ThreadMsgManager.addMapping(TcpMsg.MINA_CLIENT_CREATE_CONNECT, new int[] { 1, 1 });
	ThreadMsgManager.addMapping(TcpMsg.MINA_CLIENT_DISCONNECT, new int[] { 1, 1 });
	// 注册关注的消息
	TestMsgService testService = new TestMsgService();
	MsgManager.addMsgListener(testService);
	// 映射操作码解析类
	ThreadTcpManager.addThreadMapping(TestTCode.TEST_RPC_C, RPCTestC.class, null);
	ThreadTcpManager.addThreadMapping(TestTCode.TEST_RPC_S, RPCTestS.class, null);
	ThreadTcpManager.addThreadMapping(TestTCode.TEST_RPC_SERVER, RPCTestS.class, null);
	ThreadTcpManager.addThreadMapping(TestTCode.TEST_RPC_CLIENT, RPCTestC.class, null);
	// 注册tcp回调函数
	TestRPCServiceS testRPCServiceS = new TestRPCServiceS();
	TcpManager.addTcpListener(testRPCServiceS);
	WaitLockManager.init(120000);
	ThreadTcpManager.init();
	// 创建TCP服务器
	MinaServer.init("0.0.0.0", 7005, ThreadMinaServerHandler.class, true, grainLog);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:28,代码来源:RPCServerTest.java

示例11: minaServerConnected

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
/**
 * 通知叫name的锁服务器可以使用了
 * 
 * @param msgPacket
 */
public void minaServerConnected(MsgPacket msgPacket) {
	IoSession ioSession = (IoSession) msgPacket.getOtherData();
	String name = (String) msgPacket.getData();
	ioSessionServerMap.put(name, ioSession);
	ThreadMsgManager.dispatchThreadMsg(DistributedlockMsg.DISTRIBUTEDLOCK_SERVER_CAN_USE, name, null);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:12,代码来源:MinaClientService.java

示例12: onDistributedlockCanUse

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
public void onDistributedlockCanUse(MsgPacket msgPacket) {
	// 发布四条消息,分配至随机线程,不同类型互补影响,相同类型不同键值互不影响
	ThreadMsgManager.dispatchThreadMsg("DISTRIBUTEDLOCK_TEST", null, null);
	ThreadMsgManager.dispatchThreadMsg("DISTRIBUTEDLOCK_TEST", null, null);
	ThreadMsgManager.dispatchThreadMsg("DISTRIBUTEDLOCK_TEST1", null, null);
	ThreadMsgManager.dispatchThreadMsg("DISTRIBUTEDLOCK_TEST1", null, null);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:8,代码来源:TestMsgService.java

示例13: main

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	GrainLog grainLog = new GrainLog(LoggerFactory.getLogger("minaLog"));
	GrainLog grainLog1 = new GrainLog(LoggerFactory.getLogger("msgLog"));

	// 初始化线程消息
	AsyncThreadManager.init(100, 10, 3, 1, grainLog1);
	AsyncThreadManager.start();
	MsgManager.init(true, grainLog1);
	// 设置消息归属线程,不设置则随机分配
	ThreadMsgManager.addMapping(TcpMsg.MINA_SERVER_CONNECTED, new int[] { 1, 1 });
	ThreadMsgManager.addMapping(TcpMsg.MINA_SERVER_DISCONNECT, new int[] { 1, 1 });
	ThreadMsgManager.addMapping(DistributedlockMsg.DISTRIBUTEDLOCK_SERVER_CAN_USE, new int[] { 1, 1 });
	// 注册关注的消息
	MinaClientService minaClientService = new MinaClientService();
	MsgManager.addMsgListener(minaClientService);
	TestMsgService testMsgService = new TestMsgService();
	MsgManager.addMsgListener(testMsgService);

	WaitLockManager.init(120000);
	ThreadTcpManager.init();
	// 初始化分布式锁客户端
	Map<String, String> lockToServer = new HashMap<String, String>();
	lockToServer.put("user", "testserver");
	lockToServer.put("group", "testserver");
	DistributedLockClient.init(lockToServer, grainLog1);
	// 创建TCP客户端
	MinaClient.init(new String[] { "0.0.0.0" }, new int[] { 7005 }, new String[] { "testserver" }, ThreadMinaClientHandler.class, 10, true, grainLog);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:29,代码来源:DistributedlockClientTest.java

示例14: main

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	GrainLog grainLog = new GrainLog(LoggerFactory.getLogger("minaLog"));
	GrainLog grainLog1 = new GrainLog(LoggerFactory.getLogger("msgLog"));
	// 初始化线程消息
	AsyncThreadManager.init(100, 10, 3, 1, grainLog1);
	AsyncThreadManager.start();
	MsgManager.init(true, grainLog1);
	// 设置消息归属线程,不设置则随机分配
	ThreadMsgManager.addMapping(TcpMsg.MINA_SERVER_CONNECTED, new int[] { 1, 1 });
	ThreadMsgManager.addMapping(TcpMsg.MINA_SERVER_DISCONNECT, new int[] { 1, 1 });
	// 注册关注的消息
	TestMsgService testService = new TestMsgService();
	MsgManager.addMsgListener(testService);
	// 映射操作码解析类
	ThreadTcpManager.addThreadMapping(TestTCode.TEST_RPC_C, RPCTestC.class, null);
	ThreadTcpManager.addThreadMapping(TestTCode.TEST_RPC_S, RPCTestS.class, null);
	ThreadTcpManager.addThreadMapping(TestTCode.TEST_RPC_SERVER, RPCTestS.class, null);
	ThreadTcpManager.addThreadMapping(TestTCode.TEST_RPC_CLIENT, RPCTestC.class, null);
	
	TestRPCServiceC testRPCServiceC = new TestRPCServiceC();
	TcpManager.addTcpListener(testRPCServiceC);
	WaitLockManager.init(120000);
	ThreadTcpManager.init();
	// 创建TCP客户端
	MinaClient.init(new String[] { "0.0.0.0" }, new int[] { 7005 }, new String[] { "testserver" }, ThreadMinaClientHandler.class, 10, true, grainLog);

}
 
开发者ID:dianbaer,项目名称:grain,代码行数:28,代码来源:RPCClientTest.java

示例15: init

import org.grain.threadmsg.ThreadMsgManager; //导入依赖的package包/类
public static void init() {
	ThreadMsgManager.addMapping(ADD_NOTIFY, null);
}
 
开发者ID:dianbaer,项目名称:epay,代码行数:4,代码来源:MsgOpCode.java


注:本文中的org.grain.threadmsg.ThreadMsgManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。