• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why can't we reuse an interface for both remote and local clients?

 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In the simplified spec (3.2), it says "The same business interface cannot be both a local and a remote business interface of the bean.".

I wondered why that was? Let's say that I have a class, which implements a method doStuff() from an interface. Why can't I reuse that interface from both a local and remote perspective, assuming that I want local and remote clients to access it in the same way?

Thanks,

MG
 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remote interfaces provides access to the EJB, through a serialization protocol. If the client attempts to access a Remote method (on the remote application server, on another machine), the data which is send, should be serialized before sending through the network. Remote interfaces do this for you.

We can use Remote interfaces to access beans in the same JVM too. But it may cause a performance hit, when it is doing the unwanted serialization and deserialization. To prevent this unwanted performance hit on local access, Local interfaces are used.

Both @Remote and @Local annotations cannot be used together, because the container doesn't know how to manage the method invocation in this case.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Local is faster whereas @Remote is comparatively slow as already explained above.
You could design in another if you want both @local and @Remote
Have one common interface
public interface ProcessPayment {

public boolean byCheck(Customer customer, CheckDO check, double amount)
throws PaymentException;

public boolean byCash(Customer customer, double amount)
throws PaymentException;

public boolean byCredit(Customer customer, CreditCardDO card,
double amount) throws PaymentException;


}


Extend 2 intefaces(@Local and @Remote ) to the above Parent Interface and use the child interfaces accordingly

@Local
public interface ProcessPaymentLocal extends ProcessPayment {

}

@Remote
public interface ProcessPaymentRemote extends ProcessPayment {

}
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to reuse the same interface for Local and Remote, the caller needs to specify that it will use Local or Remote interface which is not the case in the current specification.
 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Treimin, Aleem and Kengkaj,

Thank you very much for your kind responses.

As I understand it, when an object is bound against JNDI, it is the Interface that a client uses.
If it were possible to reuse an interface and both a local and remote, the container would not know how to handle this (i.e. whether the client was within the same JVM (local) or whether they were accessing it remotely over RMI (remote)).

I do like the extending interfaces trick to get around this though.

Thanks once again,

MG
 
reply
    Bookmark Topic Watch Topic
  • New Topic