當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。