pl.bristleback.server.bristle.messages
Class SingleThreadedMessageDispatcher

java.lang.Object
  extended by pl.bristleback.server.bristle.messages.AbstractMessageDispatcher
      extended by pl.bristleback.server.bristle.messages.SingleThreadedMessageDispatcher
All Implemented Interfaces:
MessageDispatcher

public class SingleThreadedMessageDispatcher
extends AbstractMessageDispatcher

This class provides thread safe way to collect and send all outbound messages. It is a default implementation of MessageDispatcher. It uses LinkedBlockingQueue, which allows thread safe adding messages by any number of threads using senders. It creates one consumer thread which is waiting for incoming messages.

Created on: 2010-09-24 22:13:40

Author:
Wojciech Niemiec

Constructor Summary
SingleThreadedMessageDispatcher()
           
 
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 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.
 
Methods inherited from class pl.bristleback.server.bristle.messages.AbstractMessageDispatcher
getServer, setServer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleThreadedMessageDispatcher

public SingleThreadedMessageDispatcher()
Method Detail

addMessage

public void addMessage(WebSocketMessage message)
Description copied from interface: MessageDispatcher
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

public void dispatchMessages()
                      throws java.lang.Exception
Description copied from interface: MessageDispatcher
Dispatches collected messages and removing them from collection.

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

startDispatching

public void startDispatching()
Description copied from interface: MessageDispatcher
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

public void stopDispatching()
Description copied from interface: MessageDispatcher
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.



Copyright © 2011. All Rights Reserved.