Search in sources :

Example 1 with ProcessEnvironment

use of org.glassfish.api.admin.ProcessEnvironment in project Payara by payara.

the class ACCModulesManager method initialize.

public static synchronized void initialize(final ClassLoader loader) throws URISyntaxException {
    /*
         * The habitat might have been initialized earlier.  Currently
         * we use a single habitat for the JVM.  
         */
    if (habitat == null) {
        habitat = prepareHabitat(loader);
        /*
             * Set up the default habitat in Globals as soon as we know
             * which habitat we'll use.
             */
        Globals.setDefaultHabitat(habitat);
        ServiceLocator locator = habitat;
        DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
        DynamicConfiguration config = dcs.createDynamicConfiguration();
        /*
             * Remove any already-loaded startup context so we can replace it
             * with the ACC one.
             */
        config.addUnbindFilter(BuilderHelper.createContractFilter(StartupContext.class.getName()));
        /*
             * Following the example from AppServerStartup, remove any
             * pre-loaded lazy inhabitant for ProcessEnvironment that exists
             * from HK2's scan for services.  Then add in
             * an ACC ProcessEnvironment.
             */
        config.addUnbindFilter(BuilderHelper.createContractFilter(ProcessEnvironment.class.getName()));
        config.commit();
        config = dcs.createDynamicConfiguration();
        StartupContext startupContext = new ACCStartupContext();
        AbstractActiveDescriptor<?> startupContextDescriptor = BuilderHelper.createConstantDescriptor(startupContext);
        startupContextDescriptor.addContractType(StartupContext.class);
        config.addActiveDescriptor(startupContextDescriptor);
        ModulesRegistry modulesRegistry = new StaticModulesRegistry(ACCModulesManager.class.getClassLoader());
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(modulesRegistry));
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new ProcessEnvironment(ProcessEnvironment.ProcessType.ACC)));
        /*
             * Create the ClientNamingConfigurator used by naming.
             */
        ClientNamingConfigurator cnc = new ClientNamingConfiguratorImpl();
        config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(cnc));
        Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
        AbstractActiveDescriptor<Logger> di = BuilderHelper.createConstantDescriptor(logger);
        di.addContractType(Logger.class);
        config.addActiveDescriptor(di);
        config.commit();
    }
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) Logger(java.util.logging.Logger) ProcessEnvironment(org.glassfish.api.admin.ProcessEnvironment) ClientNamingConfigurator(org.glassfish.api.naming.ClientNamingConfigurator) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ClientNamingConfiguratorImpl(com.sun.enterprise.naming.impl.ClientNamingConfiguratorImpl) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry)

Example 2 with ProcessEnvironment

use of org.glassfish.api.admin.ProcessEnvironment in project Payara by payara.

the class TransactionServiceProperties method getJTSProperties.

