@Override public final Future<Void> release(Channel channel) { return release(channel, channel.eventLoop().<Void>newPromise()); }
private void notifyConnect(ChannelFuture future, Promise<Channel> promise) { if (future.isSuccess()) { Channel channel = future.channel(); if (!promise.trySuccess(channel)) { // Promise was completed in the meantime (like cancelled), just release the channel again release(channel); } } else { promise.tryFailure(future.cause()); } }
@Override public final Future<Void> release(Channel channel) { return release(channel, channel.eventLoop().<Void>newPromise()); }
private void notifyConnect(ChannelFuture future, Promise<Channel> promise) { if (future.isSuccess()) { Channel channel = future.channel(); if (!promise.trySuccess(channel)) { // Promise was completed in the meantime (like cancelled), just release the channel again release(channel); } } else { promise.tryFailure(future.cause()); } }
@Override public final Future<Void> release(Channel channel) { return release(channel, channel.eventLoop().<Void>newPromise()); }
private void notifyConnect(ChannelFuture future, Promise<Channel> promise) { if (future.isSuccess()) { Channel channel = future.channel(); if (!promise.trySuccess(channel)) { // Promise was completed in the meantime (like cancelled), just release the channel again release(channel); } } else { promise.tryFailure(future.cause()); } }
private void channelRelease() { for (Entry<String, List<Channel>> entry : channelMap.entrySet()) { for (Channel each : entry.getValue()) { CLIENT_MANAGER.getBackendNettyClient(logicSchema.getName()).getPoolMap().get(entry.getKey()).release(each); } } } }
private void channelRelease() { for (Entry<String, List<Channel>> entry : channelMap.entrySet()) { for (Channel each : entry.getValue()) { CLIENT_MANAGER.getBackendNettyClient(logicSchema.getName()).getPoolMap().get(entry.getKey()).release(each); } } } }
private void initPoolMap(final Bootstrap bootstrap) throws InterruptedException { poolMap = new AbstractChannelPoolMap<String, SimpleChannelPool>() { @Override protected SimpleChannelPool newPool(final String dataSourceName) { DataSourceMetaData dataSourceMetaData = logicSchema.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); return new FixedChannelPool( bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new BackendNettyClientChannelPoolHandler(dataSourceName, logicSchema.getName()), maxConnections); } }; for (String each : logicSchema.getDataSources().keySet()) { SimpleChannelPool pool = poolMap.get(each); Channel[] channels = new Channel[maxConnections]; for (int i = 0; i < maxConnections; i++) { try { channels[i] = pool.acquire().get(connectionTimeoutSeconds, TimeUnit.SECONDS); } catch (final ExecutionException | TimeoutException ex) { log.error(ex.getMessage(), ex); } } for (int i = 0; i < maxConnections; i++) { pool.release(channels[i]); } } } }
private void initPoolMap(final Bootstrap bootstrap) throws InterruptedException { poolMap = new AbstractChannelPoolMap<String, SimpleChannelPool>() { @Override protected SimpleChannelPool newPool(final String dataSourceName) { DataSourceMetaData dataSourceMetaData = logicSchema.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); return new FixedChannelPool( bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new BackendNettyClientChannelPoolHandler(dataSourceName, logicSchema.getName()), maxConnections); } }; for (String each : logicSchema.getDataSources().keySet()) { SimpleChannelPool pool = poolMap.get(each); Channel[] channels = new Channel[maxConnections]; for (int i = 0; i < maxConnections; i++) { try { channels[i] = pool.acquire().get(connectionTimeoutSeconds, TimeUnit.SECONDS); } catch (final ExecutionException | TimeoutException ex) { log.error(ex.getMessage(), ex); } } for (int i = 0; i < maxConnections; i++) { pool.release(channels[i]); } } } }
@Override public Future<Void> release(final Channel channel, final Promise<Void> promise) { ObjectUtil.checkNotNull(promise, "promise"); final Promise<Void> p = executor.newPromise(); super.release(channel, p.addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { assert executor.inEventLoop(); if (closed) { // Since the pool is closed, we have no choice but to close the channel channel.close(); promise.setFailure(POOL_CLOSED_ON_RELEASE_EXCEPTION); return; } if (future.isSuccess()) { decrementAndRunTaskQueue(); promise.setSuccess(null); } else { Throwable cause = future.cause(); // Check if the exception was not because of we passed the Channel to the wrong pool. if (!(cause instanceof IllegalArgumentException)) { decrementAndRunTaskQueue(); } promise.setFailure(future.cause()); } } })); return promise; }
@Override public Future<Void> release(final Channel channel, final Promise<Void> promise) { ObjectUtil.checkNotNull(promise, "promise"); final Promise<Void> p = executor.newPromise(); super.release(channel, p.addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { assert executor.inEventLoop(); if (closed) { // Since the pool is closed, we have no choice but to close the channel channel.close(); promise.setFailure(POOL_CLOSED_ON_RELEASE_EXCEPTION); return; } if (future.isSuccess()) { decrementAndRunTaskQueue(); promise.setSuccess(null); } else { Throwable cause = future.cause(); // Check if the exception was not because of we passed the Channel to the wrong pool. if (!(cause instanceof IllegalArgumentException)) { decrementAndRunTaskQueue(); } promise.setFailure(future.cause()); } } })); return promise; }
@Override public Future<Void> release(final Channel channel, final Promise<Void> promise) { ObjectUtil.checkNotNull(promise, "promise"); final Promise<Void> p = executor.newPromise(); super.release(channel, p.addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception { assert executor.inEventLoop(); if (closed) { // Since the pool is closed, we have no choice but to close the channel channel.close(); promise.setFailure(POOL_CLOSED_ON_RELEASE_EXCEPTION); return; } if (future.isSuccess()) { decrementAndRunTaskQueue(); promise.setSuccess(null); } else { Throwable cause = future.cause(); // Check if the exception was not because of we passed the Channel to the wrong pool. if (!(cause instanceof IllegalArgumentException)) { decrementAndRunTaskQueue(); } promise.setFailure(future.cause()); } } })); return promise; }
public Future<Void> release(Channel ch) { return simpleChannelPool.release(ch); } }
@Override public final Future<Void> release(Channel channel) { return release(channel, channel.eventLoop().<Void>newPromise()); }
@Override public final Future<Void> release(Channel channel) { return release(channel, channel.eventLoop().<Void>newPromise()); }
@Override public final Future<Void> release(Channel channel) { return release(channel, channel.eventLoop().<Void>newPromise()); }
private void notifyConnect(ChannelFuture future, Promise<Channel> promise) { if (future.isSuccess()) { Channel channel = future.channel(); if (!promise.trySuccess(channel)) { // Promise was completed in the meantime (like cancelled), just release the channel again release(channel); } } else { promise.tryFailure(future.cause()); } }
private void notifyConnect(ChannelFuture future, Promise<Channel> promise) { if (future.isSuccess()) { Channel channel = future.channel(); if (!promise.trySuccess(channel)) { // Promise was completed in the meantime (like cancelled), just release the channel again release(channel); } } else { promise.tryFailure(future.cause()); } }
private void notifyConnect(ChannelFuture future, Promise<Channel> promise) { if (future.isSuccess()) { Channel channel = future.channel(); if (!promise.trySuccess(channel)) { // Promise was completed in the meantime (like cancelled), just release the channel again release(channel); } } else { promise.tryFailure(future.cause()); } }