net.sf.ivmaidns.util
Interface SafeRunnable

All Known Implementing Classes:
ActivityCore

public interface SafeRunnable

Interface for safely runnable objects. This interface provides the basis safe control over 'active' objects, which start running (single or multiple threads) on the creation and stop when done (or when Java VM terminates or when stop is requested by the user of the object). Active entities may be also interrupted, suspended and resumed safely.

Version:
2.0
Author:
Ivan Maidanski

Method Summary
 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.
 void resume()
          Resumes running after suspend.
 void stop()
          Initiates safe stop operation.
 void suspend()
          Initiates safe suspend operation.
 void waitSuspend()
          Initiates and waits for safe suspend.
 

Method Detail

interrupt

void interrupt()
Interrupts sleeping or waiting inside active object. Interruption means sending a special interrupt signal to each thread of active object (resulting in throwing of InterruptedException inside thread when it is waiting or sleeping). This method returns immediately.


suspend

void suspend()
Initiates safe suspend operation. This method just sets suspending flag which signals active object that all its threads (only which are alive) must be safely suspended (turned to sleeping state) as soon as possible. This method returns immediately.

See Also:
waitSuspend(), resume(), isSuspended(), stop()

waitSuspend

void waitSuspend()
Initiates and waits for safe suspend. This method sets suspending flag which signals active object that all its threads (only which are alive) must be safely suspended (turned to sleeping state) as soon as possible. This method returns just after all threads of active object have been suspended (or died).

See Also:
suspend(), resume(), isSuspended()

resume

void resume()
Resumes running after suspend. This method clears suspending flag, thus telling active object to resume normal running (stop sleeping) after safe suspend for all its still alive threads. This method returns immediately.

See Also:
suspend(), waitSuspend(), isSuspended()

stop

void stop()
Initiates safe stop operation. This method just sets stopping flag which signals active object that all its threads (only which are alive) must be safely terminated (stopped) as soon as possible. This method returns immediately. If active object is suspended then safe stop operation begins just when resuming.

See Also:
suspend(), resume(), join(), isSuspended(), isAlive()

join

void join()
Waits while active object is alive. This method infinitely waits for the death (termination) of all threads inside this active object.

See Also:
stop(), isAlive(), waitSuspend()

isSuspended

boolean isSuspended()
Tests whether this active object is suspended. This method just immediately returns suspended flag which is true only when active object is in safe-suspend state (and alive).

Returns:
true if and only if active object is suspended.
See Also:
suspend(), waitSuspend(), resume(), isAlive()

isAlive

boolean isAlive()
Tests whether this active object is still alive. This method just immediately returns the flag indicating that one or more threads (inside this active object) have not died yet.

Returns:
true if and only if active object is alive.
See Also:
stop(), join(), isSuspended()