net.sf.xenqtt.mockbroker
Class MockBroker

java.lang.Object
  extended by net.sf.xenqtt.mockbroker.MockBroker

public final class MockBroker
extends Object

Mock MQTT broker used to test MQTT clients and applications. If debug level logging is enabled all broker events will be logged.


Constructor Summary
MockBroker()
          Creates a broker with the following config: no MockBrokerHandler 15 second message resend interval port 1883 allows anonymous access captures broker events allows 50 in-flight messages
MockBroker(MockBrokerHandler brokerHandler, long messageResendIntervalSeconds, int port, boolean allowAnonymousAccess, boolean captureBrokerEvents, int maxInFlightMessages)
           
 
Method Summary
 void addCredentials(String userName, String password)
          Adds the specified credentials for authentication by ConnectMessages.
 void clearEvents()
          Removes all broker events
 List<BrokerEvent> getEvents()
           
 List<BrokerEvent> getEvents(String clientId)
           
 int getPort()
           
 void init()
          Starts the mock broker
 void removeEvents(Collection<BrokerEvent> eventsToRemove)
          Removes the specified broker events.
 boolean shutdown(long millis)
          Shuts down the mock broker
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockBroker

public MockBroker()
Creates a broker with the following config:


MockBroker

public MockBroker(MockBrokerHandler brokerHandler,
                  long messageResendIntervalSeconds,
                  int port,
                  boolean allowAnonymousAccess,
                  boolean captureBrokerEvents,
                  int maxInFlightMessages)
Parameters:
brokerHandler - Called when events happen. Can be null if you don't need to do any custom message handling.
messageResendIntervalSeconds - Seconds between attempts to resend a message that is MqttMessage.isAckable(). 0 to disable message resends.
port - The port for the server to listen on. 0 will choose an arbitrary available port which you can get from getPort() after calling init().
allowAnonymousAccess - If true then ConnectMessage with no username/password will be accepted. Otherwise only valid credentials will be accepted.
captureBrokerEvents - If true then capture all events within the broker; otherwise, do not capture any events
maxInFlightMessages - Maximum number of concurrent publish messages the broker will have in-flight to the client. This is an approximation. The actual maximum number of in-flight messages may vary slightly.
Method Detail

init

public void init()
Starts the mock broker


shutdown

public boolean shutdown(long millis)
Shuts down the mock broker

Parameters:
millis - Milliseconds to wait for shutdown to complete. 0 means to wait forever.
Returns:
true if shutdown is successful, otherwise false.

addCredentials

public void addCredentials(String userName,
                           String password)
Adds the specified credentials for authentication by ConnectMessages. If password is null any existing credentials for the user are removed.


getPort

public int getPort()
Returns:
The port the mock broker is running on. Not valid until after init() is called.

getEvents

public List<BrokerEvent> getEvents()
Returns:
All broker events. This list is a copy.

getEvents

public List<BrokerEvent> getEvents(String clientId)
Returns:
All broker events for the specified client ID. This list is a copy.

clearEvents

public void clearEvents()
Removes all broker events


removeEvents

public void removeEvents(Collection<BrokerEvent> eventsToRemove)
Removes the specified broker events.



Copyright © 2013. All Rights Reserved.