org.apache.activemq.transport.udp
Class UdpTransport

java.lang.Object
  extended by org.apache.activemq.util.ServiceSupport
      extended by org.apache.activemq.transport.TransportSupport
          extended by org.apache.activemq.transport.TransportThreadSupport
              extended by org.apache.activemq.transport.udp.UdpTransport
All Implemented Interfaces:
Runnable, Service, Transport
Direct Known Subclasses:
MulticastTransport

public class UdpTransport
extends TransportThreadSupport
implements Transport, Service, Runnable

An implementation of the Transport interface using raw UDP


Constructor Summary
protected UdpTransport(OpenWireFormat wireFormat)
           
  UdpTransport(OpenWireFormat wireFormat, int port)
          Used by the server transport
  UdpTransport(OpenWireFormat wireFormat, SocketAddress socketAddress)
           
  UdpTransport(OpenWireFormat wireFormat, URI remoteLocation)
           
 
Method Summary
protected  void bind(DatagramSocket socket, SocketAddress localAddress)
           
protected  DatagramChannel connect(DatagramChannel channel, SocketAddress targetAddress2)
           
protected  InetSocketAddress createAddress(URI remoteLocation)
          Creates an address from the given URI
protected  CommandChannel createCommandChannel()
           
protected  CommandChannel createCommandDatagramChannel()
           
protected  DatagramHeaderMarshaller createDatagramHeaderMarshaller()
           
protected  SocketAddress createLocalAddress()
           
 Replayer createReplayer()
          Creates a replayer for working with the reliable transport
protected  void doStart()
           
protected  void doStop(ServiceStopper stopper)
           
 ByteBufferPool getBufferPool()
           
protected  DatagramChannel getChannel()
           
 CommandChannel getCommandChannel()
           
 int getDatagramSize()
           
 InetSocketAddress getLocalSocketAddress()
           
 int getMinmumWireFormatVersion()
           
 int getPort()
           
protected  String getProtocolName()
           
protected  String getProtocolUriScheme()
           
 int getReceiveCounter()
          Returns a counter which gets incremented as data is read from the transport.
 String getRemoteAddress()
           
 ReplayBuffer getReplayBuffer()
           
 ReplayStrategy getReplayStrategy()
           
 IntSequenceGenerator getSequenceGenerator()
           
protected  SocketAddress getTargetAddress()
           
 OpenWireFormat getWireFormat()
           
 boolean isReplayEnabled()
           
 boolean isTrace()
           
 boolean isUseLocalHost()
           
 void oneway(Object command)
          A one way asynchronous send
 void oneway(Object command, SocketAddress address)
          A one way asynchronous send to a given address
protected  String resolveHostName(String host)
           
 void run()
          reads packets from a Socket
 void setBufferPool(ByteBufferPool bufferPool)
           
protected  void setChannel(DatagramChannel channel)
           
 void setCommandChannel(CommandDatagramChannel commandChannel)
          Sets the implementation of the command channel to use.
 void setDatagramSize(int datagramSize)
           
 void setMinmumWireFormatVersion(int minmumWireFormatVersion)
           
 void setPort(int port)
          Sets the port to connect on
 void setReplayBuffer(ReplayBuffer replayBuffer)
           
 void setReplayEnabled(boolean replayEnabled)
          Sets whether or not replay should be enabled when using the reliable transport.
 void setReplayStrategy(ReplayStrategy replayStrategy)
          Sets the strategy used to replay missed datagrams
 void setSequenceGenerator(IntSequenceGenerator sequenceGenerator)
           
 void setTargetEndpoint(Endpoint newTarget)
          We have received the WireFormatInfo from the server on the actual channel we should use for all future communication with the server, so lets set the target to be the actual channel that the server has chosen for us to talk on.
 void setTrace(boolean trace)
           
 void setUseLocalHost(boolean useLocalHost)
          Sets whether 'localhost' or the actual local host name should be used to make local connections.
 String toString()
           
 
Methods inherited from class org.apache.activemq.transport.TransportThreadSupport
getStackSize, isDaemon, setDaemon, setStackSize
 
Methods inherited from class org.apache.activemq.transport.TransportSupport
asyncRequest, checkStarted, doConsume, getTransportListener, isConnected, isDisposed, isFaultTolerant, isReconnectSupported, isUpdateURIsSupported, narrow, onException, reconnect, request, request, setTransportListener, updateURIs
 
Methods inherited from class org.apache.activemq.util.ServiceSupport
addServiceListener, dispose, isStarted, isStopped, isStopping, postStop, preStart, removeServiceListener, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.activemq.transport.Transport
asyncRequest, getTransportListener, isConnected, isDisposed, isFaultTolerant, isReconnectSupported, isUpdateURIsSupported, narrow, reconnect, request, request, setTransportListener, updateURIs
 
Methods inherited from interface org.apache.activemq.Service
start, stop
 

Constructor Detail

UdpTransport

protected UdpTransport(OpenWireFormat wireFormat)
                throws IOException
Throws:
IOException

UdpTransport

public UdpTransport(OpenWireFormat wireFormat,
                    URI remoteLocation)
             throws UnknownHostException,
                    IOException
Throws:
UnknownHostException
IOException

UdpTransport

