Search in sources :

Example 1 with UnprocessedChangeEvent

use of org.jvnet.hk2.config.UnprocessedChangeEvent 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 UnprocessedChangeEvent

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

use of org.jvnet.hk2.config.UnprocessedChangeEvent 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)

Example 4 with UnprocessedChangeEvent

use of org.jvnet.hk2.config.UnprocessedChangeEvent 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)

Example 5 with UnprocessedChangeEvent

use of org.jvnet.hk2.config.UnprocessedChangeEvent 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) ArrayList(java.util.ArrayList)

Aggregations

UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)14 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)14 PropertyChangeEvent (java.beans.PropertyChangeEvent)12 ArrayList (java.util.ArrayList)11 ActionReport (org.glassfish.api.ActionReport)4 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)3 Config (com.sun.enterprise.config.serverbeans.Config)2 DasConfig (com.sun.enterprise.config.serverbeans.DasConfig)2 PropertyVetoException (java.beans.PropertyVetoException)2 File (java.io.File)2 Logger (java.util.logging.Logger)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 ModuleMonitoringLevels (com.sun.enterprise.config.serverbeans.ModuleMonitoringLevels)1 JmsHost (com.sun.enterprise.connectors.jms.config.JmsHost)1 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)1 CurrentBeforeParentClassLoader (com.sun.enterprise.loader.CurrentBeforeParentClassLoader)1 DummyNetworkListener (com.sun.enterprise.v3.services.impl.DummyNetworkListener)1 GrizzlyService (com.sun.enterprise.v3.services.impl.GrizzlyService)1 RestMonitoringEndpointDecider (fish.payara.appserver.monitoring.rest.service.adapter.RestMonitoringEndpointDecider)1 RestMonitoringConfiguration (fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration)1