mirror of
https://gitee.com/xchao/j-im.git
synced 2024-12-02 20:08:23 +08:00
升级t-io到最新版v2.4.0,优化部分设计
This commit is contained in:
parent
0c0b5be1a2
commit
56a8638af6
@ -52,7 +52,7 @@ public class HelloClientAioHandler implements AioHandler,ClientAioHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public TcpPacket decode(ByteBuffer buffer, ChannelContext channelContext) throws AioDecodeException {
|
||||
public TcpPacket decode(ByteBuffer buffer,int limit, int position, int readableLength,ChannelContext channelContext) throws AioDecodeException {
|
||||
TcpPacket tcpPacket = TcpServerDecoder.decode(buffer, channelContext);
|
||||
return tcpPacket;
|
||||
}
|
||||
|
@ -7,13 +7,13 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.jim.common.cache.ICache;
|
||||
import org.jim.common.cache.redis.JedisTemplate.Pair;
|
||||
import org.jim.common.cache.redis.JedisTemplate.PairEx;
|
||||
import org.jim.common.utils.JsonKit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tio.utils.SystemTimer;
|
||||
import org.tio.utils.cache.ICache;
|
||||
/**
|
||||
*
|
||||
* @author wchao
|
||||
|
@ -19,13 +19,13 @@
|
||||
<id>wchao</id>
|
||||
<name>wchao</name>
|
||||
<email>wchaojava@163.com</email>
|
||||
<url>http://git.oschina.net/xchao/tio-im</url>
|
||||
<url>http://git.oschina.net/xchao/j-im</url>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:git@gitee.com:xchao/tio-im.git</connection>
|
||||
<developerConnection>scm:git:git@gitee.com:xchao/tio-im.git</developerConnection>
|
||||
<url>git@gitee.com:xchao/tio-im.git</url>
|
||||
<connection>scm:git:git@gitee.com:xchao/j-im.git</connection>
|
||||
<developerConnection>scm:git:git@gitee.com:xchao/j-im.git</developerConnection>
|
||||
<url>git@gitee.com:xchao/j-im.git</url>
|
||||
</scm>
|
||||
<modules>
|
||||
<module>../jim-client</module>
|
||||
@ -35,8 +35,8 @@
|
||||
</modules>
|
||||
<properties>
|
||||
<jim.version>1.0.1.v20180515-RELEASE</jim.version>
|
||||
<tio-core.version>2.0.8.v20180205-RELEASE</tio-core.version>
|
||||
<tio-utils.version>2.0.8.v20180205-RELEASE</tio-utils.version>
|
||||
<tio-core.version>2.4.0.v20180508-RELEASE</tio-core.version>
|
||||
<tio-utils.version>2.4.0.v20180508-RELEASE</tio-utils.version>
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
@ -58,7 +58,7 @@
|
||||
<commons-compress.version>1.14</commons-compress.version>
|
||||
<fastjson.version>1.2.35</fastjson.version>
|
||||
<testng.version>6.11</testng.version>
|
||||
<hutool.version>3.1.0</hutool.version>
|
||||
<hutool.version>4.0.10</hutool.version>
|
||||
<commons-beanutils.version>1.9.3</commons-beanutils.version>
|
||||
<jedis.version>2.7.3</jedis.version>
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.jim.server.handler.ImServerAioHandler;
|
||||
import org.jim.server.handler.ServerHandlerManager;
|
||||
import org.jim.server.listener.ImServerAioListener;
|
||||
import org.tio.server.ServerGroupContext;
|
||||
import org.tio.utils.Threads;
|
||||
import org.tio.utils.thread.pool.DefaultThreadFactory;
|
||||
import org.tio.utils.thread.pool.SynThreadPoolExecutor;
|
||||
|
||||
@ -29,7 +30,7 @@ public class ImServerGroupContext extends ServerGroupContext {
|
||||
if (this.timExecutor == null) {
|
||||
LinkedBlockingQueue<Runnable> timQueue = new LinkedBlockingQueue<>();
|
||||
String timThreadName = "jim";
|
||||
this.timExecutor = new SynThreadPoolExecutor(CORE_POOL_SIZE, CORE_POOL_SIZE, KEEP_ALIVE_TIME, timQueue,
|
||||
this.timExecutor = new SynThreadPoolExecutor(CORE_POOL_SIZE, CORE_POOL_SIZE, Threads.KEEP_ALIVE_TIME, timQueue,
|
||||
DefaultThreadFactory.getInstance(timThreadName, Thread.NORM_PRIORITY), timThreadName);
|
||||
this.timExecutor.prestartAllCoreThreads();
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import java.nio.ByteBuffer;
|
||||
|
||||
import org.jim.common.ImConfig;
|
||||
import org.tio.core.ChannelContext;
|
||||
import org.tio.core.exception.AioDecodeException;
|
||||
import org.tio.core.intf.Packet;
|
||||
import org.tio.server.intf.ServerAioHandler;
|
||||
/**
|
||||
* 版本: [1.0] 功能说明: 封装tioServerAioHandler,提供更丰富的方法供客户端定制化;
|
||||
@ -16,4 +18,10 @@ public abstract class AbServerHandler implements ServerAioHandler{
|
||||
public abstract String name();
|
||||
public abstract void init(ImConfig imConfig)throws Exception;
|
||||
public abstract boolean isProtocol(ByteBuffer byteBuffer,ChannelContext channelContext)throws Throwable;
|
||||
public abstract Packet decode(ByteBuffer buffer, ChannelContext channelContext)throws AioDecodeException;
|
||||
@Override
|
||||
public Packet decode(ByteBuffer buffer, int limit, int position,int readableLength, ChannelContext channelContext)throws AioDecodeException {
|
||||
return decode(buffer,channelContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class ImServerAioHandler implements ServerAioHandler {
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public Packet decode(ByteBuffer buffer, ChannelContext channelContext) throws AioDecodeException {
|
||||
public Packet decode(ByteBuffer buffer,int limit, int position, int readableLength,ChannelContext channelContext) throws AioDecodeException {
|
||||
ImSessionContext imSessionContext = (ImSessionContext)channelContext.getAttribute();
|
||||
AbServerHandler handler = null;
|
||||
if(imSessionContext == null){
|
||||
|
@ -77,7 +77,7 @@ public class HttpServerHandler extends AbServerHandler{
|
||||
ImConfig.groupContext.setAttribute(GroupContextKey.HTTP_SERVER_CONFIG, httpConfig);
|
||||
long end = SystemTimer.currentTimeMillis();
|
||||
long iv = end - start;
|
||||
log.info("t-im Http Server初始化完毕,耗时:{}ms", iv);
|
||||
log.info("j-im Http Server初始化完毕,耗时:{}ms", iv);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,73 +15,79 @@ public class ImServerAioListener implements ServerAioListener {
|
||||
Logger logger = Logger.getLogger(ImServerAioListener.class);
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author: WChao
|
||||
* 2016年12月16日 下午5:52:06
|
||||
*
|
||||
*/
|
||||
public ImServerAioListener() {
|
||||
}
|
||||
|
||||
public ImServerAioListener() {}
|
||||
/**
|
||||
* @param args
|
||||
*
|
||||
* 建链后触发本方法,注:建链不一定成功,需要关注参数isConnected
|
||||
* @param channelContext
|
||||
* @param isConnected 是否连接成功,true:表示连接成功,false:表示连接失败
|
||||
* @param isReconnect 是否是重连, true: 表示这是重新连接,false: 表示这是第一次连接
|
||||
* @throws Exception
|
||||
* @author: WChao
|
||||
* 2016年12月16日 下午5:52:06
|
||||
*
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterConnected(ChannelContext channelContext, boolean isConnected, boolean isReconnect) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.tio.core.intf.AioListener#onBeforeSent(org.tio.core.ChannelContext, org.tio.core.intf.Packet, int)
|
||||
*
|
||||
/**
|
||||
* 消息包发送之后触发本方法
|
||||
* @param channelContext
|
||||
* @param packet
|
||||
* @author: WChao
|
||||
* 2016年12月20日 上午11:08:44
|
||||
*
|
||||
* @param isSentSuccess true:发送成功,false:发送失败
|
||||
* @throws Exception
|
||||
* @author WChao
|
||||
*/
|
||||
@Override
|
||||
public void onAfterSent(ChannelContext channelContext, Packet packet, boolean isSentSuccess) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.tio.core.intf.AioListener#onAfterReceived(org.tio.core.ChannelContext, org.tio.core.intf.Packet, int)
|
||||
*
|
||||
* @param channelContext
|
||||
* @param packet
|
||||
* @param packetSize
|
||||
* @author: WChao
|
||||
* 2016年12月20日 上午11:08:44
|
||||
*
|
||||
/**
|
||||
* 连接关闭前触发本方法
|
||||
* @param channelContext the channelcontext
|
||||
* @param throwable the throwable 有可能为空
|
||||
* @param remark the remark 有可能为空
|
||||
* @param isRemove
|
||||
* @author WChao
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void onAfterReceived(ChannelContext channelContext, Packet packet, int packetSize) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.tio.core.intf.AioListener#onAfterClose(org.tio.core.ChannelContext, java.lang.Throwable, java.lang.String)
|
||||
*
|
||||
* @param channelContext
|
||||
* @param throwable
|
||||
* @param remark
|
||||
* @author: WChao
|
||||
* 2017年2月1日 上午11:03:11
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void onAfterClose(ChannelContext channelContext, Throwable throwable, String remark, boolean isRemove) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeClose(ChannelContext channelContext, Throwable throwable, String remark, boolean isRemove) {
|
||||
}
|
||||
/**
|
||||
* 解码成功后触发本方法
|
||||
* @param channelContext
|
||||
* @param packet
|
||||
* @param packetSize
|
||||
* @throws Exception
|
||||
* @author: WChao
|
||||
*/
|
||||
@Override
|
||||
public void onAfterDecoded(ChannelContext channelContext, Packet packet,int packetSize) throws Exception {
|
||||
|
||||
}
|
||||
/**
|
||||
* 接收到TCP层传过来的数据后
|
||||
* @param channelContext
|
||||
* @param receivedBytes 本次接收了多少字节
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void onAfterReceivedBytes(ChannelContext channelContext,int receivedBytes) throws Exception {
|
||||
|
||||
}
|
||||
/**
|
||||
* 处理一个消息包后
|
||||
* @param channelContext
|
||||
* @param packet
|
||||
* @param cost 本次处理消息耗时,单位:毫秒
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void onAfterHandled(ChannelContext channelContext, Packet packet,long cost) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user