Exemplo n.º 1
0
 public void stop() {
   LOGGER.info("Stopping BIMserver");
   executorService.shutdown();
   if (bimDatabase != null) {
     bimDatabase.close();
   }
   if (bimScheduler != null) {
     bimScheduler.close();
   }
   if (longActionManager != null) {
     longActionManager.shutdown();
   }
   if (notificationsManager != null) {
     notificationsManager.shutdown();
   }
   if (embeddedWebServer != null) {
     embeddedWebServer.shutdown();
   }
   if (protocolBuffersServer != null) {
     protocolBuffersServer.shutdown();
   }
   if (commandLine != null) {
     commandLine.shutdown();
   }
   LOGGER.info("BIMserver stopped");
 }
Exemplo n.º 2
0
  private void initDatabaseDependantItems() throws BimserverDatabaseException {
    serverSettingsCache.init();
    notificationsManager.init();

    getSerializerFactory().init(pluginManager, bimDatabase, this);
    getDeserializerFactory().init(pluginManager, bimDatabase);
    try {
      DatabaseSession session = bimDatabase.createSession();
      try {
        updatePlugins(session);
        session.commit();
      } catch (ServiceException e) {
        LOGGER.error("", e);
      } finally {
        session.close();
      }

      session = bimDatabase.createSession();
      createDatabaseObjects(session);

      ServerSettings serverSettings = serverSettingsCache.getServerSettings();

      for (WebModulePlugin webModulePlugin : pluginManager.getAllWebPlugins(true)) {
        WebModulePluginConfiguration webPluginConfiguration =
            find(serverSettings.getWebModules(), webModulePlugin.getClass().getName());
        if (webPluginConfiguration == null) {
          webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
          serverSettings.getWebModules().add(webPluginConfiguration);
          genericPluginConversion(
              session,
              webModulePlugin,
              webPluginConfiguration,
              getPluginDescriptor(session, webModulePlugin.getClass().getName()));
        } else {
          if (webPluginConfiguration == serverSettings.getWebModule()) {
            setDefaultWebModule(webModulePlugin);
          }
        }
      }

      // Set the default
      if (serverSettings.getWebModule() == null) {
        WebModulePluginConfiguration bimviewsWebModule =
            findWebModule(serverSettings, "org.bimserver.bimviews.BimViewsWebModulePlugin");
        if (bimviewsWebModule != null) {
          serverSettings.setWebModule(bimviewsWebModule);
          setDefaultWebModule(
              pluginManager.getWebModulePlugin(
                  bimviewsWebModule.getPluginDescriptor().getPluginClassName(), true));
        } else {
          WebModulePluginConfiguration defaultWebModule =
              findWebModule(
                  serverSettings, "org.bimserver.defaultwebmodule.DefaultWebModulePlugin");
          if (defaultWebModule != null) {
            serverSettings.setWebModule(defaultWebModule);
            setDefaultWebModule(
                pluginManager.getWebModulePlugin(
                    defaultWebModule.getPluginDescriptor().getPluginClassName(), true));
          }
        }
      }
      session.store(serverSettings);

      Condition condition =
          new AttributeCondition(
              StorePackage.eINSTANCE.getUser_Username(), new StringLiteral("system"));
      User systemUser = session.querySingle(condition, User.class, Query.getDefault());

      ServerStarted serverStarted = session.create(ServerStarted.class);
      serverStarted.setDate(new Date());
      serverStarted.setAccessMethod(AccessMethod.INTERNAL);
      serverStarted.setExecutor(systemUser);
      try {
        session.store(serverStarted);
        session.commit();
      } catch (BimserverLockConflictException e) {
        throw new BimserverDatabaseException(e);
      } catch (ServiceException e) {
        throw new BimserverDatabaseException(e);
      } finally {
        session.close();
      }

      webModules = new HashMap<String, WebModulePlugin>();
      DatabaseSession ses = bimDatabase.createSession();
      try {
        List<WebModulePluginConfiguration> webModuleConfigurations =
            serverSettingsCache.getServerSettings().getWebModules();
        for (WebModulePluginConfiguration webModulePluginConfiguration : webModuleConfigurations) {
          String contextPath = "";
          for (Parameter parameter : webModulePluginConfiguration.getSettings().getParameters()) {
            if (parameter.getName().equals("contextPath")) {
              contextPath = ((StringType) parameter.getValue()).getValue();
            }
          }
          webModules.put(
              contextPath,
              (WebModulePlugin)
                  pluginManager.getPlugin(
                      webModulePluginConfiguration.getPluginDescriptor().getPluginClassName(),
                      true));
        }
        //				if (serverSettingsCache.getServerSettings().getWebModule() != null) {
        //					defaultWebModule = (WebModulePlugin)
        // pluginManager.getPlugin(serverSettingsCache.getServerSettings().getWebModule().getPluginDescriptor().getPluginClassName(), true);
        //				}
      } finally {
        ses.close();
      }

      Integer protocolBuffersPort =
          getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
      if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
        try {
          protocolBuffersServer =
              new ProtocolBuffersServer(
                  protocolBuffersMetaData, serviceFactory, servicesMap, protocolBuffersPort);
          protocolBuffersServer.start();
        } catch (Exception e) {
          LOGGER.error("", e);
        }
      }

      bimServerClientFactory =
          new DirectBimServerClientFactory<ServiceInterface>(
              serverSettingsCache.getServerSettings().getSiteAddress(),
              serviceFactory,
              servicesMap,
              pluginManager,
              metaDataManager);
      pluginManager.setBimServerClientFactory(bimServerClientFactory);
    } catch (BimserverLockConflictException e) {
      throw new BimserverDatabaseException(e);
    } catch (PluginException e) {
      throw new BimserverDatabaseException(e);
    }
  }
