Search in sources :

Example 21 with Changed

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

the class CombinedJavaConfigSystemPropertyListener method changed.

/* force serial behavior; don't allow more than one thread to make a mess here */
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    // ignore a REMOVE and an ADD of the same value
    final UnprocessedChangeEvents unp = ConfigSupport.sortAndDispatch(events, new Changed() {

        @Override
        public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tc, T t) {
            NotProcessed result = null;
            if (tc == Profiler.class) {
                result = new NotProcessed("Creation or changes to a profiler require restart");
            } else if (tc == Property.class && t.getParent().getClass() == JavaConfig.class) {
                result = new NotProcessed("Addition of properties to JavaConfig requires restart");
            } else if (tc == JavaConfig.class && t instanceof JavaConfig) {
                final JavaConfig njc = (JavaConfig) t;
                logFine(type, njc);
                // we must *always* check the jvm options, no way to know except by comparing,
                // plus we should send an appropriate message back for each removed/added item
                final List<String> curProps = new ArrayList<String>(njc.getJvmOptions());
                final boolean jvmOptionsWereChanged = !oldProps.equals(curProps);
                final List<String> reasons = handle(oldProps, curProps);
                oldProps = curProps;
                // something in the JavaConfig itself changed
                // to do this well, we ought to keep a list of attributes, so we can make a good message
                // saying exactly which attribute what changed
                final Map<String, String> curAttrs = collectAttrs(njc);
                reasons.addAll(handleAttrs(oldAttrs, curAttrs));
                oldAttrs = curAttrs;
                result = reasons.isEmpty() ? null : new NotProcessed(CombinedJavaConfigSystemPropertyListener.toString(reasons));
            } else if (tc == SystemProperty.class && t instanceof SystemProperty) {
                final SystemProperty sp = (SystemProperty) t;
                // check to see if this system property is for this instance
                ConfigBeanProxy proxy = sp.getParent();
                ConfigView p = ConfigSupport.getImpl(proxy);
                if (p == ConfigSupport.getImpl(server) || p == ConfigSupport.getImpl(config) || (cluster != null && p == ConfigSupport.getImpl(cluster)) || p == ConfigSupport.getImpl(domain)) {
                    // check to see if this system property is referenced by any of the options
                    String pname = sp.getName();
                    if (referencesProperty(pname, oldProps) || referencesProperty(pname, oldAttrs.values())) {
                        result = new NotProcessed("The system-property, " + pname + ", that is referenced by the Java configuration, was modified");
                    }
                }
                if (type == TYPE.ADD || type == TYPE.CHANGE) {
                    // create-system-properties
                    if (proxy instanceof Domain) {
                        return addToDomain(sp);
                    } else if (proxy instanceof Config && p == ConfigSupport.getImpl(config)) {
                        return addToConfig(sp);
                    } else if (cluster != null && proxy instanceof Cluster && p == ConfigSupport.getImpl(cluster)) {
                        return addToCluster(sp);
                    } else if (proxy instanceof Server && p == ConfigSupport.getImpl(server)) {
                        return addToServer(sp);
                    }
                } else if (type == TYPE.REMOVE) {
                    if (proxy instanceof Domain) {
                        return removeFromDomain(sp);
                    } else if (proxy instanceof Config && p == ConfigSupport.getImpl(config)) {
                        return removeFromConfig(sp);
                    } else if (cluster != null && proxy instanceof Cluster && p == ConfigSupport.getImpl(cluster)) {
                        return removeFromCluster(sp);
                    } else if (proxy instanceof Server && p == ConfigSupport.getImpl(server)) {
                        return removeFromServer(sp);
                    }
                }
            } else {
            // ignore other changes that are reported
            }
            return result;
        }
    }, logger);
    return unp;
}
Also used : TranslatedConfigView(org.glassfish.config.support.TranslatedConfigView) TYPE(org.jvnet.hk2.config.Changed.TYPE) Property(org.jvnet.hk2.config.types.Property)

Example 22 with Changed

use of org.jvnet.hk2.config.Changed 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);
            switch(type) {
                case 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());
                    }
                    break;
                case REMOVE:
                    if (!isAdminListener) {
                        grizzlyService.removeNetworkProxy(listener);
                    }
                    break;
                case CHANGE:
                    // If the listener is the admin listener
                    if (isAdminListener) {
                        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);
                        }
                    }
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Network listener configuration error. Type: " + type, e);
        } finally {
            if (portLock != null) {
                releaseListenerLock(portLock);
            }
        }
    }
    return null;
}
Also used : 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)

