|
Page Edited :
OPENEJB :
Embedded and Remotable
Embedded and Remotable has been edited by David Blevins (Dec 15, 2007). Content:OverviewThis example shows how to use OpenEJB3's remoting capabilities in an embedded scenario. The basic recipe is the same for a standard embedded scenario but with these added ingreditents:
While creating the InitialContext, pass in the openejb.embedded.remotable property with the value of "true". When this is seen by the LocalInitialContextFactory, it will boot up the Server ServiceManager in the VM which will in turn look for ServerServices in the classpath. Provided you have the openejb-ejbd jar in your classpath along with it's dependencies (openejb-server, openejb-client, openejb-core), then those services will be brought online and remote clients will be able to connect into your vm and invoke beans. If you want to add more ServerServices such as the http version of the ejbd protocol you'd simply add the openejb-httpejbd jar to your classpath. A number of ServerServices are available currently:
To run the example simply type: $ mvn clean install
The CodeFor this example we have a simple Stateful bean called TelephoneBean as defined below. As a simple way of demonstrating the state we have to methods: speak and listen. You call speak and pass in some text, then you call listen to get your answer. beanAn error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/telephone-stateful/src/main/java/org/apache/openejb/examples/telephone/TelephoneBean.java. The system administrator has been notified.business interfaceAn error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/telephone-stateful/src/main/java/org/apache/openejb/examples/telephone/Telephone.java. The system administrator has been notified.
EmbeddingWe're going to embed OpenEJB3 into a plain JUnit TestCase as a simple means of demonstrating the remote capabilities. We'll do the embedding in our test setUp method, then will make two test methods:
setUpAn error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/telephone-stateful/src/test/java/org/apache/openejb/examples/telephone/TelephoneTest.java. The system administrator has been notified.LocalInitialContextFactory: making in-vm calls to a remote business interfaceAn error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/telephone-stateful/src/test/java/org/apache/openejb/examples/telephone/TelephoneTest.java. The system administrator has been notified.RemoteInitialContextFactory: making networked calls to a remote business interfaceThis is the part you would want to do in apps that are running a different VM than the one in which the ejb container is embedded. These "client" VMs need only have the the openejb-client jar in their classpath and connect to OpenEJB via the RemoteInitialContextFactory like any other remote EJB client. An error occurred: http://svn.apache.org/repos/asf/openejb/trunk/openejb3/examples/telephone-stateful/src/test/java/org/apache/openejb/examples/telephone/TelephoneTest.java. The system administrator has been notified.Maven setupNice thing about maven2 is it has test-only dependencies. This guarantees that non of your runtime code is dependent on any OpenEJB classes. You need this dep or no clients will be able to connect over the ejbd protocol to the embedded ejb container. Notice the other examples use 'openejb-core' and this one uses 'openejb-ejbd'. If you wanted to make more protocols available, you simply have to add deps to them and they'll get picked up in the classpath automatically. <dependency> <groupId>org.apache.openejb</groupId> <artifactId>openejb-ejbd</artifactId> <version>3.0.0-SNAPSHOT</version> <scope>test</scope> </dependency>
|
Unsubscribe or edit your notifications preferences
