ejb@glassfish.java.net

Re: Is it legal for the same bean to have the same local and remoter interface?

From: Kenneth Saks <Kenneth.Saks_at_Sun.COM>
Date: Thu, 23 Feb 2006 12:04:10 -0500

Sanjeeb Kumar Sahoo wrote:

>>
>> No, the spec doesn't allow this.
>
>
> Any spec reference on this issue will be really helpful. If it is not
> explicitly mentioned, I wish it were.

Yup, I think this prohibition is specifically stated in the latest draft.

>
>
>> Even though the rules for writing
>> the 3.0 local and remote business interfaces are more similar than
>> they were between the 2.x Remote and Local component interfaces,
>> it would be dangerous to use the same interface for both views since
>> the behavior could be different due to pass-by-value vs. pass-by-copy
>> semantics and the variance in allowed types.
>
>
> I guess, the above applies to any method that is common to both remote
> and local business interface of a bean, right?
> e.g. in the following case, although the interface names are
> different, they have the same method.
> interface SlessLocal {
> void foo(Mutable m); // Mutable is data object.
> }
>
> interface SlessRemote {
> void foo(Mutable m); // Mutable is data object.
> }

Right, it's possible for the developer to implement a method
on the bean class and expose it through more than one of the
bean's interfaces, assuming the signature contains types that are
allowed in all the chosen interfaces. There are a lot of caveats
though so in general it's probably best to keep operations for
different application tiers separate.

>
>
> @javax.ejb.Stateless
> @javax.ejb.Remote(SlessLocal.class)
> @javax.ejb.Local(SlessRemote.class)
> public class SlessBean2 {
> public void foo(Mutable p){
> ...
> }
> }
>
> This is a definitely an EJB 3.0 issue as you pointed out because for
> 2.x EJB remote interface methods and local interface methods can not
> be the same because of conflicting requirement. Did I get it right?

It definitely isn't possible to use the same interface as both a
2.x local component interface and 2.x remote component interface
since 2.x Remote component interfaces are required to be
a subtype of java.rmi.Remote and throw java.rmi.RemoteException
for each method, yet local interfaces are prohibited from doing the
same. However, technically you could have a void foo() {}
on the bean class that is exposed as

void foo() throws RemoteException on the 2.x Remote interface
and
void foo(); on the 2.x Local interface. Still, this is not something
that is encouraged.

>
>
> Thanks,
> Sahoo
>
>>>
>>> public class SlessBean2 implements Sless {
>>> public void createPerson(String name){
>>> System.out.println("createPerson " + name);
>>> }
>>> }
>>> /
>>> Since it uses annotation, will both the remote view and local view
>>> not end up having same bean-name which in this case is SlessBean2?
>>>
>>> Thanks,
>>> Sahoo
>>>
>>
>>
>>
>
>