@Override protected void doConnect() throws Throwable { connection = transport.connect(getConnectAddress()) .get(getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); }
@Override protected void doConnect() throws Throwable { connection = transport.connect(getConnectAddress()) .get(getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); }
@Override @SuppressWarnings("rawtypes") public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); int timeout = 0; try { GrizzlyFuture future = connection.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); future.get(timeout, TimeUnit.MILLISECONDS); } } catch (TimeoutException e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit", e); } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } }
@Override @SuppressWarnings("rawtypes") public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); int timeout = 0; try { GrizzlyFuture future = connection.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); future.get(timeout, TimeUnit.MILLISECONDS); } } catch (TimeoutException e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit", e); } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } }
void shutdown() { try { httpServer.shutdown(2, TimeUnit.SECONDS).get(); } catch (Exception e) { logger.info("An error occurred, trying to shutdown REST HTTP server", e); } }
@Override protected void shutDown() throws Exception { httpServer.shutdown().get(); }
@Override public void close() { if (isClosed.compareAndSet(false, true)) { try { serverConnection.close().get(); } catch (final InterruptedException e) { // Cannot handle here. Thread.currentThread().interrupt(); } catch (final Exception e) { DEBUG_LOG.log(Level.WARNING, "Exception occurred while closing listener", e); } transport.release(); } }
/** * Gracefully stop REST service. */ @Override protected void shutDown() throws Exception { long traceId = LoggerHelpers.traceEnterWithContext(log, this.objectId, "shutDown"); try { log.info("Stopping REST server listening on port: {}", this.restServerConfig.getPort()); final GrizzlyFuture<HttpServer> shutdown = httpServer.shutdown(30, TimeUnit.SECONDS); log.info("Awaiting termination of REST server"); shutdown.get(); log.info("REST server terminated"); } finally { LoggerHelpers.traceLeave(log, this.objectId, "shutDown", traceId); } } }
@Override protected void doConnect() throws Throwable { connection = transport.connect(getConnectAddress()) .get(getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); }
@Override protected void doConnect() throws Throwable { connection = transport.connect(getConnectAddress()) .get(getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); }
@Override protected void doConnect() throws Throwable { connection = transport.connect(getConnectAddress()) .get(getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); }
@Override protected void doConnect() throws Throwable { connection = transport.connect(getConnectAddress()) .get(getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); }
@Override protected void doConnect() throws Throwable { connection = transport.connect(getConnectAddress()) .get(getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); }
@Override protected void doConnect() throws Throwable { connection = transport.connect(getConnectAddress()) .get(getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS); }
@Override @SuppressWarnings("rawtypes") public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); int timeout = 0; try { GrizzlyFuture future = connection.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); future.get(timeout, TimeUnit.MILLISECONDS); } } catch (TimeoutException e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit", e); } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } }
@Override @SuppressWarnings("rawtypes") public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); int timeout = 0; try { GrizzlyFuture future = connection.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); future.get(timeout, TimeUnit.MILLISECONDS); } } catch (TimeoutException e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit", e); } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } }
@Override @SuppressWarnings("rawtypes") public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); int timeout = 0; try { GrizzlyFuture future = connection.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); future.get(timeout, TimeUnit.MILLISECONDS); } } catch (TimeoutException e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit", e); } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } }
@SuppressWarnings("rawtypes") public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); int timeout = 0; try { GrizzlyFuture future = connection.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); future.get(timeout, TimeUnit.MILLISECONDS); } } catch (TimeoutException e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit", e); } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } }
@Override @SuppressWarnings("rawtypes") public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); int timeout = 0; try { GrizzlyFuture future = connection.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); future.get(timeout, TimeUnit.MILLISECONDS); } } catch (TimeoutException e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit", e); } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } }
@Test public void testLocalAddress() throws Exception { InetSocketAddress localAddress = new InetSocketAddress("localhost", 60000); final SingleEndpointPool<SocketAddress> pool = SingleEndpointPool .builder(SocketAddress.class) .connectorHandler(transport) .endpointAddress(new InetSocketAddress("localhost", PORT)) .localEndpointAddress(localAddress) .build(); try { Connection c1 = pool.take().get(); assertEquals(localAddress, c1.getLocalAddress()); } finally { pool.close(); } }