⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 aglet的部分源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.ibm.awb.launcher;/* * @(#)Main.java * * IBM Confidential-Restricted * * OCO Source Materials * * 03L7246 (c) Copyright IBM Corp. 1996, 1998 * * The source code for this program is not published or otherwise * divested of its trade secrets, irrespective of what has been * deposited with the U.S. Copyright Office. */import java.net.URL;import java.net.UnknownHostException;import java.io.*;import java.util.Properties;import java.util.StringTokenizer;import java.util.Vector;import java.util.Enumeration;import java.security.cert.Certificate;import com.ibm.maf.*;import com.ibm.aglet.*;import com.ibm.aglet.system.*;import com.ibm.aglets.MAFAgentSystem_AgletsImpl;import com.ibm.aglets.tahiti.Tahiti;import com.ibm.aglets.tahiti.UserManager;import com.ibm.aglets.tahiti.CommandLine;import com.ibm.aglets.tahiti.TahitiDaemon;import com.ibm.awb.misc.FileUtils;import com.ibm.awb.misc.Resource;import com.ibm.awb.misc.LogStream;import org.aglets.log.LogCategory;import org.aglets.log.LogInitializer;/** *  Aglets server bootstrap. * * @author     Hideki Tai * @created    July 22, 2001 * @version    $Revision: 1.2 $ $Date: 2002/02/20 22:17:18 $ $Author: kbd4hire $ */public class Main {    private final static String         VIEWER_TAHITI =            "com.ibm.aglets.tahiti.Tahiti";    private final static String         VIEWER_COMMANDLINE =            "com.ibm.aglets.tahiti.CommandLine";    private final static String         VIEWER_TAHITI_DAEMON =            "com.ibm.aglets.tahiti.TahitiDaemon";    private final static String         DEFAULT_VIEWER = VIEWER_TAHITI;    private final static String         DELIM = ", \t\n";    private static String[]             _startup_aglets = null;    private static String               _viewer_class_name = DEFAULT_VIEWER;    private static boolean              _reactivation = true;    private static int                  _port_num = -1;    private static int                  _control_port_num = -1;    private static boolean              _verbose = false;    private static boolean              _nogui = false;    private static boolean              _daemon = false;    private static boolean              _nosound = false;    private static String               FS;    private static String               PS;    /**     *  Bootstrap aglets server. This main method takes at most one parameter     *  which specifies a name of a bootstrarp property file. The default file     *  name is "./boot.props"     *     * @param  args             The command line arguments     * @exception  IOException  Description of Exception     */    public static void main(String[] args) throws IOException {        // System.setOut(new LogStream("OUT", System.out));        // System.setErr(new LogStream("ERR", System.err));        // Get system properties        Properties system_props = System.getProperties();        FS = system_props.getProperty("file.separator");        PS = system_props.getProperty("path.separator");        setDefaultProperties();        parseArgs(args);        resolveProperties();        if (_verbose) {            system_props.put("verbose", "true");        } else {            system_props.put("verbose", "false");        }        if (_port_num > 0) {            system_props.put("maf.port", Integer.toString(_port_num));        }        if (_control_port_num > 0) {            system_props.put("maf.controlport", Integer.toString(_control_port_num));        }        try {            // Logging starts here!            bootstrap();        } catch (Exception ex) {            ex.printStackTrace();        }    }    /**     *  Creates initial aglets.     *     * @param  context  Description of Parameter     */    protected static void startupAglets(AgletContext context) {        String[] startup_aglets = null;        boolean startup = false;        String p = System.getProperties().getProperty("aglets.startup", null);        if (p != null) {            StringTokenizer st = new StringTokenizer(p, DELIM);            Vector v = new Vector();            while (st.hasMoreTokens()) {                v.addElement(st.nextToken());            }            startup_aglets = new String[v.size()];            v.copyInto(startup_aglets);            startup = true;        }        if (startup_aglets == null) {            // handle startup entry in "tahiti.properties"            Resource tahiti_res = Resource.getResourceFor("tahiti");            startup = tahiti_res.getBoolean("tahiti.startup", false);            startup_aglets = tahiti_res.getStringArray("tahiti.startupAglets",                    DELIM);        }        if (startup && startup_aglets != null) {            for (int i = 0; i < startup_aglets.length; i++) {                String initparam = null;                URL codebase = null;                String name = startup_aglets[i];                try {                    int del = name.lastIndexOf('#');                    if (del > 0) {                        initparam = name.substring(del + 1);                        name = name.substring(0, del);                    }                    del = name.lastIndexOf('/');                    if (del > 0) {                        codebase = new URL(name.substring(0, del));                        name = name.substring(del + 1);                    }                } catch (java.net.MalformedURLException ex) {                    ex.printStackTrace();                }                try {                    context.createAglet(codebase, name, initparam);                } catch (Exception e) {                    System.err.println("Failed to create the \"Startup\" Aglet:"                             + e.getMessage());                    System.err.println("[" + codebase + "] [" + name + "]");                    e.printStackTrace();                }            }        }    }    /**     *  Sets the DefaultProperties attribute of the Main class     */    private static void setDefaultProperties() {        Properties props = System.getProperties();        props.remove("java.policy");// Should be set after        props.remove("aglets.class.path");// Should be set after        props.remove("aglets.public.root");// Should be set after        props.put("verbose", "false");        props.put("maf.protocol", "atp");        props.put("maf.port", "4434");        props.put("maf.controlport", "5545");        props.remove("maf.finder.host");        props.put("maf.finder.port", "4435");        props.put("maf.finder.name", "MAFFinder");        props.put("aglets.secure", "true");        props.put("aglets.viewer", DEFAULT_VIEWER);        props.put("aglets.cleanstart", "false");        props.remove("aglets.startup");        props.put("aglets.owner.name", props.getProperty("user.name"));        props.remove("aglets.logfile");        props.put("atp.resolve", "false");        props.put("atp.useip", "false");        props.put("atp.offline", "false");        props.put("atp.authentication", "false");        props.put("atp.secureseed", "true");    }    /**     *  Gets the Viewer attribute of the Main class     *     * @return    The Viewer value     */    private static ContextListener getViewer() {        return getViewer(_viewer_class_name);    }    /**     *  Gets the Viewer attribute of the Main class     *     * @param  viewer  Description of Parameter     * @return         The Viewer value     */    private static ContextListener getViewer(String viewer) {        if (viewer != null && viewer.length() > 0) {            Class viewClass = null;            try {                viewClass = Class.forName(viewer);            } catch (ClassNotFoundException ex) {                System.err.println("[Viewer " + viewer + " not found.]");                return null;            }            if (ContextListener.class.isAssignableFrom(viewClass) == false) {                System.err.println("[Viewer " + viewer                         + " is not subclass of ContextListener interface.");                return null;            }            try {                return (ContextListener) viewClass.newInstance();            } catch (IllegalAccessException excpt) {                return null;            } catch (InstantiationException excpt) {                return null;            }        }        return null;    }    /**     *  Bootstraps aglets server. (AgletRuntime, MAFAgentSystem, and Tahiti)     *     * @exception  Exception  Description of Exception     */    private static void bootstrap() throws Exception {        // Initialize logging system.        String initializerName = System.getProperty("aglets.logger.class",            "org.aglets.log.quiet.QuietInitializer" );        Class.forName(initializerName);        LogCategory cat = LogInitializer.getCategory(Main.class.getName());        cat.info("Logging system initialized!");        // Initializes AWT and Audio classes.        if (!(_nogui || _daemon)) {            _viewer_class_name = VIEWER_TAHITI;            if (_verbose) {                System.err.print("[Loading AWT classes ... ");            }            loadAWTClasses();            if (_verbose) {                System.err.println("done.]");            }            if (!_nosound) {                if (_verbose) {                    System.err.print("[Loading Audio classes ... ");                }                loadAudioClasses();                if (_verbose) {                    System.err.println("done.]");                }            }        }        if (_nogui) {            _viewer_class_name = VIEWER_COMMANDLINE;        }        if (_daemon) {            _viewer_class_name = VIEWER_TAHITI_DAEMON;        }        // Initializes the Aglet runtime.        AgletRuntime runtime = AgletRuntime.init(null);        // Authenticate the owner of the runtime.        // At first, tries to get account information from the server property.        String owner = System.getProperty("aglets.owner.name");        boolean authenticated = false;        if (owner != null) {            String passwd = System.getProperty("aglets.owner.password");            authenticated = (runtime.authenticateOwner(owner, passwd)                     != null);            if (authenticated) {                if (_verbose) {                    System.err.println("[Succeed in owner authentication: \""                             + owner + "\"]");                }            } else {                if (_verbose) {                    System.err.println("[Failed to authenticate the owner: \""                             + owner + "\"]");                }            }        }        if (!authenticated) {            // Asks for the user to login via user interface.            if (login(runtime) == null) {                return;            }        }        // Creates MAFAgentSystem and initialize it.        MAFAgentSystem maf_system = new MAFAgentSystem_AgletsImpl(runtime);        String protocol = System.getProperties().getProperty("maf.protocol");        cat.debug("Initializing handler: "+protocol);        MAFAgentSystem.initMAFAgentSystem(maf_system, protocol);        // Initializes Tahiti(part of the agent system)        Tahiti.init();        Tahiti.installFactories();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -