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.worker;
020:
021: import java.io.*;
022: import java.net.*;
023: import javax.net.ssl.*;
024:
025: import org.apache.log4j.*;
026:
027: import org.homedns.dade.jcgrid.*;
028: import org.homedns.dade.jcgrid.vfs.*;
029: import org.homedns.dade.jcgrid.util.*;
030:
031: public class GridWorker extends GridNodeGeneric {
032: private final static String className = GridWorker.class.getName();
033: private static Logger log = Logger.getLogger(className);
034: private static Logger logDetail = Logger.getLogger("DETAIL."
035: + className);
036:
037: private Worker worker;
038: private WorkerThread wt;
039: private long maxCacheSize;
040:
041: private vfsSessionPool sessions;
042: private GridWorkerFeedback feedback;
043:
044: public GridWorker() {
045: super (new GridNodeWorkerConfig());
046:
047: if (log.isDebugEnabled())
048: log.debug("Start GridWorker()");
049:
050: worker = null;
051: wt = null;
052: maxCacheSize = 64 * 1024 * 1024;
053:
054: sessions = null;
055: feedback = null;
056:
057: if (log.isDebugEnabled())
058: log.debug("End GridWorker()");
059: }
060:
061: //----------------------------- Start & Stop -------------------------------
062:
063: public void start() throws Exception {
064: if (logDetail.isDebugEnabled())
065: logDetail.debug("Start start()");
066:
067: super .start();
068:
069: if (this .getNodeConfig().getGridConfig().getUseVFS()) {
070: sessions = new vfsSessionPool(super .getNodeConfig()
071: .getWorkingDir(), maxCacheSize);
072: sessions.start();
073: log.warn("VFS Session cache size: " + sessions.getSize()
074: / (1024 * 1024) + "/" + maxCacheSize
075: / (1024 * 1024) + "MB");
076: } else
077: sessions = null;
078:
079: wt = new WorkerThread(this );
080: wt.setWorkerFeedback(feedback);
081: wt.start();
082:
083: if (logDetail.isDebugEnabled())
084: logDetail.debug("End start()");
085: }
086:
087: public void waitShutdown() throws InterruptedException {
088: if (logDetail.isDebugEnabled())
089: logDetail.debug("Start waitShutdown()");
090:
091: wt.join();
092:
093: if (logDetail.isDebugEnabled())
094: logDetail.debug("End waitShutdown()");
095: }
096:
097: public void stop() throws Exception {
098: if (logDetail.isDebugEnabled())
099: logDetail.debug("Start stop()");
100:
101: wt.interrupt();
102: try {
103: wt.join();
104: } catch (InterruptedException iex) {
105: }
106:
107: super .stop();
108:
109: if (logDetail.isDebugEnabled())
110: logDetail.debug("End stop()");
111: }
112:
113: //------------------------------- Get & Set --------------------------------
114:
115: public void setWorkerFeedback(GridWorkerFeedback f) {
116: if (logDetail.isDebugEnabled())
117: logDetail.debug("Start setWorkerFeedback(" + f + ")");
118:
119: feedback = f;
120: if (wt != null)
121: wt.setWorkerFeedback(f);
122:
123: if (logDetail.isDebugEnabled())
124: logDetail.debug("End setWorkerFeedback()");
125: }
126:
127: public vfsSessionPool getVFSSessionPool() {
128: if (logDetail.isDebugEnabled())
129: logDetail.debug("Start getVFSSessionPool()");
130: if (logDetail.isDebugEnabled())
131: logDetail.debug("End getVFSSessionPool(" + sessions + ")");
132:
133: return sessions;
134: }
135:
136: public Worker getWorker() {
137: if (logDetail.isDebugEnabled())
138: logDetail.debug("Start getWorker()");
139: if (logDetail.isDebugEnabled())
140: logDetail.debug("End getWorker(" + worker + ")");
141:
142: return worker;
143: }
144:
145: public void setWorker(Worker w) {
146: if (logDetail.isDebugEnabled())
147: logDetail.debug("Start setWorker(" + w + ")");
148:
149: worker = w;
150:
151: if (logDetail.isDebugEnabled())
152: logDetail.debug("End setWorker()");
153: }
154:
155: public long getMaxCacheSize() {
156: if (logDetail.isDebugEnabled())
157: logDetail.debug("Start getMaxCacheSize()");
158: if (logDetail.isDebugEnabled())
159: logDetail
160: .debug("End getMaxCacheSize(" + maxCacheSize + ")");
161:
162: return maxCacheSize;
163: }
164:
165: public void setMaxCacheSize(long serverMaxCacheSize) {
166: if (logDetail.isDebugEnabled())
167: logDetail.debug("Start setMaxCacheSize("
168: + serverMaxCacheSize + ")");
169:
170: maxCacheSize = serverMaxCacheSize;
171:
172: if (logDetail.isDebugEnabled())
173: logDetail.debug("End setMaxCacheSize()");
174: }
175: }
|