Java Reference
In-Depth Information
their own
update()
methods to handle specific situations. Figure 11.3 depicts
the class diagram that defines class
EventProcess
.
11.4.3
Implementation
Class
EventProcess
implements the abstract component that represents the
generic control module of a client
server architecture. Every concrete
control module must implement the
run()
method. The
attachTo()
method
can be invoked by the object itself or by an external object that holds a
reference to this object. Clients wait for an event and suspend their execu-
tion by invoking method
waitEvent()
. Servers notify their state transitions by
notifying events with method
notifyObservers()
.
-
package
parking;
import
java.util.Observable;
import
java.util.Observer;
public class
EventProcess
extends
Observable
implements
Observer, Runnable{
String name; // the name of this EventProcess
Thread thread;
// the thread that executes the run() method
boolean
alive
#
false
; // true when the thread is running
String observable
#
"";// the name of an observable object
String event
#
"";
// the event this object is waiting for
public
EventProcess(String name) {
this
.name
#
name;
}
// the invoker of attachTo() is an Observer; the parameter
// is an Observable; it adds this object to the list of
// observers of "process";
Observable
Runnable
Observer
EventProcess
String name
Thread thread
update()
notifyObservers()
waitEvent()
run()
Figure 11.3
The class diagram