package zutil.network.nio.worker.grid; import java.io.IOException; import java.util.LinkedList; import java.util.Queue; import zutil.MultiPrintStream; import zutil.network.nio.NioClient; import zutil.network.nio.message.GridMessage; import zutil.network.nio.worker.ThreadedEventWorker; import zutil.network.nio.worker.WorkerDataEvent; /** * This class is the client part of the grid. * It connects to a grid server and requests new job. * And then sends back the result to the server. * * @author Ziver */ @SuppressWarnings({ "unchecked", "rawtypes" }) public class GridClient extends ThreadedEventWorker { private static LinkedList jobQueue; private static GridThread thread; private static NioClient network; /** * Creates a new GridClient object and registers itself at the server * and sets itself as a worker in NioClient * * @param thread the Thread interface to run for the jobs * @param network the NioClient to use to communicate to the server */ public GridClient(GridThread thread, NioClient network){ jobQueue = new LinkedList(); GridClient.thread = thread; GridClient.network = network; } /** * Starts up the client and a couple of GridThreads. * And registers itself as a worker in NioClient * @throws IOException */ public void initiate() throws IOException{ network.setDefaultWorker(this); network.send(new GridMessage(GridMessage.REGISTER)); for(int i=0; i