Distributed object life cycle

Distributed objects have the same life cycle as a non-distributed managed object. See the section called “Managed object life cycle” for details.

However, if an object maintains a reference to a distributed object, that object can be deleted on a remote node and the local object now has a stale reference. This stale reference is not detected until a field is accessed or modified, or a method is invoked. When this happens a java.lang.NullPointerException is thrown to the application.

class A { }

class B
{
   A a // This can become stale if an instance of B is a distributed object
}

The java.lang.NullPointerException can be avoided by ensuring that a write lock is taken on distributed object references before a field or method is accessed. The recommended way to take a write lock is to select the object, if it has an index, and specify a lock type of write. This will force a distributed lock request to the remote node which will either return the instance write locked, or an empty reference if the object was deleted.

In general, it is recommended that applications coordinate distributed object deletes to avoid any special case exception handling or locking code on remote nodes.

Constructors

Constructors are always executed on the node where new is called. This is true even if the master node for the object will be a remote node, for example a partitioned object whose active node is not the local node. Figure 6.1, “Constructor execution” shows new being called for an Order object on Node One. The constructor executes on Node One and then the object is created on Node Two. When the creation on Node Two completes, new returns to the caller.

Constructor execution

Figure 6.1. Constructor execution