HiveMind

HiveMind Homepage.

A short example, how you can invoke with the HiveMind framework a XML-RPC service. First you create a instance from the org.apache.hivemind.Registry to load the configuration file hivemind.xml in the META-INF folder. In the second step create a proxy object for the service interface. The proxy object delegate all calls from the service interface method to the net.sf.crispy.impl.XmlRpcExecutor. The XmlRpcExecutor make the remote calls to the MiniServer and send back the result.

MiniXmlRpcServer server = new MiniXmlRpcServer();
try {
	server.addService(Echo.class.getName(), EchoImpl.class.getName());
	server.addService(Calculator.class.getName(), CalculatorImpl.class.getName());

	server.start();
			
	Registry registry =  RegistryBuilder.constructDefaultRegistry();			
	Calculator calculator = (Calculator) registry.getService(Calculator.class);
	System.out.println("2 + 3 = " + calculator.add(2, 3));
		
	Echo echo = (Echo) registry.getService(Echo.class);
	System.out.println("Echo: " + echo.echo("Hello Crispy!"));
				
} catch (Exception e) {
	e.printStackTrace();
}
finally {
	server.stop();
}

In this example you load a configuration file (hivemind.xml). This file is description here:

<?xml version="1.0"?>
<module id="net.sf.crispy.extension.hivemind" version="1.0.0" package="hivemind.examples">

<configuration-point id="ConfigCrispyFactoryRMI" schema-id="CrispySchema"/>
<configuration-point id="ConfigCrispyFactoryXMLRPC" schema-id="CrispySchema"/>

  <schema id="CrispySchema">
    <element name="property" key-attribute="key">
      <attribute name="key"/>
      <attribute name="value" required="true"/>

      <conversion class="net.sf.crispy.extension.hivemind.KeyValue"/>
    </element>
  </schema>


<contribution configuration-id="ConfigCrispyFactoryXMLRPC">
  <property key="crispy.prop.server.url" value="http://localhost:9090"/>
  <property key="crispy.prop.executor.class" value="net.sf.crispy.impl.XmlRpcExecutor"/>
</contribution>

<contribution configuration-id="ConfigCrispyFactoryRMI">
  <property key="crispy.prop.server.url" value="rmi://localhost:1099"/>
  <property key="crispy.prop.executor.class" value="net.sf.crispy.impl.RmiExecutor"/>
  <property key="test.crispy.example.service.Echo" value="test.crispy.example.service.EchoImpl"/>
  <property key="test.crispy.example.service.Calculator" value="test.crispy.example.service.CalculatorImpl"/>
</contribution>



<service-point id="calc" interface="test.crispy.example.service.Calculator">
	<invoke-factory  service-id="CrispyFactory">
		<construct class="net.sf.crispy.extension.hivemind.CrispyFactory" /> 
	</invoke-factory>	
</service-point>

<service-point id="echo" interface="test.crispy.example.service.Echo">
	<invoke-factory  service-id="CrispyFactory">
		<construct class="net.sf.crispy.extension.hivemind.CrispyFactory" /> 
	</invoke-factory>	
</service-point>

<service-point id="CrispyFactory" interface="org.apache.hivemind.ServiceImplementationFactory">
	  <invoke-factory>
	    <construct class="net.sf.crispy.extension.hivemind.CrispyFactory" initialize-method="init"> 	    
	    	<!-- !!!!!!!!!!! set the configiguration for the Crispy Factory !!!!!!!!!!! -->
		<set-configuration property="properties" configuration-id="ConfigCrispyFactoryXMLRPC"/>
		<!-- set-configuration property="properties" configuration-id="ConfigCrispyFactoryRMI"/ -->
	    </construct>
	  </invoke-factory>      
</service-point>   
  
</module>