Exemplo n.º 3
0
  /**
   * Create a new BIMserver
   *
   * @param homeDir A directory where the user can store instance specific configuration files
   * @param resourceFetcher A resource fetcher
   */
  public BimServer(BimServerConfig config) {
    this.config = config;
    try {
      if (config.getHomeDir() != null) {
        initHomeDir();
      }

      fixLogging();
      UncaughtExceptionHandler uncaughtExceptionHandler =
          new UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread t, Throwable e) {
              if (e instanceof OutOfMemoryError) {
                serverInfoManager.setOutOfMemory();
                LOGGER.error("", e);
              } else if (e instanceof Error) {
                serverInfoManager.setErrorMessage(e.getMessage());
                LOGGER.error("", e);
              } else {
                LOGGER.error("", e);
              }
            }
          };

      Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);
      LOGGER = LoggerFactory.getLogger(BimServer.class);

      LOGGER.info("Starting BIMserver");
      if (config.getHomeDir() != null) {
        LOGGER.info("Using \"" + config.getHomeDir().toString() + "\" as homedir");
      } else {
        LOGGER.info("Not using a homedir");
      }

      servicesMap = InterfaceList.createSServicesMap();
      LOGGER.debug("SServiceMap Created");

      jsonSocketReflectorFactory = new JsonSocketReflectorFactory(servicesMap);
      LOGGER.debug("JsonSocketReflectorFactory created");

      serverInfoManager = new ServerInfoManager();
      LOGGER.debug("ServerInfoManager created");

      notificationsManager = new NotificationsManager(this, jsonSocketReflectorFactory);
      LOGGER.debug("NotificationsManager created");

      internalServicesManager =
          new InternalServicesManager(this, notificationsManager.getSiteAddress());
      LOGGER.debug("InternalServicesManager created");

      serviceFactory = new PublicInterfaceFactory(this);
      LOGGER.debug("PublicInterfaceFactory created");

      pluginManager =
          new PluginManager(
              config.getHomeDir().resolve("tmp"),
              config.getClassPath(),
              serviceFactory,
              internalServicesManager,
              servicesMap);
      metaDataManager = new MetaDataManager(pluginManager);
      pluginManager.setMetaDataManager(metaDataManager);
      LOGGER.debug("PluginManager created");

      versionChecker = new VersionChecker(config.getResourceFetcher());
      LOGGER.debug("Version Checker created");

      compareCache = new CompareCache();
      LOGGER.debug("Compare cache created");
      if (config.isStartEmbeddedWebServer()) {
        embeddedWebServer = new EmbeddedWebServer(this, config.isLocalDev());
        LOGGER.debug("Embedded webserver created");
      }

      LOGGER.debug("Done with initial setup");
    } catch (Throwable e) {
      if (LOGGER == null) {
        e.printStackTrace();
      } else {
        LOGGER.error("", e);
      }
      serverInfoManager.setErrorMessage(e.getMessage());
    }
  }