public EndpointState getLocalState() { return connection.getLocalState(); }
@Override public void onConnectionUnbound(Event event) { final Connection connection = event.getConnection(); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info(String.format(Locale.US, "onConnectionUnbound: hostname[%s], state[%s], remoteState[%s]", connection.getHostname(), connection.getLocalState(), connection.getRemoteState())); } // if failure happened while establishing transport - nothing to free up. if (connection.getRemoteState() != EndpointState.UNINITIALIZED) connection.free(); }
@Override public long keepAlive() throws IOException { long rescheduleAt = 0l; LOG.trace("Performing connection:{} keep-alive processing", amqpTransport.getRemoteAddress()); if (protonConnection.getLocalState() != EndpointState.CLOSED) { // Using nano time since it is not related to the wall clock, which may change long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); long deadline = protonTransport.tick(now); pumpProtonToSocket(); if (protonTransport.isClosed()) { LOG.debug("Transport closed after inactivity check."); throw new InactivityIOException("Channel was inactive for too long"); } else { if(deadline != 0) { // caller treats 0 as no-work, ensure value is at least 1 as there was a deadline rescheduleAt = Math.max(deadline - now, 1); } } } LOG.trace("Connection:{} keep alive processing done, next update in {} milliseconds.", amqpTransport.getRemoteAddress(), rescheduleAt); return rescheduleAt; }
@Override public long tick(boolean firstTick) { if (!firstTick) { try { if (connection.getLocalState() != EndpointState.CLOSED) { long rescheduleAt = transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); if (transport.isClosed()) { throw new IllegalStateException("Channel was inactive for to long"); } return rescheduleAt; } } catch (Exception e) { transport.close(); connection.setCondition(new ErrorCondition()); } return 0; } return transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); }
@Override public long keepAlive() throws IOException { long rescheduleAt = 0l; LOG.trace("Performing connection:{} keep-alive processing", amqpTransport.getRemoteAddress()); if (protonConnection.getLocalState() != EndpointState.CLOSED) { // Using nano time since it is not related to the wall clock, which may change long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); long deadline = protonTransport.tick(now); pumpProtonToSocket(); if (protonTransport.isClosed()) { LOG.debug("Transport closed after inactivity check."); throw new InactivityIOException("Channel was inactive for too long"); } else { if(deadline != 0) { // caller treats 0 as no-work, ensure value is at least 1 as there was a deadline rescheduleAt = Math.max(deadline - now, 1); } } } LOG.trace("Connection:{} keep alive processing done, next update in {} milliseconds.", amqpTransport.getRemoteAddress(), rescheduleAt); return rescheduleAt; }
if (!firstTick) { try { if (connection.getLocalState() != EndpointState.CLOSED) { long rescheduleAt = transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); if (transport.isClosed()) {
public Long tick(boolean firstTick) { requireHandler(); if (!firstTick) { try { if (connection.getLocalState() != EndpointState.CLOSED) { long rescheduleAt = transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); if (transport.isClosed()) { throw new IllegalStateException("Channel was inactive for to long"); } return rescheduleAt; } } catch (Exception e) { log.warn(e.getMessage(), e); transport.close(); connection.setCondition(new ErrorCondition()); } finally { flush(); } return 0L; } return transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); }
if (currentConnection.getLocalState() != EndpointState.CLOSED)
@Override public void run() { try { if (getEndpoint().getLocalState() != EndpointState.CLOSED) { LOG.debug("Client performing next idle check"); // Using nano time since it is not related to the wall clock, which may change long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); long deadline = protonTransport.tick(now); pumpToProtonTransport(); if (protonTransport.isClosed()) { LOG.debug("Transport closed after inactivity check."); throw new InactivityIOException("Channel was inactive for too long"); } else { if (deadline != 0) { getScheduler().schedule(this, deadline - now, TimeUnit.MILLISECONDS); } } } } catch (Exception e) { try { transport.close(); } catch (IOException e1) { } fireClientException(e); } } }, initialKeepAliveDeadline - initialNow, TimeUnit.MILLISECONDS);
Connection getConnection() { if (this.connection == null || this.connection.getLocalState() == EndpointState.CLOSED || this.connection.getRemoteState() == EndpointState.CLOSED) { TRACE_LOGGER.info("Creating connection to host '{}:{}'", this.connectionHandler.getOutboundSocketHostName(), this.connectionHandler.getOutboundSocketPort()); this.connection = this.getReactor().connectionToHost( this.connectionHandler.getOutboundSocketHostName(), this.connectionHandler.getOutboundSocketPort(), this.connectionHandler); } return this.connection; }
@Override public void onConnectionRemoteClose(Event event) { final Connection connection = event.getConnection(); final ErrorCondition error = connection.getRemoteCondition(); TRACE_LOGGER.debug("onConnectionRemoteClose: hostname:{},errorCondition:{}", connection.getHostname(), error != null ? error.getCondition() + "," + error.getDescription() : null); boolean shouldFreeConnection = connection.getLocalState() == EndpointState.CLOSED; this.messagingFactory.onConnectionError(error); if(shouldFreeConnection) { connection.free(); } }
if (oldConnection.getLocalState() != EndpointState.CLOSED) { if (TRACE_LOGGER.isWarnEnabled()) { TRACE_LOGGER.warn(String.format(Locale.US, "onConnectionError: messagingFactory[%s], hostname[%s], closing current connection",
@Override public void handle(Long event) { boolean checkScheduled = false; if (connection.getLocalState() == EndpointState.ACTIVE) { // Using nano time since it is not related to the wall clock, which may change long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); long deadline = transport.tick(now); flush(); if (transport.isClosed()) { LOG.info("IdleTimeoutCheck closed the transport due to the peer exceeding our requested idle-timeout."); disconnect(); } else { if (deadline != 0) { // timer treats 0 as error, ensure value is at least 1 as there was a deadline long delay = Math.max(deadline - now, 1); checkScheduled = true; LOG.trace("IdleTimeoutCheck rescheduling with delay: {0}", delay); idleTimeoutCheckTimerId = vertx.setTimer(delay, this); } } } else { LOG.trace("IdleTimeoutCheck skipping check, connection is not active."); } if (!checkScheduled) { idleTimeoutCheckTimerId = null; LOG.trace("IdleTimeoutCheck exiting"); } } }
if (oldConnection.getLocalState() != EndpointState.CLOSED) { if (TRACE_LOGGER.isWarnEnabled()) { TRACE_LOGGER.warn(String.format(Locale.US, "onReactorError: messagingFactory[%s], hostname[%s], closing current connection",
@Override public Session getSession(final String path, final Consumer<Session> onRemoteSessionOpen, final BiConsumer<ErrorCondition, Exception> onRemoteSessionOpenError) { if (this.getIsClosingOrClosed()) { onRemoteSessionOpenError.accept(null, new OperationCancelledException("underlying messagingFactory instance is closed")); return null; } if (this.connection == null || this.connection.getLocalState() == EndpointState.CLOSED || this.connection.getRemoteState() == EndpointState.CLOSED) { this.connection = this.getReactor().connectionToHost( this.connectionHandler.getRemoteHostName(), this.connectionHandler.getRemotePort(), this.connectionHandler); } final Session session = this.connection.session(); BaseHandler.setHandler(session, new SessionHandler(path, onRemoteSessionOpen, onRemoteSessionOpenError, this.operationTimeout)); session.open(); return session; }
if (connection != null && connection.getRemoteState() != EndpointState.CLOSED && connection.getLocalState() != EndpointState.CLOSED) { connection.close();
if (protonConnection.getLocalState() == EndpointState.UNINITIALIZED && protonConnection.getRemoteState() != EndpointState.UNINITIALIZED) {
if (protonConnection.getLocalState() == EndpointState.UNINITIALIZED && protonConnection.getRemoteState() != EndpointState.UNINITIALIZED) {
if (connection.getLocalState() == EndpointState.UNINITIALIZED) if (connection.getLocalState() == EndpointState.ACTIVE)
if (event.getConnection().getLocalState() == EndpointState.CLOSED || engineConnection.openRequest == null) { if (!engineConnection.closed) { engineConnection.notifyInflightQos0(true);