Global Positioning System Reference
In-Depth Information
exchange
server machine Objects client machine
-------------- -------- --------------
<- client - server.identify( me )
client.getIdentity() -----------> wait for keyboard input!
approve / deny ?
<- Object -
return
return
- feedback -> ENTRYAPPROVED ?
After one client has passed its remote reference, the server calls back and
tries to retrieve an ID via
client.getIdentity()
. Technically, the client
invokes a method on the remote server, which invokes a method on the
remote client. Although the nested construction works, it can be tough to
debug. The actual problem arises, if the client response is too slow.
The sequence diagram indicates that the identification could be provided
via keyboard on the client side. In case the client operator is distracted
by something the server keeps waiting for the ID to be returned,
1
and
the server method cannot continue or can get confused with other clients.
In general, it is unwise to call a method from a thread, if the method is
open for implementations like a method from an interface or an overriding
method. The programmer simply can not make any assumptions on the
client method's return.
Server programming is about handling many client threads at a time,
while managing resources and balancing the load. The client call and the
server callback have introduced this issue; general ways to handle the chal-
lenge will be discussed in Section 11.7.
To avoid an identification issue, a simple
Map
is created to make use of
Java standard implementations. Java supplies a runtime (!)
hashCode()
and an
equals()
method for the
RemoteClient
and a
HashMap
to detect
duplicate clients:
private Map<RemoteObject,??> connectedClients
= new HashMap<RemoteObject,??>();
The
??
indicate the need to identify server-side objects relating to each
client object. The map
connectedClients
collects unique
RemoteObject
s as
mapping keys. The
RemoteObject
s are local representatives of the client
inside the server environment|
ServerObject
is or SOs. A SO is the coun-
terpart or reflection of any
RemoteObject
, and the server is the mirror!
11.6 SOs:
ServerObject
s
Each SO is a dedicated server process for every RO. The
ServerObject
provides an individual programming environment on the server side for each
remote client. For the ROServer, it is easier to deal with local objects and
1
Although
void
methods don't return a value, even they do return!
Search WWH ::
Custom Search