Package com.rabbitmq.client.impl

Examples of com.rabbitmq.client.impl.SocketFrameHandler


* Check that protocol negotiation works
*/
public class ConnectionOpen extends TestCase {
    public void testCorrectProtocolHeader() throws IOException {
        ConnectionFactory factory = new ConnectionFactory();
        SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT));
        fh.sendHeader();
        AMQCommand command = new AMQCommand();
        while (!command.handleFrame(fh.readFrame())) { }
        Method m = command.getMethod();
        //    System.out.println(m.getClass());
        assertTrue("First command must be Connection.start",
                m instanceof AMQP.Connection.Start);
        AMQP.Connection.Start start = (AMQP.Connection.Start) m;
View Full Code Here


    public void testCrazyProtocolHeader() throws IOException {
        ConnectionFactory factory = new ConnectionFactory();
        // keep the frame handler's socket
        Socket fhSocket = factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT);
        SocketFrameHandler fh = new SocketFrameHandler(fhSocket);
        fh.sendHeader(100, 3); // major, minor
        DataInputStream in = fh.getInputStream();
        // we should get a valid protocol header back
        byte[] header = new byte[4];
        in.read(header);
        // The protocol header is "AMQP" plus a version that the server
        // supports.  We can really only test for the first bit.
        assertEquals("AMQP", new String(header));
        in.read(header);
        assertEquals(in.available(), 0);
        // At this point the socket should have been closed.  We can
        // directly test for this, but since Socket.isClosed is purported to be
        // unreliable, we can also test whether trying to read more bytes
        // gives an error.
        if (!fhSocket.isClosed()) {
            fh.setTimeout(500);
            // NB the frame handler will return null if the socket times out
            try {
                fh.readFrame();
                fail("Expected socket read to fail due to socket being closed");
            } catch (MalformedFrameException mfe) {
                fail("Expected nothing, rather than a badly-formed something");
            } catch (IOException ioe) {
                return;
View Full Code Here

    }

    protected FrameHandler createFrameHandler(Socket sock)
        throws IOException
    {
        return new SocketFrameHandler(sock);
    }
View Full Code Here

            throws IOException {

            String hostName = addr.getHost();
            int portNumber = addr.getPort();
            if (portNumber == -1) portNumber = AMQP.PROTOCOL.PORT;
            return new SocketFrameHandler(getSocketFactory().createSocket(hostName, portNumber)) {
                    public void sendHeader() throws IOException {
                        sendHeader(protocolMajor, protocolMinor);
                    }
                };
        }
View Full Code Here

    }

    private SpecialConnection(ConnectionFactory factory) throws Exception{
      super(factory.getUsername(),
            factory.getPassword(),
            new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", AMQP.PROTOCOL.PORT)),
            Executors.newFixedThreadPool(1),
            factory.getVirtualHost(),
            factory.getClientProperties(),
            factory.getRequestedFrameMax(),
            factory.getRequestedChannelMax(),
View Full Code Here

* Check that protocol negotiation works
*/
public class ConnectionOpen extends TestCase {
    public void testCorrectProtocolHeader() throws IOException {
        ConnectionFactory factory = new ConnectionFactory();
        SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT));
        fh.sendHeader();
        AMQCommand command = new AMQCommand();
        while (!command.handleFrame(fh.readFrame())) { }
        Method m = command.getMethod();
        //    System.out.println(m.getClass());
        assertTrue("First command must be Connection.start",
                m instanceof AMQP.Connection.Start);
        AMQP.Connection.Start start = (AMQP.Connection.Start) m;
View Full Code Here

    public void testCrazyProtocolHeader() throws IOException {
        ConnectionFactory factory = new ConnectionFactory();
        // keep the frame handler's socket
        Socket fhSocket = factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT);
        SocketFrameHandler fh = new SocketFrameHandler(fhSocket);
        fh.sendHeader(100, 3); // major, minor
        DataInputStream in = fh.getInputStream();
        // we should get a valid protocol header back
        byte[] header = new byte[4];
        in.read(header);
        // The protocol header is "AMQP" plus a version that the server
        // supports.  We can really only test for the first bit.
        assertEquals("AMQP", new String(header));
        in.read(header);
        assertEquals(in.available(), 0);
        // At this point the socket should have been closed.  We can
        // directly test for this, but since Socket.isClosed is purported to be
        // unreliable, we can also test whether trying to read more bytes
        // gives an error.
        if (!fhSocket.isClosed()) {
            fh.setTimeout(500);
            // NB the frame handler will return null if the socket times out
            try {
                fh.readFrame();
                fail("Expected socket read to fail due to socket being closed");
            } catch (MalformedFrameException mfe) {
                fail("Expected nothing, rather than a badly-formed something");
            } catch (IOException ioe) {
                return;
View Full Code Here

            @Override
            public FrameHandler create(Address addr) throws IOException {
                String hostName = addr.getHost();
                int portNumber = addr.getPort();
                if (portNumber == -1) portNumber = AMQP.PROTOCOL.PORT;
                return new SocketFrameHandler(getSocketFactory().createSocket(hostName, portNumber)) {
                    @Override
                    public void sendHeader() throws IOException {
                        sendHeader(protocolMajor, protocolMinor);
                    }
                };
View Full Code Here

        public SpecialConnection(int channelMax) throws Exception {
            this(new ConnectionFactory(), channelMax);
        }

        private SpecialConnection(ConnectionFactory factory, int channelMax) throws Exception {
            super(factory.params(Executors.newFixedThreadPool(1)), new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", AMQP.PROTOCOL.PORT)));
            this.channelMax = channelMax;
        }
View Full Code Here

      return validShutdown.get();
    }

    public SpecialConnection() throws Exception {
        super(specialConnectionFactory().params(Executors.newFixedThreadPool(1)),
              new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", AMQP.PROTOCOL.PORT)));
        this.start();
    }
View Full Code Here

TOP

Related Classes of com.rabbitmq.client.impl.SocketFrameHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.