net.sf.xenqtt
Class SimpleBroker

java.lang.Object
  extended by net.sf.xenqtt.SimpleBroker
Direct Known Subclasses:
MockBroker, ProxyBroker

public class SimpleBroker
extends Object

Simple broker implementation. Can be used as the base class for more advanced broker implementations. Handles accepting new connections and adding them to a ChannelManager.


Field Summary
protected  ChannelManager manager
          ChannelManager all new broker channels are added to.
 
Constructor Summary
SimpleBroker(long messageResendIntervalSeconds, int port)
           
 
Method Summary
 int getPort()
           
 String getURI()
           
 void init(MessageHandler messageHandler, String serverThreadName)
          Starts the broker.
 boolean shutdown(long millis)
          Shuts down the broker.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

manager

protected final ChannelManager manager
ChannelManager all new broker channels are added to.

Constructor Detail

SimpleBroker

public SimpleBroker(long messageResendIntervalSeconds,
                    int port)
Parameters:
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().
Method Detail

init

public final void init(MessageHandler messageHandler,
                       String serverThreadName)
Starts the broker. Blocks until startup is complete.

Parameters:
messageHandler - Called when events happen
serverThreadName - Name to give the server thread

shutdown

public boolean shutdown(long millis)
Shuts down the broker. Blocks until shutdown is complete.

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

getURI

public final String getURI()
Returns:
The URI to this broker

getPort

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


Copyright © 2013. All Rights Reserved.