org.teleal.cling.transport.impl
Class DatagramIOImpl

java.lang.Object
  extended by org.teleal.cling.transport.impl.DatagramIOImpl
All Implemented Interfaces:
Runnable, DatagramIO<DatagramIOConfigurationImpl>

public class DatagramIOImpl
extends Object
implements DatagramIO<DatagramIOConfigurationImpl>

Default implementation based on a single shared (receive/send) UDP MulticastSocket.

Although we do not receive multicast datagrams with this service, sending multicast datagrams with a configuration time-to-live requires a MulticastSocket.

Thread-safety is guaranteed through synchronization of methods of this service and by the thread-safe underlying socket.

Author:
Christian Bauer

Field Summary
protected  DatagramIOConfigurationImpl configuration
           
protected  DatagramProcessor datagramProcessor
           
protected  InetSocketAddress localAddress
           
protected  Router router
           
protected  MulticastSocket socket
           
 
Constructor Summary
DatagramIOImpl(DatagramIOConfigurationImpl configuration)
           
 
Method Summary
 DatagramIOConfigurationImpl getConfiguration()
           
 void init(InetAddress bindAddress, Router router, DatagramProcessor datagramProcessor)
          Configures the service and starts any listening sockets.
 void run()
           
 void send(DatagramPacket datagram)
          The actual sending of a UDP datagram.
 void send(OutgoingDatagramMessage message)
          Sends a datagram after conversion with DatagramProcessor.write(org.teleal.cling.model.message.OutgoingDatagramMessage).
 void stop()
          Stops the service, closes any listening sockets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

configuration

protected final DatagramIOConfigurationImpl configuration

router

protected Router router

datagramProcessor

protected DatagramProcessor datagramProcessor

localAddress

protected InetSocketAddress localAddress

socket

protected MulticastSocket socket
Constructor Detail

DatagramIOImpl

public DatagramIOImpl(DatagramIOConfigurationImpl configuration)
Method Detail

getConfiguration

public DatagramIOConfigurationImpl getConfiguration()
Specified by:
getConfiguration in interface DatagramIO<DatagramIOConfigurationImpl>
Returns:
This service's configuration.

init

public void init(InetAddress bindAddress,
                 Router router,
                 DatagramProcessor datagramProcessor)
          throws InitializationException
Description copied from interface: DatagramIO
Configures the service and starts any listening sockets.

Specified by:
init in interface DatagramIO<DatagramIOConfigurationImpl>
Parameters:
bindAddress - The address to bind any sockets on.
router - The router which handles received IncomingDatagramMessages.
datagramProcessor - Reads and writes datagrams.
Throws:
InitializationException - If the service could not be initialized or started.

stop

public void stop()
Description copied from interface: DatagramIO
Stops the service, closes any listening sockets.

Specified by:
stop in interface DatagramIO<DatagramIOConfigurationImpl>

run

public void run()
Specified by:
run in interface Runnable

send

public void send(OutgoingDatagramMessage message)
Description copied from interface: DatagramIO
Sends a datagram after conversion with DatagramProcessor.write(org.teleal.cling.model.message.OutgoingDatagramMessage).

Specified by:
send in interface DatagramIO<DatagramIOConfigurationImpl>
Parameters:
message - The message to send.

send

public void send(DatagramPacket datagram)
Description copied from interface: DatagramIO
The actual sending of a UDP datagram.

Recoverable errors should be logged, if appropriate only with debug level. Any non-recoverable errors should be thrown as RuntimeExceptions.

Specified by:
send in interface DatagramIO<DatagramIOConfigurationImpl>
Parameters:
datagram - The UDP datagram to send.


Copyright © 2010 Teleal GmbH, Switzerland. All Rights Reserved.