Example 23 with Changed

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

the class TransactionServiceConfigListener method changed.

/**
 *************************************************************************
 */
/**
 * Implementation of org.jvnet.hk2.config.ConfigListener ********************
 */
/**
 *************************************************************************
 */
@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    // Events that we can't process now because they require server restart.
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    for (PropertyChangeEvent event : events) {
        String eventName = event.getPropertyName();
        Object oldValue = event.getOldValue();
        Object newValue = event.getNewValue();
        boolean accepted = true;
        _logger.log(Level.FINE, "Got TransactionService change event ==== {0} {1} {2} {3}", new Object[] { event.getSource(), eventName, oldValue, newValue });
        if (oldValue != null && oldValue.equals(newValue)) {
            _logger.log(Level.FINE, "Event {0} did not change existing value of {1}", new Object[] { eventName, oldValue });
            continue;
        }
        if (event.getSource() instanceof ModuleMonitoringLevels) {
            if (eventName.equals(ServerTags.TRANSACTION_SERVICE)) {
                String newlevel = newValue.toString();
                _logger.log(Level.FINE, "Changing transaction monitoring level");
                if ("OFF".equals(newlevel)) {
                    tm.setMonitoringEnabled(false);
                } else if ("LOW".equals(newlevel) || "HIGH".equals(newlevel)) {
                    tm.setMonitoringEnabled(true);
                }
            }
        // else skip
        } else if (eventName.equals(ServerTags.TIMEOUT_IN_SECONDS)) {
            try {
                tm.setDefaultTransactionTimeout(Integer.parseInt((String) newValue, 10));
                _logger.log(Level.FINE, " Transaction Timeout interval event processed for: {0}", newValue);
            } catch (Exception ex) {
                _logger.log(Level.WARNING, "transaction.reconfig_txn_timeout_failed", ex);
            }
        // timeout-in-seconds
        } else if (eventName.equals(ServerTags.KEYPOINT_INTERVAL) || eventName.equals(ServerTags.RETRY_TIMEOUT_IN_SECONDS)) {
            tm.handlePropertyUpdate(eventName, newValue);
            _logger.log(Level.FINE, "{0} reconfig event processed for new value: {1}", new Object[] { eventName, newValue });
        } else if (event.getPropertyName().equals("value")) {
            eventName = ((Property) event.getSource()).getName();
            _logger.log(Level.FINE, "Got Property change event for {0}", eventName);
            if (eventName.equals("purge-cancelled-transactions-after")) {
                String v = (String) newValue;
                if (v == null || v.length() == 0) {
                    tm.setPurgeCancelledTtransactionsAfter(0);
                } else {
                    tm.setPurgeCancelledTtransactionsAfter(Integer.parseInt(v, 10));
                }
            } else {
                // Not handled dynamically. Restart is required.
                accepted = false;
            }
        } else if (event.getPropertyName().equals("name") || event.getPropertyName().equals("property")) {
            // skip - means a new property added, was processed above as "value".
            _logger.log(Level.FINE, "...skipped");
        } else {
            // Not handled dynamically. Restart is required.
            accepted = false;
        }
        if (!accepted) {
            String msg = sm.getString("enterprise_distributedtx.restart_required", eventName);
            _logger.log(Level.INFO, msg);
            unprocessedEvents.add(new UnprocessedChangeEvent(event, msg));
        }
    }
    return (unprocessedEvents.size() > 0) ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) ModuleMonitoringLevels(com.sun.enterprise.config.serverbeans.ModuleMonitoringLevels) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) Property(org.jvnet.hk2.config.types.Property)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)12 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)11 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)10 ArrayList (java.util.ArrayList)9 Property (org.jvnet.hk2.config.types.Property)7 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)6 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)6 Config (com.sun.enterprise.config.serverbeans.Config)4 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)4 PropertyVetoException (java.beans.PropertyVetoException)4 List (java.util.List)3 Properties (java.util.Properties)3 ActionReport (org.glassfish.api.ActionReport)3 DasConfig (com.sun.enterprise.config.serverbeans.DasConfig)2 Domain (com.sun.enterprise.config.serverbeans.Domain)2 HttpService (com.sun.enterprise.config.serverbeans.HttpService)2 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)2 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)2 JmsService (com.sun.enterprise.connectors.jms.config.JmsService)2 LifecycleException (org.apache.catalina.LifecycleException)2