com.github.libxjava.concurrent
Class AbstractSingleThreadRunner

java.lang.Object
  extended by com.github.libxjava.concurrent.AbstractSingleThreadRunner

public abstract class AbstractSingleThreadRunner
extends Object

Version:
libxjava-cldc - 0.3
Author:
Marcel Patzlaff

Field Summary
static byte STARTED
           
static byte STOPPED
           
 
Constructor Summary
protected AbstractSingleThreadRunner(String name)
           
 
Method Summary
protected abstract  void doRun()
           
protected  void forkExecution(Runnable runnable, String name)
          This method is called on behalf of the start() method.
 String getName()
           
protected  boolean isCancelled()
           
 boolean isInState(byte requiredState)
           
 boolean start()
           
 boolean stop()
           
protected  void unblock()
          This method is called on behalf of the stop() method.
 boolean waitForState(int timeout, byte requiredState)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STARTED

public static final byte STARTED
See Also:
Constant Field Values

STOPPED

public static final byte STOPPED
See Also:
Constant Field Values
Constructor Detail

AbstractSingleThreadRunner

protected AbstractSingleThreadRunner(String name)
Method Detail

getName

public final String getName()

start

public final boolean start()

stop

public final boolean stop()

isInState

public final boolean isInState(byte requiredState)

waitForState

public final boolean waitForState(int timeout,
                                  byte requiredState)
                           throws InterruptedException
Throws:
InterruptedException

doRun

protected abstract void doRun()

forkExecution

protected void forkExecution(Runnable runnable,
                             String name)
This method is called on behalf of the start() method. It must set up the concurrent execution of the specified runnable.

The default implementation just creates a new thread and starts it.

Parameters:
runnable - to execute in a concurrent thread
name - an optional name for the thread

unblock

protected void unblock()
This method is called on behalf of the stop() method.

If the runner performs blocking operations like I/O reads or synchronized waits, the implementing class should unblock/notify the runner in this method.

The default implementation just signals interruption to the working thread


isCancelled

protected final boolean isCancelled()


Copyright © 2011 Marcel Patzlaff. All Rights Reserved.