users@grizzly.java.net

Re: Async Client

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Tue, 18 Feb 2014 14:10:40 -0800

Hi Paul,


> 1) Is this a legitimate way to build an async client. I want to
> offload the borrow from the connection pool to another thread.
>
> public void send(final BaseMessage message) {
> transport.getWorkerThreadPool().submit(new Runnable() {
> @Override
> public void run() {
> Connection connection = null;
> try {
> connection = pool.borrow();
> connection.write(message);
> } catch (Exception e) {
> throw new ClientException("Failed to send
> message.", e);
> } finally {
> if (connection != null) {
> pool.release(connection);
> }
> }
> }
> });
> }
If you're talking about Grizzly connection pool implementation (AFAIR we
don't have borrow method :)), it might be better to use
pool.take(CompletionHandler), which won't block if there's no available
connection in the pool.

> 2) When using SingleEndpointPool in what order should I close/shutdown
> the pool/transport?
it's probably better to shutdown pool and then transport, but it doesn't
really matter, either way should work.

WBR,
Alexey.