|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.fourthline.cling.transport.RouterImpl
@ApplicationScoped public class RouterImpl
Default implementation of network message router.
Initializes and starts listening for data on the network when enabled.
| Field Summary | |
|---|---|
protected UpnpServiceConfiguration |
configuration
|
protected Map<InetAddress,DatagramIO> |
datagramIOs
|
protected boolean |
enabled
|
protected Map<NetworkInterface,MulticastReceiver> |
multicastReceivers
|
protected NetworkAddressFactory |
networkAddressFactory
|
protected ProtocolFactory |
protocolFactory
|
protected Lock |
readLock
|
protected ReentrantReadWriteLock |
routerLock
|
protected StreamClient |
streamClient
|
protected Map<InetAddress,StreamServer> |
streamServers
|
protected Lock |
writeLock
|
| Constructor Summary | |
|---|---|
protected |
RouterImpl()
|
|
RouterImpl(UpnpServiceConfiguration configuration,
ProtocolFactory protocolFactory)
|
| Method Summary | |
|---|---|
void |
broadcast(byte[] bytes)
Sends the given bytes as a broadcast on all bound DatagramIOs,
using source port 9. |
boolean |
disable()
Unbinds all sockets and stops all listening threads for datagrams and streams. |
boolean |
disable(DisableRouter event)
|
boolean |
enable()
Initializes listening services: First an instance of MulticastReceiver
is bound to each network interface. |
boolean |
enable(EnableRouter event)
|
List<NetworkAddress> |
getActiveStreamServers(InetAddress preferredAddress)
|
UpnpServiceConfiguration |
getConfiguration()
|
protected int |
getLockTimeoutMillis()
|
ProtocolFactory |
getProtocolFactory()
|
void |
handleStartFailure(InitializationException ex)
Called by the Router.enable() method before it returns. |
boolean |
isEnabled()
|
protected void |
lock(Lock lock)
|
protected void |
lock(Lock lock,
int timeoutMilliseconds)
|
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 DatagramIOs. |
StreamResponseMessage |
send(StreamRequestMessage msg)
Sends the TCP stream request with the StreamClient. |
void |
shutdown()
Disables the router and releases all other resources. |
protected void |
startAddressBasedTransports(Iterator<InetAddress> addresses)
|
protected void |
startInterfaceBasedTransports(Iterator<NetworkInterface> interfaces)
|
protected void |
unlock(Lock lock)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected UpnpServiceConfiguration configuration
protected ProtocolFactory protocolFactory
protected volatile boolean enabled
protected ReentrantReadWriteLock routerLock
protected Lock readLock
protected Lock writeLock
protected NetworkAddressFactory networkAddressFactory
protected StreamClient streamClient
protected final Map<NetworkInterface,MulticastReceiver> multicastReceivers
protected final Map<InetAddress,DatagramIO> datagramIOs
protected final Map<InetAddress,StreamServer> streamServers
| Constructor Detail |
|---|
protected RouterImpl()
@Inject
public RouterImpl(UpnpServiceConfiguration configuration,
ProtocolFactory protocolFactory)
configuration - The configuration used by this router.protocolFactory - The protocol factory used by this router.| Method Detail |
|---|
public boolean enable(@Observes@Default
EnableRouter event)
throws RouterException
RouterException
public boolean disable(@Observes@Default
DisableRouter event)
throws RouterException
RouterExceptionpublic UpnpServiceConfiguration getConfiguration()
getConfiguration in interface Routerpublic ProtocolFactory getProtocolFactory()
getProtocolFactory in interface Router
public boolean enable()
throws RouterException
MulticastReceiver
is bound to each 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.
enable in interface Routertrue if the router was enabled. false if it's already running.
RouterException
public boolean disable()
throws RouterException
Router
disable in interface Routertrue if the router was disabled. false if it wasn't running.
RouterException
public void shutdown()
throws RouterException
Router
shutdown in interface RouterRouterExceptionpublic boolean isEnabled()
isEnabled in interface Routertrue if the router is currently enabled.
public void handleStartFailure(InitializationException ex)
throws InitializationException
RouterRouter.enable() method before it returns.
handleStartFailure in interface Routerex - The cause of the failure.
InitializationException - if the exception was not recoverable.
public List<NetworkAddress> getActiveStreamServers(InetAddress preferredAddress)
throws RouterException
getActiveStreamServers in interface RouterpreferredAddress - A preferred stream server bound address or null.
RouterExceptionpublic 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 resources. 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 Routermsg - The received datagram message.public void received(UpnpStream stream)
Executor and runs the
UpnpStream directly.
received in interface Routerstream - The received UpnpStream.
public void send(OutgoingDatagramMessage msg)
throws RouterException
DatagramIOs.
send in interface Routermsg - The UDP datagram message to send.
RouterException - if a recoverable error, such as thread interruption, occurs.
public StreamResponseMessage send(StreamRequestMessage msg)
throws RouterException
StreamClient.
send in interface Routermsg - The TCP (HTTP) stream message to send.
StreamClient.sendRequest(StreamRequestMessage)
method or null if no StreamClient is available.
RouterException - if a recoverable error, such as thread interruption, occurs.
public void broadcast(byte[] bytes)
throws RouterException
DatagramIOs,
using source port 9.
TODO: Support source port parameter
broadcast in interface Routerbytes - The byte payload of the UDP datagram.
RouterException - if a recoverable error, such as thread interruption, occurs.
protected void startInterfaceBasedTransports(Iterator<NetworkInterface> interfaces)
throws InitializationException
InitializationException
protected void startAddressBasedTransports(Iterator<InetAddress> addresses)
throws InitializationException
InitializationException
protected void lock(Lock lock,
int timeoutMilliseconds)
throws RouterException
RouterException
protected void lock(Lock lock)
throws RouterException
RouterExceptionprotected void unlock(Lock lock)
protected int getLockTimeoutMillis()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||