Coverage Report - argos.Argos
 
Classes in this File Line Coverage Branch Coverage Complexity
Argos
0%
0/43
0%
0/14
0
 
 1  
 /*
 2  
 Copyright (c) 2006, University of Tromsø
 3  
 All rights reserved.
 4  
 
 5  
 Redistribution and use in source and binary forms, with or without 
 6  
 modification, are permitted provided that the following conditions are met:
 7  
 
 8  
  * Redistributions of source code must retain the above copyright notice, this list 
 9  
    of conditions and the following disclaimer.
 10  
 
 11  
  * Redistributions in binary form must reproduce the above copyright notice, this 
 12  
    list of conditions and the following disclaimer in the documentation and/or other 
 13  
    materials provided with the distribution.
 14  
 
 15  
  * Neither the name of the University of Tromsø nor the names of its contributors may 
 16  
    be used to endorse or promote products derived from this software without specific 
 17  
    prior written permission.
 18  
 
 19  
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 20  
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
 21  
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
 22  
 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 23  
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
 24  
 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
 25  
 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 26  
 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 27  
 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 
 28  
 DAMAGE.
 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  
 //TODO RUn assembly:assembly on deploy. what is deploy? should it be package?
 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  
 //        System.setErr(Console.console);
 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  
         // Create MBean server
 78  0
         ManagementFactory.getPlatformMBeanServer();
 79  0
         logger.info("MBean server created.");
 80  
 
 81  
         // Instrument console
 82  0
         DynamicProxyUtil.instrument("Console", Console.console);
 83  
 
 84  
         // Register Config as MBean
 85  0
         DynamicProxyUtil.instrument("Config", config);
 86  
 
 87  
         // Component manager
 88  0
         DynamicProxyUtil.instrument("ComponentManager", ComponentManager.getInstance());
 89  0
         logger.info("Component Manager created.");
 90  
 
 91  
         // Naming Service
 92  0
         DynamicProxyUtil.instrument("NamingService", NamingService.getInstance());
 93  0
         logger.info("Naming service created.");
 94  
 
 95  
         // Hot deployer
 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  
         // Done
 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  
 }