public UdpTransport(OpenWireFormat wireFormat,
                    SocketAddress socketAddress)
             throws IOException
Throws:
IOException

UdpTransport

public UdpTransport(OpenWireFormat wireFormat,
                    int port)
             throws UnknownHostException,
                    IOException
Used by the server transport

Throws:
UnknownHostException
IOException
Method Detail

createReplayer

public Replayer createReplayer()
                        throws IOException
Creates a replayer for working with the reliable transport

Throws:
IOException

oneway

public void oneway(Object command)
            throws IOException
A one way asynchronous send

Specified by:
oneway in interface Transport
Throws:
IOException

oneway

public void oneway(Object command,
                   SocketAddress address)
            throws IOException
A one way asynchronous send to a given address

Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object
Returns:
pretty print of 'this'

run

public void run()
reads packets from a Socket

Specified by:
run in interface Runnable

setTargetEndpoint

public void setTargetEndpoint(Endpoint newTarget)
We have received the WireFormatInfo from the server on the actual channel we should use for all future communication with the server, so lets set the target to be the actual channel that the server has chosen for us to talk on.


isTrace

public boolean isTrace()

setTrace

public void setTrace(boolean trace)

getDatagramSize

public int getDatagramSize()

setDatagramSize

public void setDatagramSize(int datagramSize)

isUseLocalHost

public boolean isUseLocalHost()

setUseLocalHost

public void setUseLocalHost(boolean useLocalHost)
Sets whether 'localhost' or the actual local host name should be used to make local connections. On some operating systems such as Macs its not possible to connect as the local host name so localhost is better.


getCommandChannel

public CommandChannel getCommandChannel()
                                 throws IOException
Throws:
IOException

setCommandChannel

public void setCommandChannel(CommandDatagramChannel commandChannel)
Sets the implementation of the command channel to use.


getReplayStrategy

public ReplayStrategy getReplayStrategy()

setReplayStrategy

public void setReplayStrategy(ReplayStrategy replayStrategy)
Sets the strategy used to replay missed datagrams


getPort

public int getPort()

setPort

public void setPort(int port)
Sets the port to connect on


getMinmumWireFormatVersion

public int getMinmumWireFormatVersion()

setMinmumWireFormatVersion

public void setMinmumWireFormatVersion(int minmumWireFormatVersion)

getWireFormat

public OpenWireFormat getWireFormat()

getSequenceGenerator

public IntSequenceGenerator getSequenceGenerator()

setSequenceGenerator

public void setSequenceGenerator(IntSequenceGenerator sequenceGenerator)

isReplayEnabled

public boolean isReplayEnabled()

setReplayEnabled

public void setReplayEnabled(boolean replayEnabled)
Sets whether or not replay should be enabled when using the reliable transport. i.e. should we maintain a buffer of messages that can be replayed?


getBufferPool

public ByteBufferPool getBufferPool()

setBufferPool

public void setBufferPool(ByteBufferPool bufferPool)

getReplayBuffer

public ReplayBuffer getReplayBuffer()

setReplayBuffer

public void setReplayBuffer(ReplayBuffer replayBuffer)
                     throws IOException
Throws:
IOException

createAddress

protected InetSocketAddress createAddress(URI remoteLocation)
                                   throws UnknownHostException,
                                          IOException
Creates an address from the given URI

Throws:
UnknownHostException
IOException

resolveHostName

protected String resolveHostName(String host)
                          throws UnknownHostException
Throws:
UnknownHostException

doStart

protected void doStart()
                throws Exception
Overrides:
doStart in class TransportThreadSupport
Throws:
Exception

createCommandChannel

protected CommandChannel createCommandChannel()
                                       throws IOException
Throws:
IOException

createCommandDatagramChannel

protected CommandChannel createCommandDatagramChannel()

bind

protected void bind(DatagramSocket socket,
                    SocketAddress localAddress)
             throws IOException
Throws:
IOException

connect

protected DatagramChannel connect(DatagramChannel channel,
                                  SocketAddress targetAddress2)
                           throws IOException
Throws:
IOException

createLocalAddress

protected SocketAddress createLocalAddress()

doStop

protected void doStop(ServiceStopper stopper)
               throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception

createDatagramHeaderMarshaller

protected DatagramHeaderMarshaller createDatagramHeaderMarshaller()

getProtocolName

protected String getProtocolName()

getProtocolUriScheme

protected String getProtocolUriScheme()

getTargetAddress

protected SocketAddress getTargetAddress()

getChannel

protected DatagramChannel getChannel()

setChannel

protected void setChannel(DatagramChannel channel)

getLocalSocketAddress

public InetSocketAddress getLocalSocketAddress()

getRemoteAddress

public String getRemoteAddress()
Specified by:
getRemoteAddress in interface Transport
Returns:
the remote address for this connection

getReceiveCounter

public int getReceiveCounter()
Description copied from interface: Transport
Returns a counter which gets incremented as data is read from the transport. It should only be used to determine if there is progress being made in reading the next command from the transport. The value may wrap into the negative numbers.

Specified by:
getReceiveCounter in interface Transport
Returns:
a counter which gets incremented as data is read from the transport.


Copyright © 2005–2013 The Apache Software Foundation. All rights reserved.