Search in sources :

Example 6 with NotProcessed

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

the class AddPropertyTest method transactionEvents.

@Test
public void transactionEvents() throws TransactionFailure {
    final Domain domain = getHabitat().getService(Domain.class);
    final TransactionListener listener = new TransactionListener() {

        public void transactionCommited(List<PropertyChangeEvent> changes) {
            events = changes;
        }

        public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
        }
    };
    Transactions transactions = getHabitat().getService(Transactions.class);
    try {
        transactions.addTransactionsListener(listener);
        assertTrue(domain != null);
        ConfigSupport.apply(new SingleConfigCode<Domain>() {

            public Object run(Domain domain) throws PropertyVetoException, TransactionFailure {
                Property prop = domain.createChild(Property.class);
                domain.getProperty().add(prop);
                prop.setName("Jerome");
                prop.setValue("was here");
                return prop;
            }
        }, domain);
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.fine("Number of events " + events.size());
        assertTrue(events.size() == 3);
        for (PropertyChangeEvent event : events) {
            logger.fine(event.toString());
        }
        Map<String, String> configChanges = new HashMap<String, String>();
        configChanges.put("name", "julien");
        configChanges.put("value", "petit clown");
        ConfigBean domainBean = (ConfigBean) Dom.unwrap(domain);
        ConfigSupport.createAndSet(domainBean, Property.class, configChanges);
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.fine("Number of events " + events.size());
        assertTrue(events.size() == 3);
        for (PropertyChangeEvent event : events) {
            logger.fine(event.toString());
        }
        final UnprocessedChangeEvents unprocessed = ConfigSupport.sortAndDispatch(events.toArray(new PropertyChangeEvent[0]), new Changed() {

            /**
             * Notification of a change on a configuration object
             *
             * @param type            type of change : ADD mean the changedInstance was added to the parent
             *                        REMOVE means the changedInstance was removed from the parent, CHANGE means the
             *                        changedInstance has mutated.
             * @param changedType     type of the configuration object
             * @param changedInstance changed instance.
             */
            public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> changedType, T changedInstance) {
                return new NotProcessed("unimplemented by AddPropertyTest");
            }
        }, logger);
    } finally {
        transactions.removeTransactionsListener(listener);
    }
}
Also used : TransactionListener(org.jvnet.hk2.config.TransactionListener) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) HashMap(java.util.HashMap) ConfigBean(org.jvnet.hk2.config.ConfigBean) PropertyVetoException(java.beans.PropertyVetoException) Transactions(org.jvnet.hk2.config.Transactions) Changed(org.jvnet.hk2.config.Changed) NotProcessed(org.jvnet.hk2.config.NotProcessed) List(java.util.List) Domain(com.sun.enterprise.config.serverbeans.Domain) Property(org.jvnet.hk2.config.types.Property) Test(org.junit.Test)

Example 7 with NotProcessed

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

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

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

the class MessageSecurityConfigEventListenerImpl method handleUpdate.

/**
 * @param event - Event to be processed.
 * @throws AdminEventListenerException when the listener is unable to process the event.
 */
public <T extends ConfigBeanProxy> NotProcessed handleUpdate(T instance) {
    NotProcessed notProcessed = null;
    logger.fine("MessageSecurityConfigEventListenerImpl - handleUpdate called");
    // Handle only the MessageSecurityConfig.
    if (instance instanceof MessageSecurityConfig) {
        GFServerConfigProvider.loadConfigContext(service);
    } else {
        notProcessed = new NotProcessed("unimplemented: unknown instance: " + instance.getClass().getName());
    }
    return notProcessed;
}
Also used : NotProcessed(org.jvnet.hk2.config.NotProcessed) MessageSecurityConfig(com.sun.enterprise.config.serverbeans.MessageSecurityConfig)

Aggregations

NotProcessed (org.jvnet.hk2.config.NotProcessed)7 MessageSecurityConfig (com.sun.enterprise.config.serverbeans.MessageSecurityConfig)3 Property (org.jvnet.hk2.config.types.Property)3 MonitoringService (com.sun.enterprise.config.serverbeans.MonitoringService)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)2 Changed (org.jvnet.hk2.config.Changed)2 AvailabilityService (com.sun.enterprise.config.serverbeans.AvailabilityService)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 HttpService (com.sun.enterprise.config.serverbeans.HttpService)1 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)1 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1