In the previous chapters we implemented a simple stateful web service that used local attributes to keep stateful information.
In this chapter we will learn how to write a service that, using a design pattern known as the factory pattern, will be able to manage multiple resources. To accomplish this we'll specify our service's state through resource properties and manage that state through WSRF specific mechanisms.
The factory pattern is a well-known design pattern in software design, especially in object-oriented languages ( Wikipedia entry for factory pattern). In this pattern, we are not allowed to create instances of objects directly, but must do so through a factory that will provide a create operation.
When dealing with multiple resources, the WSRF specs recommend that we follow this pattern, having one service in charge of creating the resources ("the factory service") and another one to actually access the information contained in the resources ("the instance service").
Figure 4-1 summarizes the relationship between these two services, the resources, and the client. Whenever the client wants to create a new resource, it does so through a factory service interface (in OO terms, a factory method). It is up to the programmer to implement the factory service. The pyGridWare infrastructure cannot create it automatically since the input parameters depend entirely on the details of the implementation. The factory service must return a reference to the created service instance and resource, in the form of an endpoint reference(EPR). This reference can be used to in subsequent interactions with the newly created service instance and its associated resource.
![]() | Remember from that endpoint references are a part of the WS-Addressing specification. EPRs allow us to uniquely address a single WS-Resource. Also, remember that a WS-Resource is the pairing of a service with a particular resource. In our first example client, our EPR included only the service's URI (because we had a single resource). In this chapter, our EPR will have both the service's URI and the resource's key. |
Using the EPR returned by the factory, the client can now invoke the service instance's operations. This service instance, in turn, will perform the operations using the recently created resource. If you found this confusing, you should go back and review the WS-RF concepts and terminology presented in Chapter 1.
One new term that we will use below is resource context, which is essentially just an aggregation of its current status.