| Modifier and Type | Field and Description |
|---|---|
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 |
| Modifier | Constructor and Description |
|---|---|
protected |
RouterImpl() |
|
RouterImpl(UpnpServiceConfiguration configuration,
ProtocolFactory protocolFactory) |
| Modifier and Type | Method and Description |
|---|---|
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) |
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
protected RouterImpl()
public RouterImpl(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory)
configuration - The configuration used by this router.protocolFactory - The protocol factory used by this router.public boolean enable(EnableRouter event) throws RouterException
RouterExceptionpublic boolean disable(DisableRouter event) throws RouterException
RouterExceptionpublic UpnpServiceConfiguration getConfiguration()
getConfiguration in interface Routerpublic ProtocolFactory getProtocolFactory()
getProtocolFactory in interface Routerpublic 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.RouterExceptionpublic boolean disable()
throws RouterException
Routerdisable in interface Routertrue if the router was disabled. false if it wasn't running.RouterExceptionpublic void shutdown()
throws RouterException
Routershutdown in interface RouterRouterExceptionpublic boolean isEnabled()
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.
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
InitializationExceptionprotected void startAddressBasedTransports(Iterator<InetAddress> addresses) throws InitializationException
InitializationExceptionprotected void lock(Lock lock, int timeoutMilliseconds) throws RouterException
RouterExceptionprotected void lock(Lock lock) throws RouterException
RouterExceptionprotected void unlock(Lock lock)
protected int getLockTimeoutMillis()
Copyright © 2023 jUPnP.org. All rights reserved.