| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
package argos; |
| 32 | |
|
| 33 | |
import java.io.File; |
| 34 | |
import java.io.FileInputStream; |
| 35 | |
import java.io.IOException; |
| 36 | |
import java.lang.management.ManagementFactory; |
| 37 | |
import java.rmi.RMISecurityManager; |
| 38 | |
import java.util.ArrayList; |
| 39 | |
import java.util.List; |
| 40 | |
import java.util.logging.LogManager; |
| 41 | |
import java.util.logging.Logger; |
| 42 | |
|
| 43 | |
import argos.config.Config; |
| 44 | |
import argos.deploy.ComponentManager; |
| 45 | |
import argos.deploy.HotDeployer; |
| 46 | |
import argos.logging.Console; |
| 47 | |
import argos.naming.NamingService; |
| 48 | |
import argos.proxy.DynamicProxyUtil; |
| 49 | |
import argos.util.Util; |
| 50 | |
|
| 51 | 0 | public class Argos { |
| 52 | 0 | private static final Logger logger = Logger.getLogger(Argos.class.getName()); |
| 53 | |
public static final String DEPLOY_DIR = "deploy"; |
| 54 | |
public static final String LOG_DIR = "logs"; |
| 55 | |
public static final String TEMP_DIR = "temp"; |
| 56 | |
private static final String ARGOS_POLICY_FILE = "argos.policy"; |
| 57 | |
|
| 58 | |
public static void main(String[] args) throws IOException { |
| 59 | 0 | long start = System.currentTimeMillis(); |
| 60 | |
|
| 61 | 0 | createFolders(TEMP_DIR, LOG_DIR, DEPLOY_DIR); |
| 62 | 0 | if (!new File(Config.CONFIG_FILE).exists()) { |
| 63 | 0 | Util.writeResourceToFile("/" + Config.CONFIG_FILE, Config.CONFIG_FILE); |
| 64 | |
} |
| 65 | 0 | Config config = Config.getInstance(); |
| 66 | |
|
| 67 | 0 | LogManager.getLogManager().readConfiguration(new FileInputStream(Config.CONFIG_FILE)); |
| 68 | 0 | logger.info("Log configuration file loaded."); |
| 69 | |
|
| 70 | 0 | String tempPolicyFile = TEMP_DIR + File.pathSeparator + ARGOS_POLICY_FILE; |
| 71 | 0 | Util.writeResourceToFile("/" + ARGOS_POLICY_FILE, tempPolicyFile); |
| 72 | 0 | System.setProperty("java.security.policy", tempPolicyFile); |
| 73 | 0 | if (System.getSecurityManager() == null) { |
| 74 | 0 | System.setSecurityManager(new RMISecurityManager()); |
| 75 | |
} |
| 76 | |
|
| 77 | |
|
| 78 | 0 | ManagementFactory.getPlatformMBeanServer(); |
| 79 | 0 | logger.info("MBean server created."); |
| 80 | |
|
| 81 | |
|
| 82 | 0 | DynamicProxyUtil.instrument("Console", Console.console); |
| 83 | |
|
| 84 | |
|
| 85 | 0 | DynamicProxyUtil.instrument("Config", config); |
| 86 | |
|
| 87 | |
|
| 88 | 0 | DynamicProxyUtil.instrument("ComponentManager", ComponentManager.getInstance()); |
| 89 | 0 | logger.info("Component Manager created."); |
| 90 | |
|
| 91 | |
|
| 92 | 0 | DynamicProxyUtil.instrument("NamingService", NamingService.getInstance()); |
| 93 | 0 | logger.info("Naming service created."); |
| 94 | |
|
| 95 | |
|
| 96 | 0 | if (args.length == 0) { |
| 97 | 0 | HotDeployer deployer = HotDeployer.getInstance(); |
| 98 | 0 | DynamicProxyUtil.instrument("HotDeployer", deployer, false); |
| 99 | 0 | deployer.start(); |
| 100 | 0 | logger.info("Hot deployer started."); |
| 101 | 0 | } else { |
| 102 | 0 | logger.info("Prefined files given on command line, not starting Hot deployer. Loading files..."); |
| 103 | 0 | List<File> files = new ArrayList<File>(); |
| 104 | 0 | for (String filename : args) { |
| 105 | 0 | files.add(new File(filename)); |
| 106 | |
} |
| 107 | 0 | ComponentManager.getInstance().deploy(files); |
| 108 | |
} |
| 109 | |
|
| 110 | 0 | Runtime.getRuntime().addShutdownHook(new ShutdownHook()); |
| 111 | |
|
| 112 | |
|
| 113 | 0 | double used = (System.currentTimeMillis() - start) / 1000.0; |
| 114 | 0 | logger.info("Argos core started successfully in " + used + "s."); |
| 115 | 0 | } |
| 116 | |
|
| 117 | |
private static void createFolders(String... filenames) { |
| 118 | 0 | for (String filename : filenames) { |
| 119 | 0 | File directory = new File(filename); |
| 120 | 0 | if (!directory.exists() || !directory.isDirectory()) { |
| 121 | 0 | logger.info("Creating directory " + filename); |
| 122 | 0 | directory.mkdir(); |
| 123 | |
} |
| 124 | |
} |
| 125 | 0 | } |
| 126 | |
} |