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


Java MsgPacket类代码示例

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


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

示例1: onServerConnected

import org.grain.msg.MsgPacket; //导入依赖的package包/类
public void onServerConnected(MsgPacket msgPacket) {
	IoSession session = (IoSession) msgPacket.getOtherData();
	System.out.println("接到消息:" + msgPacket.getMsgOpCode());
	RPCTestC.Builder builder = RPCTestC.newBuilder();
	builder.setName("RPC你好啊");
	TcpPacket pt = new TcpPacket(TestTCode.TEST_RPC_C, builder.build());

	TcpPacket ptReturn = WaitLockManager.lock(session, pt);
	RPCTestS rpcTestS = (RPCTestS) ptReturn.getData();
	System.out.println("接到RPC消息:" + rpcTestS.getName());

	RPCTestC.Builder builder1 = RPCTestC.newBuilder();
	builder1.setName("TCP你好啊");
	TcpPacket pt1 = new TcpPacket(TestTCode.TEST_RPC_C, builder1.build());
	session.write(pt1);

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

示例2: dispatchThreadMsg

import org.grain.msg.MsgPacket; //导入依赖的package包/类
/**
 * 发布消息,推送至异步线程
 * 
 * @param msgOpCode
 *            消息操作码
 * @param data
 *            可序列化数据
 * @param otherData
 *            其他数据
 * @return
 */
public static boolean dispatchThreadMsg(String msgOpCode, Object data, Object otherData) {
	// 消息未被注册过,不能发送
	if (!MsgManager.msgListenerMap.containsKey(msgOpCode)) {
		if (MsgManager.log != null) {
			MsgManager.log.warn("消息类型:" + msgOpCode + ",不存在,无法注册");
		}
		return false;
	}
	// 创建消息包
	MsgPacket msgPacket = new MsgPacket(msgOpCode, data, otherData, MsgManager.USE_MSG_MONITOR);
	// 获取归属线程和优先级,如果为空则随机一个
	int[] msgTypeArray = msgOpcodeType.get(msgPacket.getMsgOpCode());
	if (msgTypeArray == null || msgTypeArray.length != 2) {
		msgTypeArray = AsyncThreadManager.getRandomThreadPriority();
	}
	msgPacket.putMonitor("分发至线程:" + msgTypeArray[0] + ",优先级:" + msgTypeArray[1]);
	// 初始化回调函数

	ThreadHandle threadHandle = new ThreadHandle(msgPacket, MsgManager.method, null);
	// 加入异步线程
	boolean result = AsyncThreadManager.addHandle(threadHandle, msgTypeArray[0], msgTypeArray[1]);
	return result;
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:35,代码来源:ThreadMsgManager.java

示例3: addNotifyHandle

import org.grain.msg.MsgPacket; //导入依赖的package包/类
public void addNotifyHandle(MsgPacket msgPacket) {
	AddNotify message = (AddNotify) msgPacket.getData();
	HttpConfig.log.info("接到推送请求orderRecordId:" + message.getOrderRecordId());
	int[] threadId = AsyncThreadManager.getRandomThread();
	NotifyClient notifyClient = notifyClientMap.get(threadId[0]);
	notifyClient.addNotifyOrder(message.getOrderRecordId());
	HttpConfig.log.info("推送请求orderRecordId:" + message.getOrderRecordId() + "到线程" + threadId[0]);
}
 
开发者ID:dianbaer,项目名称:epay,代码行数:9,代码来源:NotifyService.java

示例4: userOfflineHandle

import org.grain.msg.MsgPacket; //导入依赖的package包/类
/**
 * 线程1的业务
 * 
 * @param msgPacket
 */
public void userOfflineHandle(MsgPacket msgPacket) {
	OnlineUser onlineUser = (OnlineUser) msgPacket.getOtherData();
	List<UserData> friendList = null;
	if (!StringUtil.stringIsNull(onlineUser.getUserData().getUserGroupTopId())) {
		friendList = IdentityAction.getFriendList(onlineUser.getUserData().getUserGroupTopId(), onlineUser.getToken());
		if (friendList != null && friendList.size() != 0) {
			ChatUserOfflineS.Builder chatUserOfflineSBuilder = ChatUserOfflineS.newBuilder();
			chatUserOfflineSBuilder.setWsOpCode(WsOpCodeChat.USER_OFFLINE_S);
			chatUserOfflineSBuilder.setUserId(onlineUser.getUserId());
			WsPacket sendOfflineWsPacket = new WsPacket(WsOpCodeChat.USER_OFFLINE_S, chatUserOfflineSBuilder.build());
			// 广播给在线好友上线
			for (int i = 0; i < friendList.size(); i++) {
				UserData friendUserData = friendList.get(i);
				if (friendUserData.getUserId().equals(onlineUser.getUserId())) {
					// 排除自己
					continue;
				}
				OnlineUser friendOnlineUser = OnlineUserManager.getOnlineUserByUserId(friendUserData.getUserId());
				if (friendOnlineUser == null) {
					continue;
				}
				friendOnlineUser.send(sendOfflineWsPacket);
			}
		}
	}
	OnlineUserManager.removeOnlineUser(onlineUser);
	onlineUser.clear();
}
 
开发者ID:dianbaer,项目名称:anychat,代码行数:34,代码来源:LoginChatService.java

示例5: webSocketCientDisConnectHandle

import org.grain.msg.MsgPacket; //导入依赖的package包/类
/**
 * 线程1的业务
 * 
 * @param msgPacket
 */
public void webSocketCientDisConnectHandle(MsgPacket msgPacket) {
	Session session = (Session) msgPacket.getOtherData();
	OnlineUser onlineUser = OnlineUserManager.getOnlineUserBySessionId(session.getId());
	if (onlineUser != null) {
		onlineUser.setDisConnect(true);
	} else {
		WSManager.log.info("该链接未登陆,不用走下线流程或者是主动下线");
	}
}
 
开发者ID:dianbaer,项目名称:anychat,代码行数:15,代码来源:LoginChatService.java

示例6: userOfflineHandle

import org.grain.msg.MsgPacket; //导入依赖的package包/类
/**
 * 线程1的业务
 * 
 * @param msgPacket
 */
public void userOfflineHandle(MsgPacket msgPacket) {
	OnlineUserMongodb onlineUser = (OnlineUserMongodb) msgPacket.getOtherData();
	List<UserData> friendList = null;
	if (!StringUtil.stringIsNull(onlineUser.getUserData().getUserGroupTopId())) {
		friendList = IdentityAction.getFriendList(onlineUser.getUserData().getUserGroupTopId(), onlineUser.getToken());
		if (friendList != null && friendList.size() != 0) {
			ChatUserOfflineS.Builder chatUserOfflineSBuilder = ChatUserOfflineS.newBuilder();
			chatUserOfflineSBuilder.setWsOpCode(WsOpCodeChat.USER_OFFLINE_S);
			chatUserOfflineSBuilder.setUserId(onlineUser.getUserId());
			WsPacket sendOfflineWsPacket = new WsPacket(WsOpCodeChat.USER_OFFLINE_S, chatUserOfflineSBuilder.build());
			// 广播给在线好友上线
			for (int i = 0; i < friendList.size(); i++) {
				UserData friendUserData = friendList.get(i);
				if (friendUserData.getUserId().equals(onlineUser.getUserId())) {
					// 排除自己
					continue;
				}
				OnlineUserMongodb friendOnlineUser = OnlineUserManagerMongodb.getOnlineUserByUserId(friendUserData.getUserId());
				if (friendOnlineUser == null) {
					continue;
				}
				friendOnlineUser.send(sendOfflineWsPacket);
			}
		}
	}
	OnlineUserManagerMongodb.removeOnlineUser(onlineUser);
	onlineUser.clear();
}
 
开发者ID:dianbaer,项目名称:anychat,代码行数:34,代码来源:LoginChatServiceMongodb.java

示例7: webSocketCientDisConnectHandle

import org.grain.msg.MsgPacket; //导入依赖的package包/类
/**
 * 线程1的业务
 * 
 * @param msgPacket
 */
public void webSocketCientDisConnectHandle(MsgPacket msgPacket) {
	Session session = (Session) msgPacket.getOtherData();
	OnlineUserMongodb onlineUser = OnlineUserManagerMongodb.getOnlineUserBySessionId(session.getId());
	if (onlineUser != null) {
		onlineUser.setDisConnect(true);
	} else {
		WSManager.log.info("该链接未登陆,不用走下线流程或者是主动下线");
	}
}
 
开发者ID:dianbaer,项目名称:anychat,代码行数:15,代码来源:LoginChatServiceMongodb.java

示例8: onServerConnected

import org.grain.msg.MsgPacket; //导入依赖的package包/类
public void onServerConnected(MsgPacket msgPacket) {
	IoSession session = (IoSession) msgPacket.getOtherData();
	System.out.println("接到消息:" + msgPacket.getMsgOpCode());
	TestC.Builder builder = TestC.newBuilder();
	builder.setName("你好啊");
	TcpPacket pt = new TcpPacket(TestTCode.TESTC, builder.build());
	session.write(pt);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:9,代码来源:TestMsgService.java

示例9: onClientConnected

import org.grain.msg.MsgPacket; //导入依赖的package包/类
public void onClientConnected(MsgPacket msgPacket) {
	IoSession session = (IoSession) msgPacket.getOtherData();
	System.out.println("接到消息:" + msgPacket.getMsgOpCode());
	RPCTestS.Builder builder = RPCTestS.newBuilder();
	builder.setName("RPC你好啊");
	TcpPacket pt = new TcpPacket(TestTCode.TEST_RPC_SERVER, builder.build());

	TcpPacket ptReturn = WaitLockManager.lock(session, pt);
	RPCTestC rpcTestC = (RPCTestC) ptReturn.getData();
	System.out.println("接到RPC消息:" + rpcTestC.getName());

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

示例10: minaServerConnected

import org.grain.msg.MsgPacket; //导入依赖的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

示例11: onDistributedlockCanUse

import org.grain.msg.MsgPacket; //导入依赖的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

示例12: onDistributedlockTest

import org.grain.msg.MsgPacket; //导入依赖的package包/类
public void onDistributedlockTest(MsgPacket msgPacket) {
	// 获取锁
	int lockId = DistributedLockClient.getLock("111", "user");
	if (lockId == 0) {
		return;
	}
	/*********** 执行分布式锁业务逻辑 *********/
	System.out.println("分布式锁id为:" + lockId);
	/*********** 执行分布式锁业务逻辑 *********/
	// 释放锁
	DistributedLockClient.unLock("111", "user", lockId);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:13,代码来源:TestMsgService.java

示例13: onDistributedlockTest1

import org.grain.msg.MsgPacket; //导入依赖的package包/类
public void onDistributedlockTest1(MsgPacket msgPacket) {
	// 获取锁
	int lockId = DistributedLockClient.getLock("222", "user");
	if (lockId == 0) {
		return;
	}
	/*********** 执行分布式锁业务逻辑 *********/
	System.out.println("分布式锁id为:" + lockId);
	/*********** 执行分布式锁业务逻辑 *********/
	// 释放锁
	DistributedLockClient.unLock("222", "user", lockId);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:13,代码来源:TestMsgService.java

示例14: minaServerDisConnect

import org.grain.msg.MsgPacket; //导入依赖的package包/类
public void minaServerDisConnect(MsgPacket msgPacket) {
	String name = (String) msgPacket.getData();
	ioSessionServerMap.remove(name);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:5,代码来源:MinaClientService.java

示例15: createUserHandle

import org.grain.msg.MsgPacket; //导入依赖的package包/类
public void createUserHandle(MsgPacket msgPacket) {
	System.out.println("createUserHandle接到消息:" + msgPacket.getMsgOpCode());
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:4,代码来源:TestThreadMsgListener.java


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