本文整理汇总了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);
}
示例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;
}
示例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]);
}
示例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();
}
示例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("该链接未登陆,不用走下线流程或者是主动下线");
}
}
示例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();
}
示例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("该链接未登陆,不用走下线流程或者是主动下线");
}
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例14: minaServerDisConnect
import org.grain.msg.MsgPacket; //导入依赖的package包/类
public void minaServerDisConnect(MsgPacket msgPacket) {
String name = (String) msgPacket.getData();
ioSessionServerMap.remove(name);
}
示例15: createUserHandle
import org.grain.msg.MsgPacket; //导入依赖的package包/类
public void createUserHandle(MsgPacket msgPacket) {
System.out.println("createUserHandle接到消息:" + msgPacket.getMsgOpCode());
}