Search in sources :

Example 1 with CoreServiceImpl

use of com.newrelic.agent.core.CoreServiceImpl in project newrelic-java-agent by newrelic.

the class Agent method tryToInitializeServiceManager.

private static boolean tryToInitializeServiceManager(Instrumentation inst) {
    try {
        CoreService coreService = new CoreServiceImpl(inst);
        ConfigService configService = ConfigServiceFactory.createConfigService(Agent.LOG, System.getProperty("newrelic.checkconfig") != null);
        ServiceManager serviceManager = new ServiceManagerImpl(coreService, configService);
        ServiceFactory.setServiceManager(serviceManager);
        if (isLicenseKeyEmpty(serviceManager.getConfigService().getDefaultAgentConfig().getLicenseKey())) {
            LOG.error("license_key is empty in the config. Not starting New Relic Agent.");
            return false;
        }
        if (!serviceManager.getConfigService().getDefaultAgentConfig().isAgentEnabled()) {
            LOG.warning("agent_enabled is false in the config. Not starting New Relic Agent.");
            return false;
        }
        // Now that we know the agent is enabled, add the ApiClassTransformer
        BootstrapLoader.forceCorrectNewRelicApi(inst);
        // init problem classes before class transformer service is active
        InitProblemClasses.loadInitialClasses();
    } catch (ForceDisconnectException e) {
        /* Note: Our use of ForceDisconnectException is a bit misleading here as we haven't even tried to connect
             * to RPM at this point (that happens a few lines down when we call serviceManager.start()). This exception
             * comes from ConfigServiceFactory when it attempts to validate the local yml and finds that both HSM and
             * LASP are enabled. The LASP spec says in this scenario that "Shutdown will follow the behavior of the
             * ForceDisconnectException response from "New Relic." Not specifically that we should throw ForceDisconnectException.
             * Perhaps we should throw a different, more accurately named exception, that simply has the same behavior
             * as ForceDisconnectException as it will be replaced by a 410 response code in Protocol 17.
             */
        LOG.log(Level.SEVERE, e.getMessage());
        return false;
    } catch (Throwable t) {
        // this is the last point where we can stop the agent gracefully if something has gone wrong.
        LOG.log(Level.SEVERE, t, "Unable to start the New Relic Agent. Your application will continue to run but it will not be monitored.");
        return false;
    }
    return true;
}
Also used : ServiceManager(com.newrelic.agent.service.ServiceManager) ServiceManagerImpl(com.newrelic.agent.service.ServiceManagerImpl) CoreService(com.newrelic.agent.core.CoreService) CoreServiceImpl(com.newrelic.agent.core.CoreServiceImpl)

Aggregations

CoreService (com.newrelic.agent.core.CoreService)1 CoreServiceImpl (com.newrelic.agent.core.CoreServiceImpl)1 ServiceManager (com.newrelic.agent.service.ServiceManager)1 ServiceManagerImpl (com.newrelic.agent.service.ServiceManagerImpl)1