Search in sources :

Example 11 with ObservableBean

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

the class ConfigInstanceListener method lifecycleEvent.

/* (non-Javadoc)
     * @see org.glassfish.hk2.api.InstanceLifecycleListener#lifecycleEvent(org.glassfish.hk2.api.InstanceLifecycleEvent)
     */
@Override
public void lifecycleEvent(InstanceLifecycleEvent lifecycleEvent) {
    if (!lifecycleEvent.getEventType().equals(InstanceLifecycleEventType.POST_PRODUCTION)) {
        return;
    }
    Map<Injectee, Object> injectees = lifecycleEvent.getKnownInjectees();
    if (injectees == null)
        return;
    ConfigListener listener = (ConfigListener) lifecycleEvent.getLifecycleObject();
    for (Object injectee : injectees.values()) {
        if (!(injectee instanceof ConfigBeanProxy))
            continue;
        ConfigBeanProxy configBeanProxy = (ConfigBeanProxy) injectee;
        Object impl = ConfigSupport.getImpl(configBeanProxy);
        if (!(impl instanceof ObservableBean))
            continue;
        ObservableBean ob = (ObservableBean) impl;
        ob.addListener(listener);
    }
}
Also used : Injectee(org.glassfish.hk2.api.Injectee) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigListener(org.jvnet.hk2.config.ConfigListener) ObservableBean(org.jvnet.hk2.config.ObservableBean)

Example 12 with ObservableBean

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

the class ConfigTest method testGetImplAndAddListener.

// @Test
public void testGetImplAndAddListener() {
    SimpleConnector sc = habitat.getService(SimpleConnector.class);
    final EjbContainerAvailability ejb = sc.getEjbContainerAvailability();
    ObservableBean obean = (ObservableBean) ConfigSupport.getImpl(ejb);
    EjbObservableBean ejbBean = new EjbObservableBean();
    assert (ejbBean.getCount() == 0);
    obean.addListener(ejbBean);
    try {
        ConfigSupport.apply(new SingleConfigCode<EjbContainerAvailability>() {

            @Override
            public Object run(EjbContainerAvailability param) throws PropertyVetoException, TransactionFailure {
                param.setSfsbHaPersistenceType("DynamicData");
                param.setSfsbCheckpointEnabled("**MUST BE**");
                assert (!ejb.getSfsbHaPersistenceType().equals(param.getSfsbHaPersistenceType()));
                return null;
            }
        }, ejb);
        // printEjb("AFTER CHANGES", ejb);
        assert (ejb.getSfsbHaPersistenceType().equals("DynamicData") && ejb.getSfsbCheckpointEnabled().equals("**MUST BE**"));
        assert (ejbBean.getCount() == 1);
    } catch (Exception e) {
        e.printStackTrace();
        assert (false);
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<EjbContainerAvailability>() {

            @Override
            public Object run(EjbContainerAvailability param) throws PropertyVetoException, TransactionFailure {
                param.setSfsbHaPersistenceType("DynamicData1");
                param.setSfsbCheckpointEnabled("**MUST BE**");
                assert (!ejb.getSfsbHaPersistenceType().equals(param.getSfsbHaPersistenceType()));
                return null;
            }
        }, ejb);
        // printEjb("AFTER CHANGES", ejb);
        assert (ejb.getSfsbHaPersistenceType().equals("DynamicData1") && ejb.getSfsbCheckpointEnabled().equals("**MUST BE**"));
        assert (ejbBean.getCount() == 2);
        System.out.println("getImpl(ejb) == > " + ConfigSupport.getImpl(ejb).getClass().getName());
        System.out.println("getImpl(ejb).getMasterView() == > " + ConfigSupport.getImpl(ejb).getMasterView().getClass().getName());
        System.out.println("getImpl(ejb).getProxyType() == > " + ConfigSupport.getImpl(ejb).getProxyType().getClass().getName());
    } catch (Exception e) {
        e.printStackTrace();
        assert (false);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ObservableBean(org.jvnet.hk2.config.ObservableBean) PropertyVetoException(java.beans.PropertyVetoException)

Example 13 with ObservableBean

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

the class JobCleanUpService method postConstruct.

@Override
public void postConstruct() {
    logger.log(Level.FINE, KernelLoggerInfo.initializingJobCleanup);
    scheduler = Executors.newScheduledThreadPool(10, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread result = new Thread(r);
            result.setDaemon(true);
            return result;
        }
    });
    if (Version.getFullVersion().contains("Micro")) {
        // if Micro we don't have any jobs to cleanup
        return;
    }
    managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class);
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(managedJobConfig);
    logger.fine(KernelLoggerInfo.initializingManagedConfigBean);
    bean.addListener(this);
    scheduleCleanUp();
}
Also used : ManagedJobConfig(com.sun.enterprise.config.serverbeans.ManagedJobConfig) ObservableBean(org.jvnet.hk2.config.ObservableBean)

