Refine search
private Handler eventHandler(Event event) { Handler result; if (event.getLink() != null) { result = BaseHandler.getHandler(event.getLink()); if (result != null) return result; } if (event.getSession() != null) { result = BaseHandler.getHandler(event.getSession()); if (result != null) return result; } if (event.getConnection() != null) { result = BaseHandler.getHandler(event.getConnection()); if (result != null) return result; } if (event.getTask() != null) { result = BaseHandler.getHandler(event.getTask()); if (result != null) return result; } if (event.getSelectable() != null) { result = BaseHandler.getHandler(event.getSelectable()); if (result != null) return result; } return handler; }
@Override public void onUnhandled(Event event) { int window = this.window; Link link = event.getLink(); switch(event.getType()) { case LINK_LOCAL_OPEN: case LINK_REMOTE_OPEN: case LINK_FLOW: case DELIVERY: if (link instanceof Receiver) { this.drained += link.drained(); if (this.drained == 0) { topup((Receiver)link, window); } } break; default: break; } } }
@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(); } } }
Map<Map<Integer, Venue>,String> uniqueMap = new HashMap<>(); for (Event event: events) { // assuming events is ArrayList Map<Integer, Venue> sessionVenueMap = new HashMap<>(); sessionVenueMap.put(event.getSession(), event.getVenue()); //check if we stored this pair in our cool map if (uniqueMap.get(sessionVenueMap) == null) { //if not //store this in our uniqieMap in our method uniqueMap.put(sessionVenueMap, event.getAct); sessionVenueMap.put(event.getSession(), event.getVenue); } else { // if map has this pair // then it is not unique return false; } venueSessionMap.put(.getVenue(); event.getSession(); } return true;
public static void dispatch(Event event, EventHandler handler) throws Exception { switch (event.getType()) { case CONNECTION_INIT: handler.onInit(event.getConnection()); break; case CONNECTION_LOCAL_OPEN: handler.onLocalOpen(event.getConnection()); break; case CONNECTION_REMOTE_OPEN: handler.onRemoteOpen(event.getConnection()); break; case CONNECTION_LOCAL_CLOSE: handler.onLocalClose(event.getConnection()); break; case CONNECTION_REMOTE_CLOSE: handler.onRemoteClose(event.getConnection()); break; case CONNECTION_FINAL: handler.onFinal(event.getConnection()); break; case SESSION_INIT: handler.onInit(event.getSession()); break; case SESSION_LOCAL_OPEN: handler.onLocalOpen(event.getSession()); break; case SESSION_REMOTE_OPEN: handler.onRemoteOpen(event.getSession()); break; case SESSION_LOCAL_CLOSE:
Event protonEvent = null; while ((protonEvent = protonCollector.peek()) != null) { if (!protonEvent.getType().equals(Type.TRANSPORT)) { LOG.trace("Client: New Proton Event: {}", protonEvent.getType()); switch (protonEvent.getType()) { case CONNECTION_REMOTE_CLOSE: amqpEventSink = (AmqpEventSink) protonEvent.getConnection().getContext(); amqpEventSink.processRemoteClose(this); break; case CONNECTION_REMOTE_OPEN: amqpEventSink = (AmqpEventSink) protonEvent.getConnection().getContext(); amqpEventSink.processRemoteOpen(this); break; case SESSION_REMOTE_CLOSE: amqpEventSink = (AmqpEventSink) protonEvent.getSession().getContext(); amqpEventSink.processRemoteClose(this); break; case SESSION_REMOTE_OPEN: amqpEventSink = (AmqpEventSink) protonEvent.getSession().getContext(); amqpEventSink.processRemoteOpen(this); break; case LINK_REMOTE_CLOSE: amqpEventSink = (AmqpEventSink) protonEvent.getLink().getContext(); amqpEventSink.processRemoteClose(this); break; case LINK_REMOTE_DETACH: amqpEventSink = (AmqpEventSink) protonEvent.getLink().getContext(); amqpEventSink.processRemoteDetach(this);
/** * Event handler for the delivery event. This method handles both sending and receiving a message. * @param event The Proton Event object. */ @Override public void onDelivery(Event event) { logger.LogDebug("Entered in method %s", logger.getMethodName()); AmqpMessage message = amqpDeviceOperations.receiverMessageFromLink(event.getLink().getName()); if (message == null) { //Sender specific section for dispositions it receives if (event.getType() == Event.Type.DELIVERY) { // Codes_SRS_AMQPSIOTHUBCONNECTION_15_038: [If this link is the Sender link and the event type is DELIVERY, the event handler shall get the Delivery (Proton) object from the event.] Delivery d = event.getDelivery(); DeliveryState remoteState = d.getRemoteState(); // Codes_SRS_AMQPSIOTHUBCONNECTION_15_039: [The event handler shall note the remote delivery state and use it and the Delivery (Proton) hash code to inform the AmqpsIotHubConnection of the message receipt.] boolean state = remoteState.equals(Accepted.getInstance()); //let any listener know that the message was received by the server // release the delivery object which created in sendMessage(). d.free(); } } else { msgListener.messageReceived(message); } logger.LogDebug("Exited from method %s", logger.getMethodName()); }
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 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 onLinkRemoteClose(Event event) { close(event.getLink()); } }
@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(); } } }
@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 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(); } }
logger.entry(this, methodName, event); EngineConnection engineConnection = (EngineConnection)event.getConnection().getContext(); Delivery delivery = event.getDelivery(); if (event.getLink() instanceof Sender) { SendRequest sr = engineConnection.inProgressOutboundDeliveries.remove(delivery); Exception exception = null; event.getLink().close(); event.getLink().free(); Receiver receiver = (Receiver)event.getLink(); int amount = delivery.pending(); byte[] data = new byte[amount]; receiver.advance(); EngineConnection.SubscriptionData subData = engineConnection.subscriptionData.get(event.getLink().getName()); subData.unsettled++; QOS qos = delivery.remotelySettled() ? QOS.AT_MOST_ONCE : QOS.AT_LEAST_ONCE; subData.subscriber.tell(new DeliveryRequest(data, qos, event.getLink().getName(), delivery, event.getConnection()), this);
@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 onDelivery(Event event) { //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_023: [ The event handler shall get the Delivery from the event only if the event type is DELIVERY **]** if(event.getType() == Event.Type.DELIVERY) { // Codes_SRS_AMQPSIOTHUBCONNECTION_15_038: [If this link is the Sender link and the event type is DELIVERY, the event handler shall get the Delivery (Proton) object from the event.] Delivery d = event.getDelivery(); //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_024: [ The event handler shall get the Delivery remote state from the delivery **]** DeliveryState remoteState = d.getRemoteState(); //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_025: [ The event handler shall verify the Amqp response and add the response to a queue. **]** sendStatusQueue.add(new AmqpResponseVerification(remoteState)); //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_026: [ The event handler shall settle the delivery. **]** d.settle(); //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_027: [ The event handler shall get the Sender (Proton) object from the event **]** Sender snd = event.getSender(); //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_028: [ The event handler shall close the Sender, Session and Connection **]** snd.close(); snd.getSession().close(); snd.getSession().getConnection().close(); isConnected = false; } }
@Override public void onUnhandled(Event event) { try { ReactorImpl reactor = (ReactorImpl)event.getReactor(); Selector selector = reactor.getSelector(); if (selector == null) { switch(event.getType()) { case SELECTABLE_INIT: selectable = event.getSelectable(); selector.add(selectable); break; case SELECTABLE_UPDATED: selectable = event.getSelectable(); selector.update(selectable); break; case SELECTABLE_FINAL: selectable = event.getSelectable(); selector.remove(selectable); selectable.release(); break; case TRANSPORT_CLOSED: event.getTransport().unbind(); break; case REACTOR_QUIESCED:
@Override protected void notifyTransportErrors(final Event event) { final Transport transport = event.getTransport(); final Connection connection = event.getConnection(); if (connection == null || transport == null) { return; final String hostName = event.getReactor().getConnectionAddress(connection); final ProxySelector proxySelector = ProxySelector.getDefault();
@Override public void onSessionRemoteOpen(Event event) { open(event.getSession()); }
@Override public void onConnectionRemoteOpen(Event event) { TRACE_LOGGER.debug("Connection.onConnectionRemoteOpen: hostname:{}, remotecontainer:{}", event.getConnection().getHostname(), event.getConnection().getRemoteContainer()); this.messagingFactory.onConnectionOpen(); }