|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.fourthline.cling.transport.RouterImpl
public class RouterImpl
Default implementation of network message router.
Initializes and starts listening for data on the network immediately on construction.
Field Summary | |
---|---|
protected UpnpServiceConfiguration |
configuration
|
protected Map<InetAddress,DatagramIO> |
datagramIOs
|
protected Map<NetworkInterface,MulticastReceiver> |
multicastReceivers
|
protected NetworkAddressFactory |
networkAddressFactory
|
protected ProtocolFactory |
protocolFactory
|
protected StreamClient |
streamClient
|
protected Map<InetAddress,StreamServer> |
streamServers
|
Constructor Summary | |
---|---|
RouterImpl(UpnpServiceConfiguration configuration,
ProtocolFactory protocolFactory)
Creates a NetworkAddressFactory from the given
UpnpServiceConfiguration and initializes listening services. |
Method Summary | |
---|---|
void |
broadcast(byte[] bytes)
Sends the given bytes as a broadcast on all bound DatagramIO s,
using source port 9. |
List<NetworkAddress> |
getActiveStreamServers(InetAddress preferredAddress)
|
UpnpServiceConfiguration |
getConfiguration()
|
protected Map<InetAddress,DatagramIO> |
getDatagramIOs()
|
protected Map<NetworkInterface,MulticastReceiver> |
getMulticastReceivers()
|
NetworkAddressFactory |
getNetworkAddressFactory()
|
ProtocolFactory |
getProtocolFactory()
|
protected StreamClient |
getStreamClient()
|
protected Map<InetAddress,StreamServer> |
getStreamServers()
|
void |
received(IncomingDatagramMessage msg)
Obtains the asynchronous protocol Executor and runs the protocol created
by the ProtocolFactory for the given message. |
void |
received(UpnpStream stream)
Obtains the synchronous protocol Executor and runs the
UpnpStream directly. |
void |
send(OutgoingDatagramMessage msg)
Sends the UDP datagram on all bound DatagramIO s. |
StreamResponseMessage |
send(StreamRequestMessage msg)
Sends the TCP stream request with the StreamClient . |
void |
shutdown()
Unbinds all sockets and stops all listening threads for datagrams and streams. |
protected void |
startAddressBasedTransports(Iterator<InetAddress> addresses)
|
protected void |
startInterfaceBasedTransports(Iterator<NetworkInterface> interfaces)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final UpnpServiceConfiguration configuration
protected final ProtocolFactory protocolFactory
protected final StreamClient streamClient
protected final NetworkAddressFactory networkAddressFactory
protected final Map<NetworkInterface,MulticastReceiver> multicastReceivers
protected final Map<InetAddress,DatagramIO> datagramIOs
protected final Map<InetAddress,StreamServer> streamServers
Constructor Detail |
---|
public RouterImpl(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory) throws InitializationException
NetworkAddressFactory
from the given
UpnpServiceConfiguration
and initializes listening services. First an instance
of MulticastReceiver
is bound to eatch network interface. Then
an instance of DatagramIO
and StreamServer
is bound to each bind address
returned by the network address factory, respectively. There is only one instance of
StreamClient
created and managed by this router.
configuration
- The configuration used by this router.protocolFactory
- The protocol factory used by this router.
InitializationException
- When initialization of any listening network service fails.Method Detail |
---|
protected void startInterfaceBasedTransports(Iterator<NetworkInterface> interfaces) throws InitializationException
InitializationException
protected void startAddressBasedTransports(Iterator<InetAddress> addresses) throws InitializationException
InitializationException
public UpnpServiceConfiguration getConfiguration()
getConfiguration
in interface Router
public ProtocolFactory getProtocolFactory()
getProtocolFactory
in interface Router
public NetworkAddressFactory getNetworkAddressFactory()
getNetworkAddressFactory
in interface Router
protected Map<NetworkInterface,MulticastReceiver> getMulticastReceivers()
protected Map<InetAddress,DatagramIO> getDatagramIOs()
protected StreamClient getStreamClient()
protected Map<InetAddress,StreamServer> getStreamServers()
public List<NetworkAddress> getActiveStreamServers(InetAddress preferredAddress)
getActiveStreamServers
in interface Router
preferredAddress
- A preferred stream server bound address or null
.
public void shutdown()
Router
shutdown
in interface Router
public void received(IncomingDatagramMessage msg)
Executor
and runs the protocol created
by the ProtocolFactory
for the given message.
If the factory doesn't create a protocol, the message is dropped immediately without creating another thread or consuming further resoures. This means we can filter the datagrams in the protocol factory and e.g. completely disable discovery or only allow notification message from some known services we'd like to work with.
received
in interface Router
msg
- The received datagram message.public void received(UpnpStream stream)
Executor
and runs the
UpnpStream
directly.
received
in interface Router
stream
- The received UpnpStream
.public void send(OutgoingDatagramMessage msg)
DatagramIO
s.
send
in interface Router
msg
- The UDP datagram message to send.public StreamResponseMessage send(StreamRequestMessage msg)
StreamClient
.
send
in interface Router
msg
- The TCP (HTTP) stream message to send.
StreamClient.sendRequest(StreamRequestMessage)
method or null
if no StreamClient
is available.public void broadcast(byte[] bytes)
DatagramIO
s,
using source port 9.
TODO: Support source port parameter
broadcast
in interface Router
bytes
- The byte payload of the UDP datagram.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |