Search in sources :

Example 11 with OpenWireFormat

use of org.apache.activemq.openwire.OpenWireFormat in project activemq-artemis by apache.

the class UdpTransportTest method createProducer.

@Override
protected Transport createProducer() throws Exception {
    LOG.info("Producer using URI: " + producerURI);
    // we are not using the TransportFactory as this assumes that
    // UDP transports talk to a server using a WireFormat Negotiation step
    // rather than talking directly to each other
    OpenWireFormat wireFormat = createWireFormat();
    UdpTransport transport = new UdpTransport(wireFormat, new URI(producerURI));
    transport.setSequenceGenerator(new IntSequenceGenerator());
    return new CommandJoiner(transport, wireFormat);
}
Also used : OpenWireFormat(org.apache.activemq.openwire.OpenWireFormat) IntSequenceGenerator(org.apache.activemq.util.IntSequenceGenerator) CommandJoiner(org.apache.activemq.transport.CommandJoiner) URI(java.net.URI)

Example 12 with OpenWireFormat

use of org.apache.activemq.openwire.OpenWireFormat in project activemq-artemis by apache.

the class InactivityMonitorTest method testClientHang.

public void testClientHang() throws Exception {
    // Manually create a client transport so that it does not send KeepAlive
    // packets.  this should simulate a client hang.
    clientTransport = new TcpTransport(new OpenWireFormat(), SocketFactory.getDefault(), new URI("tcp://localhost:" + serverPort), null);
    clientTransport.setTransportListener(new TransportListener() {

        @Override
        public void onCommand(Object command) {
            clientReceiveCount.incrementAndGet();
            if (clientRunOnCommand != null) {
                clientRunOnCommand.run();
            }
        }

        @Override
        public void onException(IOException error) {
            if (!ignoreClientError.get()) {
                LOG.info("Client transport error:");
                error.printStackTrace();
                clientErrorCount.incrementAndGet();
            }
        }

        @Override
        public void transportInterupted() {
        }

        @Override
        public void transportResumed() {
        }
    });
    clientTransport.start();
    WireFormatInfo info = new WireFormatInfo();
    info.setVersion(OpenWireFormat.DEFAULT_LEGACY_VERSION);
    info.setMaxInactivityDuration(1000);
    clientTransport.oneway(info);
    assertEquals(0, serverErrorCount.get());
    assertEquals(0, clientErrorCount.get());
    // Server should consider the client timed out right away since the
    // client is not hart beating fast enough.
    Thread.sleep(6000);
    assertEquals(0, clientErrorCount.get());
    assertTrue(serverErrorCount.get() > 0);
}
Also used : OpenWireFormat(org.apache.activemq.openwire.OpenWireFormat) TransportListener(org.apache.activemq.transport.TransportListener) WireFormatInfo(org.apache.activemq.command.WireFormatInfo) IOException(java.io.IOException) URI(java.net.URI)

Example 13 with OpenWireFormat

use of org.apache.activemq.openwire.OpenWireFormat in project activemq-artemis by apache.

the class UnreliableUdpTransportTest method createConsumer.

@Override
protected Transport createConsumer() throws Exception {
    LOG.info("Consumer on port: " + consumerPort);
    OpenWireFormat wireFormat = createWireFormat();
    UdpTransport transport = new UdpTransport(wireFormat, consumerPort);
    ReliableTransport reliableTransport = new ReliableTransport(transport, transport);
    Replayer replayer = reliableTransport.getReplayer();
    reliableTransport.setReplayStrategy(createReplayStrategy(replayer));
    ResponseRedirectInterceptor redirectInterceptor = new ResponseRedirectInterceptor(reliableTransport, transport);
    return new CommandJoiner(redirectInterceptor, wireFormat);
}
Also used : OpenWireFormat(org.apache.activemq.openwire.OpenWireFormat) UdpTransport(org.apache.activemq.transport.udp.UdpTransport) CommandJoiner(org.apache.activemq.transport.CommandJoiner) ResponseRedirectInterceptor(org.apache.activemq.transport.udp.ResponseRedirectInterceptor)

