Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.fourthline.cling.mock
Class MockRouter

    java.lang.Object
      org.fourthline.cling.mock.MockRouter

All Implemented Interfaces:
  Router

    @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.

Author:
  Christian Bauer

Field Summary
`List<byte[]>` | `broadcastedBytes`
`protected UpnpServiceConfiguration` | `configuration`
`int` | `counter`
`List<IncomingDatagramMessage>` | `incomingDatagramMessages`
`List<OutgoingDatagramMessage>` | `outgoingDatagramMessages`
`protected ProtocolFactory` | `protocolFactory`
`List<UpnpStream>` | `receivedUpnpStreams`
`List<StreamRequestMessage>` | `sentStreamRequestMessages`

Constructor Summary
`MockRouter(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory)`

Method Summary
`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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### counter

    public int counter

### incomingDatagramMessages

    public List<IncomingDatagramMessage> incomingDatagramMessages

### outgoingDatagramMessages

    public List<OutgoingDatagramMessage> outgoingDatagramMessages

### receivedUpnpStreams

    public List<UpnpStream> receivedUpnpStreams

### sentStreamRequestMessages

    public List<StreamRequestMessage> sentStreamRequestMessages

### broadcastedBytes

    public List<byte[]> broadcastedBytes

### configuration

    protected UpnpServiceConfiguration configuration

### protocolFactory

    protected ProtocolFactory protocolFactory

Constructor Detail

### MockRouter

    public MockRouter(UpnpServiceConfiguration configuration,
                      ProtocolFactory protocolFactory)

Method Detail

### getConfiguration

    public UpnpServiceConfiguration getConfiguration()

  Specified by:
    `getConfiguration` in interface `Router`
  Returns:
    The configuration used by this router.

### getProtocolFactory

    public ProtocolFactory getProtocolFactory()

  Specified by:
    `getProtocolFactory` in interface `Router`
  Returns:
    The protocol factory used by this router.

### enable

    public boolean enable()
                   throws RouterException

  Description copied from interface: `Router`
  Starts all sockets and listening threads for datagrams and streams.

  Specified by:
    `enable` in interface `Router`
  Returns:
    `true` if the router was enabled. `false` if it's already running.
  Throws:
    `RouterException`

### disable

    public boolean disable()
                    throws RouterException

  Description copied from interface: `Router`
  Unbinds all sockets and stops all listening threads for datagrams and streams.

  Specified by:
    `disable` in interface `Router`
  Returns:
    `true` if the router was disabled. `false` if it wasn't running.
  Throws:
    `RouterException`

### shutdown

    public void shutdown()
                  throws RouterException

  Description copied from interface: `Router`
  Disables the router and releases all other resources.

  Specified by:
    `shutdown` in interface `Router`
  Throws:
    `RouterException`

### isEnabled

    public boolean isEnabled()
                      throws RouterException

  Specified by:
    `isEnabled` in interface `Router`
  Returns:
    `true` if the router is currently enabled.
  Throws:
    `RouterException`

### handleStartFailure

    public void handleStartFailure(InitializationException ex)
                            throws InitializationException

  Description copied from interface: `Router`
  Called by the `Router.enable()` method before it returns.

  Specified by:
    `handleStartFailure` in interface `Router`
  Parameters:
    `ex` - The cause of the failure.
  Throws:
    `InitializationException` - if the exception was not recoverable.

### getActiveStreamServers

    public List<NetworkAddress> getActiveStreamServers(InetAddress preferredAddress)
                                                throws RouterException

  Specified by:
    `getActiveStreamServers` in interface `Router`
  Parameters:
    `preferredAddress` - A 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.
  Throws:
    `RouterException`

### received

    public void received(IncomingDatagramMessage msg)

  Description copied from interface: `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.

  Specified by:
    `received` in interface `Router`
  Parameters:
    `msg` - The received datagram message.

### received

    public void received(UpnpStream stream)

  Description copied from interface: `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.

  Specified by:
    `received` in interface `Router`

### send

    public void send(OutgoingDatagramMessage msg)
              throws RouterException

  Description copied from interface: `Router`

  Call this method to send a UDP datagram message.

  Specified by:
    `send` in interface `Router`
  Parameters:
    `msg` - The UDP datagram message to send.
  Throws:
    `RouterException` - if a recoverable error, such as thread interruption, occurs.

### send

    public StreamResponseMessage send(StreamRequestMessage msg)
                               throws RouterException

  Description copied from interface: `Router`

  Call this method to send a TCP (HTTP) stream message.

  Specified by:
    `send` in interface `Router`
  Parameters:
    `msg` - The TCP (HTTP) stream message to send.
  Returns:
    The response received from the server.
  Throws:
    `RouterException` - if a recoverable error, such as thread interruption, occurs.

### broadcast

    public void broadcast(byte[] bytes)

  Description copied from interface: `Router`

  Call this method to broadcast a UDP message to all hosts on the network.

  Specified by:
    `broadcast` in interface `Router`
  Parameters:
    `bytes` - The byte payload of the UDP datagram.

### resetStreamRequestMessageCounter

    public void resetStreamRequestMessageCounter()

### getIncomingDatagramMessages

    public List<IncomingDatagramMessage> getIncomingDatagramMessages()

### getOutgoingDatagramMessages

    public List<OutgoingDatagramMessage> getOutgoingDatagramMessages()

### getReceivedUpnpStreams

    public List<UpnpStream> getReceivedUpnpStreams()

### getSentStreamRequestMessages

    public List<StreamRequestMessage> getSentStreamRequestMessages()

### getBroadcastedBytes

    public List<byte[]> getBroadcastedBytes()

### getStreamResponseMessages

    public StreamResponseMessage[] getStreamResponseMessages()

### getStreamResponseMessage

    public StreamResponseMessage getStreamResponseMessage(StreamRequestMessage request)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2013 4th Line GmbH, Switzerland. All Rights Reserved.