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);
}
}
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);
}
}
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();
}
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);
}
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);
}
}
Aggregations