This page last changed on Jul 07, 2006 by aperepel.

Mule uses GigaSpaces for interacting within a JavaSpace environment. GigaSpaces is a highly-scalable spaces technology that have a free community edition that you can try.

Mule allows Services to subscribe to events in the space and to publish events to a space. For example, the following will subscribe all objects placed in a space and send the resulting object to a Jms Queue -

<mule-descriptor name="unprocessedOrders" implementation="com.foo.ProcessingComponent">
    <inbound-router>
        <endpoint address="gs:java://localhost/mule-space_container/mule-space?schema=cache"/>
    </inbound-router>

    <outbound-router>
        <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
            <endpoint address="jms://processed"/>
        </router>
    </outbound-router>
</mule-descriptor>

Notice the subscription endpoint address uses a gs: scheme, This means that the URL proceeding it will be passed to GigaSpaces to get a reference to the space and register interest on it.

The URL -

java://localhost/mule-space_container/mule-space?schema=cache

Is a GigaSpaces URL for referencing a local (in memory) space. To connect to a remote GigaSpaces space you can use other protocols such as RMI -

gs:rmi://localhost:10096/container1/space1

or

gs:jini://192.168.1.2/myContainer/JavaSpaces

See the GigaSpaces documentation for more information about connecting and configuring spaces.

Using templates

The example above shows how to register interest in all events in a space. However, JavaSpaces uses a template mechanism for selecting which events to receive. You can define these templates in Mule using filters.

<mule-descriptor name="unprocessedOrders" implementation="com.foo.ProcessingComponent">
    <inbound-router>
        <endpoint address="gs:java://localhost/mule-space_container/mule-space?schema=cache">
            <filter className="org.mule.providers.gs.filters.JavaSpaceTemplateFilter" expectedType="com.foo.Order" >
                <properties>
                   <map name="fields">
                      <property name="processed" value="false"/>
                   </map>
                </properties>
            </filter>
        </endpoint>
    </inbound-router>

    <outbound-router>
        <router className="org.mule.routing.outbound.OutboundPassThroughRouter">
            <endpoint address="jms://processed"/>
        </router>
    </outbound-router>
</mule-descriptor>

The example shows how to configure a filter to receive events of type com.foo.Order and where the processed property of the Order object is false.

Note that the com.foo.Order object adheres to the JavaSpaces specification for objects and not the JavaBean spec. So the Order object looks like -

public class Order implements Entry {

    public String orderId;
    public Boolean processed = Boolean.FALSE;


    public String toString(){
        return "Order{id=" + orderId + ", processed=" + processed.booleanValue() + "}";
    }
}

For people who don't like to break their encapsulation (including myself ) can either add a transformer to the endpoints that convert the Order object into a JavaBean Order object or maybe a JavaBean Proxy adapter could be written to make JavaBeans look like a JavaSpace object. I'll leave this one to the reader.

Also, bear in mind that all object fields need to be Objects, primitive types cannot be used.

Document generated by Confluence on Nov 27, 2006 10:27