public class DatagramIOImpl extends Object implements DatagramIO<DatagramIOConfigurationImpl>
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.
Modifier and Type | Field and Description |
---|---|
protected DatagramIOConfigurationImpl |
configuration |
protected DatagramProcessor |
datagramProcessor |
protected InetSocketAddress |
localAddress |
protected Router |
router |
protected MulticastSocket |
socket |
Constructor and Description |
---|
DatagramIOImpl(DatagramIOConfigurationImpl configuration) |
Modifier and Type | Method and Description |
---|---|
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.fourthline.cling.model.message.OutgoingDatagramMessage) . |
void |
stop()
Stops the service, closes any listening sockets.
|
protected final DatagramIOConfigurationImpl configuration
protected Router router
protected DatagramProcessor datagramProcessor
protected InetSocketAddress localAddress
protected MulticastSocket socket
public DatagramIOImpl(DatagramIOConfigurationImpl configuration)
public DatagramIOConfigurationImpl getConfiguration()
getConfiguration
in interface DatagramIO<DatagramIOConfigurationImpl>
public void init(InetAddress bindAddress, Router router, DatagramProcessor datagramProcessor) throws InitializationException
DatagramIO
init
in interface DatagramIO<DatagramIOConfigurationImpl>
bindAddress
- The address to bind any sockets on.router
- The router which handles received IncomingDatagramMessage
s.datagramProcessor
- Reads and writes datagrams.InitializationException
- If the service could not be initialized or started.public void stop()
DatagramIO
stop
in interface DatagramIO<DatagramIOConfigurationImpl>
public void send(OutgoingDatagramMessage message)
DatagramIO
DatagramProcessor.write(org.fourthline.cling.model.message.OutgoingDatagramMessage)
.send
in interface DatagramIO<DatagramIOConfigurationImpl>
message
- The message to send.public void send(DatagramPacket datagram)
DatagramIO
Recoverable errors should be logged, if appropriate only with debug level. Any
non-recoverable errors should be thrown as RuntimeException
s.
send
in interface DatagramIO<DatagramIOConfigurationImpl>
datagram
- The UDP datagram to send.Copyright © 2016 4th Line GmbH, Switzerland. All rights reserved.