Search in sources :

Example 1 with GrizzlyListener

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

the class DynamicConfigListener method processNetworkListener.

private <T extends ConfigBeanProxy> NotProcessed processNetworkListener(Changed.TYPE type, NetworkListener listener, final PropertyChangeEvent[] changedProperties) {
    if (findConfigName(listener).equals(findConfigName(config))) {
        boolean isAdminListener = ADMIN_LISTENER.equals(listener.getName());
        Lock portLock = null;
        try {
            portLock = acquirePortLock(listener);
            if (type == Changed.TYPE.ADD) {
                final int[] ports = portLock.getPorts();
                if (isAdminListener && ports[ports.length - 1] == -1) {
                    return null;
                }
                final Future future = grizzlyService.createNetworkProxy(listener);
                if (future != null) {
                    future.get(RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS);
                    grizzlyService.registerContainerAdapters();
                } else {
                    logger.log(Level.FINE, "Skipping proxy registration for the listener {0}", listener.getName());
                }
            } else if (type == Changed.TYPE.REMOVE) {
                if (!isAdminListener) {
                    grizzlyService.removeNetworkProxy(listener);
                }
            } else if (type == Changed.TYPE.CHANGE) {
                // If the listener is the admin listener
                if (isAdminListener) {
                    final boolean dynamic = isAdminDynamic(changedProperties);
                    // If configuration is dynamic then make the change
                    if (dynamic) {
                        GrizzlyProxy proxy = (GrizzlyProxy) grizzlyService.lookupNetworkProxy(listener);
                        if (proxy != null) {
                            GrizzlyListener netListener = proxy.getUnderlyingListener();
                            netListener.processDynamicConfigurationChange(grizzlyService.getHabitat(), changedProperties);
                            return null;
                        }
                    }
                    // Otherwise return the unprocessed event, describing the changed values.
                    if (!isRedundantChange(changedProperties)) {
                        StringBuilder eventsMessage = new StringBuilder();
                        /* Add list of changed events to an events message.
                            *  Usually only one message is sent to this method at a time, so the for loop should only run once,
                            *  but it's there just in case.
                            */
                        for (PropertyChangeEvent event : changedProperties) {
                            eventsMessage.append("\"" + event.getPropertyName() + "\" changed from \"" + event.getOldValue() + "\" to \"" + event.getNewValue() + "\".\n");
                        }
                        return new NotProcessed(listener.getThreadPool() + " attribute " + eventsMessage.toString());
                    }
                    return null;
                }
                // Only restart the network listener if something hasn't changed
                if (!isRedundantChange(changedProperties)) {
                    MonitoringService ms = config.getMonitoringService();
                    String level = ms.getModuleMonitoringLevels().getHttpService();
                    // We only need to throw an unprocessed change event if monitoring is enabled for the HTTP service
                    if (level != null && (!level.equals(OFF))) {
                        String eventsMessage = "Monitoring statistics will be incorrect for " + listener.findHttpProtocolName() + " until restart due to changed attribute(s): ";
                        // so the for loop should only run once, but it's there just in case.
                        for (PropertyChangeEvent event : changedProperties) {
                            eventsMessage += ("\"" + event.getPropertyName() + "\" changed from \"" + event.getOldValue() + "\" to \"" + event.getNewValue() + "\".\n");
                        }
                        // Still restart the network listener, as it's only the monitoring that breaks.
                        grizzlyService.restartNetworkListener(listener, RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS);
                        return new NotProcessed(eventsMessage);
                    } else {
                        // Restart the network listener without throwing an unprocessed change
                        grizzlyService.restartNetworkListener(listener, RECONFIG_LOCK_TIMEOUT_SEC, TimeUnit.SECONDS);
                    }
                }
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Network listener configuration error. Type: " + type, e);
        } finally {
            if (portLock != null) {
                releaseListenerLock(portLock);
            }
        }
    }
    return null;
}
Also used : GrizzlyListener(org.glassfish.grizzly.config.GrizzlyListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) Future(java.util.concurrent.Future) NotProcessed(org.jvnet.hk2.config.NotProcessed) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ReentrantLock(java.util.concurrent.locks.ReentrantLock)

Aggregations

MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 GrizzlyListener (org.glassfish.grizzly.config.GrizzlyListener)1 NotProcessed (org.jvnet.hk2.config.NotProcessed)1