org.apache.qpid.proton.engine.Connection Java Examples
The following examples show how to use
org.apache.qpid.proton.engine.Connection.
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: EventImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public Connection getConnection() { if (context instanceof Connection) { return (Connection) context; } else if (context instanceof Transport) { Transport transport = getTransport(); if (transport == null) { return null; } return ((TransportImpl) transport).getConnectionImpl(); } else { Session ssn = getSession(); if (ssn == null) { return null; } return ssn.getConnection(); } }
Example #2
Source File: NettySimpleAmqpServer.java From qpid-jms with Apache License 2.0 | 6 votes |
protected void processConnectionOpen(Connection connection) throws Exception { ErrorCondition failure = null; protonConnection.setContext(this); protonConnection.setOfferedCapabilities(getConnectionCapabilitiesOffered()); protonConnection.setProperties(getConnetionProperties()); protonConnection.setContainer("Netty-Server"); protonConnection.open(); if (connectionIntercepter != null) { failure = connectionIntercepter.apply(connection); } if (failure == null) { failure = handleConnectionRegistration(connection); } if (failure != null) { protonConnection.setProperties(getFailedConnetionProperties()); protonConnection.setCondition(failure); protonConnection.close(); } }
Example #3
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testOpenSessionBeforeOpenConnection() { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); transport.bind(connection); Session session = connection.session(); session.open(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 0, transport.writes.size()); connection.open(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size()); assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open); assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin); }
Example #4
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testOutputTooBigToBeWrittenInOneGo() { int smallMaxFrameSize = 512; _transport = new TransportImpl(smallMaxFrameSize); Connection conn = new ConnectionImpl(); _transport.bind(conn); // Open frame sized in order to produce a frame that will almost fill output buffer conn.setHostname(stringOfLength("x", 500)); conn.open(); // Close the connection to generate a Close frame which will cause an overflow // internally - we'll get the remaining bytes on the next interaction. conn.close(); ByteBuffer buf = _transport.getOutputBuffer(); assertEquals("Expecting buffer to be full", smallMaxFrameSize, buf.remaining()); buf.position(buf.limit()); _transport.outputConsumed(); buf = _transport.getOutputBuffer(); assertTrue("Expecting second buffer to have bytes", buf.remaining() > 0); assertTrue("Expecting second buffer to not be full", buf.remaining() < Transport.MIN_MAX_FRAME_SIZE); }
Example #5
Source File: EventImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testGetTransportWithDeliveryContext() { Transport transport = Transport.Factory.create(); Connection connection = Connection.Factory.create(); transport.bind(connection); Session session = connection.session(); Sender sender = session.sender("mySender"); Delivery delivery = sender.delivery("tag".getBytes()); EventImpl event = createEvent(delivery, Event.Type.DELIVERY); assertNotNull("No transport returned", event.getTransport()); assertSame("Incorrect transport returned", transport, event.getTransport()); }
Example #6
Source File: SimpleTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void test() { Connection connection1 = Proton.connection(); Connection connection2 = Proton.connection();; Transport transport1 = Proton.transport(); transport1.bind(connection1); Transport transport2 = Proton.transport(); transport2.bind(connection2); assertEquals(EndpointState.UNINITIALIZED, connection1.getLocalState()); assertEquals(EndpointState.UNINITIALIZED, connection1.getRemoteState()); connection1.open(); connection2.open(); }
Example #7
Source File: ProtonTransport.java From vertx-proton with Apache License 2.0 | 6 votes |
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); }
Example #8
Source File: EventImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public Reactor getReactor() { if (context instanceof Reactor) { return (Reactor) context; } else if (context instanceof Task) { return ((Task)context).getReactor(); } else if (context instanceof Transport) { return ((TransportImpl)context).getReactor(); } else if (context instanceof Delivery) { return ((Delivery)context).getLink().getSession().getConnection().getReactor(); } else if (context instanceof Link) { return ((Link)context).getSession().getConnection().getReactor(); } else if (context instanceof Session) { return ((Session)context).getConnection().getReactor(); } else if (context instanceof Connection) { return ((Connection)context).getReactor(); } else if (context instanceof Selectable) { return ((Selectable)context).getReactor(); } return null; }
Example #9
Source File: EventImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public Transport getTransport() { if (context instanceof Transport) { return (Transport) context; } else if (context instanceof Connection) { return ((Connection)context).getTransport(); } else { Session session = getSession(); if (session == null) { return null; } Connection connection = session.getConnection(); if (connection == null) { return null; } return connection.getTransport(); } }
Example #10
Source File: TransportImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void bind(Connection conn) { // TODO - check if already bound _connectionEndpoint = (ConnectionImpl) conn; put(Event.Type.CONNECTION_BOUND, conn); _connectionEndpoint.setTransport(this); _connectionEndpoint.incref(); if(getRemoteState() != EndpointState.UNINITIALIZED) { _connectionEndpoint.handleOpen(_open); if(getRemoteState() == EndpointState.CLOSED) { _connectionEndpoint.setRemoteState(EndpointState.CLOSED); } _frameParser.flush(); } }
Example #11
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 #12
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void testProtocolTracingLogsFrameToSystem() { Connection connection = new ConnectionImpl(); TransportImpl spy = spy(_transport); assertTrue(spy.isHandlingFrames()); spy.bind(connection); assertTrue(spy.isHandlingFrames()); spy.handleFrame(TRANSPORT_FRAME_OPEN); assertTrue(spy.isHandlingFrames()); ArgumentCaptor<TransportFrame> frameCatcher = ArgumentCaptor.forClass(TransportFrame.class); Mockito.verify(spy).log(eq(TransportImpl.INCOMING), frameCatcher.capture()); assertEquals(TRANSPORT_FRAME_OPEN.getChannel(), frameCatcher.getValue().getChannel()); assertTrue(frameCatcher.getValue().getBody() instanceof Open); assertNull(frameCatcher.getValue().getPayload()); }
Example #13
Source File: NettySimpleAmqpServer.java From qpid-jms with Apache License 2.0 | 6 votes |
private synchronized boolean registerNewConnection(Connection connection, boolean exclusiveContainerId) { String containerId = connection.getContainer(); List<Connection> connectionList = this.connections.get(containerId); if (connectionList == null) { connectionList = new LinkedList<Connection>(); connections.put(containerId, connectionList); } if (exclusiveContainerId && !connectionList.isEmpty()) { return false; } else { Connection head = connectionList.isEmpty() ? null : connectionList.get(0); if (head != null) { ProtonConnection protonConnection = (ProtonConnection)head.getContext(); if (protonConnection.isExclusiveContainerId()) { return false; } } connectionList.add(connection); return true; } }
Example #14
Source File: Driver.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private static Transport makeTransport(Connection conn) { Transport transport = Transport.Factory.create(); Sasl sasl = transport.sasl(); sasl.setMechanisms("ANONYMOUS"); sasl.client(); transport.bind(conn); return transport; }
Example #15
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); }
Example #16
Source File: NettySimpleAmqpServer.java From qpid-jms with Apache License 2.0 | 5 votes |
private synchronized void unregisterConnection(Connection connection) { String containerId = connection.getContainer(); List<Connection> connectionList = this.connections.get(containerId); if (connectionList != null) { Iterator<Connection> iterator = connectionList.iterator(); while (iterator.hasNext()) { Connection registeredConnection = iterator.next(); if (registeredConnection.equals(connection)) { iterator.remove(); return; } } } }
Example #17
Source File: Driver.java From qpid-proton-j with Apache License 2.0 | 5 votes |
public void selected() throws IOException { SocketChannel sock = socket.accept(); System.out.println("ACCEPTED: " + sock); Connection conn = Connection.Factory.create(); conn.collect(collector); Transport transport = Transport.Factory.create(); Sasl sasl = transport.sasl(); sasl.setMechanisms("ANONYMOUS"); sasl.server(); sasl.done(Sasl.PN_SASL_OK); transport.bind(conn); new ChannelHandler(sock, SelectionKey.OP_READ, transport); }
Example #18
Source File: AmqpConnection.java From activemq-artemis with Apache License 2.0 | 5 votes |
public AmqpConnection(NettyTransport transport, String username, String password) { setEndpoint(Connection.Factory.create()); getEndpoint().collect(protonCollector); this.transport = transport; this.username = username; this.password = password; this.connectionId = CONNECTION_ID_GENERATOR.generateId(); this.remoteURI = transport.getRemoteLocation(); this.serializer = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { @Override public Thread newThread(Runnable runner) { Thread serial = new Thread(runner); serial.setDaemon(true); serial.setName(toString()); return serial; } }); // Ensure timely shutdown this.serializer.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); this.serializer.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); this.transport.setTransportListener(this); this.transport.setMaxFrameSize(getMaxFrameSize()); }
Example #19
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 #20
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 #21
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testTickRemoteTimeout() { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); transport.bind(connection); int timeout = 4000; Open open = new Open(); open.setIdleTimeOut(new UnsignedInteger(4000)); TransportFrame openFrame = new TransportFrame(CHANNEL_ID, open, null); transport.handleFrame(openFrame); pumpMockTransport(transport); long deadline = transport.tick(0); assertEquals("Expected to be returned a deadline of 2000", 2000, deadline); // deadline = 4000 / 2 deadline = transport.tick(1000); // Wait for less than the deadline with no data - get the same value assertEquals("When the deadline hasn't been reached tick() should return the previous deadline", 2000, deadline); assertEquals("When the deadline hasn't been reached tick() shouldn't write data", 0, transport.writes.size()); deadline = transport.tick(timeout/2); // Wait for the deadline - next deadline should be (4000/2)*2 assertEquals("When the deadline has been reached expected a new deadline to be returned 4000", 4000, deadline); assertEquals("tick() should have written data", 1, transport.writes.size()); assertEquals("tick() should have written an empty frame", null, transport.writes.get(0)); transport.writeFrame(CHANNEL_ID, new Begin(), null, null); while(transport.pending() > 0) transport.pop(transport.head().remaining()); int framesWrittenBeforeTick = transport.writes.size(); deadline = transport.tick(3000); assertEquals("Writing data resets the deadline", 5000, deadline); assertEquals("When the deadline is reset tick() shouldn't write an empty frame", 0, transport.writes.size() - framesWrittenBeforeTick); transport.writeFrame(CHANNEL_ID, new Attach(), null, null); assertTrue(transport.pending() > 0); framesWrittenBeforeTick = transport.writes.size(); deadline = transport.tick(4000); assertEquals("Having pending data does not reset the deadline", 5000, deadline); assertEquals("Having pending data prevents tick() from sending an empty frame", 0, transport.writes.size() - framesWrittenBeforeTick); }
Example #22
Source File: AmqpConnectionBuilder.java From qpid-jms with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override protected Connection createEndpoint(JmsConnectionInfo resourceInfo) { String hostname = getParent().getVhost(); if (hostname == null) { hostname = getParent().getRemoteURI().getHost(); } else if (hostname.isEmpty()) { hostname = null; } final Map<Symbol, Object> props = new LinkedHashMap<Symbol, Object>(); if (resourceInfo.getExtensionMap().containsKey(JmsConnectionExtensions.AMQP_OPEN_PROPERTIES)) { final Map<String, Object> userConnectionProperties = (Map<String, Object>) resourceInfo.getExtensionMap().get( JmsConnectionExtensions.AMQP_OPEN_PROPERTIES).apply(resourceInfo.getConnection(), parent.getTransport().getRemoteLocation()); if (userConnectionProperties != null && !userConnectionProperties.isEmpty()) { userConnectionProperties.forEach((key, value) -> props.put(Symbol.valueOf(key), value)); } } // Client properties override anything the user added. props.put(AmqpSupport.PRODUCT, MetaDataSupport.PROVIDER_NAME); props.put(AmqpSupport.VERSION, MetaDataSupport.PROVIDER_VERSION); props.put(AmqpSupport.PLATFORM, MetaDataSupport.PLATFORM_DETAILS); Connection connection = getParent().getProtonConnection(); connection.setHostname(hostname); connection.setContainer(resourceInfo.getClientId()); connection.setDesiredCapabilities(new Symbol[] { SOLE_CONNECTION_CAPABILITY, DELAYED_DELIVERY, ANONYMOUS_RELAY, SHARED_SUBS}); connection.setProperties(props); return connection; }
Example #23
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
void doOpenLinkBeforeOpenConnectionTestImpl(boolean receiverLink) { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); transport.bind(connection); Session session = connection.session(); session.open(); Link link = null; if(receiverLink) { link = session.receiver("myReceiver"); } else { link = session.sender("mySender"); } link.open(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 0, transport.writes.size()); // Now open the connection, expect the Open, Begin, and Attach frames connection.open(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size()); assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open); assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin); assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach); }
Example #24
Source File: EventImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testGetTransportWithLinkContext() { Transport transport = Transport.Factory.create(); Connection connection = Connection.Factory.create(); transport.bind(connection); Session session = connection.session(); Link link = session.receiver("myReceiver"); EventImpl event = createEvent(link, Event.Type.LINK_INIT); assertNotNull("No transport returned", event.getTransport()); assertSame("Incorrect transport returned", transport, event.getTransport()); }
Example #25
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testReceiverFlowBeforeOpenConnection() { MockTransportImpl transport = new MockTransportImpl(); Connection connection = Proton.connection(); transport.bind(connection); Session session = connection.session(); session.open(); Receiver reciever = session.receiver("myReceiver"); reciever.flow(5); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 0, transport.writes.size()); // Now open the connection, expect the Open and Begin frames but // nothing else as we haven't opened the receiver itself yet. connection.open(); pumpMockTransport(transport); assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size()); assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open); assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin); }
Example #26
Source File: EventImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testGetTransportWithTransportContext() { Transport transport = Transport.Factory.create(); Connection connection = Connection.Factory.create(); transport.bind(connection); EventImpl event = createEvent(transport, Event.Type.TRANSPORT); assertNotNull("No transport returned", event.getTransport()); assertSame("Incorrect transport returned", transport, event.getTransport()); }
Example #27
Source File: EventImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testGetTransportWithConnectionContext() { Transport transport = Transport.Factory.create(); Connection connection = Connection.Factory.create(); transport.bind(connection); EventImpl event = createEvent(connection, Event.Type.CONNECTION_BOUND); assertNotNull("No transport returned", event.getTransport()); assertSame("Incorrect transport returned", transport, event.getTransport()); }
Example #28
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void doProtocolTracingLogsOutboundHeaderToSystemTestImpl(boolean sasl) { Connection connection = new ConnectionImpl(); AtomicReference<String> headerRef = new AtomicReference<>(); AtomicReference<String> eventRef = new AtomicReference<>(); TransportImpl transport = new TransportImpl() { @Override public void log(String event, String header) { assertTrue(eventRef.compareAndSet(null, event)); assertTrue(headerRef.compareAndSet(null, header)); } }; transport.trace(2); if (sasl) { transport.sasl(); } transport.bind(connection); ByteBuffer expected = ByteBuffer.wrap(sasl ? AmqpHeader.SASL_HEADER : AmqpHeader.HEADER); transport.pending(); assertEquals(expected, transport.getOutputBuffer()); assertEquals(TransportImpl.OUTGOING, eventRef.get()); assertEquals(sasl ? "SASL" : "AMQP", headerRef.get()); }
Example #29
Source File: AmqpConnection.java From qpid-jms with Apache License 2.0 | 5 votes |
public AmqpConnection(AmqpProvider provider, JmsConnectionInfo info, Connection protonConnection) { super(info, protonConnection, provider); this.provider = provider; this.remoteURI = provider.getRemoteURI(); this.amqpMessageFactory = new AmqpJmsMessageFactory(this); // Create connection properties initialized with defaults from the JmsConnectionInfo this.properties = new AmqpConnectionProperties(info, provider); }
Example #30
Source File: AMQPConnectionContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
@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) { scheduleOp.setDelay(nextKeepAliveTime - TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); scheduledFutureRef.getAndUpdate(scheduleOp); } } }