Package org.jupnp.transport
Klasse RouterImpl
java.lang.Object
org.jupnp.transport.RouterImpl
- Alle implementierten Schnittstellen:
Router
Default implementation of network message router.
Initializes and starts listening for data on the network when enabled.
- Autor:
- Christian Bauer, Kai Kreuzer - added multicast response port
-
Feldübersicht
FelderModifizierer und TypFeldBeschreibungprotected UpnpServiceConfigurationprotected final Map<InetAddress, DatagramIO> protected booleanprotected final Map<NetworkInterface, MulticastReceiver> protected NetworkAddressFactoryprotected ProtocolFactoryprotected Lockprotected ReentrantReadWriteLockprotected StreamClientprotected final Map<InetAddress, StreamServer> protected Lock -
Konstruktorübersicht
KonstruktorenModifiziererKonstruktorBeschreibungprotectedRouterImpl(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory) -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoidbroadcast(byte[] bytes) Sends the given bytes as a broadcast on all boundDatagramIOs, using source port 9.booleandisable()Unbinds all sockets and stops all listening threads for datagrams and streams.booleandisable(DisableRouter event) booleanenable()Initializes listening services: First an instance ofMulticastReceiveris bound to each network interface.booleanenable(EnableRouter event) getActiveStreamServers(InetAddress preferredAddress) protected intvoidCalled by theRouter.enable()method before it returns.booleanprotected voidprotected voidvoidObtains the asynchronous protocolExecutorand runs the protocol created by theProtocolFactoryfor the given message.voidreceived(UpnpStream stream) Obtains the synchronous protocolExecutorand runs theUpnpStreamdirectly.voidSends the UDP datagram on all boundDatagramIOs.send(StreamRequestMessage msg) Sends the TCP stream request with theStreamClient.voidshutdown()Disables the router and releases all other resources.protected voidstartAddressBasedTransports(Iterator<InetAddress> addresses) protected voidstartInterfaceBasedTransports(Iterator<NetworkInterface> interfaces) protected void
-
Felddetails
-
configuration
-
protocolFactory
-
enabled
protected volatile boolean enabled -
routerLock
-
readLock
-
writeLock
-
networkAddressFactory
-
streamClient
-
multicastReceivers
-
datagramIOs
-
streamServers
-
-
Konstruktordetails
-
RouterImpl
protected RouterImpl() -
RouterImpl
- Parameter:
configuration- The configuration used by this router.protocolFactory- The protocol factory used by this router.
-
-
Methodendetails
-
enable
- Löst aus:
RouterException
-
disable
- Löst aus:
RouterException
-
getConfiguration
- Angegeben von:
getConfigurationin SchnittstelleRouter- Gibt zurück:
- The configuration used by this router.
-
getProtocolFactory
- Angegeben von:
getProtocolFactoryin SchnittstelleRouter- Gibt zurück:
- The protocol factory used by this router.
-
enable
Initializes listening services: First an instance ofMulticastReceiveris bound to each network interface. Then an instance ofDatagramIOandStreamServeris bound to each bind address returned by the network address factory, respectively. There is only one instance ofStreamClientcreated and managed by this router.- Angegeben von:
enablein SchnittstelleRouter- Gibt zurück:
trueif the router was enabled.falseif it's already running.- Löst aus:
RouterException
-
disable
Beschreibung aus Schnittstelle kopiert:RouterUnbinds all sockets and stops all listening threads for datagrams and streams.- Angegeben von:
disablein SchnittstelleRouter- Gibt zurück:
trueif the router was disabled.falseif it wasn't running.- Löst aus:
RouterException
-
shutdown
Beschreibung aus Schnittstelle kopiert:RouterDisables the router and releases all other resources.- Angegeben von:
shutdownin SchnittstelleRouter- Löst aus:
RouterException
-
isEnabled
public boolean isEnabled() -
handleStartFailure
Beschreibung aus Schnittstelle kopiert:RouterCalled by theRouter.enable()method before it returns.- Angegeben von:
handleStartFailurein SchnittstelleRouter- Parameter:
e- The cause of the failure.- Löst aus:
InitializationException- if the exception was not recoverable.
-
getActiveStreamServers
public List<NetworkAddress> getActiveStreamServers(InetAddress preferredAddress) throws RouterException - Angegeben von:
getActiveStreamServersin SchnittstelleRouter- Parameter:
preferredAddress- A preferred stream server bound address ornull.- Gibt zurück:
- 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.
- Löst aus:
RouterException
-
received
Obtains the asynchronous protocolExecutorand runs the protocol created by theProtocolFactoryfor 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
Obtains the synchronous protocolExecutorand runs theUpnpStreamdirectly.- Angegeben von:
receivedin SchnittstelleRouter- Parameter:
stream- The receivedUpnpStream.
-
send
Sends the UDP datagram on all boundDatagramIOs.- Angegeben von:
sendin SchnittstelleRouter- Parameter:
msg- The UDP datagram message to send.- Löst aus:
RouterException- if a recoverable error, such as thread interruption, occurs.
-
send
Sends the TCP stream request with theStreamClient.- Angegeben von:
sendin SchnittstelleRouter- Parameter:
msg- The TCP (HTTP) stream message to send.- Gibt zurück:
- The return value of the
StreamClient.sendRequest(StreamRequestMessage)method ornullif noStreamClientis available. - Löst aus:
RouterException- if a recoverable error, such as thread interruption, occurs.
-
broadcast
Sends the given bytes as a broadcast on all boundDatagramIOs, using source port 9.TODO: Support source port parameter
- Angegeben von:
broadcastin SchnittstelleRouter- Parameter:
bytes- The byte payload of the UDP datagram.- Löst aus:
RouterException- if a recoverable error, such as thread interruption, occurs.
-
startInterfaceBasedTransports
protected void startInterfaceBasedTransports(Iterator<NetworkInterface> interfaces) throws InitializationException - Löst aus:
InitializationException
-
startAddressBasedTransports
protected void startAddressBasedTransports(Iterator<InetAddress> addresses) throws InitializationException - Löst aus:
InitializationException
-
lock
- Löst aus:
RouterException
-
lock
- Löst aus:
RouterException
-
unlock
-
getLockTimeoutMillis
protected int getLockTimeoutMillis()- Gibt zurück:
- Defaults to 6 seconds, should be longer than it takes the router to be enabled/disabled.
-