|
| United States Worldwide |
|
Converting to PJama 1.xThere are three changes that you need to be aware of when converting from PJama 0.x to PJama 1.x,
Converting to the New OPJ APIWe strongly recommend that you convert your applications to use the new API. In this section we explain how to transform programs written using the old API. The old API is still supported and, with a couple of exceptions, works as before, but it is deprecated and will be removed in the next major release.In general, the new API is substantially simpler, and results in a reduction of boilerplate code. Persistent StoreIn the old API, the persistent store was explicitly represented by the PJStore interface and the PJStoreImpl class. In the new API, the persistent store is implicit and the relevant features of PJStore have been moved into the OPRuntime class. In particular, the PJStore.stabilizeAll method has been replaced by OPRuntime.checkpoint.Persistent Store CreationApplications no longer create persistent stores explicitly through the API. Persistent stores are created implicitly if necessary when the "-store" argument is specifed as a command line argument to the OPJ Virtual Machine. This means that an application can be written with the assumption that the store exists, which is one less special case for the programmer to deal with.Persistent RootsThe way that persistent roots are specified has changed significantly in the new API. The change was motivated by the focus in the OPJ specification on persistent computation where it is expected that non-persistent objects are the exception rather than the rule. In general, if an object is (persistence) reachable when a checkpoint occurs, then it will (must) be made persistent to maintain the semantics of the computation correctly. This approach is strongly tied to using (persistent) threads as the roots of reachability. However, since our current prototype still does not support persistent threads, it continues to be necessary to establish explicit roots of persistence. To maximize the persistence independence of source code, we have also provided some convenience options to the OPJ Virtual Machine that handle root registration.In the old API, persistent roots were created by the newPRoot
method of PJStore, and were registered under a user-provided name.
Choosing this name could be a problem, since the root names had to kept
unique. One general solution was to prefix the name with the fully qualified
name of the class that the root was associated with. An equivalent
approach is to exploit the naming mechanisms of the Java language directly,
by using static variables as roots, since these are guaranteed to be unique.
Accordingly, the new API simply provides a set (actually a java.util.Set)
in the variable OPRuntime.roots, with the expectation that instances
of java.lang.Class will added to this set, and that static variables
in such classes will acts as roots. The following class demonstrates the
new API and, at the same time, shows how the previous style of API can
still be supported if required.
Implicit Root RegistrationThe OPJ Virtual Machine provides two convenience options that avoid having to explicitly register classes as roots in the source code, which can, in many circumstances, allow an application to be executed under OPJ without any source changes. The basic option is "-classroot classname". This option causes the class "classname", which must be a fully qualified name, to be loaded, initialized, if this has not been done in a previous run, and added to the root set, immediately prior to the invocation of the main class. For example, the NamedRoots class, defined above, could be modified to remove the call to OPRuntime.roots.add and instead this could be achieved by adding "-classroot com.acme.util.NamedRoots" to the command line.The second option. "-mainroot", is simply a special case of the first, and is equivalent to "-classroot mainclass". Action HandlersThe old PJActionHandler API works as before, but we encourage you to convert to the new event listener API in OPRuntime. This API follows the conventions of the standard Java event model.Using the Old APIIf you currently use opjcs to create your stores, you can continue to do so. Otherwise, you must convert your code as the PJStoreImpl(name) constructor is not supported.There is one other situation where the old API does not work as expected. In the run of an application in which the store is (implicitly) created, the PJStoreImpl.getStore method throws an NoStoreException exception. The easiest way to finesse this is to use opjcs to create an empty store and then run the application. Last changed: Dec 7th 1999 Questions and comments to forest-info@sunlabs.com | ||||||||||||||||||||||