Skip to main content

Space Basics

jPOS's Space component, although not a direct implementation of Linda, shares conceptual similarities. Familiarizing yourself with Linda can provide useful context and understanding of the Space component's design and functionality.

The Space component in jPOS functions similarly to a synchronized Map, where each key maps to a list of objects. The operations on this Map are thread-safe and executed atomically.

The Space component supports three primary operations:

  • void out (Object key, Object value): This method is used to add an object to the Space. If there's already an object associated with the specified key, the new object is appended to the end of the list under that key.
  • Object rd (Object key): This method retrieves, but does not remove, the first object associated with the specified key. If there is no object available, the method blocks until one becomes available.
  • Object in (Object key): Similar to rd, this method retrieves and removes the first object associated with the specified key. It also blocks if no object is available under the key until an object is put into the space.

These operations form the core of the Space component, allowing for synchronized, concurrent operations on a shared data structure.

tip

We picked those cryptic operation names after the Linda Coordination Language basic operations, but could have used easier to remember names such as:

  • write instead of out
  • read instead of just rd
  • take instead of in

After two consecutive 'out' operations using the same 'key' value, the Space would look like this (first entry is printed as a blue circle while the second one is red):

Then an rd operation would return the first entry (the blue one), without removing it from the space. The space remains with two entries for that particular key.

The 'in' operation on the other hand, takes the first entry (the blue one) off the Space, leaving just the red one.

At this point, a new rd operation will return the second entry (the red one) and an 'in' operation would return the red one as well, but leaving the space empty (further rd or in operations on that particular key will block.