pl.bristleback.server.bristle.messages
Interface MessageDispatcher

All Known Implementing Classes:
AbstractMessageDispatcher, SingleThreadedMessageDispatcher

public interface MessageDispatcher

Message dispatcher is responsible for collecting all outbound messages and sending them in thread safe way. The idea of dispatcher is to guarantee that no matter from how many threads will send message by MessageSender implementations, those messages will be redirected to dispatcher and dispatcher maintains sending them to jwebsocket server. Implementations must be able to send single targeted message or broadcasting messages. Dispatchers should not perform filtering or any extra operations related with choosing sending target. Only one instance of dispatcher is created at plugin start. Any new threads used by dispatcher should be interrupted in stopDispatching() method. In future versions, messages will contain priority, so dispatcher will be able to sort messages into more and less important. In addition, future versions will be able to make use of configuration file, for example, to specify interval of message dispatching.

Created on: 2010-09-21 20:43:55

Author:
Wojciech Niemiec

Method Summary
 void addMessage(WebSocketMessage message)
          Adds message containing token and one or more target connectors.
 void dispatchMessages()
          Dispatches collected messages and removing them from collection.
 void setServer(org.jwebsocket.api.WebSocketServer server)
          Sets server implementing jwebsocket framework server interface.
 void startDispatching()
          Describes operations, like dispatcher thread start, which will be invoked when framework will be ready for sending messages.
 void stopDispatching()
          Operations executed when framework stops and no messages can be sent anymore.
 

Method Detail

addMessage

void addMessage(WebSocketMessage message)
Adds message containing token and one or more target connectors. Adding messages should be thread safe, which means, any thread invoking this method must be able to do so without any synchronisation from user side.

Parameters:
message - message.

dispatchMessages

void dispatchMessages()
                      throws java.lang.Exception
Dispatches collected messages and removing them from collection.

Throws:
java.lang.Exception - if any exception occurs.

startDispatching

void startDispatching()
Describes operations, like dispatcher thread start, which will be invoked when framework will be ready for sending messages. This method is invoked by plugin and should not be used by user.


stopDispatching

void stopDispatching()
Operations executed when framework stops and no messages can be sent anymore. If any messages remain in collection while this method is being invoked, they can not be sent because of framework engine stop.


setServer

void setServer(org.jwebsocket.api.WebSocketServer server)
Sets server implementing jwebsocket framework server interface. This method is invoked by plugin internally at plugin start.

Parameters:
server - jwebsocket server implementation.


Copyright © 2011. All Rights Reserved.