net.sf.xenqtt.mockbroker
Class MockBroker

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

public final class MockBroker
extends SimpleBroker

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


Field Summary
 
Fields inherited from class net.sf.xenqtt.SimpleBroker
manager
 
Constructor Summary
MockBroker()
          Creates a broker with the following config: no MockBrokerHandler 15 second message resend interval Any available port.
MockBroker(MockBrokerHandler brokerHandler)
          Creates a broker with the specified handler and the following config: 15 second message resend interval Any available port.
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)
           
 void init()
          Starts the mock broker
 void removeEvents(Collection<BrokerEvent> eventsToRemove)
          Removes the specified broker events.
 
Methods inherited from class net.sf.xenqtt.SimpleBroker
getPort, getURI, init, shutdown
 
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)
Creates a broker with the specified handler and 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 SimpleBroker.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


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.


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.