Explanation
The RemoteServerImpl class declares a number of variables. A Vector
("messages") is declared to store messages that will be posted to the
client. The setup() method is used to
create various components and to show the main window. The bindIt()
method is used to bind the server with the registry service.The getRegistered()
method is used by a client to get registered with the server. The method
gets a reference to the remote client as its argument. The passMessage()
method is called by a remote client to post messages to the server.
It takes a string object as its argument. The method appends the message
received to the end of the text area. The startThread()
method creates a Vector to store messages,
then it creates a new thread, and starts the thread. When you click
the "Send Message" button, the message is added to the Vector
and the waiting thread is notified. The thread gets the message from
the Vector and posts it to the client.
The ButtonHandler class implements
the ActionListener interface. When a
user clicks the "Send Message" button, the actionPerformed()
method of this class is invoked. The actionPerformed()
method adds the message to the Vector,
clears the text area, sets the focus on the text area, and calls the
wakeIt() method of the ThreadHandler
class to notify the waiting thread.
The ThreadHandler class implements
the Runnable interface. The wakeUp()
method of this class notifies the waiting thread. This method is called
when the data is available.The submit()
method is used to post messages to the server. The method first checks
whether the data is available or not. If there is no data available,
the thread simply enters the pool of waiting threads, otherwise it posts
the message to client. The run method
simply calls the submit method to post a message.
|