Class Dispatcher<T>

java.lang.Object
org.flasby.util.Dispatcher<T>
Type Parameters:
T -

public class Dispatcher<T> extends Object
invokes a list of registered Callbacks with either an error or a success message. Can be used to easily add event listeners to event-driven, network socket listeners. I use it to dispatch messages to registers listeners:
 
 				Dispatcher<Msg> dispatcher = new Dispatcher<Msg>();
 				Msg msg; 
 				do {
 					try {;
 						msg = readMessage();
 						if ( msg!=null ) {
 							dispatcher.dispatch(msg);
 						}
 					} catch ( Exception ioe ) {
 						ex = ioe;
 						dispatcher.dispatchError(ioe);
 					}
 				} while ( ex==null && !(msg instanceof EndOfSessionMsg) );
 
  
Author:
steve
  • Constructor Details

    • Dispatcher

      public Dispatcher()
  • Method Details

    • dispatch

      public void dispatch(T toDispatch)
    • dispatchError

      public void dispatchError(Exception ex)
    • register

      public int register(Callback<T> callback)
    • unregister

      public void unregister(int idFrom)
    • close

      public void close()
      is a polite thing to do.