cacheWorker.README.html Maven / Gradle / Ivy
vFabric™ GemFire®
cacheWorker
OSGi Application Bundle Example
This project is part of the cacheWorker and
cacheWorkerFragment OSGi Deployment Example. Contained herein is the
source code for the cacheWorker example application and the Ant build.xml for
building it as a JAR that's ready to be deployed as an OSGi bundle. This
project is presented as a template to extend and use for building your own
GemFire application for deployment as an OSGi bundle.
Locating the GemFire product
By default, the Ant build.xml will attempt to use GEMFIRE_HOME if this is
defined as an environment variable. You can edit the build.xml and hardcode
the "gemfire.home" property value if you prefer:
The value of "gemfire.home" must be a valid GemFire installation with a
GEMFIRE_HOME/lib directory containing gemfire.jar.
Locating the Bundlor task definitions for Ant
You can download Bundlor from
http://www.springsource.org/bundlor. Unzip the bundlor-1.0.0.RELEASE.zip
file to BUNDLOR_HOME.
By default the Ant build.xml will attempt to use BUNDLOR_HOME if this is
defined as an environment variable. You can edit the build.xml and hardcode
the "bundlor.home" property value if you prefer:
Modifying the GemFire configuration files
The cacheWorker example application defines its GemFire Cache using the
configuration files found in src/main/config:
- cache.xml - defines the cache config
- gemfire.properties - defines the distribution config
These are examples; feel free to alter them for your environment. The
example source code assumes it can find the "exampleRegion" defined in
the cache.xml. Note that an OSGi bundle cannot export the "default" package
and since these end up stored in the root of the cacheworker.jar, only the
cacheWorker application in this bundle can access them and use them to
configure GemFire.
Using the Ant build.xml
The supplied build.xml will locate all the necessary files, compile the
example source code, package it as a .jar and use bundlor to transform
it into an OSGi bundle.
Simply type "ant". The default target is "all" which will compile, package,
and use bundlor. The cacheWorker/target directory will contain the bundle
cacheworker-1.0.0.jar ready for deploying into an OSGi container in which
you've also deployed the GEMFIRE_HOME/lib/gemfire.jar,
GEMFIRE_HOME/lib/antlr.jar and cacheworker.fragment-1.0.0.jar bundles.
There's also a "debug" target to unjar the bundle as a convenience for
viewing the generated MANIFEST.MF and other contents of
cacheworker-1.0.0.jar.
About the example application
The example application has lifecycle controlled by a bundle activator.
When the bundle is started, the CacheWorkerActivator will start the
CacheWorker which creates a GemFire Cache and then uses it. The Cache it
defines will also register cacheworker.SimpleCacheListener which then receives
various notifications and prints to System.out. The GemFire bundle will load
the cacheworker.SimpleCacheListener class from the cacheWorker bundle via the
imports defined by the attached cachWorkerFragment bundle. A GemFire thread
then invokes the listener callbacks while the CacheWorker is running. When
the CacheWorker's bundle is stopped, it will close the Cache it created.
Instructions for running cacheWorker in Virgo Server 2.1.1
Assuming VIRGO_HOME is the location for your installation of
Virgo Server 2.1.1, copy the
GEMFIRE_HOME/lib/gemfire.jar and the GEMFIRE_HOME/lib/antlr.jar files into
the VIRGO_HOME/repository/usr directory. The GEMFIRE/lib/antlr.jar bundle
is required in order to use the GemFire QueryService.
Next, copy the example cacheworker.fragment-1.0.0.jar into
VIRGO_HOME/repostiory/usr. Startup the Virgo Server 2.1.1 process. After it has
completed startup, copy the example cacheworker-1.0.0.jar into the
VIRGO_HOME/pickup directory. Virgo will detect the presence of the JAR and
initiate deployment of the example. The example will successfully start and
begin using a GemFire Cache only if the GEMFIRE_HOME/lib/gemfire.jar,
GEMFIRE_HOME/lib/antlr.jar and cacheworker.fragment-1.0.0.jar have all been
copied into the VIRGO_HOME/repostiory/usr directory. Output from the example
will print to the VIRGO_HOME/serviceability/logs/log.log file.