org.apache.avro.ipc
Class NettyTransceiver

java.lang.Object
  extended by org.apache.avro.ipc.Transceiver
      extended by org.apache.avro.ipc.NettyTransceiver
All Implemented Interfaces:
Closeable

public class NettyTransceiver
extends Transceiver

A Netty-based Transceiver implementation.


Constructor Summary
NettyTransceiver(InetSocketAddress addr)
          Creates a NettyTransceiver, and attempts to connect to the given address.
NettyTransceiver(InetSocketAddress addr, org.jboss.netty.channel.ChannelFactory channelFactory)
          Creates a NettyTransceiver, and attempts to connect to the given address.
 
Method Summary
 void close()
           
 Protocol getRemote()
          Returns the protocol passed to Transceiver.setRemote(Protocol).
 String getRemoteName()
           
 boolean isConnected()
          True if a handshake has been completed for this connection.
 void lockChannel()
          Netty channels are thread-safe, so there is no need to acquire locks.
 List<ByteBuffer> readBuffers()
          Called by the default definition of Transceiver.transceive(List).
 void setRemote(Protocol protocol)
          Called with the remote protocol when a handshake has been completed.
 List<ByteBuffer> transceive(List<ByteBuffer> request)
          Override as non-synchronized method because the method is thread safe.
 void transceive(List<ByteBuffer> request, Callback<List<ByteBuffer>> callback)
          Called by Requestor.request(String,Object,Callback) for two-way messages using callbacks.
 void unlockChannel()
          Netty channels are thread-safe, so there is no need to acquire locks.
 void writeBuffers(List<ByteBuffer> buffers)
          Called by Requestor.request(String,Object) for one-way messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NettyTransceiver

public NettyTransceiver(InetSocketAddress addr)
                 throws IOException
Creates a NettyTransceiver, and attempts to connect to the given address.

Parameters:
addr - the address to connect to.
Throws:
IOException - if an error occurs connecting to the given address.

NettyTransceiver

public NettyTransceiver(InetSocketAddress addr,
                        org.jboss.netty.channel.ChannelFactory channelFactory)
                 throws IOException
Creates a NettyTransceiver, and attempts to connect to the given address.

Parameters:
addr - the address to connect to.
channelFactory - the factory to use to create a new Netty Channel.
Throws:
IOException - if an error occurs connecting to the given address.
Method Detail

lockChannel

public void lockChannel()
Netty channels are thread-safe, so there is no need to acquire locks. This method is a no-op.

Overrides:
lockChannel in class Transceiver

unlockChannel

public void unlockChannel()
Netty channels are thread-safe, so there is no need to acquire locks. This method is a no-op.

Overrides:
unlockChannel in class Transceiver

close

public void close()
Specified by:
close in interface Closeable
Overrides:
close in class Transceiver

getRemoteName

public String getRemoteName()
                     throws IOException
Specified by:
getRemoteName in class Transceiver
Throws:
IOException

transceive

public List<ByteBuffer> transceive(List<ByteBuffer> request)
                            throws IOException
Override as non-synchronized method because the method is thread safe.

Overrides:
transceive in class Transceiver
Throws:
IOException

transceive

public void transceive(List<ByteBuffer> request,
                       Callback<List<ByteBuffer>> callback)
                throws IOException
Description copied from class: Transceiver
Called by Requestor.request(String,Object,Callback) for two-way messages using callbacks.

Overrides:
transceive in class Transceiver
Throws:
IOException

writeBuffers

public void writeBuffers(List<ByteBuffer> buffers)
                  throws IOException
Description copied from class: Transceiver
Called by Requestor.request(String,Object) for one-way messages.

Specified by:
writeBuffers in class Transceiver
Throws:
IOException

readBuffers

public List<ByteBuffer> readBuffers()
                             throws IOException
Description copied from class: Transceiver
Called by the default definition of Transceiver.transceive(List).

Specified by:
readBuffers in class Transceiver
Throws:
IOException

getRemote

public Protocol getRemote()
Description copied from class: Transceiver
Returns the protocol passed to Transceiver.setRemote(Protocol). Throws IllegalStateException by default.

Overrides:
getRemote in class Transceiver

isConnected

public boolean isConnected()
Description copied from class: Transceiver
True if a handshake has been completed for this connection. Used to determine whether a handshake need be completed prior to a one-way message. Requests and responses are always prefixed by handshakes, but one-way messages. If the first request sent over a connection is one-way, then a handshake-only response is returned. Subsequent one-way messages over the connection will have no response data sent. Returns false by default.

Overrides:
isConnected in class Transceiver

setRemote

public void setRemote(Protocol protocol)
Description copied from class: Transceiver
Called with the remote protocol when a handshake has been completed. After this has been called and while a connection is maintained, Transceiver.isConnected() should return true and #getRemote() should return this protocol. Does nothing by default.

Overrides:
setRemote in class Transceiver


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.