Package ds.node

Source Code of ds.node.Main

package ds.node;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.rmi.Naming;
import java.rmi.Remote;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import asg.cliche.Shell;
import asg.cliche.ShellFactory;
import ds.node.local.StorageActionImpl;
import ds.node.rmi.ClientFileServerImpl;
import ds.shared.socket.ServerSocketHandler;

/**
* Startup code for the node.
*
* @author save
*/
public class Main {
 
  // Define a static logger variable
  static Logger logger = Logger.getLogger(Main.class);

  /**
   * @param args
   */
  public static void main(String[] args) {
   
    // Initialise logging
    // BasicConfigurator replaced with PropertyConfigurator.
      PropertyConfigurator.configure("config/logging.conf");
    logger.info("Starting Node");
     
      // Read general config file
      Properties conf = new Properties();
      try {
      InputStream is = new FileInputStream("config/general.conf");
        conf.load(is);       
    } catch (Exception e) {
      e.printStackTrace();
      logger.warn("Could not read config file");
      return;
    }

    logger.info("Base folder "+conf.getProperty("node.folder"));
   
    // Determine the actions during file operations
    StorageActionImpl fileAction = new StorageActionImpl(conf);
   
    // Create but don't start the server socket handler
    ServerSocketHandler handler = new ServerSocketHandler(fileAction);
    logger.info("ServerSocket created");
   
    // Register remote object with unique name (for this machine)
    String name = "NodeServer-"+System.currentTimeMillis();
   
    try {
      Remote object = new ClientFileServerImpl(handler, conf);
      Naming.rebind (name, object);
   
      logger.info("Registered remote object as " + name);
     
      // Create the folder which will contain the files
      String path = conf.getProperty("node.folder")+"/"+name;
      boolean success = (new File(path)).mkdir();
      if (success) {
        logger.info("Created folder " + path);
      } else {
        logger.info("Could not create folder " + path);
      }
      // Update the config setting
      conf.setProperty("node.folder", path);
       
      // Create a command line
      Commands com = new Commands(conf, name, object);
      com.connect();
      Shell s = ShellFactory.createConsoleShell("node", "", com);
      s.commandLoop();
     
    } catch (Exception e) {
      e.printStackTrace();
    }
   
    logger.debug("Main thread halted");
  }

}
TOP

Related Classes of ds.node.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.