本文整理汇总了Java中org.grain.thread.AsyncThreadManager类的典型用法代码示例。如果您正苦于以下问题:Java AsyncThreadManager类的具体用法?Java AsyncThreadManager怎么用?Java AsyncThreadManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AsyncThreadManager类属于org.grain.thread包,在下文中一共展示了AsyncThreadManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.grain.thread.AsyncThreadManager; //导入依赖的package包/类
@Override
public void init(HttpServlet servlet) throws Exception {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
ServletContext servletContext = servlet.getServletContext();
String configFileName = servletContext.getInitParameter("configFileName");
Properties properties = loadConfig(configFileName);
MybatisManager.init(properties.getProperty("config_dir"), "mybatis-config.xml", new MariadbLog());
HttpUtil.init("UTF-8", new HttpclientLog());
ThreadmsgLog threadmsgLog = new ThreadmsgLog();
AsyncThreadManager.init(100, 10, 3, 0, threadmsgLog);
AsyncThreadManager.start();
MsgManager.init(true, threadmsgLog);
CommonConfig.init(properties);
HOpCode.init();
MsgOpCode.init();
HttpManager.addFilter(new TokenHttpFilter());
HttpManager.addHttpListener(new AppService());
HttpManager.addHttpListener(new OrderRecordService());
HttpManager.addHttpListener(new PayService());
HttpManager.addHttpListener(new LoginService());
MsgManager.addMsgListener(new NotifyService(10));
}
示例2: cycle
import org.grain.thread.AsyncThreadManager; //导入依赖的package包/类
@Override
public void cycle() throws Exception {
// 扫描自身消息队列发送消息
// 如果被踢或者自行断开,走下线流程
if (isKick || isDisConnect) {
AsyncThreadManager.removeCycle(this, threadPriority[0], threadPriority[1]);
return;
}
ArrayList<Chat> userChatArray = getHandleUserChat();
ArrayList<Chat> groupChatArray = getHandleGroupChat();
// 发送此次轮训的用户聊天
if (userChatArray.size() != 0) {
Map<String, List<Chat>> userChatMap = getUserChatMap(userChatArray);
sendUserChat(userChatMap);
}
// 发送此次轮训的组聊天
if (groupChatArray.size() != 0) {
Map<String, List<Chat>> groupChatMap = getGroupChatMap(groupChatArray);
sendGroupChat(groupChatMap);
}
}
示例3: cycle
import org.grain.thread.AsyncThreadManager; //导入依赖的package包/类
@Override
public void cycle() throws Exception {
// 扫描自身消息队列发送消息
// 如果被踢或者自行断开,走下线流程
if (isKick || isDisConnect) {
AsyncThreadManager.removeCycle(this, threadPriority[0], threadPriority[1]);
return;
}
ArrayList<ChatObj> userChatArray = getHandleUserChat();
ArrayList<ChatObj> groupChatArray = getHandleGroupChat();
// 发送此次轮训的用户聊天
if (userChatArray.size() != 0) {
Map<String, List<ChatObj>> userChatMap = getUserChatMap(userChatArray);
sendUserChat(userChatMap);
}
// 发送此次轮训的组聊天
if (groupChatArray.size() != 0) {
Map<String, List<ChatObj>> groupChatMap = getGroupChatMap(groupChatArray);
sendGroupChat(groupChatMap);
}
}
示例4: dispatchWS
import org.grain.thread.AsyncThreadManager; //导入依赖的package包/类
/**
* 将消息包分发到系统多线程模型进行处理
*
* @param wsPacket
* @return
*/
public static boolean dispatchWS(WsPacket wsPacket) {
if (wsPacket == null) {
if (WSManager.log != null) {
WSManager.log.warn("派发ws包为空");
}
return false;
}
wsPacket.openRunMonitor();
int[] wsTypeArray = wsOpCodeType.get(wsPacket.getWsOpCode());
if (wsTypeArray == null || wsTypeArray.length != 2) {
wsTypeArray = AsyncThreadManager.getRandomThreadPriority();
}
wsPacket.putMonitor("分发至线程:" + wsTypeArray[0] + ",优先级:" + wsTypeArray[1]);
ThreadHandle threadHandle = new ThreadHandle(wsPacket, WSManager.method, null);
boolean result = AsyncThreadManager.addHandle(threadHandle, wsTypeArray[0], wsTypeArray[1]);
return result;
}
示例5: init
import org.grain.thread.AsyncThreadManager; //导入依赖的package包/类
@Override
public void init() throws ServletException {
// TODO Auto-generated method stub
super.init();
try {
GrainLog grainLog = new GrainLog(LoggerFactory.getLogger("minaLog"));
GrainLog grainLog1 = new GrainLog(LoggerFactory.getLogger("msgLog"));
// 初始化线程消息
AsyncThreadManager.init(100, 10, 3, 0, grainLog1);
AsyncThreadManager.start();
MsgManager.init(true, grainLog1);
WSManager.init(grainLog1);
// 映射操作码解析类,如果不设置线程优先级则随机线程优先级
ThreadWSManager.addThreadMapping("testc", TestC.class, new int[] { 2, 1 });
ThreadWSManager.addThreadMapping("tests", TestS.class, null);
// 注册tcp回调函数
TestWSService testWSService = new TestWSService();
WSManager.addWSListener(testWSService);
} catch (Exception e) {
// TODO: handle exception
}
}
示例6: dispatchThreadMsg
import org.grain.thread.AsyncThreadManager; //导入依赖的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;
}
示例7: addNotifyHandle
import org.grain.thread.AsyncThreadManager; //导入依赖的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]);
}
示例8: dispatchTcp
import org.grain.thread.AsyncThreadManager; //导入依赖的package包/类
public static boolean dispatchTcp(TcpPacket tcpPacket) {
if (tcpPacket == null) {
if (MinaConfig.log != null) {
MinaConfig.log.warn("派发tcp包为空");
}
return false;
}
// 打开监控日志
if (MinaConfig.USE_TCP_MONITOR) {
tcpPacket.openRunMonitor();
}
int[] tcpTypeArray = null;
// 专门的解锁线程
if (tcpPacket.unlockedId != 0) {
tcpTypeArray = AsyncThreadManager.getLockThreadPriority(1);
} else {
// 一般的tcp消息分发
tcpTypeArray = tOpCodeType.get(tcpPacket.gettOpCode());
if (tcpTypeArray == null || tcpTypeArray.length != 2) {
tcpTypeArray = AsyncThreadManager.getRandomThreadPriority();
}
}
tcpPacket.putMonitor("分发至线程:" + tcpTypeArray[0] + ",优先级:" + tcpTypeArray[1]);
ThreadHandle threadHandle = new ThreadHandle(tcpPacket, ThreadTcpManager.method, null);
boolean result = AsyncThreadManager.addHandle(threadHandle, tcpTypeArray[0], tcpTypeArray[1]);
return result;
}
示例9: main
import org.grain.thread.AsyncThreadManager; //导入依赖的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);
}
示例10: main
import org.grain.thread.AsyncThreadManager; //导入依赖的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);
}
示例11: dispatchTcp
import org.grain.thread.AsyncThreadManager; //导入依赖的package包/类
public static boolean dispatchTcp(TcpPacket tcpPacket) {
if (tcpPacket == null) {
if (MinaConfig.log != null) {
MinaConfig.log.warn("派发tcp包为空");
}
return false;
}
// 打开监控日志
if (MinaConfig.USE_TCP_MONITOR) {
tcpPacket.openRunMonitor();
}
int[] tcpTypeArray = null;
// 说明是获取锁的
// 分布式锁获取线程
int threadId = DistributedLockServer.getTypeKeyThreadBelong(tcpPacket);
if (threadId != 0) {
tcpTypeArray = new int[] { threadId, 1 };
}
// 没有说明还没人要,随机一个
if (tcpTypeArray == null || tcpTypeArray.length != 2) {
tcpTypeArray = AsyncThreadManager.getRandomThreadPriority();
}
// 没存过,存一次
if (threadId == 0) {
DistributedLockServer.saveTypeKeyThreadBelong(tcpPacket, tcpTypeArray[0]);
}
tcpPacket.putMonitor("分发至线程:" + tcpTypeArray[0] + ",优先级:" + tcpTypeArray[1]);
ThreadHandle threadHandle = new ThreadHandle(tcpPacket, ThreadTcpManager.method, null);
boolean result = AsyncThreadManager.addHandle(threadHandle, tcpTypeArray[0], tcpTypeArray[1]);
return result;
}
示例12: main
import org.grain.thread.AsyncThreadManager; //导入依赖的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);
}
示例13: main
import org.grain.thread.AsyncThreadManager; //导入依赖的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);
}
示例14: setUpBeforeClass
import org.grain.thread.AsyncThreadManager; //导入依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
AsyncThreadManager.init(100, 10, 3, 0, null);
AsyncThreadManager.start();
MsgManager.init(true, null);
ThreadMsgManager.addMapping("createuser", new int[] { 1, 1 });
TestThreadMsgListener testThreadMsgListener = new TestThreadMsgListener();
MsgManager.addMsgListener(testThreadMsgListener);
}
示例15: init
import org.grain.thread.AsyncThreadManager; //导入依赖的package包/类
@Override
public void init() throws ServletException {
// TODO Auto-generated method stub
super.init();
WebSocketLog log = null;
try {
log = new WebSocketLog();
WSManager.init(log);
ThreadmsgLog threadmsgLog = new ThreadmsgLog();
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
ServletContext servletContext = this.getServletContext();
String configFileName = servletContext.getInitParameter("configFileName");
Properties properties = loadConfig(configFileName);
MybatisManager.init(properties.getProperty("config_dir"), "mybatis-config.xml", new MariadbLog());
HttpUtil.init("UTF-8", new HttpclientLog());
// 初始化线程消息
AsyncThreadManager.init(100, 10, 3, 0, threadmsgLog);
AsyncThreadManager.start();
MsgManager.init(true, threadmsgLog);
WsOpCodeChat.init();
CommonConfigChat.init(properties);
MsgOpCodeChat.init();
if (CommonConfigChat.IS_USE_MONGODB) {
MongodbManager.init(CommonConfigChat.MONGODB_URL, CommonConfigChat.MONGODB_PORT, CommonConfigChat.MONGODB_USERNAME, CommonConfigChat.MONGODB_PASSWORD, CommonConfigChat.MONGODB_DBNAME, new MongodbLog());
LoginChatServiceMongodb loginChatServiceMongodb = new LoginChatServiceMongodb();
MsgManager.addMsgListener(loginChatServiceMongodb);
WSManager.addWSListener(loginChatServiceMongodb);
WSManager.addWSListener(new MessageServiceMongodb());
} else {
LoginChatService loginChatService = new LoginChatService();
MsgManager.addMsgListener(loginChatService);
WSManager.addWSListener(loginChatService);
WSManager.addWSListener(new MessageService());
}
} catch (Exception e) {
if (log != null) {
log.error("启动失败", e);
}
}
}