public static synchronized Properties getJTSProperties(ServiceLocator serviceLocator, boolean isORBAvailable) {
    if (orbAvailable == isORBAvailable && properties != null) {
        // We will need to update the properties if ORB availability changed
        return properties;
    }
    Properties jtsProperties = new Properties();
    if (serviceLocator != null) {
        jtsProperties.put(HABITAT, serviceLocator);
        ProcessEnvironment processEnv = serviceLocator.getService(ProcessEnvironment.class);
        if (processEnv.getProcessType().isServer()) {
            TransactionService txnService = serviceLocator.getService(TransactionService.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
            if (txnService != null) {
                jtsProperties.put(Configuration.HEURISTIC_DIRECTION, txnService.getHeuristicDecision());
                jtsProperties.put(Configuration.KEYPOINT_COUNT, txnService.getKeypointInterval());
                String automaticRecovery = txnService.getAutomaticRecovery();
                boolean isAutomaticRecovery = (isValueSet(automaticRecovery) && "true".equals(automaticRecovery));
                if (isAutomaticRecovery) {
                    _logger.log(Level.FINE, "Recoverable J2EE Server");
                    jtsProperties.put(Configuration.MANUAL_RECOVERY, "true");
                }
                boolean disable_distributed_transaction_logging = false;
                String dbLoggingResource = null;
                for (Property prop : txnService.getProperty()) {
                    String name = prop.getName();
                    String value = prop.getValue();
                    if (name.equals("disable-distributed-transaction-logging")) {
                        if (isValueSet(value) && "true".equals(value)) {
                            disable_distributed_transaction_logging = true;
                        }
                    } else if (name.equals("xaresource-txn-timeout")) {
                        if (isValueSet(value)) {
                            _logger.log(Level.FINE, "XAResource transaction timeout is" + value);
                            TransactionManagerImpl.setXAResourceTimeOut(Integer.parseInt(value));
                        }
                    } else if (name.equals("db-logging-resource")) {
                        dbLoggingResource = value;
                        _logger.log(Level.FINE, "Transaction DB Logging Resource Name" + dbLoggingResource);
                        if (dbLoggingResource != null && (" ".equals(dbLoggingResource) || "".equals(dbLoggingResource))) {
                            dbLoggingResource = "jdbc/TxnDS";
                        }
                    } else if (name.equals("xa-servername")) {
                        if (isValueSet(value)) {
                            jtsProperties.put(JTS_XA_SERVER_NAME, value);
                        }
                    } else if (name.equals("pending-txn-cleanup-interval")) {
                        if (isValueSet(value)) {
                            jtsProperties.put("pending-txn-cleanup-interval", value);
                        }
                    } else if (name.equals(Configuration.COMMIT_ONE_PHASE_DURING_RECOVERY)) {
                        if (isValueSet(value)) {
                            jtsProperties.put(Configuration.COMMIT_ONE_PHASE_DURING_RECOVERY, value);
                        }
                    } else if (name.equals("add-wait-point-during-recovery")) {
                        if (isValueSet(value)) {
                            try {
                                FailureInducer.setWaitPointRecovery(Integer.parseInt(value));
                            } catch (Exception e) {
                                _logger.log(Level.WARNING, e.getMessage());
                            }
                        }
                    }
                }
                if (dbLoggingResource != null) {
                    disable_distributed_transaction_logging = true;
                    jtsProperties.put(Configuration.DB_LOG_RESOURCE, dbLoggingResource);
                }
                /**
                 *                       JTS_SERVER_ID needs to be unique for each for server instance.
                 *                       This will be used as recovery identifier along with the hostname
                 *                       for example: if the hostname is 'tulsa' and iiop-listener-port is 3700
                 *                       recovery identifier will be tulsa,P3700
                 */
                // default value
                int jtsServerId = DEFAULT_SERVER_ID;
                if (isORBAvailable) {
                    jtsServerId = serviceLocator.<GlassFishORBHelper>getService(GlassFishORBHelper.class).getORBInitialPort();
                    if (jtsServerId == 0) {
                        // XXX Can this ever happen?
                        // default value
                        jtsServerId = DEFAULT_SERVER_ID;
                    }
                }
                jtsProperties.put(JTS_SERVER_ID, String.valueOf(jtsServerId));
                /* ServerId is an J2SE persistent server activation
                       API.  ServerId is scoped at the ORBD.  Since
                       There is no ORBD present in J2EE the value of
                       ServerId is meaningless - except it must have
                       SOME value if persistent POAs are created.
                     */
                // For clusters - all servers in the cluster MUST
                // have the same ServerId so when failover happens
                // and requests are delivered to a new server, the
                // ServerId in the request will match the new server.
                String serverId = String.valueOf(DEFAULT_SERVER_ID);
                System.setProperty(J2EE_SERVER_ID_PROP, serverId);
                ServerContext ctx = serviceLocator.getService(ServerContext.class);
                String instanceName = ctx.getInstanceName();
                /**
                 * if the auto recovery is true, always transaction logs will be written irrespective of
                 * disable_distributed_transaction_logging.
                 * if the auto recovery is false, then disable_distributed_transaction_logging will be used
                 * to write transaction logs are not.If disable_distributed_transaction_logging is set to
                 * false(by default false) logs will be written, set to true logs won't be written.
                 */
                if (!isAutomaticRecovery && disable_distributed_transaction_logging) {
                    Configuration.disableFileLogging();
                } else {
                    // if (dbLoggingResource == null) {
                    Domain domain = serviceLocator.getService(Domain.class);
                    Server server = domain.getServerNamed(instanceName);
                    // Check if the server system property is set
                    String logdir = getTXLogDir(server);
                    // if not, check if the cluster system property is set
                    if (logdir == null) {
                        Cluster cluster = server.getCluster();
                        if (cluster != null) {
                            logdir = getTXLogDir(cluster);
                        }
                    }
                    // No system properties are set - get tx log dir from transaction service
                    if (logdir == null) {
                        logdir = txnService.getTxLogDir();
                    }
                    if (logdir == null) {
                        logdir = domain.getLogRoot();
                        if (logdir == null) {
                            // logdir = FileUtil.getAbsolutePath(".." + File.separator + "logs");
                            logdir = ".." + File.separator + "logs";
                        }
                    } else if (!(new File(logdir)).isAbsolute()) {
                        if (_logger.isLoggable(Level.FINE)) {
                            _logger.log(Level.FINE, "Relative pathname specified for transaction log directory : " + logdir);
                        }
                        String logroot = domain.getLogRoot();
                        if (logroot != null) {
                            logdir = logroot + File.separator + logdir;
                        } else {
                            // logdir = FileUtil.getAbsolutePath(".." + File.separator + "logs"
                            // + File.separator + logdir);
                            logdir = ".." + File.separator + "logs" + File.separator + logdir;
                        }
                    }
                    logdir += File.separator + instanceName + File.separator + "tx";
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, "JTS log directory: " + logdir);
                        _logger.log(Level.FINE, "JTS Server id " + jtsServerId);
                    }
                    jtsProperties.put(Configuration.LOG_DIRECTORY, logdir);
                }
                jtsProperties.put(Configuration.COMMIT_RETRY, txnService.getRetryTimeoutInSeconds());
                jtsProperties.put(Configuration.INSTANCE_NAME, instanceName);
            }
        }
    }
    properties = jtsProperties;
    orbAvailable = isORBAvailable;
    return properties;
}
Also used : TransactionService(com.sun.enterprise.transaction.config.TransactionService) Server(com.sun.enterprise.config.serverbeans.Server) Cluster(com.sun.enterprise.config.serverbeans.Cluster) GlassFishORBHelper(org.glassfish.enterprise.iiop.api.GlassFishORBHelper) Properties(java.util.Properties) ProcessEnvironment(org.glassfish.api.admin.ProcessEnvironment) ServerContext(org.glassfish.internal.api.ServerContext) Domain(com.sun.enterprise.config.serverbeans.Domain) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) File(java.io.File)

