001: /*
002: License $Id: JoPropertySessionContextBuilder.java,v 1.5 2003/09/16 04:24:10 hendriks73 Exp $
003:
004: Copyright (c) 2001-2005 tagtraum industries.
005:
006: LGPL
007: ====
008:
009: jo! is free software; you can redistribute it and/or
010: modify it under the terms of the GNU Lesser General Public
011: License as published by the Free Software Foundation; either
012: version 2.1 of the License, or (at your option) any later version.
013:
014: jo! is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018:
019: You should have received a copy of the GNU Lesser General Public
020: License along with this library; if not, write to the Free Software
021: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022:
023: For LGPL see <http://www.fsf.org/copyleft/lesser.txt>
024:
025:
026: Sun license
027: ===========
028:
029: This release contains software by Sun Microsystems. Therefore
030: the following conditions have to be met, too. They apply to the
031: files
032:
033: - lib/mail.jar
034: - lib/activation.jar
035: - lib/jsse.jar
036: - lib/jcert.jar
037: - lib/jaxp.jar
038: - lib/crimson.jar
039: - lib/servlet.jar
040: - lib/jnet.jar
041: - lib/jaas.jar
042: - lib/jaasmod.jar
043:
044: contained in this release.
045:
046: a. Licensee may not modify the Java Platform
047: Interface (JPI, identified as classes contained within the javax
048: package or any subpackages of the javax package), by creating additional
049: classes within the JPI or otherwise causing the addition to or modification
050: of the classes in the JPI. In the event that Licensee creates any
051: Java-related API and distribute such API to others for applet or
052: application development, you must promptly publish broadly, an accurate
053: specification for such API for free use by all developers of Java-based
054: software.
055:
056: b. Software is confidential copyrighted information of Sun and
057: title to all copies is retained by Sun and/or its licensors. Licensee
058: shall not modify, decompile, disassemble, decrypt, extract, or otherwise
059: reverse engineer Software. Software may not be leased, assigned, or
060: sublicensed, in whole or in part. Software is not designed or intended
061: for use in on-line control of aircraft, air traffic, aircraft navigation
062: or aircraft communications; or in the design, construction, operation or
063: maintenance of any nuclear facility. Licensee warrants that it will not
064: use or redistribute the Software for such purposes.
065:
066: c. Software is provided "AS IS," without a warranty
067: of any kind. ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES,
068: INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
069: PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
070:
071: d. This License is effective until terminated. Licensee may
072: terminate this License at any time by destroying all copies of Software.
073: This License will terminate immediately without notice from Sun if Licensee
074: fails to comply with any provision of this License. Upon such termination,
075: Licensee must destroy all copies of Software.
076:
077: e. Software, including technical data, is subject to U.S.
078: export control laws, including the U.S. Export Administration Act and its
079: associated regulations, and may be subject to export or import regulations
080: in other countries. Licensee agrees to comply strictly with all such
081: regulations and acknowledges that it has the responsibility to obtain
082: licenses to export, re-export, or import Software. Software may not be
083: downloaded, or otherwise exported or re-exported (i) into, or to a national
084: or resident of, Cuba, Iraq, Iran, North Korea, Libya, Sudan, Syria or any
085: country to which the U.S. has embargoed goods; or (ii) to anyone on the
086: U.S. Treasury Department's list of Specially Designated Nations or the U.S.
087: Commerce Department's Table of Denial Orders.
088:
089:
090: Feedback
091: ========
092:
093: We encourage your feedback and suggestions and want to use your feedback to
094: improve the Software. Send all such feedback to:
095: <feedback@tagtraum.com>
096:
097: For more information on tagtraum industries and jo!
098: please see <http://www.tagtraum.com/>.
099:
100:
101: */
102: package com.tagtraum.jobalancer.builder;
103:
104: import com.tagtraum.framework.log.C_Log;
105: import com.tagtraum.framework.log.Log;
106: import com.tagtraum.framework.log.LogFileWriter;
107: import com.tagtraum.framework.log.LogWriter;
108: import com.tagtraum.framework.server.I_BasicService;
109: import com.tagtraum.framework.util.BuildException;
110: import com.tagtraum.framework.util.PlatformHelper;
111: import com.tagtraum.jo.builder.I_JoHostBuilder;
112: import com.tagtraum.jo.builder.JoPropertyBuilder;
113: import com.tagtraum.jobalancer.C_JoBalancer;
114: import com.tagtraum.jobalancer.I_JoRemoteSessionContext;
115:
116: import java.io.IOException;
117: import java.net.URL;
118: import java.rmi.RMISecurityManager;
119: import java.rmi.registry.LocateRegistry;
120: import java.rmi.registry.Registry;
121: import java.util.Properties;
122:
123: /**
124: *
125: * @author Hendrik Schreiber
126: * @version 1.1beta1 $Id: JoPropertySessionContextBuilder.java,v 1.5 2003/09/16 04:24:10 hendriks73 Exp $
127: */
128: public class JoPropertySessionContextBuilder extends JoPropertyBuilder
129: implements C_JoBalancer {
130:
131: /**
132: * Source-Version
133: */
134: public static String vcid = "$Id: JoPropertySessionContextBuilder.java,v 1.5 2003/09/16 04:24:10 hendriks73 Exp $";
135:
136: /**
137: * Returns false for now.
138: */
139: public boolean needsRebuild() {
140: return false;
141: }
142:
143: /**
144: * Not implemented.
145: */
146: public void rebuild(Object obj) throws BuildException {
147: throw new BuildException("Not implemented.");
148: }
149:
150: /**
151: * Method declaration
152: *
153: *
154: * @return
155: *
156: * @throws BuildException
157: *
158: * @see
159: */
160: public Object build() throws BuildException {
161: I_JoRemoteSessionContext theRemoteSessionContext = null;
162: Properties theProperties = new Properties();
163:
164: try {
165: theProperties = loadProperties(new URL(getURL(),
166: "sessionserver.properties"));
167: } catch (IOException ioe) {
168: Log.getLog(getName()).log(
169: "Failed to load 'sessioncontext.properties', will use defaults: "
170: + ioe.toString());
171: }
172:
173: try {
174:
175: URL theEventLogURL = new URL(getURL(),
176: "sessionserverevent.log");
177: String para = theProperties.getProperty("eventlog");
178:
179: if (para != null) {
180: theEventLogURL = new URL(getURL(), para);
181: }
182:
183: para = theProperties.getProperty("eventlogbuffer");
184:
185: int theEventLogBuffer = 0;
186:
187: if (para != null) {
188: try {
189: theEventLogBuffer = Integer.parseInt(para);
190: } catch (Exception e) {
191: Log.getLog(getName()).log(
192: "Couldn't parse 'eventlogbuffer'. Using default value: "
193: + theEventLogBuffer, C_Log.METHOD);
194: }
195: }
196:
197: LogWriter theEventLog = new LogFileWriter(PlatformHelper
198: .getOSSpecificPath(theEventLogURL.getFile()), true,
199: theEventLogBuffer);
200:
201: Log.getLog(getName()).addI_LogEventListener(theEventLog);
202:
203: // eventlog level
204: para = theProperties.getProperty("eventloglevel");
205:
206: if (para != null) {
207: try {
208: Log.getLog(getName()).setLevel(
209: Integer.parseInt(para));
210: } catch (Exception e) {
211: Log.getLog(getName()).log(
212: "Couldn't parse 'eventloglevel'. Using default value: "
213: + Log.getLog(getName()).getLevel(),
214: C_Log.METHOD);
215: }
216: }
217:
218: // registry host
219: String theRegistryHost = theProperties
220: .getProperty("registryhost");
221:
222: if (theRegistryHost == null) {
223: theRegistryHost = C_Default_RegistryHost;
224:
225: Log.getLog(getName()).log(
226: "'registryhost' not set, will use defaultvalue: "
227: + theRegistryHost);
228: }
229:
230: // registry name
231: String theRegistryEntryName = theProperties
232: .getProperty("registryentryname");
233:
234: if (theRegistryEntryName == null) {
235: theRegistryEntryName = C_Default_RegistryEntryName;
236:
237: Log.getLog(getName()).log(
238: "'registryentryname' not set, will use defaultvalue: "
239: + theRegistryEntryName);
240: }
241:
242: // registry port
243: para = theProperties.getProperty("registryport");
244:
245: int theRegistryPort = C_Default_RegistryPort;
246:
247: if (para != null) {
248: try {
249: theRegistryPort = Integer.parseInt(para);
250: } catch (NumberFormatException nfe) {
251: Log.getLog(getName()).log(
252: "Failed to parse 'registryport', will use defaultvalue: "
253: + theRegistryPort);
254: }
255: } else {
256: Log.getLog(getName()).log(
257: "'registryport' not set, will use defaultvalue: "
258: + theRegistryPort);
259: }
260:
261: // session timeout
262: para = theProperties.getProperty("sessiontimeout");
263:
264: int theSessionTimeout = DEFAULT_SESSION_TIMEOUT;
265:
266: if (para != null) {
267: try {
268: theSessionTimeout = Integer.parseInt(para);
269: } catch (NumberFormatException nfe) {
270: Log.getLog(getName()).log(
271: "Failed to parse 'sessiontimeout', will use defaultvalue: "
272: + theSessionTimeout + " min.");
273: }
274: } else {
275: Log.getLog(getName()).log(
276: "'sessiontimeout' not set, will use defaultvalue: "
277: + theSessionTimeout);
278: }
279:
280: // context classname
281: String theContextClassname = theProperties
282: .getProperty("classname");
283:
284: if (theContextClassname == null) {
285: theContextClassname = C_Default_SessionContextClassname;
286:
287: Log.getLog(getName()).log(
288: "'classname' not set, will use defaultvalue: "
289: + theContextClassname);
290: }
291:
292: // do we need this?
293: System.setSecurityManager(new RMISecurityManager());
294:
295: // load stub
296: Class.forName(theContextClassname + "_Stub");
297:
298: Registry theRegistry;
299:
300: // create Registry if necessary
301: try {
302: theRegistry = LocateRegistry.getRegistry(
303: theRegistryHost, theRegistryPort);
304:
305: theRegistry.list();
306: } catch (Exception e) {
307: theRegistry = null;
308: }
309:
310: if (theRegistry == null) {
311: theRegistry = LocateRegistry
312: .createRegistry(theRegistryPort);
313: }
314:
315: theRemoteSessionContext = (I_JoRemoteSessionContext) Class
316: .forName(theContextClassname).newInstance();
317:
318: theRemoteSessionContext
319: .setDefaultMaxInactiveInterval(theSessionTimeout * 60); // we need seconds here
320: ((I_BasicService) theRemoteSessionContext)
321: .setName(getName());
322: theRegistry.rebind(theRegistryEntryName,
323: theRemoteSessionContext);
324:
325: } catch (Throwable t) {
326: throw new BuildException(t);
327: }
328:
329: return theRemoteSessionContext;
330: }
331:
332: }
|