Search in sources :

Example 1 with ProfilerServiceFactory

use of com.microsoft.applicationinsights.profiler.ProfilerServiceFactory in project ApplicationInsights-Java by microsoft.

the class ProfilerServiceInitializer method initialize.

public static synchronized void initialize(Supplier<String> appIdSupplier, String processId, ServiceProfilerServiceConfig config, String machineName, String roleName, TelemetryClient telemetryClient, String userAgent, GcEventMonitor.GcEventMonitorConfiguration gcEventMonitorConfiguration, HttpPipeline httpPipeline) {
    if (!initialized) {
        initialized = true;
        ProfilerServiceFactory factory = null;
        try {
            factory = loadProfilerServiceFactory();
        } catch (RuntimeException e) {
            LOGGER.error("Failed to load profiler factory", e);
        }
        if (factory == null) {
            LOGGER.error("Profiling has been enabled however no profiler implementation was provided. Please install an ApplicationInsights agent which provides a profiler.");
            return;
        }
        ScheduledExecutorService serviceProfilerExecutorService = Executors.newScheduledThreadPool(2, ThreadPoolUtils.createDaemonThreadFactory(ProfilerServiceFactory.class, "ServiceProfilerService"));
        ScheduledExecutorService alertServiceExecutorService = Executors.newScheduledThreadPool(2, ThreadPoolUtils.createDaemonThreadFactory(ProfilerServiceFactory.class, "ServiceProfilerAlertingService"));
        AlertingSubsystem alerting = createAlertMonitor(alertServiceExecutorService, telemetryClient, gcEventMonitorConfiguration);
        Future<ProfilerService> future = factory.initialize(appIdSupplier, sendServiceProfilerIndex(telemetryClient), updateAlertingConfig(alerting), processId, config, machineName, telemetryClient.getInstrumentationKey(), httpPipeline, serviceProfilerExecutorService, userAgent, roleName);
        serviceProfilerExecutorService.submit(() -> {
            try {
                profilerService = future.get();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            } catch (Exception e) {
                LOGGER.error("Unable to obtain JFR connection, this may indicate that your JVM does not have JFR enabled. JFR profiling system will shutdown", e);
                alertServiceExecutorService.shutdown();
                serviceProfilerExecutorService.shutdown();
            }
        });
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ProfilerServiceFactory(com.microsoft.applicationinsights.profiler.ProfilerServiceFactory) ProfilerService(com.microsoft.applicationinsights.profiler.ProfilerService) AlertingSubsystem(com.microsoft.applicationinsights.alerting.AlertingSubsystem)

Aggregations

AlertingSubsystem (com.microsoft.applicationinsights.alerting.AlertingSubsystem)1 ProfilerService (com.microsoft.applicationinsights.profiler.ProfilerService)1 ProfilerServiceFactory (com.microsoft.applicationinsights.profiler.ProfilerServiceFactory)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1