Space Factory
jPOS comes with several space implementations:
- TSpace : An in-memory space footnote:[TSpace implements LocalSpace]
- JDBMSpace : a persistent JDBM based space implementation
- JESpace : a persistent Berkeley DB Java Edition based implementation
that can be instantiated using the SpaceFactory.
Although most Space implementations have either public constructors or factory methods that can be used to create instances of their respective classes, we highly recommend using the SpaceFactory
as the entry point for space creation or to obtain references to spaces that were previously created.
Using the SpaceFactory is very simple:
import org.jpos.space.Space;
import org.jpos.space.SpaceFactory;
Space sp = SpaceFactory.getSpace();
The previous example returns a reference to the default space, which happens to be a TSpace implementation registered with the name default
. It's the same as calling:
Space sp = SpaceFactory.getSpace("tspace");
which is also the same as calling:
Space sp = SpaceFactory.getSpace("tspace:default");
SpaceFactory decodes a space name based on the space implementation type, followed by an optional name and optional parameter(s): spacetype[:spacename[:spaceparam]]
Type | Implementation |
---|---|
tspace | Creates or returns a reference to a previously-created instance of TSpace . TSpace operates in memory and implements the LocalSpace` interface. |
jdbm | Creates or returns a reference to a previously-created instance of JDBMSpace . This type accepts an optional parameter (after the Space name) which is a path to the persistent store, e.g., jdbm:myspace:/tmp/myjespace . JDBMSpace is a persistent space based on the JDBM library. |
je | Creates or returns a reference to a previously-created instance of JESpace . This type accepts an optional parameter (after the Space name) which is a path to the persistent store, e.g., je:myspace:/tmp/myjespace . JESpace is a persistent space based on Berkeley DB Java Edition. |
Some components communicate through a default space, which can vary over time. Therefore, it's important to always use SpaceFactory.getSpace()
instead of creating your own space instance. While in previous versions the default space was identified as transient:default
, it has now been updated to tspace:default
. However, this default may change in future jPOS versions as new Space implementations are introduced. Using SpaceFactory.getSpace()
ensures that you always access the current default space for the version of jPOS you are using.