Skip to content

Commit

Permalink
https://github.com/tywo45/t-io/issues/14
Browse files Browse the repository at this point in the history
  • Loading branch information
tywo45 committed Feb 20, 2019
1 parent 31e7dbf commit 2bead54
Showing 1 changed file with 3 additions and 69 deletions.
72 changes: 3 additions & 69 deletions src/core/src/main/java/org/tio/core/Tio.java
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,6 @@ public static <T> Page<T> getPageOfAll(GroupContext groupContext, Integer pageIn
* @author tanyaowu
*/
public static Page<ChannelContext> getPageOfConnecteds(ClientGroupContext clientGroupContext, Integer pageIndex, Integer pageSize) {
// SetWithLock<ChannelContext> setWithLock = Tio.getAllConnectedsChannelContexts(clientGroupContext);
// return PageUtils.fromSetWithLock(setWithLock, pageIndex, pageSize);
return getPageOfConnecteds(clientGroupContext, pageIndex, pageSize, null);
}

Expand Down Expand Up @@ -542,8 +540,6 @@ public static <T> Page<T> getPageOfConnecteds(ClientGroupContext clientGroupCont
* @author tanyaowu
*/
public static Page<ChannelContext> getPageOfGroup(GroupContext groupContext, String group, Integer pageIndex, Integer pageSize) {
// SetWithLock<ChannelContext> setWithLock = Tio.getChannelContextsByGroup(groupContext, group);
// return PageUtils.fromSetWithLock(setWithLock, pageIndex, pageSize);
return getPageOfGroup(groupContext, group, pageIndex, pageSize, null);
}

Expand Down Expand Up @@ -589,27 +585,6 @@ public static boolean isInGroup(String group, ChannelContext channelContext) {
return false;
}
return set.getObj().contains(group);
//
// MapWithLock<ChannelContext, SetWithLock<String>> mapWithLock =
// channelContext.groupContext.groups.getChannelmap();
// ReadLock lock = mapWithLock.readLock();
// lock.lock();
// try {
// Map<ChannelContext, SetWithLock<String>> m = mapWithLock.getObj();
// if (m == null || m.size() == 0) {
// return false;
// }
// SetWithLock<String> set = m.get(channelContext);
// if (set == null) {
// return false;
// }
// return set.getObj().contains(group);
// } catch (Throwable e) {
// log.error(e.toString(), e);
// return false;
// } finally {
// lock.unlock();
// }
}

/**
Expand Down Expand Up @@ -770,28 +745,25 @@ public static Boolean send(ChannelContext channelContext, Packet packet) {
*/
private static Boolean send(final ChannelContext channelContext, final Packet packet, CountDownLatch countDownLatch, PacketSendMode packetSendMode) {
try {
if (packet == null) {
if (packet == null || channelContext == null) {
if (countDownLatch != null) {
countDownLatch.countDown();
}
return false;
}

if (channelContext.isVirtual) {
if (countDownLatch != null) {
countDownLatch.countDown();
}
return true;
}

if (channelContext == null || channelContext.isClosed || channelContext.isRemoved) {
if (channelContext.isClosed || channelContext.isRemoved) {
if (countDownLatch != null) {
countDownLatch.countDown();
}
if (channelContext != null) {
// log.error("can't send data, {}, isClosed:{}, isRemoved:{}, stack:{} ", channelContext, channelContext.isClosed, channelContext.isRemoved,
// ThreadUtils.stackTrace());

log.info("can't send data, {}, isClosed:{}, isRemoved:{}", channelContext, channelContext.isClosed, channelContext.isRemoved);
}
return false;
Expand Down Expand Up @@ -825,10 +797,7 @@ private static Boolean send(final ChannelContext channelContext, final Packet pa
if (isSingleBlock) {
long timeout = 10;
try {
// channelContext.traceBlockPacket(SynPacketAction.BEFORE_WAIT, packet, countDownLatch, null);
Boolean awaitFlag = countDownLatch.await(timeout, TimeUnit.SECONDS);
// channelContext.traceBlockPacket(SynPacketAction.AFTER__WAIT, packet, countDownLatch, null);

if (!awaitFlag) {
log.error("{}, 阻塞发送超时, timeout:{}s, packet:{}", channelContext, timeout, packet.logstr());
}
Expand Down Expand Up @@ -1014,9 +983,6 @@ private static Boolean sendToGroup(GroupContext groupContext, String group, Pack
TioClusterConfig tioClusterConfig = groupContext.getTioClusterConfig();

if (tioClusterConfig.isCluster4group()) {
// TioClusterVo tioClusterVo = new TioClusterVo(packet);
// tioClusterVo.setGroup(group);
// tioClusterConfig.publish(tioClusterVo);
notifyClusterForGroup(groupContext, group, packet);
}
}
Expand Down Expand Up @@ -1107,10 +1073,6 @@ private static Boolean sendToIp(GroupContext groupContext, String ip, Packet pac
TioClusterConfig tioClusterConfig = groupContext.getTioClusterConfig();

if (tioClusterConfig.isCluster4ip()) {
// TioClusterVo tioClusterVo = new TioClusterVo(packet);
// tioClusterVo.setIp(ip);
// tioClusterConfig.publish(tioClusterVo);

notifyClusterForIp(groupContext, ip, packet);
}
}
Expand Down Expand Up @@ -1140,17 +1102,6 @@ public static void sendToSet(GroupContext groupContext, SetWithLock<ChannelConte
*/
private static Boolean sendToSet(GroupContext groupContext, SetWithLock<ChannelContext> setWithLock, Packet packet, ChannelContextFilter channelContextFilter,
boolean isBlock) {
// if (isBlock)
// {
// try
// {
// org.tio.core.GroupContext.SYN_SEND_SEMAPHORE.acquire();
// } catch (InterruptedException e)
// {
// log.error(e.toString(), e);
// }
// }

boolean releasedLock = false;
Lock lock = setWithLock.readLock();
lock.lock();
Expand All @@ -1160,10 +1111,6 @@ private static Boolean sendToSet(GroupContext groupContext, SetWithLock<ChannelC
log.debug("{}, 集合为空", groupContext.getName());
return false;
}
// if (!groupContext.isEncodeCareWithChannelContext()) {
// ByteBuffer byteBuffer = groupContext.getAioHandler().encode(packet, groupContext, null);
// packet.setPreEncodedByteBuffer(byteBuffer);
// }

CountDownLatch countDownLatch = null;
if (isBlock) {
Expand All @@ -1183,7 +1130,6 @@ private static Boolean sendToSet(GroupContext groupContext, SetWithLock<ChannelC

sendCount++;
if (isBlock) {
// channelContext.traceBlockPacket(SynPacketAction.BEFORE_WAIT, packet, countDownLatch, null);
send(channelContext, packet, countDownLatch, PacketSendMode.GROUP_BLOCK);
} else {
send(channelContext, packet, null, null);
Expand Down Expand Up @@ -1220,10 +1166,6 @@ private static Boolean sendToSet(GroupContext groupContext, SetWithLock<ChannelC
log.error(e.toString(), e);
return false;
} finally {
// if (isBlock)
// {
// org.tio.core.GroupContext.SYN_SEND_SEMAPHORE.release();
// }
if (!releasedLock) {
lock.unlock();
}
Expand Down Expand Up @@ -1286,10 +1228,6 @@ private static Boolean sendToToken(GroupContext groupContext, String token, Pack
TioClusterConfig tioClusterConfig = groupContext.getTioClusterConfig();

if (tioClusterConfig.isCluster4user()) {
// TioClusterVo tioClusterVo = new TioClusterVo(packet);
// tioClusterVo.setToken(token);
// tioClusterConfig.publish(tioClusterVo);

notifyClusterForToken(groupContext, token, packet);
}
}
Expand Down Expand Up @@ -1351,10 +1289,6 @@ private static Boolean sendToUser(GroupContext groupContext, String userid, Pack
TioClusterConfig tioClusterConfig = groupContext.getTioClusterConfig();

if (tioClusterConfig.isCluster4user()) {
// TioClusterVo tioClusterVo = new TioClusterVo(packet);
// tioClusterVo.setUserid(userid);
// tioClusterConfig.publish(tioClusterVo);

notifyClusterForUser(groupContext, userid, packet);
}
}
Expand Down

0 comments on commit 2bead54

Please sign in to comment.