Search in sources :

Example 1 with UnprocessedChangeEvents

use of org.jvnet.hk2.config.UnprocessedChangeEvents in project Payara by payara.

the class AddLibraryCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = Logger.getLogger("org.glassfish.deployment.admin");
    File libDir = env.getLibPath();
    if (type.equals("ext")) {
        libDir = new File(libDir, "ext");
    } else if (type.equals("app")) {
        libDir = new File(libDir, "applibs");
    }
    // library directory
    try {
        List<UnprocessedChangeEvent> unprocessed = new ArrayList<UnprocessedChangeEvent>();
        StringBuilder msg = new StringBuilder();
        ClassLoader commonLoader = commonClsLdr.getCommonClassLoader();
        CurrentBeforeParentClassLoader loader = null;
        if (commonLoader instanceof CurrentBeforeParentClassLoader) {
            loader = (CurrentBeforeParentClassLoader) commonLoader;
        }
        for (File libraryFile : files) {
            if (libraryFile.exists()) {
                logger.log(Level.FINER, "ready to add new library");
                File result = DeploymentCommandUtils.renameUploadedFileOrCopyInPlaceFile(libDir, libraryFile, logger, env);
                // Applib is its own classloader which does not have a method to load files,
                if (loader != null && !type.equals("applibs")) {
                    loader.addURL(result.toURI().toURL());
                    logger.log(Level.FINE, "added library to classloader", loader);
                } else {
                    PropertyChangeEvent pe = new PropertyChangeEvent(libDir, "add-library", null, libraryFile);
                    UnprocessedChangeEvent uce = new UnprocessedChangeEvent(pe, "add-library");
                    unprocessed.add(uce);
                    logger.log(Level.FINER, "library not added to classloader");
                }
            } else {
                msg.append(localStrings.getLocalString("lfnf", "Library file not found", libraryFile.getAbsolutePath()));
            }
        }
        if (msg.length() > 0) {
            logger.log(Level.WARNING, msg.toString());
            report.setActionExitCode(ActionReport.ExitCode.WARNING);
            report.setMessage(msg.toString());
        }
        if (!unprocessed.isEmpty()) {
            // set the restart required flag
            UnprocessedChangeEvents uces = new UnprocessedChangeEvents(unprocessed);
            List<UnprocessedChangeEvents> ucesList = new ArrayList<UnprocessedChangeEvents>();
            ucesList.add(uces);
            ucl.unprocessedTransactedEvents(ucesList);
        }
        // touch the domain.xml so instances restart will synch
        // over the libraries.
        dxp.touch();
    } catch (Exception e) {
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(e.getMessage());
    }
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) CurrentBeforeParentClassLoader(com.sun.enterprise.loader.CurrentBeforeParentClassLoader) CurrentBeforeParentClassLoader(com.sun.enterprise.loader.CurrentBeforeParentClassLoader) File(java.io.File)

Example 2 with UnprocessedChangeEvents

use of org.jvnet.hk2.config.UnprocessedChangeEvents in project Payara by payara.

the class WebConfigListener method changed.

/**
 * Handles HttpService change events
 * @param events the PropertyChangeEvent
 */
