Spaces
XOOM Spaces uses our cluster-based Grid as both a distributed object storage and a means of object exchange within a single scaled microservice (i.e. Bounded Context).
XOOM Spaces facilitates local and distributed object storages and exchanges. A distributed space can exist over a number of clustered XOOM Grid nodes, and is transactionally replicated for fail-safe access. A distributed space keeps frequently used data near the actor behaviors and processes that need it.
Such technologies are often referred to as data grids and data fabrics. Even so, the distributed cached data is only half of the story. The point is to use the distributed object storage for the business-driven operational purposes of the application.
Using Spaces
To start a local or distributed Spaces first you need to obtain an Accessor
instance:
An Accessor
instance is used to create either a local or a distributed space. Overloaded spaceFor(...)
methods are used to create a local Space
instance, whereas the distributedSpaceFor(...)
overloaded methods are employed to create a distributed Space
instance. It is important to mention here that local and distributed spaces are represented by the Space
protocol, which in both cases is backed by an actor. When the Space is local only, the actor resides only on the one node. On the other hand, a distributed Space
has a backing actor on a number of different clustered Grid
nodes.
Space type
The Space
protocol is the central component of Spaces API:
It contains the Space
messages put()
, get()
, and take()
. The get()
and take()
methods accept Period
parameter. This value indicates how long the result will be to be awaited. Also any new Item
added to a Space
has a Lease
property. This property defines the length of time the Item
will be stored, which can be indefinitely. When a lease expires, the Item
is evicted from the Space
. The Period
and Lease
values work together.
The following table describes the full Space
protocol.
put(Key key, Item<T> item)
Puts a new Item<T>
that is referenced by the Key
into the Space
, or replaces an existing Item<T>
in the Space
matching Key
with the given Item
. The new Item
and its Key
are eventually answered as a KeyItem
pair.
get(Key key, Period until)
Gets and eventually answers the Item
identified by the Key from the Space. If the Key
does not (yet) exist, a periodic query is run until the defined Period
elapses or the Key
is resolved, whichever occurs first. The Period
may be None
, Forever
, or some other period of time between the two extremes. The found Item
and its Key
are eventually answered as an Optional
of KeyItem
pair; otherwise, if not found, an empty Optional
is eventually answered.
take(Key key, Period until)
Takes the Item
identified by the Key
out from the Space
by removing it. If the Key
does not (yet) exist, a periodic query is run until the defined Period
elapses or the Key
is resolved, whichever occurs first. The Period
may be None
, Forever
, or some other period of time between the two extremes. The found Item
and its Key
are eventually answered as an Optional
of KeyItem
pair; otherwise, if not found, an empty Optional
is eventually answered.
Last updated