Example 14 with OpenWireFormat

use of org.apache.activemq.openwire.OpenWireFormat in project activemq-artemis by apache.

the class SslTransportFactoryTest method testCompositeConfigure.

public void testCompositeConfigure() throws IOException {
    // The 5 options being tested.
    int[] optionSettings = new int[5];
    String[] optionNames = { "wantClientAuth", "needClientAuth", "socket.wantClientAuth", "socket.needClientAuth", "socket.useClientMode" };
    // 3^5 = 243 combos.
    for (int i = 0; i < 243; ++i) {
        Map<String, String> options = new HashMap<>();
        for (int j = 0; j < 5; ++j) {
            // -1 since the option range is [-1,1], not [0,2].
            optionSettings[j] = getMthNaryDigit(i, j, 3) - 1;
            if (optionSettings[j] != -1) {
                options.put(optionNames[j], optionSettings[j] == 1 ? "true" : "false");
            }
        }
        StubSSLSocket socketStub = new StubSSLSocket(null);
        StubSslTransport transport = null;
        try {
            transport = new StubSslTransport(null, socketStub);
        } catch (Exception e) {
            fail("Unable to create StubSslTransport: " + e.getMessage());
        }
        if (verbose) {
            LOG.info("");
            LOG.info("Iteration: " + i);
            LOG.info("Map settings: " + options);
            for (int x = 0; x < optionSettings.length; x++) {
                LOG.info("optionSetting[" + x + "] = " + optionSettings[x]);
            }
        }
        factory.compositeConfigure(transport, new OpenWireFormat(), options);
        // lets start the transport to force the introspection
        try {
            transport.start();
        } catch (Exception e) {
        // ignore bad connection
        }
        if (socketStub.getWantClientAuthStatus() != optionSettings[2]) {
            LOG.info("sheiite");
        }
        assertEquals("wantClientAuth was not properly set for iteration: " + i, optionSettings[0], transport.getWantClientAuthStatus());
        assertEquals("needClientAuth was not properly set for iteration: " + i, optionSettings[1], transport.getNeedClientAuthStatus());
        assertEquals("socket.wantClientAuth was not properly set for iteration: " + i, optionSettings[2], socketStub.getWantClientAuthStatus());
        assertEquals("socket.needClientAuth was not properly set for iteration: " + i, optionSettings[3], socketStub.getNeedClientAuthStatus());
        assertEquals("socket.useClientMode was not properly set for iteration: " + i, optionSettings[4], socketStub.getUseClientModeStatus());
    }
}
Also used : OpenWireFormat(org.apache.activemq.openwire.OpenWireFormat) HashMap(java.util.HashMap) IOException(java.io.IOException)

Aggregations

OpenWireFormat (org.apache.activemq.openwire.OpenWireFormat)14 CommandJoiner (org.apache.activemq.transport.CommandJoiner)6 URI (java.net.URI)5 IntSequenceGenerator (org.apache.activemq.util.IntSequenceGenerator)4 IOException (java.io.IOException)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Message (javax.jms.Message)1 ConnectionEntry (org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry)1 FilePendingQueueMessageStoragePolicy (org.apache.activemq.broker.region.policy.FilePendingQueueMessageStoragePolicy)1 VMPendingQueueMessageStoragePolicy (org.apache.activemq.broker.region.policy.VMPendingQueueMessageStoragePolicy)1 WireFormatInfo (org.apache.activemq.command.WireFormatInfo)1 CommandVisitor (org.apache.activemq.state.CommandVisitor)1 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)1 JDBCPersistenceAdapter (org.apache.activemq.store.jdbc.JDBCPersistenceAdapter)1 KahaDBPersistenceAdapter (org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)1 TransportListener (org.apache.activemq.transport.TransportListener)1 WireFormatNegotiator (org.apache.activemq.transport.WireFormatNegotiator)1 ResponseRedirectInterceptor (org.apache.activemq.transport.udp.ResponseRedirectInterceptor)1 UdpTransport (org.apache.activemq.transport.udp.UdpTransport)1