Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //  The contents of this file are subject to the Mozilla Public License
  //  Version 1.1 (the "License"); you may not use this file except in
  //  compliance with the License. You may obtain a copy of the License
  //  at http://www.mozilla.org/MPL/
  //
  //  Software distributed under the License is distributed on an "AS IS"
  //  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  //  the License for the specific language governing rights and
  //  limitations under the License.
 //
 //  The Original Code is RabbitMQ.
 //
 //  The Initial Developer of the Original Code is VMware, Inc.
 //  Copyright (c) 2007-2011 VMware, Inc.  All rights reserved.
 //
 
 package com.rabbitmq.client.impl;
 
 
A socket-based frame handler.
 
 
 public class SocketFrameHandler implements FrameHandler {
    
The underlying socket
 
     private final Socket _socket;

    
Socket's inputstream - data from the broker - synchronized on
 
     private final DataInputStream _inputStream;

    
Socket's outputstream - data to the broker - synchronized on
 
     private final DataOutputStream _outputStream;

    
Time to linger before closing the socket forcefully.
 
     public static final int SOCKET_CLOSING_TIMEOUT = 1;

    

Parameters:
socket the socket to use
 
     public SocketFrameHandler(Socket socketthrows IOException {
          = socket;
 
          = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
          = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
     }
 
     public InetAddress getAddress() {
         return .getInetAddress();
     }
 
     // For testing only
     public DataInputStream getInputStream() {
         return ;
     }
 
     public int getPort() {
         return .getPort();
     }
 
     public void setTimeout(int timeoutMs)
         throws SocketException
     {
         .setSoTimeout(timeoutMs);
     }
 
     public int getTimeout()
         throws SocketException
     {
         return .getSoTimeout();
     }

    
Write a 0-8-style connection header to the underlying socket, containing the specified version information, kickstarting the AMQP protocol version negotiation process.

Parameters:
major major protocol version number
minor minor protocol version number
Throws:
java.io.IOException if there is a problem accessing the connection
See also:
sendHeader()
 
     public void sendHeader(int majorint minorthrows IOException {
         synchronized () {
             .write("AMQP".getBytes("US-ASCII"));
             .write(1);
             .write(1);
             .write(major);
             .write(minor);
             .flush();
        }
    }

   
Write a 0-9-1-style connection header to the underlying socket, containing the specified version information, kickstarting the AMQP protocol version negotiation process.

Parameters:
major major protocol version number
minor minor protocol version number
revision protocol revision number
Throws:
java.io.IOException if there is a problem accessing the connection
See also:
sendHeader()
  public void sendHeader(int majorint minorint revisionthrows IOException {
        synchronized () {
            .write("AMQP".getBytes("US-ASCII"));
            .write(0);
            .write(major);
            .write(minor);
            .write(revision);
            .flush();
        }
    }
    public void sendHeader() throws IOException {
    }
    public Frame readFrame() throws IOException {
        synchronized () {
            return Frame.readFrom();
        }
    }
    public void writeFrame(Frame framethrows IOException {
        synchronized () {
            frame.writeTo();
            .flush();
        }
    }
    public void close() {
        try {
            .setSoLinger(true);
            .close();
        } catch (IOException ioe) {
            // Ignore.
        }
    }
New to GrepCode? Check out our FAQ X