Search in sources :

Example 16 with UnprocessedChangeEvents

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

the class PayaraExecutorService method changed.

@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
    List<UnprocessedChangeEvent> unprocessedChanges = new ArrayList<>();
    boolean keepAliveChanged = false;
    for (PropertyChangeEvent propertyChangeEvent : propertyChangeEvents) {
        switch(propertyChangeEvent.getPropertyName()) {
            case "thread-pool-executor-core-pool-size":
                if (isCurrentInstanceMatchTarget(propertyChangeEvent) && !propertyChangeEvent.getOldValue().equals(propertyChangeEvent.getNewValue())) {
                    threadPoolExecutor.setCorePoolSize((Integer) propertyChangeEvent.getNewValue());
                }
                break;
            case "thread-pool-executor-max-pool-size":
                if (isCurrentInstanceMatchTarget(propertyChangeEvent) && !propertyChangeEvent.getOldValue().equals(propertyChangeEvent.getNewValue())) {
                    threadPoolExecutor.setMaximumPoolSize((Integer) propertyChangeEvent.getNewValue());
                }
                break;
            case "thread-pool-executor-keep-alive-time":
                if (isCurrentInstanceMatchTarget(propertyChangeEvent) && !propertyChangeEvent.getOldValue().equals(propertyChangeEvent.getNewValue())) {
                    if (!keepAliveChanged) {
                        for (PropertyChangeEvent pce : propertyChangeEvents) {
                            if (isCurrentInstanceMatchTarget(pce) && pce.getPropertyName().equals("thread-pool-executor-keep-alive-time-unit")) {
                                if (!pce.getOldValue().equals(pce.getNewValue())) {
                                    keepAliveChanged = true;
                                    threadPoolExecutor.setKeepAliveTime(Long.valueOf((String) propertyChangeEvent.getNewValue()), TimeUnit.valueOf((String) pce.getNewValue()));
                                } else {
                                    threadPoolExecutor.setKeepAliveTime((Integer) propertyChangeEvent.getNewValue(), TimeUnit.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorKeepAliveTimeUnit()));
                                }
                            }
                        }
                        if (!keepAliveChanged) {
                            threadPoolExecutor.setKeepAliveTime(Long.valueOf((String) propertyChangeEvent.getNewValue()), TimeUnit.valueOf(payaraExecutorServiceConfiguration.getThreadPoolExecutorKeepAliveTimeUnit()));
                        }
                    }
                }
                break;
            case "thread-pool-executor-keep-alive-time-unit":
                if (isCurrentInstanceMatchTarget(propertyChangeEvent) && !propertyChangeEvent.getOldValue().equals(propertyChangeEvent.getNewValue())) {
                    if (!keepAliveChanged) {
                        for (PropertyChangeEvent pce : propertyChangeEvents) {
                            if (isCurrentInstanceMatchTarget(pce) && pce.getPropertyName().equals("thread-pool-executor-keep-alive-time")) {
                                if (!pce.getOldValue().equals(pce.getNewValue())) {
                                    keepAliveChanged = true;
                                    threadPoolExecutor.setKeepAliveTime(Long.valueOf((String) pce.getNewValue()), TimeUnit.valueOf((String) propertyChangeEvent.getNewValue()));
                                } else {
                                    threadPoolExecutor.setKeepAliveTime(Long.valueOf((String) payaraExecutorServiceConfiguration.getThreadPoolExecutorKeepAliveTime()), TimeUnit.valueOf((String) propertyChangeEvent.getNewValue()));
                                }
                            }
                        }
                        if (!keepAliveChanged) {
                            threadPoolExecutor.setKeepAliveTime(Long.valueOf((String) payaraExecutorServiceConfiguration.getThreadPoolExecutorKeepAliveTime()), TimeUnit.valueOf((String) propertyChangeEvent.getNewValue()));
                        }
                    }
                }
                break;
            case "thread-pool-executor-queue-size":
                if (isCurrentInstanceMatchTarget(propertyChangeEvent) && !propertyChangeEvent.getOldValue().equals(propertyChangeEvent.getNewValue())) {
                    unprocessedChanges.add(new UnprocessedChangeEvent(propertyChangeEvent, "Payara Executor Service requires restarting"));
                }
                break;
            case "scheduled-thread-pool-executor-core-pool-size":
                if (isCurrentInstanceMatchTarget(propertyChangeEvent) && !propertyChangeEvent.getOldValue().equals(propertyChangeEvent.getNewValue())) {
                    scheduledThreadPoolExecutor.setCorePoolSize((Integer) propertyChangeEvent.getNewValue());
                }
                break;
        }
    }
    if (unprocessedChanges.isEmpty()) {
        return null;
    } else {
        return new UnprocessedChangeEvents(unprocessedChanges);
    }
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList)

Example 17 with UnprocessedChangeEvents

