📄 main.java
字号:
// Creates the default context. To dispatch to this context, you have to // specify the destination, for example, // "atp://aglets.trl.ibm.com:4434/" AgletContext cxt = runtime.createAgletContext(""); // Attatches a viewer to the default context. ContextListener viewer = getViewer(); if (viewer != null) { cxt.addContextListener(viewer); } // Installs the Aglets security manager. Tahiti.installSecurity(); // Starts the MAFAgentSystem. MAFAgentSystem.startMAFAgentSystem(maf_system, protocol); // Starts the default context. cxt.start(_reactivation); // Creates initial aglets which are specified by the server properties. startupAglets(cxt); if (_verbose) { System.err.println("Aglets server started"); } } /** * Description of the Method */ private static void loadAudioClasses() { try { Class.forName("sun.audio.AudioPlayer"); } catch (Throwable ex) { ex.printStackTrace(); } } /** * Description of the Method */ private static void loadAWTClasses() { try { // Disabled for test on VAJava2(HT) // Class.forName("sun.awt.image.JPEGImageDecoder"); java.awt.Frame f = new java.awt.Frame(); f.addNotify(); f.dispose(); // Class.forName("sun.awt.PlatformFont"); // for 1.1 // Class.forName("sun.awt.ScreenUpdater"); } catch (Throwable ex) { ex.printStackTrace(); } } /** * Description of the Method * * @param runtime Description of Parameter * @return Description of the Returned Value */ private static Certificate login(AgletRuntime runtime) { UserManager userManager = null; // decide UI if (VIEWER_TAHITI.equals(_viewer_class_name)) { userManager = Tahiti.getUserManager(); } else if (VIEWER_COMMANDLINE.equals(_viewer_class_name)) { userManager = CommandLine.getUserManager(); } else if (VIEWER_TAHITI_DAEMON.equals(_viewer_class_name)) { userManager = TahitiDaemon.getUserManager(); } //else? throw exception, or default to what? // user authentication on UI String username = runtime.getOwnerName(); if (username == null) { username = UserManager.getDefaultUsername(); } if (username == null) { System.err.println("No username."); return null; } /* * -------------- * while (!UserManager.isUserRegistered()) { * user registration is needed * System.err.println("No user is registered. Register yourself."); * userManager.registration(); * } * --------------- */ // try to login with no password Certificate cert = runtime.authenticateOwner(username, ""); if (cert == null) { // login failed. try to login with password if (userManager != null) { cert = userManager.login(); username = userManager.getUsername(); } } if (cert == null) { System.err.println("Authentication of user '" + username + "' is failed."); } return cert; } /** * Description of the Method * * @param args Description of Parameter */ private static void parseArgs(String[] args) { if (args.length <= 0) { return; } for (int i = 0; i < args.length; i++) { if (args[i].equalsIgnoreCase("-help")) { } else if (args[i].equalsIgnoreCase("-verbose")) { _verbose = true; } else if (args[i].equalsIgnoreCase("-nogui")) { _nogui = true; } else if (args[i].equalsIgnoreCase("-daemon")) { _daemon = true; } else if (args[i].equalsIgnoreCase("-nosound")) { _nosound = true; } else if (args[i].equalsIgnoreCase("-cleanstart")) { _reactivation = false; } else if (args[i].equalsIgnoreCase("-f")) { if (i + 1 >= args.length) { usage(); } i++; try { readProperties(args[i]); } catch (IOException ex) { System.err.println("Server property file was not found: " + args[i]); usage(); } } else if (args[i].equalsIgnoreCase("-port")) { if (i + 1 >= args.length) { usage(); } i++; try { _port_num = Integer.parseInt(args[i]); } catch (NumberFormatException ex) { ex.printStackTrace(); } } else if (args[i].equalsIgnoreCase("-controlport")) { if (i + 1 >= args.length) { usage(); } i++; try { _control_port_num = Integer.parseInt(args[i]); } catch (NumberFormatException ex) { ex.printStackTrace(); } } } } /** * Concatenates path strings(util method). * * @param p1 Preceding path string. * @param p2 Posterior path string. * @return A concatenated path string. */ private static String pathConcat(String p1, String p2) { p2 = p2.replace('/', FS.charAt(0)); if (!p1.endsWith(FS)) { p1 = p1 + FS; } if (p2.startsWith(FS)) { p2 = p2.substring(0, p2.length() - 1); } return (p1 + p2); } /** * Reads property from specified file(util method). * * @param file name of the property file. * @exception IOException if it failed to read the property file. */ private static void readProperties(String file) throws IOException { if (_verbose) { System.err.println("[Reading property file: " + file + "]"); } InputStream is = new FileInputStream(file); Properties system_props = System.getProperties(); Properties props = new Properties(); props.load(is); // Copy properties into the system property for (Enumeration e = props.propertyNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); String val = (String) props.get(key); if (("aglets.viewer".equals(key)) || (val != null && val.length() > 0)) { if (val == null) { system_props.remove(key); } else { system_props.put(key, val); } } } } /** * Description of the Method */ private static void resolveProperties() { Properties props = System.getProperties(); // Get mandatory properties String aglets_home = props.getProperty("install.root"); // install.root will be given the script produced // by InstallShield JavaEdition. if (aglets_home == null) { aglets_home = props.getProperty("aglets.home", null); if (aglets_home == null || aglets_home.length() == 0) { System.err.println("Please specify aglets.home property"); System.exit(1); } } String user_home = props.getProperty("user.home", null); if (user_home == null || user_home.length() == 0) { user_home = FileUtils.getUserHome(); } if (user_home == null || user_home.length() == 0) { System.err.println("Please specify user.home property"); System.exit(1); } String p; // java.policy p = props.getProperty("java.policy", null); if (p == null) { props.put("java.policy", pathConcat(user_home, ".aglets/security/aglets.policy")); } // aglets.class.path p = props.getProperty("aglets.class.path", null); if (p == null) { props.put("aglets.class.path", pathConcat(aglets_home, "public")); } // aglets.public.root p = props.getProperty("aglets.public.root", null); if (p == null) { props.put("aglets.public.root", pathConcat(aglets_home, "public")); } // aglets.viewer _viewer_class_name = props.getProperty("aglets.viewer", null); // aglets.logfile p = props.getProperty("aglets.logfile", null); if (p != null) { try { LogStream log = new LogStream("LOG", new FileOutputStream(p)); // OutputStream log = new java.io.FileOutputStream(p); OutputStream tee = new com.ibm.awb.misc.TeeOutputStream(System.out, log); PrintStream ps = new java.io.PrintStream(tee); System.setOut(ps); System.setErr(ps); } catch (Exception ex) { ex.printStackTrace(); } } // aglets.cleanstart p = props.getProperty("aglets.cleanstart", "false"); if ("true".equalsIgnoreCase(p)) { _reactivation = false; } } /** * Description of the Method */ private static void usage() { System.err.println("\nAglet Server(com.ibm.awb.launcher.Main) usage:"); System.err.println("options:"); System.err.println(" -f <file.props> server property file"); System.err.println(" -port <num> port number (default 4434)"); System.err.println(" -controlport <num> port number (default 4444)"); System.err.println(" -verbose verbose output"); System.err.println(" -nogui omit AWT initialization"); System.err.println(" -daemon run as a daemon"); System.err.println(" -nosound omit Sound initialization"); System.err.println(" -cleanstart kill deactivated aglets"); System.err.println(" -help print this message"); System.err.println("note: '-f' option can be specified more than once,"); System.err.println(" properties in the following file will override"); System.exit(1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -