Search in sources :

Example 41 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class DynamicConfigListener method changed.

@Override
public synchronized UnprocessedChangeEvents changed(final PropertyChangeEvent[] events) {
    return ConfigSupport.sortAndDispatch(events, new Changed() {

        @Override
        public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "NetworkConfig changed {0} {1} {2}", new Object[] { type, tClass, t });
            }
            if (tClass == NetworkListener.class && t instanceof NetworkListener) {
                return processNetworkListener(type, (NetworkListener) t, events);
            } else if (tClass == Http.class && t instanceof Http) {
                return processProtocol(type, (Protocol) t.getParent(), events);
            } else if (tClass == FileCache.class && t instanceof FileCache) {
                return processProtocol(type, (Protocol) t.getParent().getParent(), null);
            } else if (tClass == Ssl.class && t instanceof Ssl) {
                /*
                         * Make sure the SSL parent is in fact a protocol.  It could
                         * be a jmx-connector.
                     */
                final ConfigBeanProxy parent = t.getParent();
                if (parent instanceof Protocol) {
                    return processProtocol(type, (Protocol) parent, null);
                }
            } else if (tClass == Protocol.class && t instanceof Protocol) {
                return processProtocol(type, (Protocol) t, null);
            } else if (tClass == ThreadPool.class && t instanceof ThreadPool) {
                NotProcessed notProcessed = null;
                ThreadPool threadPool = (ThreadPool) t;
                for (NetworkListener listener : threadPool.findNetworkListeners()) {
                    notProcessed = processNetworkListener(type, listener, null);
                }
                // Throw an unprocessed event change if one hasn't already if HTTP or ThreadPool monitoring is enabled.
                MonitoringService ms = config.getMonitoringService();
                String threadPoolLevel = ms.getModuleMonitoringLevels().getThreadPool();
                String httpServiceLevel = ms.getModuleMonitoringLevels().getHttpService();
                if (((threadPoolLevel != null && !threadPoolLevel.equals(OFF)) || (httpServiceLevel != null && !httpServiceLevel.equals(OFF))) && notProcessed == null) {
                    notProcessed = new NotProcessed("Monitoring statistics will be incorrect for " + threadPool.getName() + " until restart due to changed attribute(s).");
                }
                return notProcessed;
            } else if (tClass == Transport.class && t instanceof Transport) {
                NotProcessed notProcessed = null;
                for (NetworkListener listener : ((Transport) t).findNetworkListeners()) {
                    notProcessed = processNetworkListener(type, listener, null);
                }
                return notProcessed;
            } else if (tClass == VirtualServer.class && t instanceof VirtualServer && !grizzlyService.hasMapperUpdateListener()) {
                return processVirtualServer(type, (VirtualServer) t);
            } else if (tClass == SystemProperty.class && t instanceof SystemProperty) {
                NetworkConfig networkConfig = config.getNetworkConfig();
                if ((networkConfig != null) && ((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
                    for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
                        if (listener.getPort().equals(((SystemProperty) t).getValue())) {
                            return processNetworkListener(Changed.TYPE.CHANGE, listener, events);
                        }
                    }
                }
                return null;
            }
            return null;
        }
    }, logger);
}
Also used : ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) Ssl(org.glassfish.grizzly.config.dom.Ssl) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) FileCache(org.glassfish.grizzly.config.dom.FileCache) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Changed(org.jvnet.hk2.config.Changed) NotProcessed(org.jvnet.hk2.config.NotProcessed) Protocol(org.glassfish.grizzly.config.dom.Protocol) Transport(org.glassfish.grizzly.config.dom.Transport) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 42 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class GlassfishNetworkListener method configureHttpProtocol.

@Override
protected void configureHttpProtocol(final ServiceLocator habitat, final NetworkListener networkListener, final Http http, final FilterChainBuilder filterChainBuilder, boolean securityEnabled) {
    if (httpAdapter == null) {
        registerMonitoringStatsProviders();
        final V3Mapper mapper = new V3Mapper(logger);
        mapper.setPort(port);
        mapper.setId(name);
        final ContainerMapper containerMapper = new ContainerMapper(grizzlyService, this);
        containerMapper.setMapper(mapper);
        containerMapper.setDefaultHost(http.getDefaultVirtualServer());
        containerMapper.setRequestURIEncoding(http.getUriEncoding());
        containerMapper.configureMapper();
        VirtualServer vs = null;
        String webAppRootPath = null;
        final Collection<VirtualServer> list = grizzlyService.getHabitat().getAllServices(VirtualServer.class);
        final String vsName = http.getDefaultVirtualServer();
        for (final VirtualServer virtualServer : list) {
            if (virtualServer.getId().equals(vsName)) {
                vs = virtualServer;
                webAppRootPath = vs.getDocroot();
                if (!grizzlyService.hasMapperUpdateListener() && vs.getProperty() != null && !vs.getProperty().isEmpty()) {
                    for (final Property p : vs.getProperty()) {
                        final String propertyName = p.getName();
                        if (propertyName.startsWith("alternatedocroot")) {
                            String value = p.getValue();
                            String[] mapping = value.split(" ");
                            if (mapping.length != 2) {
                                logger.log(Level.WARNING, "Invalid alternate_docroot {0}", value);
                                continue;
                            }
                            String docBase = mapping[1].substring("dir=".length());
                            String urlPattern = mapping[0].substring("from=".length());
                            containerMapper.addAlternateDocBase(urlPattern, docBase);
                        }
                    }
                }
                break;
            }
        }
        httpAdapter = new HttpAdapterImpl(vs, containerMapper, webAppRootPath);
        containerMapper.addDocRoot(webAppRootPath);
        AbstractActiveDescriptor<V3Mapper> aad = BuilderHelper.createConstantDescriptor(mapper);
        aad.addContractType(Mapper.class);
        aad.setName(address.toString() + port);
        ServiceLocatorUtilities.addOneDescriptor(grizzlyService.getHabitat(), aad);
        super.configureHttpProtocol(habitat, networkListener, http, filterChainBuilder, securityEnabled);
        final Protocol protocol = http.getParent();
        for (NetworkListener listener : protocol.findNetworkListeners()) {
            grizzlyService.notifyMapperUpdateListeners(listener, mapper);
        }
    } else {
        super.configureHttpProtocol(habitat, networkListener, http, filterChainBuilder, securityEnabled);
    }
}
Also used : Protocol(org.glassfish.grizzly.config.dom.Protocol) V3Mapper(org.glassfish.internal.grizzly.V3Mapper) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 43 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener 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<Future<Result<Thread>>>();
        // 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.getAddress() + ":" + listener.getPort()).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) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) 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) 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) 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) HttpService(com.sun.enterprise.config.serverbeans.HttpService) 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) 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) 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) Future(java.util.concurrent.Future) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 44 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class DeleteHttpListener method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    ActionReport report = context.getActionReport();
    networkConfig = config.getNetworkConfig();
    if (!exists()) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_LISTENER_NOT_EXISTS), listenerId));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    try {
        NetworkListener ls = networkConfig.getNetworkListener(listenerId);
        final String name = ls.getProtocol();
        VirtualServer vs = config.getHttpService().getVirtualServerByName(ls.findHttpProtocol().getHttp().getDefaultVirtualServer());
        ConfigSupport.apply(new DeleteNetworkListener(), networkConfig.getNetworkListeners());
        ConfigSupport.apply(new UpdateVirtualServer(), vs);
        cleanUp(name);
        report.setActionExitCode(ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_HTTP_LISTENER_FAIL), listenerId));
        report.setActionExitCode(ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ActionReport(org.glassfish.api.ActionReport) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 45 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class DeleteNetworkListener method findListener.

private boolean findListener(final NetworkListeners networkListeners, ActionReport report) {
    for (NetworkListener listener : networkListeners.getNetworkListener()) {
        if (listener.getName().equals(networkListenerName)) {
            listenerToBeRemoved = listener;
        }
    }
    if (listenerToBeRemoved == null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_NETWORK_LISTENER_NOT_EXISTS), networkListenerName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return false;
    }
    return true;
}
Also used : NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)74 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)21 Protocol (org.glassfish.grizzly.config.dom.Protocol)18 Config (com.sun.enterprise.config.serverbeans.Config)17 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)14 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)12 Test (org.junit.Test)11 ActionReport (org.glassfish.api.ActionReport)10 CommandTarget (org.glassfish.config.support.CommandTarget)9 Target (org.glassfish.internal.api.Target)9 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 HttpService (com.sun.enterprise.config.serverbeans.HttpService)7 ArrayList (java.util.ArrayList)7 Protocols (org.glassfish.grizzly.config.dom.Protocols)7 ObservableBean (org.jvnet.hk2.config.ObservableBean)7 Transactions (org.jvnet.hk2.config.Transactions)7 IOException (java.io.IOException)6 Http (org.glassfish.grizzly.config.dom.Http)6 PropertyVetoException (java.beans.PropertyVetoException)5 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)5