Search in sources :

Example 1 with StructrLicenseManager

use of org.structr.util.StructrLicenseManager in project structr by structr.

the class Services method doInitialize.

private void doInitialize() {
    configurationClass = Settings.Configuration.getValue();
    configuredServiceNames = Settings.Services.getValue();
    // create set of configured services
    configuredServiceClasses.addAll(Arrays.asList(configuredServiceNames.split("[ ,]+")));
    if (!isTesting()) {
        // read license
        licenseManager = new StructrLicenseManager(Settings.getBasePath() + "license.key");
    }
    // if configuration is not yet established, instantiate it
    // this is the place where the service classes get the
    // opportunity to modify the default configuration
    getConfigurationProvider();
    // do simple heap size check
    final Runtime runtime = Runtime.getRuntime();
    final long max = runtime.maxMemory() / 1024 / 1024 / 1024;
    final int processors = runtime.availableProcessors();
    logger.info("{} processors available, {} GB max heap memory", processors, max);
    if (max < 8) {
        logger.warn("Maximum heap size is smaller than recommended, this can lead to problems with large databases!");
        logger.warn("Please configure AT LEAST 8 GBs of heap memory using -Xmx8g.");
    }
    logger.info("Starting services..");
    // initialize other services
    for (final String serviceClassName : configuredServiceClasses) {
        Class serviceClass = getServiceClassForName(serviceClassName);
        if (serviceClass != null) {
            startService(serviceClass);
        }
    }
    logger.info("{} service(s) processed", serviceCache.size());
    logger.info("Registering shutdown hook.");
    // register shutdown hook
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            shutdown();
        }
    });
    // read permissions for ownerless nodes
    final String configForOwnerlessNodes = Settings.OwnerlessNodes.getValue();
    if (StringUtils.isNotBlank(configForOwnerlessNodes)) {
        for (final String permission : configForOwnerlessNodes.split("[, ]+")) {
            final String trimmed = permission.trim();
            if (StringUtils.isNotBlank(trimmed)) {
                final Permission val = Permissions.valueOf(trimmed);
                if (val != null) {
                    permissionsForOwnerlessNodes.add(val);
                } else {
                    logger.warn("Invalid permisson {}, ignoring.", trimmed);
                }
            }
        }
    } else {
        // default
        permissionsForOwnerlessNodes.add(Permission.read);
    }
    // a configuration file, i.e. when this is NOT this first start.
    try {
        final ExecutorService service = Executors.newSingleThreadExecutor();
        service.submit(new Runnable() {

            @Override
            public void run() {
                // wait a second
                try {
                    Thread.sleep(100);
                } catch (Throwable ignore) {
                }
                // call initialization callbacks from a different thread
                for (final InitializationCallback callback : singletonInstance.callbacks) {
                    callback.initializationDone();
                }
            }
        }).get();
    } catch (Throwable t) {
        logger.warn("Exception while executing post-initialization tasks", t);
    }
    // Don't use logger here because start/stop scripts rely on this line.
    System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.ms").format(new Date()) + "  ---------------- Initialization complete ----------------");
    setOverridingSchemaTypesAllowed(false);
    initializationDone = true;
}
Also used : InitializationCallback(org.structr.api.service.InitializationCallback) Date(java.util.Date) StructrLicenseManager(org.structr.util.StructrLicenseManager) Permission(org.structr.common.Permission) ExecutorService(java.util.concurrent.ExecutorService) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 ExecutorService (java.util.concurrent.ExecutorService)1 InitializationCallback (org.structr.api.service.InitializationCallback)1 Permission (org.structr.common.Permission)1 StructrLicenseManager (org.structr.util.StructrLicenseManager)1