001: /*
002: Copyright (C) 2004 David Bucciarelli (davibu@interfree.it)
003:
004: This program is free software; you can redistribute it and/or
005: modify it under the terms of the GNU General Public License
006: as published by the Free Software Foundation; either version 2
007: of the License, or (at your option) any later version.
008:
009: This program is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: GNU General Public License for more details.
013:
014: You should have received a copy of the GNU General Public License
015: along with this program; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: */
018:
019: package org.homedns.dade.jcgrid;
020:
021: import java.io.*;
022: import java.util.*;
023:
024: import org.homedns.dade.jcgrid.server.*;
025:
026: public class GridConfig implements Cloneable {
027: public final static int DEFAULT_CLIENT_PORT = 10101;
028: public final static int DEFAULT_WORKER_PORT = 10102;
029: public final static int DEFAULT_ADMIN_PORT = 10103;
030:
031: private String serverAddress;
032:
033: private int serverClientPort;
034: private int serverWorkerPort;
035: private int serverAdminPort;
036:
037: private boolean useSecureConnection;
038: private boolean useCompression;
039: private boolean useVFS;
040: private String serverPassword;
041:
042: public GridConfig(Properties prop) {
043: serverAddress = prop.getProperty("grid.server.hostname",
044: "localhost");
045:
046: serverClientPort = Integer.parseInt(prop.getProperty(
047: "grid.server.client.port", Integer
048: .toString(GridConfig.DEFAULT_CLIENT_PORT)));
049: serverWorkerPort = Integer.parseInt(prop.getProperty(
050: "grid.server.worker.port", Integer
051: .toString(GridConfig.DEFAULT_WORKER_PORT)));
052: serverAdminPort = Integer.parseInt(prop.getProperty(
053: "grid.server.admin.port", Integer
054: .toString(GridConfig.DEFAULT_ADMIN_PORT)));
055:
056: useSecureConnection = Boolean.valueOf(
057: prop.getProperty("grid.server.useencryption", Boolean
058: .toString(false))).booleanValue();
059: useCompression = Boolean.valueOf(
060: prop.getProperty("grid.server.usecompression", Boolean
061: .toString(false))).booleanValue();
062: useVFS = Boolean.valueOf(
063: prop.getProperty("grid.server.usevfs", Boolean
064: .toString(true))).booleanValue();
065: }
066:
067: public GridConfig() {
068: serverAddress = "localhost";
069:
070: serverClientPort = GridConfig.DEFAULT_CLIENT_PORT;
071: serverWorkerPort = GridConfig.DEFAULT_WORKER_PORT;
072: serverAdminPort = GridConfig.DEFAULT_ADMIN_PORT;
073:
074: useSecureConnection = false;
075: useCompression = false;
076: useVFS = true;
077: }
078:
079: public Object clone() {
080: try {
081: GridConfig cfg = (GridConfig) super .clone();
082: cfg.serverAddress = serverAddress;
083:
084: cfg.serverClientPort = serverClientPort;
085: cfg.serverWorkerPort = serverWorkerPort;
086: cfg.serverAdminPort = serverAdminPort;
087:
088: cfg.useSecureConnection = useSecureConnection;
089: cfg.useCompression = useCompression;
090: cfg.serverPassword = serverPassword;
091: cfg.useVFS = useVFS;
092:
093: return cfg;
094: } catch (CloneNotSupportedException e) {
095: throw new InternalError(e.toString());
096: }
097: }
098:
099: public Properties toProperties() {
100: Properties prop = new Properties();
101:
102: prop.put("grid.server.hostname", serverAddress);
103: prop.put("grid.server.client.port", Integer
104: .toString(serverClientPort));
105: prop.put("grid.server.worker.port", Integer
106: .toString(serverWorkerPort));
107: prop.put("grid.server.admin.port", Integer
108: .toString(serverAdminPort));
109: prop.put("grid.server.useencryption", Boolean
110: .toString(useSecureConnection));
111: prop.put("grid.server.usecompression", Boolean
112: .toString(useCompression));
113: prop.put("grid.server.usevfs", Boolean.toString(useVFS));
114:
115: return prop;
116: }
117:
118: //------------------------------- Get & Set --------------------------------
119:
120: public String getServerAddress() {
121: return serverAddress;
122: }
123:
124: public void setServerAddress(String server) {
125: serverAddress = server;
126: }
127:
128: public int getServerClientPort() {
129: return serverClientPort;
130: }
131:
132: public void setServerClientPort(int port) {
133: serverClientPort = port;
134: }
135:
136: public int getServerWorkerPort() {
137: return serverWorkerPort;
138: }
139:
140: public void setServerWorkerPort(int port) {
141: serverWorkerPort = port;
142: }
143:
144: public int getServerAdminPort() {
145: return serverAdminPort;
146: }
147:
148: public void setServerAdminPort(int port) {
149: serverAdminPort = port;
150: }
151:
152: public String getServerPassword() {
153: return serverPassword;
154: }
155:
156: public void setServerPassword(String pwd) {
157: serverPassword = pwd;
158: }
159:
160: public boolean getUseSecureConnection() {
161: return useSecureConnection;
162: }
163:
164: public void setUseSecureConnection(boolean use) {
165: useSecureConnection = use;
166: }
167:
168: public boolean getUseCompression() {
169: return useCompression;
170: }
171:
172: public void setUseCompression(boolean use) {
173: useCompression = use;
174: }
175:
176: public boolean getUseVFS() {
177: return useVFS;
178: }
179:
180: public void setUseVFS(boolean use) {
181: useVFS = use;
182: }
183: }
|