@Alternative public class MockRouter extends Object implements Router
This is not a real network transport layer, it collects all messages instead and makes
them available for testing with getOutgoingDatagramMessages()
,
getSentStreamRequestMessages()
, etc. Mock responses for TCP (HTTP) stream requests
can be returned by overriding getStreamResponseMessage(org.fourthline.cling.model.message.StreamRequestMessage)
or getStreamResponseMessages()
if you know the order of requests.
Modifier and Type | Field and Description |
---|---|
List<byte[]> |
broadcastedBytes |
protected UpnpServiceConfiguration |
configuration |
int |
counter |
List<IncomingDatagramMessage> |
incomingDatagramMessages |
List<OutgoingDatagramMessage> |
outgoingDatagramMessages |
protected ProtocolFactory |
protocolFactory |
List<UpnpStream> |
receivedUpnpStreams |
List<StreamRequestMessage> |
sentStreamRequestMessages |
Constructor and Description |
---|
MockRouter(UpnpServiceConfiguration configuration,
ProtocolFactory protocolFactory) |
Modifier and Type | Method and Description |
---|---|
void |
broadcast(byte[] bytes)
Call this method to broadcast a UDP message to all hosts on the network.
|
boolean |
disable()
Unbinds all sockets and stops all listening threads for datagrams and streams.
|
boolean |
enable()
Starts all sockets and listening threads for datagrams and streams.
|
List<NetworkAddress> |
getActiveStreamServers(InetAddress preferredAddress) |
List<byte[]> |
getBroadcastedBytes() |
UpnpServiceConfiguration |
getConfiguration() |
List<IncomingDatagramMessage> |
getIncomingDatagramMessages() |
List<OutgoingDatagramMessage> |
getOutgoingDatagramMessages() |
ProtocolFactory |
getProtocolFactory() |
List<UpnpStream> |
getReceivedUpnpStreams() |
List<StreamRequestMessage> |
getSentStreamRequestMessages() |
StreamResponseMessage |
getStreamResponseMessage(StreamRequestMessage request) |
StreamResponseMessage[] |
getStreamResponseMessages() |
void |
handleStartFailure(InitializationException ex)
Called by the
Router.enable() method before it returns. |
boolean |
isEnabled() |
void |
received(IncomingDatagramMessage msg)
This method is called internally by the transport layer when a datagram, either unicast or
multicast, has been received.
|
void |
received(UpnpStream stream)
This method is called internally by the transport layer when a TCP stream connection has
been made and a response has to be returned to the sender.
|
void |
resetStreamRequestMessageCounter() |
void |
send(OutgoingDatagramMessage msg)
Call this method to send a UDP datagram message.
|
StreamResponseMessage |
send(StreamRequestMessage msg)
Call this method to send a TCP (HTTP) stream message.
|
void |
shutdown()
Disables the router and releases all other resources.
|
public int counter
public List<IncomingDatagramMessage> incomingDatagramMessages
public List<OutgoingDatagramMessage> outgoingDatagramMessages
public List<UpnpStream> receivedUpnpStreams
public List<StreamRequestMessage> sentStreamRequestMessages
public List<byte[]> broadcastedBytes
protected UpnpServiceConfiguration configuration
protected ProtocolFactory protocolFactory
public MockRouter(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory)
public UpnpServiceConfiguration getConfiguration()
getConfiguration
in interface Router
public ProtocolFactory getProtocolFactory()
getProtocolFactory
in interface Router
public boolean enable() throws RouterException
Router
enable
in interface Router
true
if the router was enabled. false
if it's already running.RouterException
public boolean disable() throws RouterException
Router
disable
in interface Router
true
if the router was disabled. false
if it wasn't running.RouterException
public void shutdown() throws RouterException
Router
shutdown
in interface Router
RouterException
public boolean isEnabled() throws RouterException
isEnabled
in interface Router
true
if the router is currently enabled.RouterException
public void handleStartFailure(InitializationException ex) throws InitializationException
Router
Router.enable()
method before it returns.handleStartFailure
in interface Router
ex
- The cause of the failure.InitializationException
- if the exception was not recoverable.public List<NetworkAddress> getActiveStreamServers(InetAddress preferredAddress) throws RouterException
getActiveStreamServers
in interface Router
preferredAddress
- A preferred stream server bound address or null
.RouterException
public void received(IncomingDatagramMessage msg)
Router
This method is called internally by the transport layer when a datagram, either unicast or multicast, has been received. An implementation of this interface has to handle the received message, e.g. selecting and executing a UPnP protocol. This method should not block until the execution completes, the calling thread should be free to handle the next reception as soon as possible.
public void received(UpnpStream stream)
Router
This method is called internally by the transport layer when a TCP stream connection has been made and a response has to be returned to the sender. An implementation of this interface has to handle the received stream connection and return a response, e.g. selecting and executing a UPnP protocol. This method should not block until the execution completes, the calling thread should be free to process the next reception as soon as possible. Typically this means starting a new thread of execution in this method.
public void send(OutgoingDatagramMessage msg) throws RouterException
Router
Call this method to send a UDP datagram message.
send
in interface Router
msg
- The UDP datagram message to send.RouterException
- if a recoverable error, such as thread interruption, occurs.public StreamResponseMessage send(StreamRequestMessage msg) throws RouterException
Router
Call this method to send a TCP (HTTP) stream message.
send
in interface Router
msg
- The TCP (HTTP) stream message to send.RouterException
- if a recoverable error, such as thread interruption, occurs.public void broadcast(byte[] bytes)
Router
Call this method to broadcast a UDP message to all hosts on the network.
public void resetStreamRequestMessageCounter()
public List<IncomingDatagramMessage> getIncomingDatagramMessages()
public List<OutgoingDatagramMessage> getOutgoingDatagramMessages()
public List<UpnpStream> getReceivedUpnpStreams()
public List<StreamRequestMessage> getSentStreamRequestMessages()
public List<byte[]> getBroadcastedBytes()
public StreamResponseMessage[] getStreamResponseMessages()
public StreamResponseMessage getStreamResponseMessage(StreamRequestMessage request)
Copyright © 2016 4th Line GmbH, Switzerland. All rights reserved.