/******************************************************************************* * Copyright (c) 2011 Ziver Koc * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ package zutil.net.nio.worker.grid; import java.io.IOException; import java.util.LinkedList; import java.util.Queue; import zutil.io.MultiPrintStream; import zutil.net.nio.NioClient; import zutil.net.nio.message.GridMessage; import zutil.net.nio.worker.ThreadedEventWorker; import zutil.net.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