EOB 1.1
About EOB
Overview
News & History
Downloads
Persistence
Development
J2EE comparison
Requirements
Bugs & Issues
Limitations of use
Info & Credits
Enterprise Object Broker |
|
Tutorial 0 - Basic bean publication
OK, for this tutorial, we're going to build a distributed
thermometer. It reads the temp on the server, and publishes that
over RPC to clients. The server-side implementation is fake here,
but there could be some cached JNI using implementation in a real case.
public interface Thermometer {2) Create a simple implementation.
float getTemperature();
}
public class DefaultThermometer {3) Create a bean manifest.
public float getTemperature() {
return (float) Math.random();
}
}
<?xml version="1.0"?>The 'name' is the name by which this thermometer will be looked up. The 'facade' is the actual interface being implemented. The 'impl' is the implementation of that facade that EOB will instantiate and route requests through to.
<beans-info>
<bean-info name="My-Thermometer" facade="Thermometer" impl="DefaultThermometer"/>
</beans-info>
Thermometer.class5) Create a manifest for the application
DefaultThermometer.class
EOB-INF/beans.xml
META-INF/manifest.mf (created by Sun's jar utility)
<?xml version="1.0"?>EOB uses this to work out how to publish the multiple beans that might be included in the application.
<application-info>
<publish-info type="SocketCustomStream" bind-to="*" port="22222"/>
</application-info>
beans/DefaultThermometer.jarYou could drop that .eob into EOB's startupApps/ directory.
application.xml
public class ThermometerTest {Package this how you like, but it will need AltRMI's client and common jars in the classpath. There is also a way of doing the lookup using JNDI meaning that yout don't have to import any AltRMI classes (but still need them in your classpath).
public static void main(String[] args) throws Exception {
Factory af = new ServerSideClassFactory();
af.setHostContext(new SocketCustomStreamHostContext("localhost", 22222));
printTemp((Thermometer) af.lookup("My-Thermometer"));
}
private static void printTemp(Thermometer thermometer) {
System.out.println("The temperature on the server is : " + thermometer.getTemperature());
}
}
$Revision: 1.5 $ $Date: 2003/04/15 22:47:07 $