Пример #1
0
  private Main() throws Exception {

    ValidityTools.checkAccessibilityOfFiles(
        DEFAULT_GSN_LOG4J_PROPERTIES,
        WrappersUtil.DEFAULT_WRAPPER_PROPERTIES_FILE,
        DEFAULT_GSN_CONF_FILE);
    ValidityTools.checkAccessibilityOfDirs(DEFAULT_VIRTUAL_SENSOR_DIRECTORY);
    PropertyConfigurator.configure(Main.DEFAULT_GSN_LOG4J_PROPERTIES);
    //  initializeConfiguration();
    try {
      controlSocket = new GSNController(null, gsnControllerPort);
      containerConfig = loadContainerConfiguration();
      updateSplashIfNeeded(
          new String[] {
            "GSN is starting at port:" + containerConfig.getContainerPort(),
            "All GSN logs are available at: logs/gsn.log"
          });
      System.out.println(
          "Global Sensor Networks (GSN) is Starting on port "
              + containerConfig.getContainerPort()
              + "...");
      System.out.println("The logs of GSN server are available in logs/gsn.log file.");
      System.out.println("To Stop GSN execute the gsn-stop script.");
    } catch (FileNotFoundException e) {
      logger.error(
          new StringBuilder()
              .append("The the configuration file : conf/gsn.xml")
              .append(" doesn't exist.")
              .toString());
      logger.error(e.getMessage());
      logger.error("Check the path of the configuration file and try again.");
      if (logger.isDebugEnabled()) logger.debug(e.getMessage(), e);
      throw new Exception(e);
    }
    int maxDBConnections =
        System.getProperty("maxDBConnections") == null
            ? DEFAULT_MAX_DB_CONNECTIONS
            : Integer.parseInt(System.getProperty("maxDBConnections"));
    int maxSlidingDBConnections =
        System.getProperty("maxSlidingDBConnections") == null
            ? DEFAULT_MAX_DB_CONNECTIONS
            : Integer.parseInt(System.getProperty("maxSlidingDBConnections"));
    int maxServlets =
        System.getProperty("maxServlets") == null
            ? DEFAULT_JETTY_SERVLETS
            : Integer.parseInt(System.getProperty("maxServlets"));

    // Init the AC db connection.
    if (Main.getContainerConfig().isAcEnabled() == true) {
      ConnectToDB.init(
          containerConfig.getStorage().getJdbcDriver(),
          containerConfig.getStorage().getJdbcUsername(),
          containerConfig.getStorage().getJdbcPassword(),
          containerConfig.getStorage().getJdbcURL());
    }

    mainStorage =
        StorageManagerFactory.getInstance(
            containerConfig.getStorage().getJdbcDriver(),
            containerConfig.getStorage().getJdbcUsername(),
            containerConfig.getStorage().getJdbcPassword(),
            containerConfig.getStorage().getJdbcURL(),
            maxDBConnections);
    //
    StorageConfig sc =
        containerConfig.getSliding() != null
            ? containerConfig.getSliding().getStorage()
            : containerConfig.getStorage();
    windowStorage =
        StorageManagerFactory.getInstance(
            sc.getJdbcDriver(),
            sc.getJdbcUsername(),
            sc.getJdbcPassword(),
            sc.getJdbcURL(),
            maxSlidingDBConnections);
    //
    validationStorage =
        StorageManagerFactory.getInstance(
            "org.h2.Driver", "sa", "", "jdbc:h2:mem:validator", Main.DEFAULT_MAX_DB_CONNECTIONS);

    if (logger.isInfoEnabled())
      logger.info("The Container Configuration file loaded successfully.");

    try {
      logger.debug(
          "Starting the http-server @ port: "
              + containerConfig.getContainerPort()
              + " (maxDBConnections: "
              + maxDBConnections
              + ", maxSlidingDBConnections: "
              + maxSlidingDBConnections
              + ", maxServlets:"
              + maxServlets
              + ")"
              + " ...");
      Server jettyServer =
          getJettyServer(
              getContainerConfig().getContainerPort(),
              getContainerConfig().getSSLPort(),
              maxServlets);
      jettyServer.start();
      logger.debug("http-server running @ port: " + containerConfig.getContainerPort());
    } catch (Exception e) {
      throw new Exception(
          "Start of the HTTP server failed. The HTTP protocol is used in most of the communications: "
              + e.getMessage(),
          e);
    }
    VSensorLoader vsloader = VSensorLoader.getInstance(DEFAULT_VIRTUAL_SENSOR_DIRECTORY);
    controlSocket.setLoader(vsloader);

    String msrIntegration = "gsn.msr.sensormap.SensorMapIntegration";
    try {
      vsloader.addVSensorStateChangeListener(
          (VSensorStateChangeListener) Class.forName(msrIntegration).newInstance());
    } catch (Exception e) {
      logger.warn("MSR Sensor Map integration is disabled.");
    }

    vsloader.addVSensorStateChangeListener(new SQLValidatorIntegration(SQLValidator.getInstance()));
    vsloader.addVSensorStateChangeListener(DataDistributer.getInstance(LocalDeliveryWrapper.class));
    vsloader.addVSensorStateChangeListener(DataDistributer.getInstance(PushDelivery.class));
    vsloader.addVSensorStateChangeListener(DataDistributer.getInstance(RestDelivery.class));

    ContainerImpl.getInstance()
        .addVSensorDataListener(DataDistributer.getInstance(LocalDeliveryWrapper.class));
    ContainerImpl.getInstance()
        .addVSensorDataListener(DataDistributer.getInstance(PushDelivery.class));
    ContainerImpl.getInstance()
        .addVSensorDataListener(DataDistributer.getInstance(RestDelivery.class));
    vsloader.startLoading();
  }