-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an extra thread to listen to messages for each RemoteEngine.
- Loading branch information
Stellard Tom
committed
Dec 6, 2009
1 parent
5c3573a
commit ae81e99
Showing
4 changed files
with
115 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.PriorityQueue; | ||
|
||
|
||
public class MessageReader implements Runnable{ | ||
|
||
private PriorityQueue<Message> recvdMessages; | ||
private InputStream in; | ||
private LocalEngine engine; | ||
|
||
public MessageReader(LocalEngine engine, InputStream in){ | ||
|
||
this.engine = engine; | ||
this.recvdMessages = engine.recvdMessages; | ||
this.in = in; | ||
} | ||
|
||
public void run() { | ||
while (true) { | ||
try { | ||
int messageType = in.read(); | ||
switch (messageType) { | ||
case Message.SENDAGENT: | ||
Message message = new Message(engine.turn, messageType); | ||
message.recvAgent(in); | ||
synchronized (recvdMessages) { | ||
recvdMessages.add(message); | ||
} | ||
break; | ||
case Message.ENDTURN: | ||
Message.endTurn(in); | ||
break; | ||
default: | ||
System.out.println("Unknown Message type " + messageType); | ||
} | ||
if(messageType == -1){ | ||
break; | ||
|
||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters