[[space_factory]]
== 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
====
[source,java]
----
   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: 

[source,java]
----
   Space sp = SpaceFactory.getSpace("tspace");
----

...which is also the same as calling: 

[source,java]
----
   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}}+ 

.Space Names
[options="header", cols="2,6"]
|===============
|Type|Implementation
|tspace|
Creates or returns a reference to a previously-created instance of +TSpace+
|jdbm|
Creates or returns a reference to a previously-created instance of
+JDBMSpace+. This name accepts an optional
parameter (after the Space name) which is a path to the persistent
store, e.g., +jdbm:myspace:/tmp/myspace+.
|je|
Creates or returns a reference to a previously-created instance of
+JESpace+. This name accepts an optional parameter (after the Space name) 
which is a path to the persistent store, e.g., +jdbm:myspace:/tmp/myjespace+.
|spacelet|
Returns a reference to a previously-created instance of +SpaceLet+
|===============

[NOTE]
======
Some components communicate through a **default space** that may change
over time, so it is very important to +SpaceFactory.getSpace()+ instead
of instantiating your own. In previous versions, the default space was
+transient:default+, and now is +tspace:default+ but this may change
in future versions of jPOS as new Space implementations become available.

By sticking to +SpaceFactory.getSpace()+ jPOS will give you always the
default space for the version you're using.
======

