Java Reference
In-Depth Information
extends
UnicastRemoteObject
implements
Runnable {
protected
String name
#
"";
// this name is assigned by DProcess
protected
String address
#
"";
// the IP address of the hosting machine
protected
DProcess process;
protected
Thread thread;
private boolean
alive
#
false
;
public
DActivity(DProcess process)
throws
java.rmi.RemoteException {
this
.process
#
process;
}
// this method is invoked by class DProcess
// when the activity is started
void
setURL(String name, String address) {
this
.name
#
name;
this
.address
#
address;
}
// returns the URL of this activity
public
String getURL()
{
return
"//"
!
address
!
"/"
!
name; }
// repeats the invocation of method step
public void
run() {
init();
while
(alive)
step();
quit();
}
// starts the thread of this activity
public void
start() {
if
(alive)
return
;
thread
#
new
Thread(
this
);
alive
#
true
;
thread.start();
}
// stops the thread of this activity
public void
stop() {
if
(! alive)
return
;
alive
#
false
; // stops the thread
try
{
if
(Thread.currentThread() !
#
thread)
// this activity is not stopping itself
// thus waits for thread to die
thread.join();
}
catch
(InterruptedException ie) { ie.printStackTrace();
}