Framework Professional Edition Package


com.prosyst.mbs.framework.event
Class EventThread

java.lang.Object
  extended by com.prosyst.mbs.framework.event.EventThread
All Implemented Interfaces:
java.lang.Runnable

public abstract class EventThread
extends java.lang.Object
implements java.lang.Runnable

Abstract class for asynchronous event dispatching


Field Summary
 java.lang.Object bad
          The last callbacked listener.
protected  java.lang.String baseName
           
protected  int counter
          Instancies counter.
protected  java.lang.Object element
          The event to be dispatched
protected  java.lang.ThreadGroup group
           
protected  java.lang.String name
           
protected  Queue queue
          The event queue.
protected  int state
          The state of the thread.
protected  java.lang.Thread thread
           
protected  long time
          The time spent in the current callback, or 0 if the thread is not in a callback
 
Constructor Summary
protected EventThread(EventThread old)
          Constructs a new EventThread, after the old event thread has stopped responding
  EventThread(java.lang.ThreadGroup group, java.lang.String name, int size)
          Constructs the first instance of the EventThread
  EventThread(java.lang.ThreadGroup group, java.lang.String name, Queue queue)
          Constructs the first instance of the EventThread
 
Method Summary
 void addEvent(java.lang.Object event, boolean check)
          Adds an event in the event queue.
abstract  boolean checkTime()
          Checks if the thread is still active.
 java.lang.String getName()
           
 java.lang.Thread getThread()
           
abstract  int getThreadPriority()
          Returns the desired thread priority.
abstract  void newEventDispatcher()
          The method must create a new EventThread instance, using super.EventThread(this) and start it.
abstract  void print(java.lang.Throwable t)
          Logs the error.
abstract  void processEvent()
          Performs the actual event delivery.
 void run()
          Processes the event queue.
 void start()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bad

public java.lang.Object bad
The last callbacked listener. If the events thread is not responding, subclasses can take the appropriate actions - remove the listener for example


queue

protected Queue queue
The event queue. This object must be used for synchronization with the events thread's state


state

protected int state
The state of the thread.
  • bit 0: 0 = started / 1 = stopped;
  • bit 1: 0 not waiting / 1 = waiting


  • time

    protected long time
    The time spent in the current callback, or 0 if the thread is not in a callback


    counter

    protected int counter
    Instancies counter. Subclasses must not modify it.


    element

    protected java.lang.Object element
    The event to be dispatched


    baseName

    protected java.lang.String baseName

    name

    protected java.lang.String name

    thread

    protected java.lang.Thread thread

    group

    protected java.lang.ThreadGroup group
    Constructor Detail

    EventThread

    public EventThread(java.lang.ThreadGroup group,
                       java.lang.String name,
                       int size)
    Constructs the first instance of the EventThread

    Parameters:
    group - The ThreadGroup of the thread, or null for the current thread group
    name - The base name of the thread. The counter value will be added at the end of the string to construct the full name.
    size - The initial number of elements of the events queue

    EventThread

    public EventThread(java.lang.ThreadGroup group,
                       java.lang.String name,
                       Queue queue)
    Constructs the first instance of the EventThread

    Parameters:
    group - The ThreadGroup of the thread, or null for the current thread group
    name - The base name of the thread. The counter value will be added at the end of the string to construct the full name.
    queue - The events queue

    EventThread

    protected EventThread(EventThread old)
    Constructs a new EventThread, after the old event thread has stopped responding

    Parameters:
    old - The previous instance
    Method Detail

    start

    public void start()

    addEvent

    public void addEvent(java.lang.Object event,
                         boolean check)
    Adds an event in the event queue. The method must be synchronized outside, on the queue field.

    Parameters:
    event - The event to add
    check - If true, the method will check if the EventThread is still responding

    run

    public void run()
    Processes the event queue. Sets the event to be dispathed in the element field and calls processEvent

    Specified by:
    run in interface java.lang.Runnable

    getThread

    public java.lang.Thread getThread()

    getName

    public java.lang.String getName()

    getThreadPriority

    public abstract int getThreadPriority()
    Returns the desired thread priority. Called in the constructors of the class in order to set the returned value to the thread.

    Returns:

    processEvent

    public abstract void processEvent()
    Performs the actual event delivery. The event is stored in the element field. The method is supposed to perform the following for every listener:
  • synchronized on queue check the state of the thread - if it si closed - return
  • set the fields bad and time
  • callback
  • set bad to null and time to 0


  • checkTime

    public abstract boolean checkTime()
    Checks if the thread is still active. The fields time and bad must be used. The method is called from the addEvent method - thus should be synchronizes on the queue field outside and additional synchronization is not needed.


    newEventDispatcher

    public abstract void newEventDispatcher()
    The method must create a new EventThread instance, using super.EventThread(this) and start it.


    print

    public abstract void print(java.lang.Throwable t)
    Logs the error.

    Parameters:
    t -

    Framework Professional Edition Package


    Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved