aspose file tools*
The moose likes Distributed Java and the fly likes Serialization Prob in RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Serialization Prob in RMI" Watch "Serialization Prob in RMI" New topic
Author

Serialization Prob in RMI

Pratik Khetia
Ranch Hand

Joined: Jun 29, 2001
Posts: 50
Hi,
I am writting a chat server application. So I wrote an Interface for the RMI Server and it has all the methods like
public Message getMessage()
public void setMessage(Message m)
Now on the client side I am using a thread to get all the mesgs from the server every miliseconds...so even if there is no acitivity on the server ..the thread is taking lots of system resources. Now I want to do something that will directly send messages to client from the RMI.
So now the question is ...
"Is that possible for the RMI Server to communicate with all the clients ? " If yes then how ?

thanks
Pratik
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

One way: your server object could allow clients to register as listeners, and treat the messages back out to the clients as events:

Your implementation object should include a private method such as fireClientMessage() that iterates through the collection of listeners and invokes a function supported by ClientListener (and implemented by every Client).

Or something like that. I would design it so that the client exports a Remote interface to the Server side, but I'm evil like that.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
[This message has been edited by Michael Ernest (edited October 15, 2001).]


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Pratik Khetia
Ranch Hand

Joined: Jun 29, 2001
Posts: 50
Thanks for your reply. But I have difficulties regestering the clients as Listeners...
I have a client which has a thread running in it and which fetched the messages from the RMI server... how should I register the client as a listener...

I'd appriciate if you could elaborate more on that

thanks
Pratik
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

I can, but not from memory. At home I have a design for a distributed messaging system, from which I could jot down the interfaces needed to do this either point-to-point or publish-subscribe.
I'll get it up on this thread as soon as I get a chance. Patience, please.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
Pratik Khetia
Ranch Hand

Joined: Jun 29, 2001
Posts: 50
If you could do so then I would really appriciate your help !!
Looking forward to hear from you !!

thanks in advance
Pratik
Pratik Khetia
Ranch Hand

Joined: Jun 29, 2001
Posts: 50
Hi I am waiting for you to explain me about RMI issues plus I would also like for you to let me know about any good RMI resources on the net.
I am still stuck with that problem. So I am really waiting for yuor help.

thanks
Pratik
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Let me sketch out the basic elements and let's see where it takes you:
The roles to define for a remote event notification scheme:
Publisher -- server-side agent that produces events
--> requires an EventService to be constructed
Subscriber -- describes client
--> extends Remote
--> inform(Event evt)
--> concrete class has a Subscription
EventServiceInterface -- exchange btwn Subscriber/Publisher
--> extends Remote
--> publish(Event evt)
--> subscribe(Event evt, Filter flt, Subscriber sub)
--> unsubscribe(Event evt, Filter flt, Subscriber sub)
EventService
--> extends UnicastRemoteObject
--> implements EventServiceInterface
client-side: an EventServiceProxy
--> performs Naming.lookup()
--> encapsulates remote calls to publish/subscribe/unsubscribe
Subscription
--> a collection of Subscribers for a particular event type
--> optionally, has a Filter collection to refine the event list
Filter
--> remote service available to client
--> apply(Event evt):: boolean

------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
 
subject: Serialization Prob in RMI