Example 3 with ProcessEnvironment

use of org.glassfish.api.admin.ProcessEnvironment in project Payara by payara.

the class SunDeploymentManager method prepareHabitat.

private void prepareHabitat() {
    ModulesRegistry registry = new StaticModulesRegistry(getClass().getClassLoader());
    ServiceLocator serviceLocator = registry.createServiceLocator("default");
    habitat = serviceLocator.getService(ServiceLocator.class);
    StartupContext startupContext = new StartupContext();
    ServiceLocatorUtilities.addOneConstant(habitat, startupContext);
    ServiceLocatorUtilities.addOneConstant(habitat, new ProcessEnvironment(ProcessEnvironment.ProcessType.Other));
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) ProcessEnvironment(org.glassfish.api.admin.ProcessEnvironment)

Example 4 with ProcessEnvironment

use of org.glassfish.api.admin.ProcessEnvironment in project Payara by payara.

the class TransactionServiceProperties method initRecovery.

public static void initRecovery(boolean force) {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "initRecovery:recoveryInitialized: " + recoveryInitialized);
    }
    if (recoveryInitialized) {
        // Only start initial recovery if it wasn't started before
        return;
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "initRecovery:properties: " + properties);
    }
    if (properties == null) {
        if (force) {
            _logger.log(Level.WARNING, "", new IllegalStateException());
        }
        return;
    }
    // Start if force is true or automatic-recovery is set
    String value = properties.getProperty(Configuration.MANUAL_RECOVERY);
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "initRecovery:Configuration.MANUAL_RECOVERY: " + value);
    }
    if (force || (isValueSet(value) && "true".equals(value))) {
        recoveryInitialized = true;
        ServiceLocator serviceLocator = (ServiceLocator) properties.get(HABITAT);
        if (serviceLocator != null) {
            ProcessEnvironment processEnv = serviceLocator.getService(ProcessEnvironment.class);
            if (processEnv.getProcessType().isServer()) {
                // Start ResourceManager if it hadn't started yet
                serviceLocator.getAllServices(BuilderHelper.createNameFilter("ResourceManager"));
                value = properties.getProperty("pending-txn-cleanup-interval");
                int interval = -1;
                if (isValueSet(value)) {
                    interval = Integer.parseInt(value);
                }
                new RecoveryHelperThread(serviceLocator, interval).start();
            }
            // Release all locks
            RecoveryManager.startResyncThread();
            if (_logger.isLoggable(Level.FINE))
                _logger.log(Level.FINE, "[JTS] Started ResyncThread");
        }
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ProcessEnvironment(org.glassfish.api.admin.ProcessEnvironment)

Example 5 with ProcessEnvironment

use of org.glassfish.api.admin.ProcessEnvironment in project Payara by payara.

the class AppServerStartup method run.

/**
 * @return True is startup succeeded, false if an error occurred preventing
 * the server from starting
 */
public boolean run() {
    if (context == null) {
        System.err.println("Startup context not provided, cannot continue");
        return false;
    }
    if (platform == null) {
        platform = "Embedded";
    }
    platformInitTime = System.currentTimeMillis();
    if (logger.isLoggable(level)) {
        logger.log(level, "Startup class : {0}", getClass().getName());
    }
    // prepare the global variables
    DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
    DynamicConfiguration config = dcs.createDynamicConfiguration();
    config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(logger));
    config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(masterListener));
    config.addUnbindFilter(BuilderHelper.createContractFilter(ProcessEnvironment.class.getName()));
    config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(env.isEmbedded() ? new ProcessEnvironment(ProcessEnvironment.ProcessType.Embedded) : new ProcessEnvironment(ProcessEnvironment.ProcessType.Server)));
    config.commit();
    // activate the run level services
    masterListener.reset();
    long initFinishTime = 0L;
    long startupFinishTime = 0L;
    if (!proceedTo(InitRunLevel.VAL)) {
        appInstanceListener.stopRecordingTimes();
        return false;
    }
    if (!logger.isLoggable(level)) {
        // Stop recording the times, no-one cares
        appInstanceListener.stopRecordingTimes();
    } else {
        initFinishTime = System.currentTimeMillis();
        logger.log(level, "Init level done in " + (initFinishTime - context.getCreationTime()) + " ms");
    }
    appInstanceListener.startRecordingFutures();
    if (!proceedTo(StartupRunLevel.VAL)) {
        appInstanceListener.stopRecordingTimes();
        return false;
    }
    if (!postStartupJob()) {
        appInstanceListener.stopRecordingTimes();
        return false;
    }
    if (logger.isLoggable(level)) {
        startupFinishTime = System.currentTimeMillis();
        logger.log(level, "Startup level done in " + (startupFinishTime - initFinishTime) + " ms");
    }
    if (!proceedTo(PostStartupRunLevel.VAL)) {
        appInstanceListener.stopRecordingTimes();
        return false;
    }
    if (logger.isLoggable(level)) {
        long postStartupFinishTime = System.currentTimeMillis();
        logger.log(level, "PostStartup level done in " + (postStartupFinishTime - startupFinishTime) + " ms");
    }
    return true;
}
Also used : DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) ProcessEnvironment(org.glassfish.api.admin.ProcessEnvironment)

Aggregations

ProcessEnvironment (org.glassfish.api.admin.ProcessEnvironment)5 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)3 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)2 StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)2 StaticModulesRegistry (com.sun.enterprise.module.single.StaticModulesRegistry)2 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)2 DynamicConfigurationService (org.glassfish.hk2.api.DynamicConfigurationService)2 Cluster (com.sun.enterprise.config.serverbeans.Cluster)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 Server (com.sun.enterprise.config.serverbeans.Server)1 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)1 ClientNamingConfiguratorImpl (com.sun.enterprise.naming.impl.ClientNamingConfiguratorImpl)1 TransactionService (com.sun.enterprise.transaction.config.TransactionService)1 File (java.io.File)1 Properties (java.util.Properties)1 Logger (java.util.logging.Logger)1 ClientNamingConfigurator (org.glassfish.api.naming.ClientNamingConfigurator)1 GlassFishORBHelper (org.glassfish.enterprise.iiop.api.GlassFishORBHelper)1 ServerContext (org.glassfish.internal.api.ServerContext)1 Property (org.jvnet.hk2.config.types.Property)1