Search in sources :

Example 6 with UnprocessedChangeEvents

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

the class LogManagerService method generateAttributeChangeEvent.

public void generateAttributeChangeEvent(String property, String propertyDetail, Map props) {
    PropertyChangeEvent pce = new PropertyChangeEvent(this, property, propertyDetail, props.get(property));
    UnprocessedChangeEvents ucel = new UnprocessedChangeEvents(new UnprocessedChangeEvent(pce, "server log file attribute " + property + " changed."));
    List<UnprocessedChangeEvents> b = new ArrayList();
    b.add(ucel);
    ucl.unprocessedTransactedEvents(b);
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent)

Example 7 with UnprocessedChangeEvents

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

the class RemoveLibraryCommand method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    final Logger logger = context.getLogger();
    File libDir = env.getLibPath();
    if (type.equals("ext")) {
        libDir = new File(libDir, "ext");
    } else if (type.equals("app")) {
        libDir = new File(libDir, "applibs");
    }
    try {
        List<UnprocessedChangeEvent> unprocessed = new ArrayList<UnprocessedChangeEvent>();
        // delete the file from the appropriate library directory
        StringBuffer msg = new StringBuffer();
        for (String libraryName : names) {
            File libraryFile = new File(libDir, libraryName);
            if (libraryFile.exists()) {
                boolean isDeleted = FileUtils.deleteFile(libraryFile);
                if (!isDeleted) {
                    msg.append(localStrings.getLocalString("lfnd", "Could not remove library file", libraryFile.getAbsolutePath()));
                } else {
                    PropertyChangeEvent pe = new PropertyChangeEvent(libDir, "remove-library", libraryFile, null);
                    UnprocessedChangeEvent uce = new UnprocessedChangeEvent(pe, "remove-library");
                    unprocessed.add(uce);
                }
            } 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());
        }
        // 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) File(java.io.File)

Example 8 with UnprocessedChangeEvents

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

the class AutoDeployService method changed.

@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    if (autoDeployer == null) {
        return null;
    }
    /* Record any events we tried to process but could not. */
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    Boolean newEnabled = null;
    Integer newPollingIntervalInSeconds = null;
    for (PropertyChangeEvent event : events) {
        if (event.getSource() instanceof DasConfig) {
            String propName = event.getPropertyName();
            if (configPropertyNames.contains(propName) && event.getOldValue().equals(event.getNewValue())) {
                deplLogger.fine("[AutoDeploy] Ignoring reconfig of " + propName + " from " + event.getOldValue() + " to " + event.getNewValue());
                continue;
            }
            /*
                 * Substitute any placeholders in the new and old values.
                 */
            final String oldValue = replaceTokens((String) event.getOldValue(), System.getProperties());
            final String newValue = replaceTokens((String) event.getNewValue(), System.getProperties());
            if (propName.equals("autodeploy-enabled")) {
                /*
                     * Either start the currently stopped autodeployer or stop the
                     * currently running one.
                     */
                newEnabled = Boolean.valueOf(newValue);
                deplLogger.fine("[AutoDeploy] Reconfig - enabled changed to " + newEnabled);
            } else if (propName.equals("autodeploy-polling-interval-in-seconds")) {
                try {
                    newPollingIntervalInSeconds = new Integer(newValue);
                    deplLogger.fine("[AutoDeploy] Reconfig - polling interval (seconds) changed from " + oldValue + " to " + newPollingIntervalInSeconds);
                } catch (NumberFormatException ex) {
                    deplLogger.log(Level.WARNING, CONFIGURATION_CHANGE_ERROR, new Object[] { propName, oldValue, newValue, ex.getClass().getName(), ex.getLocalizedMessage() });
                }
            } else if (propName.equals("autodeploy-dir")) {
                String newDir = newValue;
                try {
                    autoDeployer.setDirectory(newDir);
                    deplLogger.fine("[AutoDeploy] Reconfig - directory changed from " + oldValue + " to " + newDir);
                } catch (AutoDeploymentException ex) {
                    deplLogger.log(Level.WARNING, CONFIGURATION_CHANGE_ERROR, new Object[] { propName, oldValue, newValue, ex.getClass().getName(), ex.getLocalizedMessage() });
                }
            } else if (propName.equals("autodeploy-verifier-enabled")) {
                boolean newVerifierEnabled = Boolean.parseBoolean(newValue);
                autoDeployer.setVerifierEnabled(newVerifierEnabled);
                deplLogger.fine("[AutoDeploy] Reconfig - verifierEnabled changed from " + Boolean.parseBoolean(oldValue) + " to " + newVerifierEnabled);
            } else if (propName.equals("autodeploy-jsp-precompilation-enabled")) {
                boolean newJspPrecompiled = Boolean.parseBoolean(newValue);
                autoDeployer.setJspPrecompilationEnabled(newJspPrecompiled);
                deplLogger.fine("[AutoDeploy] Reconfig - jspPrecompilationEnabled changed from " + Boolean.parseBoolean(oldValue) + " to " + newJspPrecompiled);
            }
        }
    }
    if (newEnabled != null) {
        if (newEnabled) {
            startAutoDeployer(newPollingIntervalInSeconds == null ? getPollingIntervalInSeconds() : newPollingIntervalInSeconds);
        } else {
            stopAutoDeployer();
        }
    } else {
        if ((newPollingIntervalInSeconds != null) && isAutoDeployEnabled()) {
            /*
                 * There is no change in whether the autodeployer 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.
                 */
            rescheduleAutoDeployer(newPollingIntervalInSeconds);
        }
    }
    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 9 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 10 with UnprocessedChangeEvents

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

the class GetRestartRequiredCommand method execute.

public void execute(AdminCommandContext context) {
    ActionReport report = context.getActionReport();
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    ActionReport.MessagePart mp = report.getTopMessagePart();
    Properties extraProperties = new Properties();
    Map<String, Object> entity = new HashMap<String, Object>();
    mp.setMessage(Boolean.toString(ucl.serverRequiresRestart()));
    entity.put("restartRequired", Boolean.toString(ucl.serverRequiresRestart()));
    List<String> unprocessedChanges = new ArrayList<String>();
    for (UnprocessedChangeEvents es : ucl.getUnprocessedChangeEvents()) {
        for (UnprocessedChangeEvent e : es.getUnprocessed()) {
            if (why) {
                mp.addChild().setMessage(e.getReason());
            }
            unprocessedChanges.add(e.getReason());
        }
    }
    if (!unprocessedChanges.isEmpty()) {
        entity.put("unprocessedChanges", unprocessedChanges);
    }
    extraProperties.put("entity", entity);
    ((ActionReport) report).setExtraProperties(extraProperties);
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) HashMap(java.util.HashMap) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)16 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)16 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)14 ArrayList (java.util.ArrayList)11 List (java.util.List)5 HashMap (java.util.HashMap)4 HttpService (com.sun.enterprise.config.serverbeans.HttpService)3 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)3 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)3 File (java.io.File)3 IOException (java.io.IOException)3 ActionReport (org.glassfish.api.ActionReport)3 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)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 Domain (com.sun.enterprise.config.serverbeans.Domain)2