use of org.jvnet.hk2.config.UnprocessedChangeEvents 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 : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) Server(com.sun.enterprise.config.serverbeans.Server) TranslatedConfigView(org.glassfish.config.support.TranslatedConfigView) ConfigView(org.jvnet.hk2.config.ConfigView) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) Config(com.sun.enterprise.config.serverbeans.Config) Cluster(com.sun.enterprise.config.serverbeans.Cluster) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Profiler(com.sun.enterprise.config.serverbeans.Profiler) Changed(org.jvnet.hk2.config.Changed) NotProcessed(org.jvnet.hk2.config.NotProcessed) ArrayList(java.util.ArrayList) List(java.util.List) Domain(com.sun.enterprise.config.serverbeans.Domain) TYPE(org.jvnet.hk2.config.Changed.TYPE) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with UnprocessedChangeEvents

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

the class TransactionListenerTest method transactionEvents.

@Test
public void transactionEvents() throws Exception, TransactionFailure {
    httpService = getHabitat().getService(HttpService.class);
    NetworkConfig networkConfig = getHabitat().getService(NetworkConfig.class);
    final NetworkListener netListener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
    final Http http = netListener.findHttpProtocol().getHttp();
    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(httpService != null);
        logger.fine("Max connections = " + http.getMaxConnections());
        ConfigSupport.apply(new SingleConfigCode<Http>() {

            public Object run(Http param) {
                param.setMaxConnections("500");
                return null;
            }
        }, http);
        assertTrue("500".equals(http.getMaxConnections()));
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.fine("Number of events " + events.size());
        assertTrue(events.size() == 1);
        PropertyChangeEvent event = events.iterator().next();
        assertTrue("max-connections".equals(event.getPropertyName()));
        assertTrue("500".equals(event.getNewValue().toString()));
        assertTrue("250".equals(event.getOldValue().toString()));
    } catch (Exception t) {
        t.printStackTrace();
        throw t;
    } finally {
        transactions.removeTransactionsListener(listener);
    }
    // put back the right values in the domain to avoid test collisions
    ConfigSupport.apply(new SingleConfigCode<Http>() {

        public Object run(Http param) {
            param.setMaxConnections("250");
            return null;
        }
    }, http);
}
Also used : TransactionListener(org.jvnet.hk2.config.TransactionListener) Transactions(org.jvnet.hk2.config.Transactions) PropertyChangeEvent(java.beans.PropertyChangeEvent) HttpService(com.sun.enterprise.config.serverbeans.HttpService) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) List(java.util.List) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 19 with UnprocessedChangeEvents

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

the class TranslatedViewCreationTest method createVirtualServerTest.

@Test
public void createVirtualServerTest() throws TransactionFailure {
    httpService = getHabitat().getService(HttpService.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(httpService != null);
        ConfigSupport.apply(new SingleConfigCode<HttpService>() {

            public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
                VirtualServer newVirtualServer = param.createChild(VirtualServer.class);
                newVirtualServer.setDocroot("${" + propName + "}");
                newVirtualServer.setId("translated-view-creation");
                param.getVirtualServer().add(newVirtualServer);
                return null;
            }
        }, httpService);
        // first let check that our new virtual server has the right translated value
        VirtualServer vs = httpService.getVirtualServerByName("translated-view-creation");
        assertTrue(vs != null);
        String docRoot = vs.getDocroot();
        assertTrue("/foo/bar/docroot".equals(docRoot));
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.fine("Number of events " + events.size());
        assertTrue(events.size() == 3);
        for (PropertyChangeEvent event : events) {
            if ("virtual-server".equals(event.getPropertyName())) {
                VirtualServer newVS = (VirtualServer) event.getNewValue();
                assertTrue(event.getOldValue() == null);
                docRoot = newVS.getDocroot();
                assertTrue("/foo/bar/docroot".equals(docRoot));
                VirtualServer rawView = GlassFishConfigBean.getRawView(newVS);
                assertTrue(rawView != null);
                assertTrue(rawView.getDocroot().equalsIgnoreCase("${" + propName + "}"));
                return;
            }
        }
        assertTrue(false);
    } finally {
        transactions.removeTransactionsListener(listener);
    }
}
Also used : TransactionListener(org.jvnet.hk2.config.TransactionListener) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Transactions(org.jvnet.hk2.config.Transactions) PropertyChangeEvent(java.beans.PropertyChangeEvent) HttpService(com.sun.enterprise.config.serverbeans.HttpService) List(java.util.List) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Test(org.junit.Test)

Example 20 with UnprocessedChangeEvents

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

the class UnprocessedEventsTest method changed.

public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
    assertEquals("Array size", propertyChangeEvents.length, 1);
    final UnprocessedChangeEvent unp = new UnprocessedChangeEvent(propertyChangeEvents[0], "Java NIO port listener cannot reconfigure its port dynamically");
    unprocessed = new UnprocessedChangeEvents(unp);
    return unprocessed;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent)

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