to.etc.domui.state
Class DelayedActivitiesManager

java.lang.Object
  extended by to.etc.domui.state.DelayedActivitiesManager
All Implemented Interfaces:
java.lang.Runnable

public class DelayedActivitiesManager
extends java.lang.Object
implements java.lang.Runnable

This helper class does all of the handling for delayed activities for a conversation. It contains all activity queues plus all handling of the executor thread.

Author:
Frits Jalvingh Created on Oct 7, 2008

Constructor Summary
protected DelayedActivitiesManager(ConversationContext conversation)
           
 
Method Summary
 void applyToTree(DelayedActivityState das)
          Apply all activity changes to the page.
 boolean callbackRequired()
          Returns whether the client needs to use it's polltimer again and poll for changes.
 boolean cancelActivity(DelayedActivityInfo dai)
          Cancels an activity, if possible.
 void cancelActivity(IActivity a)
           
 boolean isTerminated()
           
 void processDelayedResults(Page pg)
           
<T extends NodeContainer & IPolledForUpdate>
void
registerPoller(T nc)
          Registers a node as a thingy which needs to be called every polltime seconds to update the screen.
 void run()
          Main action runnert.
 DelayedActivityInfo schedule(IActivity a, AsyncContainer ac)
          Schedule a new activity for execution.
 boolean start()
          Initiate background processing, if needed.
 void terminate()
          Forcefully terminate all handling of actions.
<T extends NodeBase & IPolledForUpdate>
void
unregisterPoller(T nc)
          Deregister a node from the poll-regularly queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelayedActivitiesManager

protected DelayedActivitiesManager(ConversationContext conversation)
Method Detail

schedule

public DelayedActivityInfo schedule(IActivity a,
                                    AsyncContainer ac)
Schedule a new activity for execution. This does not actually start the executor; it merely queues the thingy. If the executor *is* running though it can start with the action.

Parameters:
a -
Returns:

cancelActivity

public void cancelActivity(IActivity a)

cancelActivity

public boolean cancelActivity(DelayedActivityInfo dai)
Cancels an activity, if possible. If the thing is pending it gets removed. If it is executing we try to cancel the executor.

Parameters:
dai -

start

public boolean start()
Initiate background processing, if needed. Returns T if background processing is active, or when data is present in the completion queue.


callbackRequired

public boolean callbackRequired()
Returns whether the client needs to use it's polltimer again and poll for changes.

Returns:

isTerminated

public boolean isTerminated()

terminate

public void terminate()
Forcefully terminate all handling of actions. Called at conversation close time. This marks this thingy as terminated (which will prevent any still running thread from barfing all over it's corpse), then clears all queues and tries to clobber the thread to death. It does so by first marking the IActivity as "cancelled", then by interrupting the thread. After this the thread is left to it's own devices; if it does not stop immediately but only after it's task has completed it's "result completed" handler will catch the fact that it's actually trying to fondle a dead body and throw (up).


run

public void run()
Main action runnert. This is the thread's executor function. While the manager is active this will execute activities in the PENDING queue one by one until the queue is empty. If that happens it will commit suicide. This suicidal act will not invalidate the manager; at any time can new actions be posted and a new thread be started.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

applyToTree

public void applyToTree(DelayedActivityState das)
Apply all activity changes to the page. The page is either in "full render" or "delta render" modus.

Parameters:
das -

processDelayedResults

public void processDelayedResults(Page pg)
                           throws java.lang.Exception
Throws:
java.lang.Exception

registerPoller

public <T extends NodeContainer & IPolledForUpdate> void registerPoller(T nc)
Registers a node as a thingy which needs to be called every polltime seconds to update the screen. This is not an asy action by itself (it starts no threads) but it will cause the poll handler to start, and will use the same response mechanism as the asy callback code.

Type Parameters:
T -
Parameters:
nc -

unregisterPoller

public <T extends NodeBase & IPolledForUpdate> void unregisterPoller(T nc)
Deregister a node from the poll-regularly queue.

Type Parameters:
T -
Parameters:
nc -