- A Lightweight Java Middleware
<< The server

The subject

is the object that provides the actual service to the client-side program. It is hosted on the server and associated with one or more proxies, through which its methods can be called.

Practically every Java object can function as a subject.

Providing a subject

A subject can be provided on the server in two ways:

The allocation of a class proxy at the client side can trigger the allocation of a corresponding subject in the server.

A subject can also be created separately and then be added to the server using one of the OCSServer addSubject() methods. This can be done either within the server process or at the client side, with the help of an OCSServerUserInterface object, which is available from an OCSClient associated with the server.

Note that an OCSServer may have set restrictions with regard to the classes of subjects it allows to create and host.

Conditions for association with proxy

If the subject is created by a class proxy, its class is necessarily a superclass of the proxy.

To allow a class proxy to attach to an existing subject, it suffices that the subject has been added to the server as an instance of the proxy's base class. It is ok, if the subject is an instance of a subclass of that class.

For an interface proxy, the requirements are even more relaxed: it may attach to a subject of any class provided the methods that get actually called on the proxy are available in the subject.


Subjects can be removed from the server in two ways:

Users can do away with a subject by directly calling one of the OCSServer removeSubject/s() methods.

Also, a subject can get removed if all the proxies that have been associated with it, detach. This detachment can be triggered in three ways:

If a proxy goes out of scope and is finalized immediately prior to its own garbage collection, the automatically invoked finalize method detaches the proxy from its remote subject. This process is known as Distributed Garbage Collection.

Also, if the process that hosts the proxy does terminate, all the proxies living in this process are automatically detached from their respective subjects.

In addition, users may explicitely invoke detachFromSubject() on a proxy. This can make sense in the rare situation where a proxy is sure not to be used anymore, but for some reason is kept referenced so that it can't get finalized. (Note that detachment renders a proxy unusable: calling a method on a detached proxy will throw an OCSRuntimeException.)

Note that whether a subject will be removed from the server and garbage collected once its references are gone, depends on how it has been installed in the server:

If created through allocation of a class proxy at the client side, the subject is automatically marked for garbage collection.
If created independently to be added to the server through one of OCSServer's addSubject() methods, it is up to the user to decide: half ot the addSubject() methods have a parameter allowing to mark a subject for garbage collection or not. (A subject added to the server in this way is initially unreferenced. Garbage collection requires that the subject first gets referenced by at least one proxy and then loses all reference(s) again.)

Subject info

Information about the subjects existing on a server can be gained by methods of class OCSServer, which are also accessible using the OCSServerUserInterface object available from an associated client.

As always, please see the API for details.

Last modified Feb 9, 2006