Package com.zfabrik.launch
Class ProcessRunner
- java.lang.Object
-
- com.zfabrik.launch.ProcessRunner
-
public class ProcessRunner extends java.lang.ObjectThis utility class is used to initialize a z2 core within another Java process. In other words this class allows to use z2 embedded.This class can be used on its own and is provided with the jar library z.jar that can be found in the
binfolder of a z2 home installation.There are some important considerations and pre-requisites to run z2 embedded successfully:
- The location of a z2 home installation must be set be either setting the system property
com.zfabrik.homeor by specifying an environment propertyZ2_HOMEpointing to a z2 home installation. This is required so that the root repository information (inZ2_HOME/bin/runtime.properties) local repository caches (inZ2_HOME/work) can be found. The system property takes precedence over the environment variable. - Many control flows in z2 require a WorkUnit on the current thread. In order to execute code safely within the z2 environment, encapsulate it as a Runnable or a Callable and use the work methods below.
public static void main(String[] args) throws Exception { ProcessRunner.start(); ProcessRunner.work(new CallableProcess running is cumulative. Repeated start/stop calls will be counted and only the outer calls are really effectiv.() { public Void call() throws Exception { ((Runnable) new InitialContext().lookup("components:<my component>?type="+Runnable.class.getName())).run(); return null; } }); ProcessRunner.stop(); } - Author:
- hb
- The location of a z2 home installation must be set be either setting the system property
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCOM_ZFABRIK_HOMEstatic java.lang.StringZ2_HOME
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidbeginWork()Begin a unit of work.static voidcloseWork()End a unit of work.booleanisRunning()check if the process is already initializedstatic voidsetRollBackOnly()Flag a unit of work as rollback only.static voidstart()Initialize the z2 environment in this process.static voidstop()stop the z2 environment in this process.static voidwork(java.lang.Runnable r)Tasks in z2 generally require an association with a work unit (an abstract transaction).static <T> Twork(java.util.concurrent.Callable<T> c)Tasks in z2 generally require an association with a work unit (an abstract transaction).
-
-
-
Field Detail
-
Z2_HOME
public static final java.lang.String Z2_HOME
- See Also:
- Constant Field Values
-
COM_ZFABRIK_HOME
public static final java.lang.String COM_ZFABRIK_HOME
- See Also:
- Constant Field Values
-
-
Method Detail
-
start
public static void start()
Initialize the z2 environment in this process. Repeated calls will be ignored.
-
work
public static void work(java.lang.Runnable r)
Tasks in z2 generally require an association with a work unit (an abstract transaction). In order to execute code safely within the z2 environment, encapsulate it as aRunnableor aCallableand use thework(java.lang.Runnable)methods.
-
work
public static <T> T work(java.util.concurrent.Callable<T> c)
Tasks in z2 generally require an association with a work unit (an abstract transaction). In order to execute code safely within the z2 environment, encapsulate it as aRunnableor aCallableand use thework(java.lang.Runnable)methods.
-
beginWork
public static void beginWork()
Begin a unit of work. Make your to close the unit of work again. Better use the work methods, unless you are really required to spread begin and end of a unit of work to different points in the control flow.
-
closeWork
public static void closeWork()
End a unit of work. Better use the work methods, unless you are really required to spread begin and end of a unit of work to different points in the control flow.
-
setRollBackOnly
public static void setRollBackOnly()
Flag a unit of work as rollback only. I.e. the work will not be committed at the close of the unit of work but rather rolled back (if there is any).
-
isRunning
public boolean isRunning()
check if the process is already initialized
-
stop
public static void stop()
stop the z2 environment in this process.
-
-