|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.ivmaidns.util.ObservedCore
net.sf.ivmaidns.util.ActivityCore
public abstract class ActivityCore
Class for active observable entities.
This is a basis implementation of SafeRunnable
interface, which also extends ObservedCore class,
providing an easy way to create a custom active observable
object, which starts running on its creation and stops when done
or when safe stop is requested by the user of the object (or when
Java Virtual Machine terminates). Active objects may be also
interrupted, suspended and resumed. The activity of such object
is implemented through the encapsulation of Thread
instance. Created thread is not daemon (unless current
thread is a daemon). Important notes: the Java Virtual Machine
exits when the only threads running are all daemons or if
exit(int) method of Runtime class is
called; Runnable interface is implemented here
entirely for the internal purpose.
| Field Summary | |
|---|---|
protected static int |
IDLE_SLEEP_MILLIS
Represents the default idle sleep time in milliseconds. |
| Constructor Summary | |
|---|---|
ActivityCore(java.lang.String name)
Constructs an active observable object with the specified thread name. |
|
| Method Summary | |
|---|---|
protected java.lang.Object |
clone()
Creates and returns a copy of this object. |
protected void |
done()
Custom clean-up method which is executed before normal termination of this active object. |
protected void |
init()
Custom initialization method which is executed just at the beginning of the execution of this active object. |
void |
integrityCheck()
Verifies this object for its integrity. |
void |
interrupt()
Interrupts sleeping or waiting inside active object. |
boolean |
isAlive()
Tests whether this active object is still alive. |
boolean |
isSuspended()
Tests whether this active object is suspended. |
void |
join()
Waits while active object is alive. |
protected abstract boolean |
loop()
Custom action main method which is executed in this
active object as many times as needed. |
void |
resume()
Resumes running after suspend. |
void |
run()
The thread execution body (an internal method). |
void |
stop()
Initiates safe stop operation. |
void |
suspend()
Initiates safe suspend operation. |
void |
trimToSize()
Frees extra memory. |
void |
waitSuspend()
Initiates and waits for safe suspend. |
| Methods inherited from class net.sf.ivmaidns.util.ObservedCore |
|---|
addObserver, hasObservers, notifyObservers, removeObserver |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final int IDLE_SLEEP_MILLIS
int (positive) value is used as a default
argument for wait(long) of Object class
and for sleep(long) of Thread class
when infinitely waiting for a particular event.
| Constructor Detail |
|---|
public ActivityCore(java.lang.String name)
throws java.lang.NullPointerException
this constructed object
may safely suspend/resume or stop its activity at any time (while
it is running). name is entirely used to identify the
thread in the computer system (for the purpose of the system
performance monitoring).
name - the name (must be non-null) of created
thread.
java.lang.NullPointerException - if name is null.
java.lang.OutOfMemoryError - if there is not enough memory.
java.lang.InternalError - if Java VM internal error occurs or if the security manager
prohibits the creation of a new thread.run(),
stop(),
join(),
isAlive()| Method Detail |
|---|
protected void init()
this active object.
This method is only called internally once (in the encapsulated
thread, not in the constructor) before calling
loop(). If OutOfMemoryError is thrown
then loop() is skipped and done() is
called. This method should be protected final in the
subclasses if overridden (if not overridden then it is dummy).
java.lang.OutOfMemoryError - if there is not enough memory.ActivityCore(java.lang.String),
loop(),
done(),
run()protected abstract boolean loop()
this
active object as many times as needed.
This method is only called internally (in the encapsulated
thread) many times (may be none) while soft stop is not requested
and result is true. If OutOfMemoryError
is thrown then loop() is not called anymore and
done() is called. This method should be
protected final in the subclasses.
true only if this method requests to be called
again.
java.lang.OutOfMemoryError - if there is not enough memory.init(),
done(),
run(),
stop()protected void done()
this active object.
This method is called internally once (in the encapsulated
thread) at the end after calling loop() method. This
method is called even if soft stop operation is being performed
or even if loop() (or init()) method
has just thrown OutOfMemoryError. If this method
throws OutOfMemoryError then it is caught silently.
This method should be protected final in the
subclasses if overridden (if not overridden then it is dummy).
java.lang.OutOfMemoryError - if there is not enough memory.init(),
loop(),
run(),
stop()public final void run()
Thread object when thread of
this is initialized (when this active
object is constructed). This method first calls
init() method then calls loop() many
times while it returns true, then calls
done() (semantics of all these three methods is
defined by the subclass), and returns. Each time, before calling
loop(), this method analyses the state of
suspending and stopping to perform safe
suspend/resume and stop operations whenever they are requested by
the user of this active object. If
suspending is set then this method waits (before
calling loop()) while suspending remains
set. Setting of stopping would stop looping, this
method calls done() and returns. If
OutOfMemoryError is thrown during execution of these
'init/loop/done' methods then it is silently ignored and has the
same effect as if stopping is true.
Important notes: on return of this method thread is
terminated; if this method is called outside Thread
then it does nothing.
run in interface java.lang.RunnableActivityCore(java.lang.String),
suspend(),
waitSuspend(),
resume(),
stop()public void trimToSize()
trimToSize in interface TrimToSizeabletrimToSize in class ObservedCoreActivityCore(java.lang.String)public void interrupt()
InterruptedException inside thread when it is
waiting or sleeping). This method returns immediately. This
method may be overridden in the subclasses. Important notes:
current thread interruption status may be cleared via
sleep(0) of Thread class.
interrupt in interface SafeRunnableisAlive()public void suspend()
suspend in interface SafeRunnablewaitSuspend(),
resume(),
isSuspended(),
stop()public void waitSuspend()
waitSuspend in interface SafeRunnablesuspend(),
resume(),
isSuspended()public final void resume()
resume in interface SafeRunnablesuspend(),
waitSuspend(),
isSuspended()public void stop()
stop in interface SafeRunnablesuspend(),
resume(),
join(),
isSuspended(),
isAlive()public final void join()
join in interface SafeRunnablestop(),
isAlive(),
waitSuspend()public final boolean isSuspended()
isSuspended in interface SafeRunnabletrue if and only if active object is suspended.suspend(),
waitSuspend(),
resume(),
isAlive()public final boolean isAlive()
isAlive in interface SafeRunnabletrue if and only if active object is alive.stop(),
join(),
isSuspended()
protected java.lang.Object clone()
throws java.lang.CloneNotSupportedException
this object.
The implementation of this method prohibits (since thread object
is not cloneable) the usage of standard clone()
method of Object (even in the subclasses) by
throwing CloneNotSupportedException. But, if needed,
this method may be overridden (and made public) in
the subclasses, providing 'pseudo-cloning' (through the
constructor of a subclass).
clone in class ObservedCorenull and != this) of
this instance.
java.lang.CloneNotSupportedException - if cloning is not implemented.
java.lang.OutOfMemoryError - if there is not enough memory.public void integrityCheck()
this object for its integrity.
For debug purpose only.
integrityCheck in interface VerifiableintegrityCheck in class ObservedCorejava.lang.InternalError - if integrity violation is detected.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||