Implementing this design pattern is very similar to the example seen in the previous chapter, with two main differences, highlighted in Figure 4-2 (compare with )
Figure 4-2. Relationships between the Factory Service, the Instance Service, the Resource Home, and the Resource
Factory method and service instance. To handle multiple resources we will deploy a single service that has a factory method to create service instances, this method will create new service instances and return an EPR. Within each of our service's methods we'll need to use the EPR to grab the appropriate resource (service instance), and access that resource's properites through the properties interface. This sounds complicated but it's very simple, basically we will be setting python attributes that represent the resource properties of the MathService.
Resource Home. The resource home maintains all resource contexts. The factory service method will use the resource home to create new resources using a NewResourceContext method, while the instance service methods will use the resource home to find a resource using the GetResourceContext method.
Let's start by examining three Python modules, generated from the WSDL presented in the last section after removing the comments around the relevant create sections, containing four classes.
Remove the comments in the WSDL by removing all UNCOMMENT sections (or get it from the next section), clean regenerate and install. The crucial parts of the WSDL you just uncommented are explained below.
<xsd:element name="Value" type="xsd:int"/><xsd:element name="LastOp" type="xsd:string"/>
<xsd:element name="MathResourceProperties">
<xsd:complexType> <xsd:sequence> <xsd:element ref="tns:Value"/> <xsd:element ref="tns:LastOp"/> </xsd:sequence> </xsd:complexType> </xsd:element> <portType name="MathPortType" wsrp:ResourceProperties="tns:MathResourceProperties">
... ... <operation name="createResource">
<input message="tns:CreateInputMessage"/> <output message="tns:CreateOutputMessage"/> </operation>