Java Reference
In-Depth Information
super
(process);
this
.socket
#
socket;
try
{
input
#
new
BufferedReader(
new
InputStreamReader
(socket.getInputStream()));
output
#
new
PrintWriter(
new
BufferedOutputStream
(socket.getOutputStream()),
false
);
}
catch
(IOException se) { se.printStackTrace(); }
}
public void
step() {
try
{
// waiting for a request
String message
#
input.readLine();
if
(message !
#
null
) {
// message format :
// "START PUSH
|
PULL activityName par1 par2 ... parN"
if
(message.substring(0,5).equals("START")) {
// verifies the synchronization mode
if
( message.substring(6,10).equals("PUSH"))
pushMode
#
true
;
String str
#
message.substring(11).trim();
// creates a service activity
if
(str.indexOf(' ') >
#
0) {
// gets the activity's class name
String activityClass
#
str.substring(0,
str.indexOf(' ')).trim();
// gets the service parameters
String parameters
#
str.substring(activityClass.
length()).trim();
// uses reflection to create a parser for the
// requested activity
parser
#
(DParser)Class.forName(activityClass
!
"Parser").newInstance();
// initializes the parser with a reference to
// the server
parser.setProcess(process);
// gets an instance of the requested service
service
#
parser.getActivity(parameters);
// starts the service
process.startActivity(service);
// parserActivity listens to the events raised
// by the service
service.addObserver(
this
.getURL(), "any");
}
}