previous next trail start tutorial home feedback openwings.org

Writing HelloWorld

2. HelloWorldProvider

Source code: HelloWorldProvider.java

The HelloWorldProvider component will:

  • Create an implementation of the service interface
  • get a reference to the component
  • distribute the object
  • provide the distributed object

HelloWorldProvider creates an implementation of the service interface when it implements the HelloWorldServiceSynchronous interface and provides details for the helloWorld() method that is listed in that interface.

public String helloWorld()
{
  return ++helloCount + "Hello World!";
}

There are a couple more things of note. One is the use of ComponentFactory and Component. The factory is a common pattern in object-oriented programming. A factory is simply an object that returns another kind of object. If you're using Component Services, you'll need an object that implements the Component interface, which you get from the ComponentFactory.

In this case, the resulting object is a component. Recall, a component is the centerpiece of the Openwings service-based architecture. Every service needs to have a reference to some implementation of Component. The Component class, among other things, provides the methods needed for publishing, unpublishing, discovering and using services.

Component component = ComponentFactory.getComponent();

In the above code file, ComponentFactory returns a Component that the application can use to provide its service. Before the service object can be provided, however, it must become distributed. A distributed object is an object that can be moved to another program, but calls on the object take effect in the original program. The component.distributeObject() method takes an interface and an object that implements that interface, and returns a wrapper object that implements the interface, but is distributed.

Object distributedObject = component.distributeObject(
HelloWorldServiceSynchronous.class, helloWorldProvider);

When the distributeObject() method is called on an object, Component Services is actually wrapping the object in a connector proxy. A connector consists of two proxies that can communicate using some protocol. The distributeObject() method initializes the receiver or "provider" proxy so that incoming calls are mapped to your object. The object returned from the distributeObject() is the sender or "user" proxy of the connector. This "user" proxy is a serializable object that can be moved to another program.

In this example, the connector part is handled by Container Services of Openwings during the call:

 Object distributedObject = component.distributeObject(
     HelloWorldServiceSynchronous.class, helloWorldProvider);

Once the Service is distributed, it can be provided to other components. The method component.provideService() publishes this service so that clients can connect to this service and use it.

Note:

There is a special notation we use to help describe service-oriented problems. Among other things, this notation demonstrates the notion of wrapping an object in a connector. Further information can be found in the Architecture Definition Language section.

Next: HelloWorldSimpleUser

back to top

Copyright 2002, General Dynamics Decision Systems. All rights reserved.

previous next trail start tutorial home feedback openwings.org