Java Gearman Service
- Project Page: https://github.com/gearman/java-service
The Java Gearman Service provides a complete gearman implementation in java. This includes the client, worker, and job server.
The Java Gearman Service jar file doubles as a fully featured gearman server.
java [jvm options] -jar java-gearman-service-X.Y.Z.jar [server options]
The server options will specify the server’s system variables and/or tell the server what actions to take. The following is a list of the available options.
|Short Name||Long Name||Description|
||Defines what port number the server will listen on (Default: 4730)|
||Display the version of java gearman service and exit|
||Print the help menu and exit|
The following is a list of some applicable jvm options.
||Use Server HotSpot VM. Must be first option (HotSpot Only)|
org.gearman.Gearman objects define gearman systems and creates gearman
services. These services include
GearmanServers. All services created by the same
are said to be in the same system, and all services in the same system
share system wide thread resources.
The following example shows how to create a gearman system using 8 threads and how to create the three gearman services:
org.gearman.GearmanWorker objects receive
GearmanJobs and distributes them
Adding Job Servers
The purpose of a
GearmanWorker is to grab jobs from a job servers implementing
the gearman protocol. For this to work, the user
will need to specify what job servers the
GearmanWorker may grab from.
JGS provides an API for creating and managing job servers in the local address
GearmanServer API. This makes it possible for services to
communicate directly with a local job server.
The following example adds a running
GearmanServer to the
allowing for direct communication (without a TCP socket):
Adding Remote Servers
GearmanWorker can connect to any job server implementing the
gearman protocol (See the
download page for more job server
implementations). This allows the user to build a very scalable
multilingual distributed system.
The following example adds a remote job server that implements the gearman protocol:
The user will also need provide a mapping from function names to
GearmanFunction objects. This will tell the worker what job queues to grab
from and what
GearmanFunction to invoke when a job is received.
The following example sets up a simple
GearmanWorker. It shows how to create
GearmanWorker, register a
GearmanFunction, and add a job server.
org.gearman.GearmanClient objects dispatch
GearmanJobs to the job servers.