File size: 1,557 Bytes
7e59e4c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | package Server;
/*
* ServerManager.java
*/
import java.io.*;
import java.net.*;
import java.util.*;
import Common.*;
/**This class runs as a separate thread and remains blocked most of the time.
* The ServerSocketReader informs this class when it reads a message from
* the client. On such a notification, this thread then calls
* gotMessageFromClient(Message msg) of the ServerNetwork class.
*/
public class ServerManager extends Thread
{
/**ServerNetwork object which this ServerManager object will manage.*/
protected ServerNetwork serverNetwork;
/**Constructor taking ServerNetwork object
* @param sn ServerNetwork object to use to build the Manager
*/
public ServerManager(ServerNetwork sn)
{
serverNetwork = sn;
this.start();
}
/**A new thread which initially gets blocked. When there is an update, the ServerReader
* unblocks this and this thread takes the appropriate action.
*/
public synchronized void run()
{
while (true)
{
try
{
//this.wait(1000);
this.wait();
}
catch (InterruptedException e)
{
}
ClientConnection c = serverNetwork.clientConnection;
if (c.update)
{
this.serverNetwork.gotMessageFromClient(c.message);
c.update = false;
}
}
}
/**A small function to display messages.
* @param msg The message string to show.
*/
private void showMessage(String msg)
{
System.err.println("ServerManager: " + msg);
}
}
|