use of org.jvnet.hk2.config.UnprocessedChangeEvents in project Payara by payara.
the class ConfigConfigBeanListener method changed.
/* force serial behavior; don't allow more than one thread to make a mess here */
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
for (PropertyChangeEvent e : events) {
// ignore all events for which the source isn't the Config
if (e.getSource().getClass() != config.getClass()) {
continue;
}
// remove the DEFAULT_INSTANCE_NAME entry for an old value
Object ov = e.getOldValue();
if (ov instanceof ConfigBeanProxy) {
ConfigBeanProxy ovbp = (ConfigBeanProxy) ov;
logger.log(Level.FINE, removingDefaultInstanceIndexFor, ConfigSupport.getImpl(ovbp).getProxyType().getName());
ServiceLocatorUtilities.removeFilter(habitat, BuilderHelper.createNameAndContractFilter(ConfigSupport.getImpl(ovbp).getProxyType().getName(), ServerEnvironment.DEFAULT_INSTANCE_NAME));
}
// add the DEFAULT_INSTANCE_NAME entry for a new value
Object nv = e.getNewValue();
if (nv instanceof ConfigBean) {
ConfigBean nvb = (ConfigBean) nv;
ConfigBeanProxy nvbp = nvb.getProxy(nvb.getProxyType());
logger.log(Level.FINE, AddingDefaultInstanceIndexFor, nvb.getProxyType().getName());
ServiceLocatorUtilities.addOneConstant(habitat, nvbp, ServerEnvironment.DEFAULT_INSTANCE_NAME, nvb.getProxyType());
}
}
return null;
}
use of org.jvnet.hk2.config.UnprocessedChangeEvents 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);
}
}
Aggregations