Using The MIF Cache
In the Base Component Model example, we showed how to package modules together into components. This section will show how to use modules and components with the MIF cache.
Cache overview
The previous examples show data moving through a MIF pipeline in a form that the implementation code at each stage will understand. In some cases this is not desirable, e.g. when the data contains complex structures and must be passed over web services endpoints. For these cases, the MIF API contains provisions for storing the data in a cache and passing references to it.
Transformers are used to generate cache references from data and retrieve the data represented by those references. Creating a reference is done by endpoints with the SiftWorkflowToObjectTransformer attached to them. This transformer stores the object in the MIF cache, and generates a reference to it in the form of an instance of SiftWorkflowObject. Any endpoints receiving on that endpoint's address will receive that reference rather than the cached data.
Another transformer, SiftWorkflowToObjectTransformer, may be set on endpoints which will be receiving references but come before implementation code which requires data. This transformer receives a SiftWorkflowObject and the object it references from the cache.
Using the cache with a module
The Hello World Example created two endpoints and a module between them using this code:
MifEndpoint inNameEndp = pipeline.addMifEndpoint("inNameEndp", EndpointType.STREAM, "console.in?promptMessage=Enter name: ");
MifEndpoint outNameEndp = pipeline.addMifEndpoint("outNameEndp", EndpointType.VM, "hal.queue");
pipeline.addMifModule("HelloNameModule", HelloNameProcessor.class.getName(), inNameEndp, outNameEndp, null);
If this module was to send and receive references over JMS rather than an incoming console stream, it would look like this:
MifEndpoint inNameEndp = pipeline.addMifEndpoint("inNameEndp", EndpointType.JMS, "topic/nameTopic");
SiftWorkflowToObjectTransformer refTrans = new SiftWorkflowToObjectTransformer();
pipeline.addSiftTransformer(refTrans);
inNameEndp.setTransformer(refTrans);
MifEndpoint outNameEndp = pipeline.addMifEndpoint("inNameEndp", EndpointType.JMS, "topic/halTopic");
ObjectToSiftWorkflowTransformer objTrans = new ObjectToSiftWorkflowTransformer();
pipeline.addSiftTransformer(objTrans);
outNameEndp.setTransformer(objTrans);
pipeline.addMifModule("HelloNameModule", HelloNameProcessor.class.getName(), inNameEndp, outNameEndp, null);
Using the cache with a component
The Base Component Model example takes the Hello World code and packages it into a MIF component which communicates over JMS endpoints. For the sake of example, lets say that this component was instead meant to be called via web services which pass in a cache reference, rather than a string. This might be the case if, for instance, an external workflow server were coordinating multiple MIF services.
The example code would be changed thus:
public class HelloWorldComponent extends AbstractMifComponent {
public HelloWorldComponent(String name, Map<String, MifEndpoint> endpointMap) {
super(name, endpointMap);
}
public void configure(MifPipeline pipeline) throws MifException {
// Get inbound / outbound endpoints from user
MifEndpoint inNameEndp = endpoints.get("name-in");
MifEndpoint outHalEndp = endpoints.get("hal-out");
// Set cache transformers on the endpoints
SiftWorkflowToObjectTransformer refTrans = new SiftWorkflowToObjectTransformer();
pipeline.addSiftTransformer(refTrans);
inNameEndp.setTransformer(refTrans);
ObjectToSiftWorkflowTransformer objTrans = new ObjectToSiftWorkflowTransformer();
pipeline.addSiftTransformer(objTrans);
outNameEndp.setTransformer(objTrans);
// Add HelloNameModule
MifEndpoint outNameEndp = pipeline.addMifEndpoint("outNameEndp", EndpointType.VM, "hal.queue");
pipeline.addMifModule("HelloNameModule", HelloNameProcessor.class.getName(), inNameEndp, outNameEndp, null);
// Add HelloHalModule
MifEndpoint inHalEndp = pipeline.addMifEndpoint("inHalEndp", EndpointType.VM, "hal.queue");
pipeline.addMifModule("HelloHalModule", HelloHalProcessor.class.getName(), inHalEndp, outHalEndp, null);
}
}
The endpoint definitions will also need to be changed, to receive and respond via web services, rather than over JMS:
MifEndpoint inNameEndp = pipeline.addMifEndpoint("inNameEndp", EndpointType.AXIS, "localhost:9999/helloService");
MifEndpoint outHalEndp = pipeline.addMifEndpoint("outHalEndp", EndpointType.AXIS, "remotehost:8080/halReturnService");
