01: /*
02: * This file is part of JGAP.
03: *
04: * JGAP offers a dual license model containing the LGPL as well as the MPL.
05: *
06: * For licencing information please see the file license.txt included with JGAP
07: * or have a look at the top of class org.jgap.Chromosome which representatively
08: * includes the JGAP license policy applicable for any file delivered with JGAP.
09: */
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 extends ClientHandlerThread {
27: /** String containing the CVS revision. Read out via reflection!*/
28: private final static String CVS_REVISION = "$Revision: 1.1 $";
29:
30: public JGAPClientHandlerThread(GridServer server, Socket socket)
31: throws IOException {
32: super (server, socket);
33: }
34:
35: protected void handleMsg(GridMessage msg) throws Exception {
36: if (msg instanceof GridMessageVFSSessionFileRequest) {
37: String n = ((GridMessageVFSSessionFileRequest) msg)
38: .getName();
39: // Read the file.
40: // --------------
41: File f = new File(super .gridServer.getVFSSessionPool()
42: .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(
52: data));
53: } else {
54: super.handleMsg(msg);
55: }
56: }
57: }
|