JoPropertySessionContextBuilder.java :  » Web-Server » jo » com » tagtraum » jobalancer » builder » Java Open Source

Java Open Source » Web Server » jo 
jo » com » tagtraum » jobalancer » builder » JoPropertySessionContextBuilder.java
/*
License $Id: JoPropertySessionContextBuilder.java,v 1.5 2003/09/16 04:24:10 hendriks73 Exp $

Copyright (c) 2001-2005 tagtraum industries.

LGPL
====

jo! is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

jo! is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

For LGPL see <http://www.fsf.org/copyleft/lesser.txt>


Sun license
===========

This release contains software by Sun Microsystems. Therefore
the following conditions have to be met, too. They apply to the
files

 - lib/mail.jar
 - lib/activation.jar
 - lib/jsse.jar
 - lib/jcert.jar
 - lib/jaxp.jar
 - lib/crimson.jar
 - lib/servlet.jar
 - lib/jnet.jar
 - lib/jaas.jar
 - lib/jaasmod.jar

contained in this release.

a. Licensee may not modify the Java Platform
   Interface (JPI, identified as classes contained within the javax
   package or any subpackages of the javax package), by creating additional
   classes within the JPI or otherwise causing the addition to or modification
   of the classes in the JPI.  In the event that Licensee creates any
   Java-related API and distribute such API to others for applet or
   application development, you must promptly publish broadly, an accurate
   specification for such API for free use by all developers of Java-based
   software.

b. Software is confidential copyrighted information of Sun and
   title to all copies is retained by Sun and/or its licensors.  Licensee
   shall not modify, decompile, disassemble, decrypt, extract, or otherwise
   reverse engineer Software.  Software may not be leased, assigned, or
   sublicensed, in whole or in part.  Software is not designed or intended
   for use in on-line control of aircraft, air traffic, aircraft navigation
   or aircraft communications; or in the design, construction, operation or
   maintenance of any nuclear facility.  Licensee warrants that it will not
   use or redistribute the Software for such purposes.

c. Software is provided "AS IS," without a warranty
   of any kind. ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES,
   INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.

d. This License is effective until terminated.  Licensee may
   terminate this License at any time by destroying all copies of Software.
   This License will terminate immediately without notice from Sun if Licensee
   fails to comply with any provision of this License.  Upon such termination,
   Licensee must destroy all copies of Software.

e. Software, including technical data, is subject to U.S.
   export control laws, including the U.S.  Export Administration Act and its
   associated regulations, and may be subject to export or import regulations
   in other countries.  Licensee agrees to comply strictly with all such
   regulations and acknowledges that it has the responsibility to obtain
   licenses to export, re-export, or import Software.  Software may not be
   downloaded, or otherwise exported or re-exported (i) into, or to a national
   or resident of, Cuba, Iraq, Iran, North Korea, Libya, Sudan, Syria or any
   country to which the U.S. has embargoed goods; or (ii) to anyone on the
   U.S. Treasury Department's list of Specially Designated Nations or the U.S.
   Commerce Department's Table of Denial Orders.


Feedback
========

We encourage your feedback and suggestions and want to use your feedback to
improve the Software. Send all such feedback to:
<feedback@tagtraum.com>

For more information on tagtraum industries and jo!
please see <http://www.tagtraum.com/>.


*/
package com.tagtraum.jobalancer.builder;

import com.tagtraum.framework.log.C_Log;
import com.tagtraum.framework.log.Log;
import com.tagtraum.framework.log.LogFileWriter;
import com.tagtraum.framework.log.LogWriter;
import com.tagtraum.framework.server.I_BasicService;
import com.tagtraum.framework.util.BuildException;
import com.tagtraum.framework.util.PlatformHelper;
import com.tagtraum.jo.builder.I_JoHostBuilder;
import com.tagtraum.jo.builder.JoPropertyBuilder;
import com.tagtraum.jobalancer.C_JoBalancer;
import com.tagtraum.jobalancer.I_JoRemoteSessionContext;

import java.io.IOException;
import java.net.URL;
import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Properties;

/**
 *
 * @author Hendrik Schreiber
 * @version 1.1beta1 $Id: JoPropertySessionContextBuilder.java,v 1.5 2003/09/16 04:24:10 hendriks73 Exp $
 */
public class JoPropertySessionContextBuilder extends JoPropertyBuilder implements C_JoBalancer {

    /**
     * Source-Version
     */
    public static String vcid = "$Id: JoPropertySessionContextBuilder.java,v 1.5 2003/09/16 04:24:10 hendriks73 Exp $";


    /**
     * Returns false for now.
     */
    public boolean needsRebuild() {
        return false;
    }

    /**
     * Not implemented.
     */
    public void rebuild(Object obj) throws BuildException {
        throw new BuildException("Not implemented.");
    }

