O'Reilly logo

Java RMI by William Grosso

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ContextImpl

Now that we have our interface and value objects firmly in place, it’s time to move on to the main object. ContextImpl is our implementation of Context. Our implementation uses two delegate objects to actually maintain the indexes, along with a special-purpose object used to associate a name with an AttributeSet. That is, our implementation of Context really consists of the following four objects:

ContextImpl

This implements the Context interface. It has very little direct state, a reference to ContextHolder and a reference to RemoteHolder, and is completely unsynchronized. Its role is to implement the Context interface by forwarding method calls to the appropriate object, either a subcontext or one of the two delegates.

ContextHolder

This is a delegate object whose role is to hold, and index, direct subcontexts. All of its methods are synchronized.

RemoteHolder

This is a delegate object whose role is to hold, and index, locally contained references to servers. All of its methods are synchronized.

NameAttributeSetPair

This is a class that combines a name and an attribute set in an indexable object. It also implements the Comparable interface so that it can be used by RemoteHolder.

The runtime structure looks something like Figure 15-7.

The runtime structure

Figure 15-7. The runtime structure

Let’s look at each of these objects in a little more detail.

NameAttributeSetPair

NameAttributeSetPair ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required