@Override
public synchronized UnprocessedChangeEvents changed(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, LogFacade.CHANGE_INVOKED, new Object[] { type, tClass, t });
            }
            try {
                if (tClass == HttpService.class) {
                    container.updateHttpService((HttpService) t);
                } else if (tClass == NetworkListener.class) {
                    if (type == TYPE.ADD) {
                        container.addConnector((NetworkListener) t, httpService, true);
                    } else if (type == TYPE.REMOVE) {
                        container.deleteConnector((NetworkListener) t);
                    } else if (type == TYPE.CHANGE) {
                        container.updateConnector((NetworkListener) t, httpService);
                    }
                } else if (tClass == VirtualServer.class) {
                    if (type == TYPE.ADD) {
                        container.createHost((VirtualServer) t, httpService, null);
                        container.loadDefaultWebModule((VirtualServer) t);
                    } else if (type == TYPE.REMOVE) {
                        container.deleteHost(httpService);
                    } else if (type == TYPE.CHANGE) {
                        container.updateHost((VirtualServer) t);
                    }
                } else if (tClass == AccessLog.class) {
                    container.updateAccessLog(httpService);
                } else if (tClass == ManagerProperties.class) {
                    return new NotProcessed("ManagerProperties requires restart");
                } else if (tClass == WebContainerAvailability.class || tClass == AvailabilityService.class) {
                    // container.updateHttpService handles SingleSignOn valve configuration
                    container.updateHttpService(httpService);
                } else if (tClass == NetworkListeners.class) {
                // skip updates
                } else if (tClass == Property.class) {
                    ConfigBeanProxy config = ((Property) t).getParent();
                    if (config instanceof HttpService) {
                        container.updateHttpService((HttpService) config);
                    } else if (config instanceof VirtualServer) {
                        container.updateHost((VirtualServer) config);
                    } else if (config instanceof NetworkListener) {
                        container.updateConnector((NetworkListener) config, httpService);
                    } else {
                        container.updateHttpService(httpService);
                    }
                } else if (tClass == SystemProperty.class) {
                    if (((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
                        for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
                            if (listener.getPort().equals(((SystemProperty) t).getValue())) {
                                container.updateConnector(listener, httpService);
                            }
                        }
                    }
                } else if (tClass == JavaConfig.class) {
                    JavaConfig jc = (JavaConfig) t;
                    final List<String> jvmOptions = new ArrayList<String>(jc.getJvmOptions());
                    for (String jvmOption : jvmOptions) {
                        if (jvmOption.startsWith("-DjvmRoute=")) {
                            container.updateJvmRoute(httpService, jvmOption);
                        }
                    }
                } else {
                // Ignore other unrelated events
                }
            } catch (LifecycleException le) {
                logger.log(Level.SEVERE, LogFacade.EXCEPTION_WEB_CONFIG, le);
            }
            return null;
        }
    }, logger);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) AvailabilityService(com.sun.enterprise.config.serverbeans.AvailabilityService) ArrayList(java.util.ArrayList) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ManagerProperties(org.glassfish.web.config.serverbeans.ManagerProperties) WebContainerAvailability(org.glassfish.web.config.serverbeans.WebContainerAvailability) HttpService(com.sun.enterprise.config.serverbeans.HttpService) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 3 with UnprocessedChangeEvents

use of org.jvnet.hk2.config.UnprocessedChangeEvents 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 4 with UnprocessedChangeEvents

use of org.jvnet.hk2.config.UnprocessedChangeEvents in project Payara by payara.

the class DynamicReloadService method changed.

public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    /*
         * Deal with any changes to the DasConfig that might affect whether
         * the reloader should be stopped or started or rescheduled with a
         * different frequency.  Those change are handled here, by this
         * class.
         */
    /* Record any events we tried to process but could not. */
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    Boolean newEnabled = null;
    Integer newPollIntervalInSeconds = null;
    for (PropertyChangeEvent event : events) {
        String propName = event.getPropertyName();
        if (event.getSource() instanceof DasConfig) {
            if (configPropertyNames.contains(propName) && (event.getOldValue().equals(event.getNewValue()))) {
                logger.fine("[DynamicReload] Ignoring reconfig of " + propName + " from " + event.getOldValue() + " to " + event.getNewValue());
                continue;
            }
            if (propName.equals("dynamic-reload-enabled")) {
                /*
                     * Either start the currently stopped reloader or stop the
                     * currently running one.
                     */
                newEnabled = Boolean.valueOf((String) event.getNewValue());
            } else if (propName.equals("dynamic-reload-poll-interval-in-seconds")) {
                try {
                    newPollIntervalInSeconds = new Integer((String) event.getNewValue());
                } catch (NumberFormatException ex) {
                    String reason = ex.getClass().getName() + " " + ex.getLocalizedMessage();
                    logger.log(Level.WARNING, reason);
                }
            }
        }
    }
    if (newEnabled != null) {
        if (newEnabled) {
            start(newPollIntervalInSeconds == null ? getPollIntervalInSeconds(activeDasConfig) : newPollIntervalInSeconds);
        } else {
            stop();
        }
    } else {
        if (newPollIntervalInSeconds != null && isEnabled(activeDasConfig)) {
            /*
                 * There is no change in whether the reloader should be running, only
                 * in how often it should run.  If it is not running now don't
                 * start it.  If it is running now, restart it to use the new
                 * polling interval.
                 */
            reschedule(newPollIntervalInSeconds);
        }
    }
    return (unprocessedEvents.size() > 0) ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) DasConfig(com.sun.enterprise.config.serverbeans.DasConfig)