    /**
     * Method declaration
     *
     *
     * @return
     *
     * @throws BuildException
     *
     * @see
     */
    public Object build() throws BuildException {
        I_JoRemoteSessionContext theRemoteSessionContext = null;
        Properties theProperties = new Properties();

        try {
            theProperties = loadProperties(new URL(getURL(), "sessionserver.properties"));
        }
        catch (IOException ioe) {
            Log.getLog(getName()).log("Failed to load 'sessioncontext.properties', will use defaults: " + ioe.toString());
        }

        try {

            URL theEventLogURL = new URL(getURL(), "sessionserverevent.log");
            String para = theProperties.getProperty("eventlog");

            if (para != null) {
                theEventLogURL = new URL(getURL(), para);
            }

            para = theProperties.getProperty("eventlogbuffer");

            int theEventLogBuffer = 0;

            if (para != null) {
                try {
                    theEventLogBuffer = Integer.parseInt(para);
                }
                catch (Exception e) {
                    Log.getLog(getName()).log("Couldn't parse 'eventlogbuffer'. Using default value: " + theEventLogBuffer, C_Log.METHOD);
                }
            }

            LogWriter theEventLog = new LogFileWriter(PlatformHelper.getOSSpecificPath(theEventLogURL.getFile()), true, theEventLogBuffer);

            Log.getLog(getName()).addI_LogEventListener(theEventLog);

            // eventlog level
            para = theProperties.getProperty("eventloglevel");

            if (para != null) {
                try {
                    Log.getLog(getName()).setLevel(Integer.parseInt(para));
                }
                catch (Exception e) {
                    Log.getLog(getName()).log("Couldn't parse 'eventloglevel'. Using default value: " + Log.getLog(getName()).getLevel(), C_Log.METHOD);
                }
            }

            // registry host
            String theRegistryHost = theProperties.getProperty("registryhost");

            if (theRegistryHost == null) {
                theRegistryHost = C_Default_RegistryHost;

                Log.getLog(getName()).log("'registryhost' not set, will use defaultvalue: " + theRegistryHost);
            }

            // registry name
            String theRegistryEntryName = theProperties.getProperty("registryentryname");

            if (theRegistryEntryName == null) {
                theRegistryEntryName = C_Default_RegistryEntryName;

                Log.getLog(getName()).log("'registryentryname' not set, will use defaultvalue: " + theRegistryEntryName);
            }

            // registry port
            para = theProperties.getProperty("registryport");

            int theRegistryPort = C_Default_RegistryPort;

            if (para != null) {
                try {
                    theRegistryPort = Integer.parseInt(para);
                }
                catch (NumberFormatException nfe) {
                    Log.getLog(getName()).log("Failed to parse 'registryport', will use defaultvalue: " + theRegistryPort);
                }
            } else {
                Log.getLog(getName()).log("'registryport' not set, will use defaultvalue: " + theRegistryPort);
            }

            // session timeout
            para = theProperties.getProperty("sessiontimeout");

            int theSessionTimeout = DEFAULT_SESSION_TIMEOUT;

            if (para != null) {
                try {
                    theSessionTimeout = Integer.parseInt(para);
                }
                catch (NumberFormatException nfe) {
                    Log.getLog(getName()).log("Failed to parse 'sessiontimeout', will use defaultvalue: " + theSessionTimeout + " min.");
                }
            } else {
                Log.getLog(getName()).log("'sessiontimeout' not set, will use defaultvalue: " + theSessionTimeout);
            }

            // context classname
            String theContextClassname = theProperties.getProperty("classname");

            if (theContextClassname == null) {
                theContextClassname = C_Default_SessionContextClassname;

                Log.getLog(getName()).log("'classname' not set, will use defaultvalue: " + theContextClassname);
            }

            // do we need this?
            System.setSecurityManager(new RMISecurityManager());

            // load stub
            Class.forName(theContextClassname + "_Stub");

            Registry theRegistry;

            // create Registry if necessary
            try {
                theRegistry = LocateRegistry.getRegistry(theRegistryHost, theRegistryPort);

                theRegistry.list();
            }
            catch (Exception e) {
                theRegistry = null;
            }

            if (theRegistry == null) {
                theRegistry = LocateRegistry.createRegistry(theRegistryPort);
            }

            theRemoteSessionContext = (I_JoRemoteSessionContext)Class.forName(theContextClassname).newInstance();

            theRemoteSessionContext.setDefaultMaxInactiveInterval(theSessionTimeout * 60);      // we need seconds here
            ((I_BasicService)theRemoteSessionContext).setName(getName());
            theRegistry.rebind(theRegistryEntryName, theRemoteSessionContext);

        }
        catch (Throwable t) {
            throw new BuildException(t);
        }

        return theRemoteSessionContext;
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.