Java Code Examples for org.apache.qpid.proton.engine.Event#getConnection()
The following examples show how to use
org.apache.qpid.proton.engine.Event#getConnection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Send.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void onConnectionInit(Event event) { Connection conn = event.getConnection(); // Every session or link could have their own handler(s) if we // wanted simply by adding the handler to the given session // or link 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. Sender snd = ssn.sender("sender"); conn.open(); ssn.open(); snd.open(); }
Example 2
Source File: Handshaker.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onConnectionRemoteOpen(Event evt) { Connection conn = evt.getConnection(); if (conn.getLocalState() == EndpointState.UNINITIALIZED) { conn.open(); } }
Example 3
Source File: Handshaker.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onConnectionRemoteClose(Event evt) { Connection conn = evt.getConnection(); if (conn.getLocalState() != EndpointState.CLOSED) { conn.close(); } }
Example 4
Source File: Driver.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onConnectionLocalOpen(Event evt) { Connection conn = evt.getConnection(); if (conn.getRemoteState() == EndpointState.UNINITIALIZED) { // Give the connection a [random] container-id conn.setContainer(UUID.randomUUID().toString()); try { new Connector(conn); } catch (IOException e) { throw new RuntimeException(e); } } }
Example 5
Source File: IOHandler.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void handleOpen(Reactor reactor, Event event) { Connection connection = event.getConnection(); if (connection.getRemoteState() != EndpointState.UNINITIALIZED) { return; } // Outgoing Reactor connections set the virtual host automatically using the // following rules: String vhost = connection.getHostname(); if (vhost == null) { // setHostname never called, use the host from the connection's // socket address as the default virtual host: String conAddr = reactor.getConnectionAddress(connection); if (conAddr != null) { Address addr = new Address(conAddr); connection.setHostname(addr.getHost()); } } else if (vhost.isEmpty()) { // setHostname called explictly with a null string. This allows // the application to completely avoid sending a virtual host // name connection.setHostname(null); } else { // setHostname set by application - use it. } Transport transport = Proton.transport(); int maxFrameSizeOption = reactor.getOptions().getMaxFrameSize(); if (maxFrameSizeOption != 0) { transport.setMaxFrameSize(maxFrameSizeOption); } if (reactor.getOptions().isEnableSaslByDefault()) { Sasl sasl = transport.sasl(); sasl.client(); sasl.setMechanisms("ANONYMOUS"); } transport.bind(connection); }
Example 6
Source File: ReactorImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
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; }
Example 7
Source File: ReactorTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onConnectionInit(Event event) { Connection conn = event.getConnection(); Session ssn = conn.session(); Sender snd = ssn.sender("sender"); conn.open(); ssn.open(); snd.open(); }
Example 8
Source File: ReactorTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void connectionRefused() throws IOException { final ServerSocket serverSocket = new ServerSocket(0, 0); class ConnectionHandler extends TestHandler { @Override public void onConnectionInit(Event event) { super.onConnectionInit(event); Connection connection = event.getConnection(); connection.open(); try { serverSocket.close(); } catch(IOException e) { AssertionFailedError afe = new AssertionFailedError(); afe.initCause(e); throw afe; } } } TestHandler connectionHandler = new ConnectionHandler(); reactor.connectionToHost("127.0.0.1", serverSocket.getLocalPort(), connectionHandler); reactor.run(); reactor.free(); serverSocket.close(); connectionHandler.assertEvents(Type.CONNECTION_INIT, Type.CONNECTION_LOCAL_OPEN, Type.CONNECTION_BOUND, Type.TRANSPORT_ERROR, Type.TRANSPORT_TAIL_CLOSED, Type.TRANSPORT_HEAD_CLOSED, Type.TRANSPORT_CLOSED, Type.CONNECTION_UNBOUND, Type.TRANSPORT); }