KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.commons.cli.*;
13 import org.apache.log4j.*;
14 import org.homedns.dade.jcgrid.cmd.*;
15 import org.homedns.dade.jcgrid.server.*;
16 import java.io.*;
17
18 /**
19  * A grid server able receiving work requests from JGAPClients, sending
20  * work units to JGAPWorkers, receiving solutions from JGAPWorkers, and
21  * sending back these solutions to the requesting JGAPClient.
22  *
23  * @author Klaus Meffert
24  * @since 3.01
25  */

26 public class JGAPServer {
27   /** String containing the CVS revision. Read out via reflection!*/
28   private final static String JavaDoc CVS_REVISION = "$Revision: 1.4 $";
29
30   private final static String JavaDoc className = JGAPServer.class.getName();
31
32   private static Logger log = Logger.getLogger(className);
33
34   private GridServer m_gs;
35
36   public JGAPServer(String JavaDoc[] args)
37       throws Exception JavaDoc {
38     m_gs = new GridServer(JGAPClientHandlerThread.class);
39     Options options = new Options();
40     CommandLine cmd = MainCmd.parseCommonOptions(options, m_gs.getNodeConfig(),
41         args);
42     // Start Server.
43
// -------------
44
m_gs.start();
45 // addFile("c:/temp/jgap/jgap.jar");
46
}
47
48   // Just for testing purposes
49
public void addFile(String JavaDoc a_filename) throws Exception JavaDoc {
50     String JavaDoc path = m_gs.getVFSSessionPool().getPath();
51     if (path == null) {
52       return;
53     }
54     if (path.charAt(path.length()-1) != '\\') {
55       path += "\\";
56     }
57     copyFile(a_filename, path);
58   }
59
60
61   public static void copyFile(String JavaDoc source, String JavaDoc dest) throws Exception JavaDoc {
62     File destFile = new File(dest);
63     if (!destFile.isFile()) {
64       String JavaDoc origFilename = new File(source).getName();
65       dest = dest + origFilename;
66     }
67
68     File inputFile = new File(source);
69     File outputFile = new File(dest);
70
71 // FileReader in = new FileReader(inputFile);
72
// FileWriter out = new FileWriter(outputFile);
73

74     FileInputStream in;
75     FileOutputStream out;
76     in = new FileInputStream(inputFile);
77     out = new FileOutputStream(outputFile);
78
79     int c;
80
81       while ( (c = in.read()) != -1)
82         out.write(c);
83
84       in.close();
85       out.close();
86   }
87
88
89   public static void main(String JavaDoc[] args)
90       throws Exception JavaDoc {
91     MainCmd.setUpLog4J("server", true);
92     // Create the server.
93
// ------------------
94
new JGAPServer(args);
95   }
96 }
97
Popular Tags