|
Summary: Setting worker names, implementation classes and arguments.
OverviewThe space workers allows you to run your business logic in the space JVM. The space starts the worker business logic when started and stops it when closed. As opposed to the space filters and the replications filters, the space does not call the worker implementation when a space operation is called. Worker Interfacepublic interface com.j_spaces.worker.IWorker extends java.lang.Runnable.
Worker SchemaThe space schema file should include the following when introducing a worker to the space: <space-config> <workers> <worker-names>WorkerName</worker-names> <!--interrupt the worker on shutdown--> <interrupt>false</interrupt> <WorkerName> <enabled>true</enabled> <class-name>worker_class_implementation</class-name> <arg>some free text</arg> <description>worker description</description> <active-when-backup>false</active-when-backup> <shutdown-space-on-init-failure>true</shutdown-space-on-init-failure> <instances>1</instances> </WorkerName> </workers> </space-config>
ExampleYou can download a simple IWorker example. See the \iworker\config\schemas space schema with the following worker definition: <workers>
<worker-names>MyWorker</worker-names>
<!--interrupt the worker on shutdown-->
<interrupt>false</interrupt>
<MyWorker>
<enabled>true</enabled>
<class-name>worker.MyWorker</class-name>
<arg></arg>
<description>MyWorker</description>
<active-when-backup>false</active-when-backup>
<shutdown-space-on-init-failure>true</shutdown-space-on-init-failure>
<instances>1</instances>
</MyWorker>
</workers>
The Worker Implementation: package worker; import com.j_spaces.core.IJSpace; import com.j_spaces.worker.IWorker; public class MyWorker implements IWorker { public void init(IJSpace space, String arg1, String arg2) throws Exception { System.out.println(" ************ MyWorker init()"); System.out.println(" ************ MyWorker space:" + space); } public void close() { System.out.println(" ************ MyWorker close()"); } public void run() { System.out.println(" ************ MyWorker run()"); } } When the space is started, the following should be displayed: ************ MyWorker init() ************ MyWorker space:com.j_spaces.core.client.JSpaceProxy@ededef6e ************ MyWorker run() |
Wiki Content Tree
Your Feedback Needed!
We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.
Add Comment