The Source for Java Technology Collaboration


Home | Changes | Index | Search | Go

WonderlandComponentAnnotations

The Cell Component system in Wonderland is a very flexible system that allows developers to easily extend the functionality of a cell, either at configuration time or at run time. Components provide both basic functionality (such as the client/server communication mechanism provided by ChannelComponent) and subsystem specific extension such as those offered in the audio module. A cell can only have a single instance of each type of component installed at any time.

During recent development it became apparent that we were repeating the same code patterns in Components, especially for those Components that used/depended upon other Components. The management of inter Component dependencies was becoming a pain, therefore we have added a couple of Annotations to the core of Wonderland which will help all Component writers cleanly specify and manage their dependencies on other Components.

Lets take a look at a simple CellComponent example and how the new annotations can be used

public class Foo extends CellComponent {

    @UsesCellComponent
    private ChannelComponent channelComp;

    public Foo() {
    }

    public void setStatus(CellStatus status) {
        super.setStatus(status);

        channelComp.addMessageListener(.....)
    }

}

The annotation @UsesCellComponent indicates to the system that channelComp is a component that we want to use in our CellComponent Foo. Now the system will automatically populate the variable channelComp before the call to setStatus (when status is BOUNDS or higher). We can then simply use channelComp from that point forward. The Wonderland core will automatically ensure that any components we specifiy are instantiated and available for our use. Note that these dependencies are resolved just before our setStatus method is called, so that is the earliest time you can access the variable.

A similar pattern is used for server side CellComponentMO's

public class FooMO extends CellComponentMO {

    @UsesCellComponentMO(ChannelComponentMO.class)
    private ManagedReference<ChannelComponentMO> channelCompRef;

    public FooMO() {
    }

    public void setLive(boolean isLive) {
        super.setStatus(isLive);

        channelCompRef.getForUpdate().addMessageListener(.....)
    }

}

The use of Darkstar ManagedObjects and requirement to always reference them through ManagedReferences leads to a slight modification of the syntax, but conceptually the code is identical. The channelComponentRef field will be populated with a valid object just before setLive(true) is called. You should take care not to attempt to access channelCompRef before setLive(true) has been called.

These annotations can also be used in Cell and CellMO to specify the components that a cell depends on.

Topic WonderlandComponentAnnotations . { Edit | Ref-By | Printable | Diffs r3 < r2 < r1 | More }
 XML java.net RSS

Revision r3 - 28 Jan 2009 - 18:34:13 - PaulByrne
Parents: WebHome > ProjectWonderland > WonderlandRoadmap > WonderlandReleasepoint5