Example usage for com.rabbitmq.client.impl AMQChannel getChannelNumber

List of usage examples for com.rabbitmq.client.impl AMQChannel getChannelNumber

Introduction

In this page you can find the example usage for com.rabbitmq.client.impl AMQChannel getChannelNumber.

Prototype

public int getChannelNumber() 

Source Link

Document

Public API - Retrieves this channel's channel number.

Usage

From source file:de.htwk_leipzig.bis.connection.handshake.clientRewrite.AMQCommand.java

License:Mozilla Public License

/**
 * Sends this command down the named channel on the channel's connection,
 * possibly in multiple frames.//from   ww w .  ja  v a 2  s.  co m
 * 
 * @param channel
 *            the channel on which to transmit the command
 * @throws IOException
 *             if an error is encountered
 */
public void transmit(AMQChannel channel) throws IOException {
    int channelNumber = channel.getChannelNumber();
    AMQConnection connection = channel.getConnection();

    synchronized (assembler) {
        Method m = this.assembler.getMethod();
        connection.writeFrame(m.toFrame(channelNumber));
        if (m.hasContent()) {
            byte[] body = this.assembler.getContentBody();

            connection.writeFrame(this.assembler.getContentHeader().toFrame(channelNumber, body.length));

            int frameMax = connection.getFrameMax();
            int bodyPayloadMax = (frameMax == 0) ? body.length : frameMax - EMPTY_FRAME_SIZE;

            for (int offset = 0; offset < body.length; offset += bodyPayloadMax) {
                int remaining = body.length - offset;

                int fragmentLength = (remaining < bodyPayloadMax) ? remaining : bodyPayloadMax;
                Frame frame = Frame.fromBodyFragment(channelNumber, body, offset, fragmentLength);
                connection.writeFrame(frame);
            }
        }
    }

    connection.flush();
}