Skip to content

Commit

Permalink
Speed up ChannelPool offering
Browse files Browse the repository at this point in the history
  • Loading branch information
slandelle committed Jan 4, 2016
1 parent 3d5a253 commit e7798c8
Showing 1 changed file with 20 additions and 5 deletions.
Expand Up @@ -243,13 +243,28 @@ public boolean offer(Channel channel, Object partitionKey) {
if (isTtlExpired(channel, now)) if (isTtlExpired(channel, now))
return false; return false;


boolean added = partitions.computeIfAbsent(partitionKey, pk -> new ConcurrentLinkedQueue<>()).add(new IdleChannel(channel, now)); boolean offered = offer0(channel, partitionKey,now);
if (added) if (offered) {
channelId2Creation.putIfAbsent(channelId(channel), new ChannelCreation(now, partitionKey)); registerChannelCreation(channel, partitionKey, now);
}


return added; return offered;
} }


private boolean offer0(Channel channel, Object partitionKey, long now) {
ConcurrentLinkedQueue<IdleChannel> partition = partitions.get(partitionKey);
if (partition == null) {
partition = partitions.computeIfAbsent(partitionKey, pk -> new ConcurrentLinkedQueue<>());
}
return partition.add(new IdleChannel(channel, now));
}

private void registerChannelCreation(Channel channel, Object partitionKey, long now) {
if (channelId2Creation.containsKey(partitionKey)) {
channelId2Creation.putIfAbsent(channelId(channel), new ChannelCreation(now, partitionKey));
}
}

/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
Expand Down

0 comments on commit e7798c8

Please sign in to comment.