Refine search
private void internalHandlerError(Exception e) { log.warn(e.getMessage(), e); ErrorCondition error = new ErrorCondition(); error.setCondition(AmqpError.INTERNAL_ERROR); error.setDescription("Unrecoverable error: " + (e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage())); connection.setCondition(error); connection.close(); flush(); }
private void performConnectionOpen(Connection connection, InputStream in, OutputStream out) throws IOException, LoginException { connection.setHostname(saslHostname); connection.setContainer(container); connection.setDesiredCapabilities(new Symbol[] {CAPABILITY_ADDRESS_AUTHZ}); connection.open(); writeToNetwork(connection, out); readFromNetwork(connection, in, () -> connection.getRemoteState() == EndpointState.UNINITIALIZED); }
@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 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(); } } }
ProtonConnectionImpl(Vertx vertx, String hostname, ContextInternal connCtx) { this.vertx = vertx; this.connCtx = connCtx; this.connection.setContext(this); this.connection.setContainer("vert.x-" + UUID.randomUUID()); this.connection.setHostname(hostname); Map<Symbol, Object> props = createInitialPropertiesMap(); connection.setProperties(props); }
@Override public void onConnectionInit(Event event) { // Codes_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_011: [The event handler shall set the host name on the connection] Connection conn = event.getConnection(); conn.setHostname(hostName); // Every session or link could have their own handler(s) if we // wanted simply by adding the handler to the given session // or link // Codes_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_012: [The event handler shall create a Session (Proton) object from the connection] Session ssn = conn.session(); // If a link doesn't have an event handler, the events go to // its parent session. If the session doesn't have a handler // the events go to its parent connection. If the connection // doesn't have a handler, the events go to the reactor. // Codes_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_013: [The event handler shall create a Receiver (Proton) object and set the protocol tag on it to a predefined constant] // Codes_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_15_017: [The Receiver object shall have the properties set to service client version identifier.] Map<Symbol, Object> properties = new HashMap<>(); properties.put(Symbol.getSymbol(TransportUtils.versionIdentifierKey), TransportUtils.USER_AGENT_STRING); Receiver receiver = ssn.receiver(RECEIVE_TAG); receiver.setProperties(properties); // Codes_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_014: [The event handler shall open the Connection, the Session and the Receiver object] conn.open(); ssn.open(); receiver.open(); }
@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 } } }
this.connectionRequest = connectRequest; protonTransport.setEmitFlowEventOnSend(false); protonTransport.setMaxFrameSize(getMaxFrameSize()); protonTransport.setOutboundFrameSizeLimit(getMaxFrameSize()); protonTransport.setIdleTimeout(idleTimeout); protonTransport.bind(protonConnection); protonConnection.collect(protonCollector);
@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 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(); } }
private void processEventSessionRemoteState(Event event) { final String methodName = "processEventSessionRemoteState"; logger.entry(this, methodName, event); if (event.getSession().getRemoteState() == EndpointState.ACTIVE) { if (event.getSession().getLocalState() == EndpointState.ACTIVE) { final EngineConnection engineConnection = (EngineConnection) event.getConnection().getContext(); if (!engineConnection.closed) { // First session has opened on the connection OpenRequest req = engineConnection.openRequest; engineConnection.openRequest = null; engineConnection.requestor.tell(new OpenResponse(req, engineConnection), this); } } else { // The remote end is trying to establish a new session with us, which is not allowed. I don't think this is a usual case, // but could occur with a badly written remote end (i.e. sends an initial AMQP open immediately followed by a begin) final Connection protonConnection = event.getConnection(); protonConnection.setCondition(new ErrorCondition(Symbol.getSymbol("mqlight:session-remote-open-rejected"), "MQ Light client is unable to accept an open session request")); protonConnection.close(); } } logger.exit(this, methodName); }
@Override public void onConnectionInit(Event event) { final Connection connection = event.getConnection(); final String hostName = new StringBuilder(messagingFactory.getHostName()) .append(":") .append(String.valueOf(this.getProtocolPort())) .toString(); TRACE_LOGGER.debug("onConnectionInit: hostname:{}", hostName); connection.setHostname(hostName); connection.setContainer(StringUtil.getShortRandomString()); final Map<Symbol, Object> connectionProperties = new HashMap<Symbol, Object>(); connectionProperties.put(AmqpConstants.PRODUCT, ClientConstants.PRODUCT_NAME); connectionProperties.put(AmqpConstants.VERSION, ClientConstants.CURRENT_JAVACLIENT_VERSION); connectionProperties.put(AmqpConstants.PLATFORM, ClientConstants.PLATFORM_INFO); connection.setProperties(connectionProperties); connection.open(); }
@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 onRemoteOpen(Connection connection) throws Exception { handler.requireHandler(); try { initInternal(); } catch (Exception e) { log.error("Error init connection", e); } if (!validateConnection(connection)) { connection.close(); } else { connection.setContext(AMQPConnectionContext.this); connection.setContainer(containerId); connection.setProperties(connectionProperties); connection.setOfferedCapabilities(getConnectionCapabilitiesOffered()); connection.open(); } initialise(); /* * This can be null which is in effect an empty map, also we really don't need to check this for in bound connections * but its here in case we add support for outbound connections. * */ if (connection.getRemoteProperties() == null || !connection.getRemoteProperties().containsKey(CONNECTION_OPEN_FAILED)) { long nextKeepAliveTime = handler.tick(true); if (nextKeepAliveTime != 0 && scheduledPool != null) { scheduledPool.schedule(new ScheduleRunnable(), (nextKeepAliveTime - TimeUnit.NANOSECONDS.toMillis(System.nanoTime())), TimeUnit.MILLISECONDS); } } }
@Override public void onConnectionLocalOpen(Event event) { Connection connection = event.getConnection(); if (connection.getRemoteState() != EndpointState.UNINITIALIZED) { return; } Transport transport = Proton.transport(); transport.sasl(); transport.setEmitFlowEventOnSend(false); transport.bind(connection); }
private void handleOpen(Event event) { Connection connection = event.getConnection(); if (connection.getRemoteState() != EndpointState.UNINITIALIZED) { return; } Transport transport = Proton.transport(); Sasl sasl = transport.sasl(); sasl.client(); sasl.setMechanisms("ANONYMOUS"); transport.webSocket(); transport.bind(connection); }
public AmqpConnection(AmqpTransport transport, BrokerService brokerService) { this.amqpTransport = transport; AmqpInactivityMonitor monitor = transport.getInactivityMonitor(); if (monitor != null) { monitor.setAmqpTransport(amqpTransport); } this.amqpWireFormat = transport.getWireFormat(); this.brokerService = brokerService; // the configured maxFrameSize on the URI. int maxFrameSize = amqpWireFormat.getMaxAmqpFrameSize(); if (maxFrameSize > AmqpWireFormat.NO_AMQP_MAX_FRAME_SIZE) { this.protonTransport.setMaxFrameSize(maxFrameSize); try { this.protonTransport.setOutboundFrameSizeLimit(maxFrameSize); } catch (Throwable e) { // Ignore if older proton-j was injected. } } this.protonTransport.bind(this.protonConnection); this.protonTransport.setChannelMax(CHANNEL_MAX); this.protonTransport.setEmitFlowEventOnSend(false); this.protonConnection.collect(eventCollector); updateTracer(); }
@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; }
ProtonTransport(Connection connection, Vertx vertx, NetClient netClient, NetSocket socket, ProtonSaslAuthenticator authenticator, ProtonTransportOptions options) { this.connection = connection; this.vertx = vertx; this.netClient = netClient; this.socket = socket; int maxFrameSize = options.getMaxFrameSize() == 0 ? DEFAULT_MAX_FRAME_SIZE : options.getMaxFrameSize(); transport.setMaxFrameSize(maxFrameSize); transport.setOutboundFrameSizeLimit(maxFrameSize); transport.setEmitFlowEventOnSend(false); // TODO: make configurable transport.setIdleTimeout(2 * options.getHeartbeat()); ((TransportInternal) transport).setUseReadOnlyOutputBuffer(false); if (authenticator != null) { authenticator.init(this.socket, (ProtonConnection) this.connection.getContext(), transport); } this.authenticator = authenticator; transport.bind(connection); connection.collect(collector); socket.endHandler(this::handleSocketEnd); socket.handler(this::handleSocketBuffer); }