J2EEOnline J2EE





EJB Architecture  «Prev  Next»
Lesson 2EJB Clients and remote objects
ObjectiveDescribe remote objects, clients, and services

EJB Clients and Remote Objects

A remote object is an object that can have messages sent to its methods from a client across a network. For the remote object to be useful, those methods must provide some useful service.
An example of a remote object could be a BankAccount or a ShoppingCart. A BankAccount object might have methods such as:
  1. public void credit(amount)
  2. public void debit(amount)
  3. public amount getBalance()
This would allow a client to deposit money to an account, withdraw it, and get the balance.
(In practice, there would be other methods that are ignored here for clarity.)

Clients depend on Remote Objects

The client can be another object or program somewhere out on the network. The client is dependent on the services provided by the remote object, but the remote object does not necessarily know who its client is or where that client is actually located.
This is similar to when you go to a store: if you pay cash, no one needs to know who you are, but if you pay by check, the clerk will want more information.

From a security perspective, the remote object may want to know much more about its client. Most distributed environments provide the hooks for the remote object to acquire this type of information.
  1. Remote object','An object that provides a service through its methods and is located on another host on the network. The location of the object needs to be known before its methods can be called.
  2. Object semantics:The term implies that the objects have typical behavior as implemented in programming languages such as Java, C++ and SmallTalk.


Remote Objects wait for Clients

The remote object waits for messages that arrive from a client. It processes the message and then returns any data or simply an acknowledgment to the client.
If the remote object is not waiting for a message, the client will not be able to send a message to the remote object. The analogy is that, if the gas station is not open, you can go there but you will not get service.
Messages are sent to remote objects using object semantics .
For example, if the client needs to get the balance from the BankAccount object, it generates a message that effectively invokes
balance = act101.getBalance()

, assuming the remote object is named "act101".


Ejb Clients Remote Objects

Remote objects may themselves be Clients

The remote object itself may act as a client, and be dependent on other remote objects.

Object Monitors

If you want a more complete discussion of the principles described in this lesson, please refer to the great book Essential Guide to Object Monitors.


Now is the time to learn more about Enterprise Java Beans. In the next lesson, you will be introduced to the mechanism used when a client accesses a remote object.