YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
org.fourthline.cling.transport.RouterImpl Class Reference

Default implementation of network message router. More...

Inheritance diagram for org.fourthline.cling.transport.RouterImpl:
Inheritance graph
Collaboration diagram for org.fourthline.cling.transport.RouterImpl:
Collaboration graph

Public Member Functions

 RouterImpl (UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory)
 
boolean enable (@Observes @Default EnableRouter event) throws RouterException
 
boolean disable (@Observes @Default DisableRouter event) throws RouterException
 
UpnpServiceConfiguration getConfiguration ()
 
ProtocolFactory getProtocolFactory ()
 
boolean enable () throws RouterException
 Initializes listening services: First an instance of org.fourthline.cling.transport.spi.MulticastReceiver is bound to each network interface.
 
boolean disable () throws RouterException
 Unbinds all sockets and stops all listening threads for datagrams and streams.
 
void shutdown () throws RouterException
 Disables the router and releases all other resources.
 
boolean isEnabled ()
 
void handleStartFailure (InitializationException ex) throws InitializationException
 Called by the enable() method before it returns.
 
List< NetworkAddress > getActiveStreamServers (InetAddress preferredAddress) throws RouterException
 
void received (IncomingDatagramMessage msg)
 Obtains the asynchronous protocol Executor and runs the protocol created by the org.fourthline.cling.protocol.ProtocolFactory for the given message.
 
void received (UpnpStream stream)
 Obtains the synchronous protocol Executor and runs the org.fourthline.cling.transport.spi.UpnpStream directly.
 
void send (OutgoingDatagramMessage msg) throws RouterException
 Sends the UDP datagram on all bound org.fourthline.cling.transport.spi.DatagramIOs.
 
StreamResponseMessage send (StreamRequestMessage msg) throws RouterException
 Sends the TCP stream request with the org.fourthline.cling.transport.spi.StreamClient.
 
void broadcast (byte[] bytes) throws RouterException
 Sends the given bytes as a broadcast on all bound org.fourthline.cling.transport.spi.DatagramIOs, using source port 9.
 

Protected Member Functions

void startInterfaceBasedTransports (Iterator< NetworkInterface > interfaces) throws InitializationException
 
void startAddressBasedTransports (Iterator< InetAddress > addresses) throws InitializationException
 
void lock (Lock lock, int timeoutMilliseconds) throws RouterException
 
void lock (Lock lock) throws RouterException
 
void unlock (Lock lock)
 
int getLockTimeoutMillis ()
 

Protected Attributes

final Map< NetworkInterface, MulticastReceiver > multicastReceivers = new HashMap<>()
 
final Map< InetAddress, DatagramIO > datagramIOs = new HashMap<>()
 
final Map< InetAddress, StreamServer > streamServers = new HashMap<>()
 
UpnpServiceConfiguration configuration
 
ProtocolFactory protocolFactory
 
volatile boolean enabled
 
ReentrantReadWriteLock routerLock = new ReentrantReadWriteLock(true)
 
Lock readLock = routerLock.readLock()
 
Lock writeLock = routerLock.writeLock()
 
NetworkAddressFactory networkAddressFactory
 
StreamClient streamClient
 

Detailed Description

Default implementation of network message router.

Initializes and starts listening for data on the network when enabled.

Author
Christian Bauer

Constructor & Destructor Documentation

◆ RouterImpl()

org.fourthline.cling.transport.RouterImpl.RouterImpl ( UpnpServiceConfiguration  configuration,
ProtocolFactory  protocolFactory 
)
Parameters
configurationThe configuration used by this router.
protocolFactoryThe protocol factory used by this router.

Member Function Documentation

◆ broadcast()

void org.fourthline.cling.transport.RouterImpl.broadcast ( byte[]  bytes) throws RouterException

Sends the given bytes as a broadcast on all bound org.fourthline.cling.transport.spi.DatagramIOs, using source port 9.

TODO: Support source port parameter

Parameters
bytesThe byte payload of the UDP datagram.

Implements org.fourthline.cling.transport.Router.

Referenced by org.fourthline.cling.transport.RouterImpl.broadcast().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disable()

boolean org.fourthline.cling.transport.RouterImpl.disable ( ) throws RouterException

Unbinds all sockets and stops all listening threads for datagrams and streams.

Returns
true if the router was disabled. false if it wasn't running.

Implements org.fourthline.cling.transport.Router.

Referenced by org.fourthline.cling.transport.RouterImpl.shutdown().

Here is the caller graph for this function:

