Skip to content

Commit

Permalink
小优化
Browse files Browse the repository at this point in the history
  • Loading branch information
tywo45 committed Feb 1, 2019
1 parent b032bef commit f3c3ab3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/core/src/main/java/org/tio/core/ChannelContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public void setAttribute(Object value) {
/**
* @param remoteNode the remoteNode to set
*/
private void setClientNode(Node clientNode) {
public void setClientNode(Node clientNode) {
if (!this.groupContext.isShortConnection) {
if (this.clientNode != null) {
groupContext.clientNodes.remove(this);
Expand Down
34 changes: 17 additions & 17 deletions src/core/src/main/java/org/tio/core/Tio.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ public static Boolean bSendToGroup(GroupContext groupContext, String group, Pack

/**
* 发消息给指定ChannelContext id
* @param channelId
* @param channelContextId
* @param packet
* @author tanyaowu
*/
public static Boolean bSendToId(GroupContext groupContext, String channelId, Packet packet) {
return sendToId(groupContext, channelId, packet, true);
public static Boolean bSendToId(GroupContext groupContext, String channelContextId, Packet packet) {
return sendToId(groupContext, channelContextId, packet, true);
}

/**
Expand Down Expand Up @@ -438,12 +438,12 @@ public static ChannelContext getChannelContextByClientNode(GroupContext groupCon

/**
* 根据id获取ChannelContext
* @param channelId
* @param channelContextId
* @return
* @author tanyaowu
*/
public static ChannelContext getChannelContextById(GroupContext groupContext, String channelId) {
return groupContext.ids.find(groupContext, channelId);
public static ChannelContext getChannelContextById(GroupContext groupContext, String channelContextId) {
return groupContext.ids.find(groupContext, channelContextId);
}

/**
Expand Down Expand Up @@ -640,15 +640,15 @@ public static void notifyClusterForGroup(GroupContext groupContext, String group
}

/**
* 在集群环境下,把channelId消息通知到集群中的其它机器
* 在集群环境下,把channelContextId消息通知到集群中的其它机器
* @param groupContext
* @param channelId
* @param channelContextId
* @param packet
*/
public static void notifyClusterForId(GroupContext groupContext, String channelId, Packet packet) {
public static void notifyClusterForId(GroupContext groupContext, String channelContextId, Packet packet) {
TioClusterConfig tioClusterConfig = groupContext.getTioClusterConfig();
TioClusterVo tioClusterVo = new TioClusterVo(packet);
tioClusterVo.setChannelId(channelId);
tioClusterVo.setChannelId(channelContextId);
tioClusterConfig.publish(tioClusterVo);
}

Expand Down Expand Up @@ -1025,30 +1025,30 @@ private static Boolean sendToGroup(GroupContext groupContext, String group, Pack

/**
* 发消息给指定ChannelContext id
* @param channelId
* @param channelContextId
* @param packet
* @author tanyaowu
*/
public static Boolean sendToId(GroupContext groupContext, String channelId, Packet packet) {
return sendToId(groupContext, channelId, packet, false);
public static Boolean sendToId(GroupContext groupContext, String channelContextId, Packet packet) {
return sendToId(groupContext, channelContextId, packet, false);
}

/**
* 发消息给指定ChannelContext id
* @param channelId
* @param channelContextId
* @param packet
* @param isBlock
* @return
* @author tanyaowu
*/
private static Boolean sendToId(GroupContext groupContext, String channelId, Packet packet, boolean isBlock) {
ChannelContext channelContext = Tio.getChannelContextById(groupContext, channelId);
private static Boolean sendToId(GroupContext groupContext, String channelContextId, Packet packet, boolean isBlock) {
ChannelContext channelContext = Tio.getChannelContextById(groupContext, channelContextId);
if (channelContext == null) {
if (groupContext.isCluster() && !packet.isFromCluster()) {
TioClusterConfig tioClusterConfig = groupContext.getTioClusterConfig();

if (tioClusterConfig.isCluster4channelId()) {
notifyClusterForId(groupContext, channelId, packet);
notifyClusterForId(groupContext, channelContextId, packet);
}
}
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/core/src/main/java/org/tio/core/maintain/Groups.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ public void unbind(String groupid, ChannelContext channelContext, boolean delete
if (setWithLock != null) {
boolean ss = setWithLock.remove(channelContext);
if (!ss) {
log.error("{}, 移除失败", channelContext);
log.error("{}, 移除失败, cid:{}", channelContext, channelContext.getId());

}

if (deleteFromChannelContext) {
Expand Down
2 changes: 1 addition & 1 deletion src/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<commons-compress.version>1.18</commons-compress.version>
<fastjson.version>1.2.56</fastjson.version>
<testng.version>6.14.3</testng.version>
<hutool.version>4.4.3</hutool.version>
<hutool.version>4.4.4</hutool.version>
<protobuf-java.version>3.6.1</protobuf-java.version>
<commons-beanutils.version>1.9.3</commons-beanutils.version>
<protobuf-java-format.version>1.4</protobuf-java-format.version>
Expand Down

0 comments on commit f3c3ab3

Please sign in to comment.