protoj.core
Class DispatchFeature

java.lang.Object
  extended by protoj.core.DispatchFeature

public final class DispatchFeature
extends java.lang.Object

Responsible for dispatching each instruction from the InstructionChain to the matching command and executing that command. See dispatchCommands().

Author:
Ashley Williams

Constructor Summary
DispatchFeature(CoreProject parent)
          The created instance will be configured to bootstrap to the currently running jvm.
 
Method Summary
 void dispatchCommands()
          Iterates over all the instructions from CoreProject.getInstructionChain() and executes each corresponding command from CoreProject.getCommandStore().
 java.lang.String getCurrentMainClass()
          Calculates the name of the main() method containing class that was used to start the currently executing vm.
 long getElapsedHours()
          The elapsed time in hours.
 long getElapsedMinutes()
          The elapsed time in minutes.
 long getElapsedSeconds()
          The elapsed time in seconds.
 java.lang.String getMainClass()
          The main() method containing entry point class for the new vm.
 java.lang.String getMainMemory()
          The maximum amount of memory that should be allocated by the new vm.
 CoreProject getProject()
           
 ProjectReporter getReporter()
          The helper used to report dispatch progress.
 ArgRunnable<StartVmCommand> getStartVmConfig()
          The instance used to provide additional configuration before the vm is launched inside the startVm(String, String[], String, ArgRunnable) method.
 java.io.File getWeaverJar()
          The jar file used for load time weaving, or null if not configured.
 void initBootstrap(java.lang.String mainClass, java.lang.String mainMemory)
          Call in order to be able to start to the specified project main with the specified amount of memory.
 void initLoadTimeWeaving(java.lang.String partialName)
          ProtoJ commands are each executed in their own virtual machines.
 boolean isScriptVm()
          Returns whether or not the current vm was started directly from the shell script or in code by using the startVm(String, String[], String, ArgRunnable) method.
 boolean isStatusWindow()
          Returns whether or not the dispatchCommands() will exit with a gui.
 void setStartVmConfig(ArgRunnable<StartVmCommand> startVmConfig)
          See setStartVmConfig(ArgRunnable).
 void setStatusWindow(boolean statusWindow)
          See isStatusWindow().
 StartVmCommand startVm(java.lang.String mainClass, java.lang.String[] args, java.lang.String memory, ArgRunnable<StartVmCommand> config)
          Starts a forked vm with the specified parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DispatchFeature

public DispatchFeature(CoreProject parent)
The created instance will be configured to bootstrap to the currently running jvm.

Parameters:
parent -
Method Detail

initBootstrap

public void initBootstrap(java.lang.String mainClass,
                          java.lang.String mainMemory)
Call in order to be able to start to the specified project main with the specified amount of memory. Instructions that don't have commands available in the initial vm are delegated to the project vm.

Parameters:
mainClass -
mainMemory -

initLoadTimeWeaving

public void initLoadTimeWeaving(java.lang.String partialName)
ProtoJ commands are each executed in their own virtual machines. Use this method to ensure that aspectj load time weaving is globally used. This works by using the weaver jar as a java agent when the vm is started, so the name of the jar file must be specified.

The lib directory will be searched for a jar file whose name contains the partial name parameter, which will be used as the javaagent jarpath. Specify null to use the default, which is "aspectjweaver.jar". If there is no match or more than one match is found then an exception is thrown

Parameters:
partialName - the partial name, specify null to use "aspectjweaver.jar"

getReporter

public ProjectReporter getReporter()
The helper used to report dispatch progress.

Returns:

getElapsedHours

public long getElapsedHours()
The elapsed time in hours.

Returns:

getElapsedMinutes

public long getElapsedMinutes()
The elapsed time in minutes.

Returns:

getElapsedSeconds

public long getElapsedSeconds()
The elapsed time in seconds.

Returns:

dispatchCommands

public void dispatchCommands()
Iterates over all the instructions from CoreProject.getInstructionChain() and executes each corresponding command from CoreProject.getCommandStore(). The instructions usually originate from the command line but may have been specified in-code.

Where there is no corresponding command in the command store then we assume that this code is running in the hand-compiled bootstrapping vm that contains just the bare minimum of commands. Therefore we attempt to bootstrap to the main project vm resulting in the following behavior:


startVm

public StartVmCommand startVm(java.lang.String mainClass,
                              java.lang.String[] args,
                              java.lang.String memory,
                              ArgRunnable<StartVmCommand> config)
Starts a forked vm with the specified parameters. Advice is also applied at a joinpoint for this method from the StandardConfig aspect in order to apply any debug settings.

This method was added to support Command.execute(Instruction), since it needs to restart the same vm for the purpose of reconfiguring memory.

Parameters:
mainClass - the class that contains the main() method
args - the arguments to the main method
memory - the maximum amount of memory to be assigned to the new vm
config - the callback used to configure the vm before it is executed
Returns:

getCurrentMainClass

public java.lang.String getCurrentMainClass()
Calculates the name of the main() method containing class that was used to start the currently executing vm.

Returns:

getMainClass

public java.lang.String getMainClass()
The main() method containing entry point class for the new vm.

Returns:

getMainMemory

public java.lang.String getMainMemory()
The maximum amount of memory that should be allocated by the new vm.

Returns:

isScriptVm

public boolean isScriptVm()
Returns whether or not the current vm was started directly from the shell script or in code by using the startVm(String, String[], String, ArgRunnable) method. Each time startVm() is called, the SCRIPT_VM_PROPERTY is added as a jvm arg so that we can tell the difference.

Returns:

setStatusWindow

public void setStatusWindow(boolean statusWindow)
See isStatusWindow().

Parameters:
statusWindow -

isStatusWindow

public boolean isStatusWindow()
Returns whether or not the dispatchCommands() will exit with a gui. If true then a window will be displayed with a green background indicating no errors or a red background indicating errors. The window will fill the screen and the application will exit when it is closed. It is an error to set this property to true in a headless environment resulting in an exception.

Returns:

setStartVmConfig

public void setStartVmConfig(ArgRunnable<StartVmCommand> startVmConfig)
See setStartVmConfig(ArgRunnable).

Parameters:
startVmConfig -

getStartVmConfig

public ArgRunnable<StartVmCommand> getStartVmConfig()
The instance used to provide additional configuration before the vm is launched inside the startVm(String, String[], String, ArgRunnable) method.

Returns:

getProject

public CoreProject getProject()

getWeaverJar

public java.io.File getWeaverJar()
The jar file used for load time weaving, or null if not configured.

Returns: