Remote Invocation of Code over a Space

ActiveSpaces allows space members to remotely invoke code on other members of the space. This feature allows the code to be co-located with the data for optimal performance.

Execution of the Invocable interface is triggered by an application that can be running on the same member or a different member of the space. In ActiveSpaces, this is referred to as remote invocation.

The invocable code is executed either on the member that contains specified data (if the Invocable interface is used) or on specified members (if the MemberInvocable interface is used). If you use the MemberInvocable interface, your application specifies which members should execute the interface.

Compare the two approaches to updating the value of a field on all of the entries stored in a space.

  • One approach is to create a browser of distribution scope all on the node to serially retrieve and update each entry in the space one entry at a time.

    This represents a non-distributed process, as a single node is actually doing the updating. It incurs a fair amount of network traffic, since retrieving an entry might require a round-trip over the network, and updating that entry might require another round-trip. The latency induced by those network round-trips has a negative impact on the overall throughput.

  • Another approach is to use remote invocation to invoke a function on all of the Space seeders in parallel. The remote function creates a browser of distribution scope seeded, to iterate only over the entries that it seeds and, therefore, avoid incurring a network round-trip.

    For each entry, the invoked function updates the field and the entry the same way as described for the non-distributed process, with the difference that the entry updates will be performed much faster since they do not incur a network round-trip.

Remote space invocation is available for all language bindings. It only takes care of function or method invocation and does not take care of distributing the code to the space members; for example, the function or method being invoked must be available in the CLASSPATH of all space members.

Invocation Patterns

With the Invocable interface, the application indicates the key of an entry stored in the space. ActiveSpaces determines which space member stores the element associated with the key or which space member would be used to store the element, if the element does not exist in the space. Execution of the Invocable interface will then occur on that space member.

The code implementing the Invocable interface needs to be included in the CLASSPATH for each member of the space.

The following remote space invocation services are available:

invoke
  Invokes a method only on the member seeding the key passed as an argument to the call.
invokeMember
  Invokes a method only on the Space member being specified as an argument to the call.
invokeMembers
  Invokes a method on all of the Space members.
invokeSeeders
  Invokes a method on all of the seeder members of the Space.

All of those calls also take as arguments:

  • A class on which the method implementing the appropriate Invocable interface is invoked
  • A context tuple that gets copied and passed as is to the method being invoked.

The invoke method takes a key tuple, which gets passed to the method implementing the Invocable (rather than MemberInvocable) interface in the class; the method gets invoked regardless whether an entry has been stored in the space at that key.

Both the Invocable and the MemberInvocable interfaces return a tuple, but the remote space invocation methods return either an InvokeResult (invoke and invokeMember) or an InvokeResultList (invokeMembers and invokeSeeders), from which the Tuple can be retrieved using the getResult (or getResults) method.

Note: The methods being invoked using remote space invocation should always be idempotent; in case there is a change in the membership (or seedership) of the space while the Remote Space Invocation is being performed, the Space can retry and re-invoke the methods once the change has happened.
Related reference