Example 5 with UnprocessedChangeEvents

use of org.jvnet.hk2.config.UnprocessedChangeEvents in project Payara by payara.

the class SetNetworkListenerConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    NetworkListener listener = config.getNetworkConfig().getNetworkListener(listenerName);
    if (!validate(actionReport)) {
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

            @Override
            public Object run(final NetworkListener listenerProxy) throws PropertyVetoException, TransactionFailure {
                if (enabled != null) {
                    listenerProxy.setEnabled(enabled.toString());
                }
                if (address != null) {
                    listenerProxy.setAddress(address);
                }
                if (port != null && !ADMIN_LISTENER.equals(listenerName)) {
                    listenerProxy.setPort(port.toString());
                }
                if (portRange != null) {
                    listenerProxy.setPortRange(portRange);
                }
                if (protocol != null) {
                    listenerProxy.setProtocol(protocol);
                }
                if (threadPool != null) {
                    listenerProxy.setThreadPool(threadPool);
                }
                if (transport != null) {
                    listenerProxy.setTransport(transport);
                }
                if (jkEnabled != null) {
                    listenerProxy.setJkEnabled(jkEnabled.toString());
                }
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return null;
            }
        }, listener);
        String oldPort = listener.getPort();
        if (port != null && ADMIN_LISTENER.equals(listenerName)) {
            UnprocessedChangeEvent unprocessed = new UnprocessedChangeEvent(new PropertyChangeEvent(this, "port", oldPort, port), listener.getName() + " port changed from " + oldPort + " to " + port);
            LOGGER.log(Level.INFO, MessageFormat.format(rb.getString(LogFacade.ADMIN_PORT_CHANGED), listenerName, oldPort, port));
            actionReport.setMessage(MessageFormat.format(rb.getString(LogFacade.ADMIN_PORT_CHANGED), listenerName, oldPort, port.toString()));
            List<UnprocessedChangeEvents> unprocessedList = new ArrayList<>();
            unprocessedList.add(new UnprocessedChangeEvents(unprocessed));
            ucl.unprocessedTransactedEvents(unprocessedList);
        }
    } catch (TransactionFailure e) {
        LOGGER.log(Level.SEVERE, null, e);
        actionReport.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL), listenerName) + (e.getMessage() == null ? "No reason given" : e.getMessage()));
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        actionReport.setFailureCause(e);
        return;
    }
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)16 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)15 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)14 ArrayList (java.util.ArrayList)12 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)5 PropertyVetoException (java.beans.PropertyVetoException)4 List (java.util.List)4 ActionReport (org.glassfish.api.ActionReport)4 HttpService (com.sun.enterprise.config.serverbeans.HttpService)3 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)3 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)3 Test (org.junit.Test)3 TransactionListener (org.jvnet.hk2.config.TransactionListener)3 Transactions (org.jvnet.hk2.config.Transactions)3 Property (org.jvnet.hk2.config.types.Property)3 Config (com.sun.enterprise.config.serverbeans.Config)2 DasConfig (com.sun.enterprise.config.serverbeans.DasConfig)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 File (java.io.File)2