@Override public final void close() { for (K key: map.keySet()) { remove(key); } } }
@Override public final P get(K key) { P pool = map.get(checkNotNull(key, "key")); if (pool == null) { pool = newPool(key); P old = map.putIfAbsent(key, pool); if (old != null) { // We need to destroy the newly created pool as we not use it. pool.close(); pool = old; } } return pool; } /**
@Override public void shutdown() { try { if (null != clientChannelPool) { clientChannelPool.close(); } this.eventLoopGroupWorker.shutdownGracefully(); if (this.defaultEventExecutorGroup != null) { this.defaultEventExecutorGroup.shutdownGracefully(); } super.destroy(); } catch (Exception exx) { LOGGER.error("shutdown error:" + exx.getMessage()); } }
/** * Retrieve a {@link ChannelPool} instance using {@link AbstractMessage} as the search key. * * @param message * An {@link AbstractMessage} to be used to derive the actual key from * * @return A {@link ChannelPool} instance */ @Override public ChannelPool get(M message) { return internalPoolMap.get(keyResolver.apply(message)); }
@Override public Iterator<Map.Entry<K, ChannelPool>> iterator() { return internalPoolMap.iterator(); } }
@Override public boolean contains(M message) { return internalPoolMap.contains(keyResolver.apply(message)); }
@Override public void send(final RawData msg) { final ChannelPool channelPool = poolMap.get(new InetSocketAddress(msg.getAddress(), msg.getPort())); Future<Channel> acquire = channelPool.acquire(); acquire.addListener(new GenericFutureListener<Future<Channel>>() { @Override public void operationComplete(Future<Channel> future) throws Exception { if (future.isSuccess()) { Channel channel = future.getNow(); try { channel.writeAndFlush(Unpooled.wrappedBuffer(msg.getBytes())); } finally { channelPool.release(channel); } } else { LOGGER.log(Level.WARNING, "Unable to open connection to " + msg.getAddress(), future.cause()); } } }); }
@Override public final void close() { for (K key: map.keySet()) { remove(key); } } }
@Override public final P get(K key) { P pool = map.get(checkNotNull(key, "key")); if (pool == null) { pool = newPool(key); P old = map.putIfAbsent(key, pool); if (old != null) { // We need to destroy the newly created pool as we not use it. pool.close(); pool = old; } } return pool; } /**
@Override public void close() throws IOException { internalPoolMap.close(); }
@Override public final void close() { for (K key: map.keySet()) { remove(key); } } }
@Override public final P get(K key) { P pool = map.get(checkNotNull(key, "key")); if (pool == null) { pool = newPool(key); P old = map.putIfAbsent(key, pool); if (old != null) { // We need to destroy the newly created pool as we not use it. pool.close(); pool = old; } } return pool; } /**
@Override public synchronized void stop() { if (poolMap != null) { poolMap.close(); } if (null != workerGroup) { workerGroup.shutdownGracefully(0, 1, TimeUnit.SECONDS).syncUninterruptibly(); workerGroup = null; } }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { // TODO: This only works with fixed sized pool with connection one. Otherwise it's not save to remove and // close the pool as soon as a single channel is closed. poolMap.remove(key); } }
@Override public final P get(K key) { P pool = map.get(checkNotNull(key, "key")); if (pool == null) { pool = newPool(key); P old = map.putIfAbsent(key, pool); if (old != null) { // We need to destroy the newly created pool as we not use it. pool.close(); pool = old; } } return pool; } /**
@Override public void shutdown() { try { if (null != clientChannelPool) { clientChannelPool.close(); } this.eventLoopGroupWorker.shutdownGracefully(); if (this.defaultEventExecutorGroup != null) { this.defaultEventExecutorGroup.shutdownGracefully(); } super.destroy(); } catch (Exception exx) { LOGGER.error("shutdown error:" + exx.getMessage()); } }
@Override public final void close() { for (K key: map.keySet()) { remove(key); } } }
@Override public final P get(K key) { P pool = map.get(checkNotNull(key, "key")); if (pool == null) { pool = newPool(key); P old = map.putIfAbsent(key, pool); if (old != null) { // We need to destroy the newly created pool as we not use it. pool.close(); pool = old; } } return pool; } /**
@Override public final void close() { for (K key: map.keySet()) { remove(key); } } }
@Override public final P get(K key) { P pool = map.get(checkNotNull(key, "key")); if (pool == null) { pool = newPool(key); P old = map.putIfAbsent(key, pool); if (old != null) { // We need to destroy the newly created pool as we not use it. pool.close(); pool = old; } } return pool; } /**