Previous: Usage Up: Usage Next: Spring configuration

Space interaction

It is sometimes slightly confusing to use space based logic. This chapter contains some hints and pointers.

Space is not intended to be used for long term storage

A tuple space is not intended to be used for long living data. If you have needs in this direction, an ORM such as Hibernate will solve this better for you.

There is nothing wrong with mixing strategies, however.

Query timeout

When you are using the master / worker pattern, you will benefit from letting the query for the master answer live slightly longer the life time of the query itself.

The reason for the slightly longer life of the wait for answer, is that you need to consider the worst case time, which also includes the network traffic time, and the processing time. If you intend to have the query live shorter, decrease both timeout values, not only one.

Space objects are serialized

The object identity is lost when you put the objects into the space. This can be used for simplifying the queries, as you can reuse the object.

Make allowances for asynchronous operations

When programming against the space, try to make allowances for the operations being asynchronous. When you are treating elements, they may appear out of order as you may have more than one set of clients. If your are dependent on a certain order, you may need two keys, representing a counter and the other an operation ID.

Use objects and not primitives

In your holder object, do not use primitives, use objects instead. Otherwise, you will always query on the primitive value, which for int will be 0 (zero). If you use Integer for int, you can omit the value, and query on anything, as it is null.

Do not query on interfaces and sub class types

When you perform a query, you essentially fill out a object which shall be matched on all fields that are filled out for a given object type. The matching is not performed on class hierarchies, i.e., you cannot query with a parent class and get results of a sub class type. Interfaces are also disregarded as well.

The reason for this, is to support other languages / structures, such as ruby or php.

Make allowances for failure when using webservices

You need to make your application tolerate failures when running against the SemiSpace webservices, as the webservices may not always be present. The problem you try to solve, is that random outages create an exception which in effect stops your program.

Write your catch in a manner similar to the following:

} catch (SemiSpaceProxyException exception) {
    log.warn("Got a problem with SemiSpace connection.", exception);
    // need to sleep in order not to hammer connection, which
    // is relevant if you are in a loop.
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        // Ignored
    }
}


Previous: Usage Up: Usage Next: Spring configuration