Example 14 with ObservableBean

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

the class PropertyChangeListenerTest method propertyChangeEventReceptionTest.

@Test
public void propertyChangeEventReceptionTest() throws TransactionFailure {
    HttpService httpService = habitat.getService(HttpService.class);
    assertNotNull(httpService);
    // let's find a acceptable target.
    VirtualServer target = null;
    for (VirtualServer vs : httpService.getVirtualServer()) {
        if (!vs.getProperty().isEmpty()) {
            target = vs;
            break;
        }
    }
    assertNotNull(target);
    ((ObservableBean) ConfigSupport.getImpl(target)).addListener(this);
    final Property prop = target.getProperty().get(0);
    ConfigSupport.apply(new SingleConfigCode<Property>() {

        public Object run(Property param) throws PropertyVetoException, TransactionFailure {
            // first one is fine...
            param.setValue(prop.getValue().toUpperCase());
            return null;
        }
    }, prop);
    getHabitat().<Transactions>getService(Transactions.class).waitForDrain();
    assertTrue(result);
    ((ObservableBean) ConfigSupport.getImpl(target)).removeListener(this);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Property(org.jvnet.hk2.config.types.Property) Test(org.junit.Test)

Example 15 with ObservableBean

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

the class UnprocessedEventsTest method unprocessedEventsTest.

@Test
public void unprocessedEventsTest() throws TransactionFailure {
    // let's find our target
    NetworkConfig service = habitat.getService(NetworkConfig.class);
    NetworkListener listener = service.getNetworkListener("http-listener-1");
    assertNotNull(listener);
    // Let's register a listener
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(listener);
    bean.addListener(this);
    Transactions transactions = getHabitat().getService(Transactions.class);
    try {
        transactions.addTransactionsListener(this);
        String originalPort = listener.getPort();
        try {
            ConfigSupport.apply(param -> {
                param.setPort("8908");
                return null;
            }, listener);
            // Check the result.
            assertEquals(listener.getPort(), "8908");
        } finally {
            // Restore the original port
            ConfigSupport.apply(param -> {
                param.setPort(originalPort);
                return null;
            }, listener);
        }
        // ensure events are delivered.
        transactions.waitForDrain();
        assertNotNull(unprocessed);
        // finally
        bean.removeListener(this);
    } finally {
        // check we recevied the event
        transactions.removeTransactionsListener(this);
    }
}
Also used : Transactions(org.jvnet.hk2.config.Transactions) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Aggregations

ObservableBean (org.jvnet.hk2.config.ObservableBean)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)7 Test (org.junit.Test)6 Transactions (org.jvnet.hk2.config.Transactions)6 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)4 Config (com.sun.enterprise.config.serverbeans.Config)3 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)3 HttpService (com.sun.enterprise.config.serverbeans.HttpService)2 ManagedJobConfig (com.sun.enterprise.config.serverbeans.ManagedJobConfig)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 PropertyVetoException (java.beans.PropertyVetoException)2 MalformedURLException (java.net.MalformedURLException)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 Level (java.util.logging.Level)2 LifecycleException (org.apache.catalina.LifecycleException)2 ModuleMonitoringLevels (com.sun.enterprise.config.serverbeans.ModuleMonitoringLevels)1 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)1 InjectionManager (com.sun.enterprise.container.common.spi.util.InjectionManager)1 TransactionService (com.sun.enterprise.transaction.config.TransactionService)1 Result (com.sun.enterprise.util.Result)1