◆ enable()

boolean org.fourthline.cling.transport.RouterImpl.enable ( ) throws RouterException

Initializes listening services: First an instance of org.fourthline.cling.transport.spi.MulticastReceiver is bound to each network interface.

Then an instance of org.fourthline.cling.transport.spi.DatagramIO and org.fourthline.cling.transport.spi.StreamServer is bound to each bind address returned by the network address factory, respectively. There is only one instance of org.fourthline.cling.transport.spi.StreamClient created and managed by this router.

Implements org.fourthline.cling.transport.Router.

Here is the call graph for this function:

◆ getActiveStreamServers()

List< NetworkAddress > org.fourthline.cling.transport.RouterImpl.getActiveStreamServers ( InetAddress  preferredAddress) throws RouterException
Parameters
preferredAddressA preferred stream server bound address or null.
Returns
An empty list if no stream server is currently active, otherwise a single network address if the preferred address is active, or a list of all active bound stream servers.

Implements org.fourthline.cling.transport.Router.

◆ getConfiguration()

UpnpServiceConfiguration org.fourthline.cling.transport.RouterImpl.getConfiguration ( )
Returns
The configuration used by this router.

Implements org.fourthline.cling.transport.Router.

Referenced by org.fourthline.cling.transport.RouterImpl.enable(), org.fourthline.cling.transport.RouterImpl.received(), and org.fourthline.cling.transport.RouterImpl.received().

Here is the caller graph for this function:

◆ getLockTimeoutMillis()

int org.fourthline.cling.transport.RouterImpl.getLockTimeoutMillis ( )
protected
Returns
Defaults to 6 seconds, should be longer than it takes the router to be enabled/disabled.

◆ getProtocolFactory()

ProtocolFactory org.fourthline.cling.transport.RouterImpl.getProtocolFactory ( )
Returns
The protocol factory used by this router.

Implements org.fourthline.cling.transport.Router.

Referenced by org.fourthline.cling.transport.RouterImpl.received().

Here is the caller graph for this function:

◆ handleStartFailure()

void org.fourthline.cling.transport.RouterImpl.handleStartFailure ( InitializationException  ex) throws InitializationException

Called by the enable() method before it returns.

Parameters
exThe cause of the failure.
Exceptions
InitializationExceptionif the exception was not recoverable.

Implements org.fourthline.cling.transport.Router.

Referenced by org.fourthline.cling.transport.RouterImpl.enable().

Here is the caller graph for this function:

◆ isEnabled()

boolean org.fourthline.cling.transport.RouterImpl.isEnabled ( )
Returns
true if the router is currently enabled.

Implements org.fourthline.cling.transport.Router.

◆ received() [1/2]

void org.fourthline.cling.transport.RouterImpl.received ( IncomingDatagramMessage  msg)

Obtains the asynchronous protocol Executor and runs the protocol created by the org.fourthline.cling.protocol.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.

Parameters
msgThe received datagram message.

Implements org.fourthline.cling.transport.Router.

Here is the call graph for this function:

◆ received() [2/2]

void org.fourthline.cling.transport.RouterImpl.received ( UpnpStream  stream)

Obtains the synchronous protocol Executor and runs the org.fourthline.cling.transport.spi.UpnpStream directly.

Parameters
streamThe received org.fourthline.cling.transport.spi.UpnpStream.

Implements org.fourthline.cling.transport.Router.

Here is the call graph for this function:

◆ send() [1/2]

void org.fourthline.cling.transport.RouterImpl.send ( OutgoingDatagramMessage  msg) throws RouterException

Sends the UDP datagram on all bound org.fourthline.cling.transport.spi.DatagramIOs.

Parameters
msgThe UDP datagram message to send.

Implements org.fourthline.cling.transport.Router.

◆ send() [2/2]

StreamResponseMessage org.fourthline.cling.transport.RouterImpl.send ( StreamRequestMessage  msg) throws RouterException

Sends the TCP stream request with the org.fourthline.cling.transport.spi.StreamClient.

Parameters
msgThe TCP (HTTP) stream message to send.
Returns
The return value of the org.fourthline.cling.transport.spi.StreamClient#sendRequest(StreamRequestMessage) method or null if no StreamClient is available.

Implements org.fourthline.cling.transport.Router.

◆ shutdown()

void org.fourthline.cling.transport.RouterImpl.shutdown ( ) throws RouterException

Disables the router and releases all other resources.

Implements org.fourthline.cling.transport.Router.

Here is the call graph for this function:

The documentation for this class was generated from the following file: