@Override public String getHostname() { return connection.getHostname(); }
@Override public void onConnectionFinal(Event event) { TRACE_LOGGER.debug("onConnectionFinal: hostname:{}", event.getConnection().getHostname()); }
@Override public void onConnectionLocalOpen(Event event) { final Connection connection = event.getConnection(); final ErrorCondition error = connection.getCondition(); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info(String.format(Locale.US, "onConnectionLocalOpen: hostname[%s], errorCondition[%s], errorDescription[%s]", connection.getHostname(), error != null ? error.getCondition() : "n/a", error != null ? error.getDescription() : "n/a")); } }
@Override public void onConnectionFinal(Event event) { final Connection connection = event.getConnection(); final ErrorCondition error = connection.getCondition(); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info(String.format(Locale.US, "onConnectionFinal: hostname[%s], errorCondition[%s], errorDescription[%s]", connection.getHostname(), error != null ? error.getCondition() : "n/a", error != null ? error.getDescription() : "n/a")); } } }
@Override public void onConnectionRemoteOpen(Event event) { if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info(String.format(Locale.US, "onConnectionRemoteOpen: hostname[%s], remoteContainer[%s]", event.getConnection().getHostname(), event.getConnection().getRemoteContainer())); } this.amqpConnection.onOpenComplete(null); }
@Override public void onTransportClosed(Event event) { final Transport transport = event.getTransport(); final Connection connection = event.getConnection(); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info(String.format(Locale.US, "onTransportClosed hostname[%s]", (connection != null ? connection.getHostname() : "n/a"))); } if (transport != null && connection != null && connection.getTransport() != null) { transport.unbind(); } } }
@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 void onConnectionRemoteClose(Event event) { final Connection connection = event.getConnection(); final ErrorCondition error = connection.getRemoteCondition(); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info(String.format(Locale.US, "onConnectionRemoteClose: hostname[%s], errorCondition[%s], errorDescription[%s]", connection.getHostname(), error != null ? error.getCondition() : "n/a", error != null ? error.getDescription() : "n/a")); } this.amqpConnection.onConnectionError(error); }
@Override public void onConnectionRemoteOpen(Event event) { TRACE_LOGGER.debug("Connection.onConnectionRemoteOpen: hostname:{}, remotecontainer:{}", event.getConnection().getHostname(), event.getConnection().getRemoteContainer()); this.messagingFactory.onConnectionOpen(); }
@Override public void onTransportClosed(Event event) { final Connection connection = event.getConnection(); final Transport transport = event.getTransport(); final ErrorCondition condition = transport.getCondition(); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info(String.format(Locale.US, "onTransportClosed: hostname[%s], error[%s]", connection != null ? connection.getHostname() : "n/a", (condition != null ? condition.getDescription() : "n/a"))); } if (connection != null && connection.getRemoteState() != EndpointState.CLOSED) { // if the remote-peer abruptly closes the connection without issuing close frame // issue one this.amqpConnection.onConnectionError(condition); } }
@Override public void onConnectionBound(Event event) { TRACE_LOGGER.debug("onConnectionBound: hostname:{}", event.getConnection().getHostname()); Transport transport = event.getTransport(); this.addTransportLayers(event, (TransportInternal) transport); Sasl sasl = transport.sasl(); sasl.setMechanisms("ANONYMOUS"); }
@Override protected void addTransportLayers(final Event event, final TransportInternal transport) { final String hostName = event.getConnection().getHostname(); final WebSocketImpl webSocket = new WebSocketImpl(); webSocket.configure( hostName, "/$servicebus/websocket", "", 0, "AMQPWSB10", null, null); transport.addTransportLayer(webSocket); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info("addWebsocketHandshake: hostname[" + hostName +"]"); } super.addTransportLayers(event, transport); }
@Override public void addTransportLayers(final Event event, final TransportInternal transport) { final String hostName = event.getConnection().getHostname(); final WebSocketImpl webSocket = new WebSocketImpl(); webSocket.configure( hostName, "/$servicebus/websocket", "", 0, "AMQPWSB10", null, null); transport.addTransportLayer(webSocket); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info("addWebsocketHandshake: hostname[" + hostName +"]"); } super.addTransportLayers(event, transport); }
@Override public void onConnectionLocalClose(Event event) { final Connection connection = event.getConnection(); final ErrorCondition error = connection.getCondition(); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info(String.format(Locale.US, "onConnectionLocalClose: hostname[%s], errorCondition[%s], errorDescription[%s]", connection.getHostname(), error != null ? error.getCondition() : "n/a", error != null ? error.getDescription() : "n/a")); } if (connection.getRemoteState() == EndpointState.CLOSED) { // This means that the CLOSE origin is Service final Transport transport = connection.getTransport(); if (transport != null) { transport.unbind(); // we proactively dispose IO even if service fails to close } } }
@Override public void addTransportLayers(final Event event, final TransportInternal transport) { super.addTransportLayers(event, transport); final ProxyImpl proxy = new ProxyImpl(); final String hostName = event.getConnection().getHostname(); final ProxyHandler proxyHandler = new ProxyHandlerImpl(); final Map<String, String> proxyHeader = getAuthorizationHeader(); proxy.configure(hostName, proxyHeader, proxyHandler, transport); transport.addTransportLayer(proxy); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info("addProxyHandshake: hostname[" + hostName + "]"); } }
@Override public void onTransportError(Event event) { ErrorCondition condition = event.getTransport().getCondition(); if (condition != null) { TRACE_LOGGER.warn("Connection.onTransportError: hostname:{}, error:{}", event.getConnection().getHostname(), condition.getDescription()); } else { TRACE_LOGGER.warn("Connection.onTransportError: hostname:{}. error:{}", event.getConnection().getHostname(), "no description returned"); } this.messagingFactory.onConnectionError(condition); Connection connection = event.getConnection(); if(connection != null) { connection.free(); } this.notifyTransportErrors(event); }
@Override protected void addTransportLayers(final Event event, final TransportInternal transport) { super.addTransportLayers(event, transport); final ProxyImpl proxy = new ProxyImpl(); // host name used to create proxy connect request // after creating the socket to proxy final String hostName = event.getConnection().getHostname(); final ProxyHandler proxyHandler = new ProxyHandlerImpl(); final Map<String, String> proxyHeader = getAuthorizationHeader(); proxy.configure(hostName, proxyHeader, proxyHandler, transport); transport.addTransportLayer(proxy); if (TRACE_LOGGER.isInfoEnabled()) { TRACE_LOGGER.info("addProxyHandshake: hostname[" + hostName +"]"); } }
@Override public void onTransportError(Event event) { final Connection connection = event.getConnection(); final Transport transport = event.getTransport(); final ErrorCondition condition = transport.getCondition(); if (TRACE_LOGGER.isWarnEnabled()) { TRACE_LOGGER.warn(String.format(Locale.US, "onTransportError: hostname[%s], error[%s]", connection != null ? connection.getHostname() : "n/a", condition != null ? condition.getDescription() : "n/a")); } if (connection != null && connection.getRemoteState() != EndpointState.CLOSED) { // if the remote-peer abruptly closes the connection without issuing close frame // issue one this.amqpConnection.onConnectionError(condition); } // onTransportError event is not handled by the global IO Handler for cleanup transport.unbind(); this.notifyTransportErrors(event); }
@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(); } }
@Override public void onConnectionLocalClose(Event event) { Connection connection = event.getConnection(); TRACE_LOGGER.debug("onConnectionLocalClose: hostname:{}", connection.getHostname()); if(connection.getRemoteState() == EndpointState.CLOSED) { // Service closed it first. In some such cases transport is not unbound and causing a leak. if(connection.getTransport() != null) { connection.getTransport().unbind(); } connection.free(); } } }