Search in sources :

Example 1 with Futures

use of org.glassfish.grizzly.utils.Futures in project Payara by payara.

the class GrizzlyService method postConstruct.

/**
 * The component has been injected with any dependency and
 * will be placed into commission by the subsystem.
 */
@Override
public void postConstruct() {
    events.register(this);
    final NetworkConfig networkConfig = config.getNetworkConfig();
    configListener = new DynamicConfigListener(config, LOGGER);
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(networkConfig.getNetworkListeners());
    bean.addListener(configListener);
    bean = (ObservableBean) ConfigSupport.getImpl(config.getHttpService());
    bean.addListener(configListener);
    transactions.addListenerForType(SystemProperty.class, configListener);
    configListener.setGrizzlyService(this);
    try {
        boolean isAtLeastOneProxyStarted = false;
        futures = new ArrayList<>();
        // Record how long it took for the listeners to start up
        final long startTime = System.currentTimeMillis();
        // Keep a list of successfully started listeners
        List<NetworkListener> startedListeners = new ArrayList<>();
        for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
            if (createNetworkProxy(listener) != null) {
                isAtLeastOneProxyStarted = true;
                startedListeners.add(listener);
            }
        }
        if (isAtLeastOneProxyStarted) {
            // Get the startup time
            final long startupTime = System.currentTimeMillis() - startTime;
            // Log the listeners which started.
            String boundAddresses = Arrays.toString(startedListeners.stream().map(listener -> listener.getName() + ":" + getRealPort(listener)).collect(Collectors.toList()).toArray());
            LOGGER.log(Level.INFO, KernelLoggerInfo.grizzlyStarted, new Object[] { Grizzly.getDotedVersion(), startupTime, boundAddresses });
            registerContainerAdapters();
        }
    } catch (RuntimeException e) {
        // So far postConstruct can not throw any other exception type
        LOGGER.log(Level.SEVERE, KernelLoggerInfo.grizzlyCantStart, e);
        for (NetworkProxy proxy : proxies) {
            try {
                proxy.stop();
            } catch (Exception proxyStopException) {
                LOGGER.log(Level.SEVERE, KernelLoggerInfo.grizzlyCloseException, new Object[] { proxy.getPort(), proxyStopException });
            }
        }
        throw e;
    }
    registerMonitoringStatsProviders();
}
Also used : Arrays(java.util.Arrays) RestrictTo(org.glassfish.api.event.RestrictTo) KernelLoggerInfo(org.glassfish.kernel.KernelLoggerInfo) Events(org.glassfish.api.event.Events) TimeoutException(java.util.concurrent.TimeoutException) RequestDispatcher(org.glassfish.api.container.RequestDispatcher) InetAddress(java.net.InetAddress) Protocol(org.glassfish.grizzly.config.dom.Protocol) Future(java.util.concurrent.Future) GrizzlyNetworkListenerRestartAdapter(org.glassfish.api.container.GrizzlyNetworkListenerRestartAdapter) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) Adapter(org.glassfish.api.container.Adapter) Map(java.util.Map) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) Futures(org.glassfish.grizzly.utils.Futures) GenericGrizzlyListener(org.glassfish.grizzly.config.GenericGrizzlyListener) Method(java.lang.reflect.Method) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Logger(java.util.logging.Logger) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) MonitoringDataSource(fish.payara.monitoring.collect.MonitoringDataSource) List(java.util.List) HttpCodecFilter(org.glassfish.grizzly.http.HttpCodecFilter) StartupRunLevel(org.glassfish.api.StartupRunLevel) Service(org.jvnet.hk2.annotations.Service) Transactions(org.jvnet.hk2.config.Transactions) Entry(java.util.Map.Entry) HttpService(com.sun.enterprise.config.serverbeans.HttpService) MonitoringDataCollection(fish.payara.monitoring.collect.MonitoringDataCollection) Queue(java.util.Queue) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Result(com.sun.enterprise.util.Result) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) FutureImpl(org.glassfish.grizzly.impl.FutureImpl) ObservableBean(org.jvnet.hk2.config.ObservableBean) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Constants(org.glassfish.common.util.Constants) GrizzlyMonitoring(com.sun.enterprise.v3.services.impl.monitor.GrizzlyMonitoring) Rank(org.glassfish.hk2.api.Rank) EventTypes(org.glassfish.api.event.EventTypes) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) HttpProbe(org.glassfish.grizzly.http.HttpProbe) StringUtils(com.sun.enterprise.util.StringUtils) FutureProvider(org.glassfish.api.FutureProvider) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Named(javax.inject.Named) EventListener(org.glassfish.api.event.EventListener) PreDestroy(org.glassfish.hk2.api.PreDestroy) RunLevel(org.glassfish.hk2.runlevel.RunLevel) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) Mapper(org.glassfish.grizzly.http.server.util.Mapper) HttpHandler(org.glassfish.grizzly.http.server.HttpHandler) IOException(java.io.IOException) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) ApplicationContainer(org.glassfish.api.deployment.ApplicationContainer) UnknownHostException(java.net.UnknownHostException) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Grizzly(org.glassfish.grizzly.Grizzly) PostConstruct(org.glassfish.hk2.api.PostConstruct) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) InvocationHandler(java.lang.reflect.InvocationHandler) Config(com.sun.enterprise.config.serverbeans.Config) Collections(java.util.Collections) CountStatistic(org.glassfish.external.statistics.CountStatistic) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)1 HttpService (com.sun.enterprise.config.serverbeans.HttpService)1 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)1 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)1 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)1 Result (com.sun.enterprise.util.Result)1 StringUtils (com.sun.enterprise.util.StringUtils)1 GrizzlyMonitoring (com.sun.enterprise.v3.services.impl.monitor.GrizzlyMonitoring)1 MonitoringDataCollection (fish.payara.monitoring.collect.MonitoringDataCollection)1 MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)1 MonitoringDataSource (fish.payara.monitoring.collect.MonitoringDataSource)1 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1