KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > distr > grid > JGAPClientHandlerThread


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.distr.grid;
11
12 import org.homedns.dade.jcgrid.server.*;
13 import org.homedns.dade.jcgrid.*;
14 import org.homedns.dade.jcgrid.vfs.*;
15 import org.homedns.dade.jcgrid.message.*;
16 import org.homedns.dade.jcgrid.util.*;
17 import java.io.*;
18 import java.net.*;
19
20 /**
21  * Handles JGAP-specific messages on the client-side that are not supported originally by JCGrid.
22  *
23  * @author Klaus Meffert
24  * @since 3.2
25  */

26 public class JGAPClientHandlerThread
27     extends ClientHandlerThread {
28   /** String containing the CVS revision. Read out via reflection!*/
29   private final static String JavaDoc CVS_REVISION = "$Revision: 1.1 $";
30
31   public JGAPClientHandlerThread(GridServer server, Socket socket)
32       throws IOException {
33     super(server, socket);
34   }
35
36   protected void handleMsg(GridMessage msg)
37       throws Exception JavaDoc {
38     if (msg instanceof GridMessageVFSSessionFileRequest) {
39       String JavaDoc n = ( (GridMessageVFSSessionFileRequest) msg).getName();
40       // Read the file.
41
// --------------
42
File f = new File(super.gridServer.getVFSSessionPool().getPath(),n);
43       long fsize = f.length();
44       if (log.isDebugEnabled())
45         log.debug(" File size: " + fsize);
46       /**@todo consider 4GB limit*/
47       byte[] data = new byte[ (int) fsize];
48       FileInputStream fis = new FileInputStream(f);
49       fis.read(data);
50       fis.close();
51       handlerChannel.send(new GridMessageVFSSessionFileResult(data));
52     }
53     else {
54       super.handleMsg(msg);
55     }
56   }
57 }
58
Popular Tags