Overview
Wiki Markup |
---|
{snippet:url=people/~dblevins/foo.txtopenejb3/examples/telephone-stateful/README.txt} |
The Code
For 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.
bean
Wiki Markup |
---|
{snippet:id=code|url=openejb3/examples/telephone-stateful/src/main/java/org/apache/openejb/examples/telephone/TelephoneBean.java|lang=java} |
business interface
Wiki Markup |
---|
{snippet:id=code|url=openejb3/examples/telephone-stateful/src/main/java/org/apache/openejb/examples/telephone/Telephone.java|lang=java} |
Tip |
---|
|
Wiki Markup |
---|
Definitely worth noting that this example uses one of the more clever EJB3 rules for default values. The bean class uses the annotation *@Remote* but does not specify a list of interfaces as is normally required. Per EJB3 rules, if the bean implements exactly *one business interface* it may use @Remote with no other values and that business interface is then implied to be a remote business interface. The same rule applies to @Local.
The critical thing to know is that if you add another interface the rules change and require that you specify both interfaces in the @Remote annotation as in @Remote({Telephone.class, SecondInterface.class}).
|
|
Wiki Markup |
---|
{snippet:id=setup|url=openejb3/examples/telephone-stateful/src/test/java/org/apache/openejb/examples/telephone/TelephoneTest.java|lang=java} |
Wiki Markup |
---|
{snippet:id=localcontext|url=openejb3/examples/telephone-stateful/src/test/java/org/apache/openejb/examples/telephone/TelephoneTest.java|lang=java} |
Wiki Markup |
---|
{snippet:id=remotecontext|url=openejb3/examples/telephone-stateful/src/test/java/org/apache/openejb/examples/telephone/TelephoneTest.java|lang=java} |