ActiveModule

public abstract class ActiveModule extends Module implements Runnable

ActiveModule is a runnable module which runs as a separated thread after started. Subclasses are expected to implement the run() method in the Runnable interface.

Author:Hugo Y. K. Lam

Constructors

ActiveModule

public ActiveModule(String descriptorLocation)

Creates a new instance of ActiveModule.

Parameters:
  • descriptorLocation – the module descriptor.
Throws:
  • ModuleException – if errors encountered when loading the module descriptor.

ActiveModule

public ActiveModule(String descriptorLocation, boolean shouldInitialize)

Creates a new instance of ActiveModule.

Parameters:
  • descriptorLocation – the module descriptor.
  • shouldInitialize – true if the module should be initialized.
Throws:
  • ModuleException – if errors encountered when loading the module descriptor.

ActiveModule

public ActiveModule(String descriptorLocation, ClassLoader loader)

Creates a new instance of ActiveModule.

Parameters:
  • descriptorLocation – the module descriptor.
  • loader – the class loader for this module.
Throws:
  • ModuleException – if errors encountered when loading the module descriptor.

ActiveModule

public ActiveModule(String descriptorLocation, ClassLoader loader, boolean shouldInitialize)

Creates a new instance of ActiveModule.

Parameters:
  • descriptorLocation – the module descriptor.
  • loader – the class loader for this module.
  • shouldInitialize – true if the module should be initialized.
Throws:
  • ModuleException – if errors encountered when loading the module descriptor.

Methods

execute

public abstract boolean execute()

Invoked by the run() method to execute this module’s job.

Returns:true if this method should be invoked again after a defined interval.

getThread

public Thread getThread()

Gets the thread of this module.

Returns:the thread of this module.

init

public void init()

Initializes this module by the following module parameters:

  • group-execution: all - started and stopped by its group; start - only started by its group; stop - only stopped by its group; none - not started or stopped by its group.
  • execution-interval: the interval (milliseconds) that this module should wait until the next execution. A negative number indicates a one-time execution.
  • stop-timeout: the maximum time (milliseconds) to wait for stopping this module.

isGroupStart

public boolean isGroupStart()

Checks if this module should be started by its group, if any.

Returns:true if this module should be started by its group.

isGroupStop

public boolean isGroupStop()

Checks if this module should be stopped by its group, if any.

Returns:true if this module should be stopped by its group.

onStart

public void onStart()

Invoked when this module starts.

See also: .start()

onStop

public void onStop()

Invoked when this module stops.

See also: .stop()

run

public void run()

Invoked by the start() method and will continuously call the execute() method to carry out the execution. This method should not be invoked directly.

See also: .start(), .execute(), java.lang.Runnable.run()

setExecutionInterval

public void setExecutionInterval(long newInterval)

Set the execution interval in the module.

start

public synchronized void start()

Starts this module. This method will invoke onStart() before starting its own thread.

See also: java.lang.Thread.start(), .onStart()

stop

public synchronized void stop()

Stops this module. This method will invoke onStop() before waiting for its thread to die.

See also: .waitForStop(), .onStop()

waitForStop

public synchronized void waitForStop()

Waits for this module’s thread to die.