use of java.util.concurrent.CopyOnWriteArraySet in project hazelcast by hazelcast.
the class MultiMapListenerTest method testMultiMapEntryListener.
@Test
public void testMultiMapEntryListener() {
final HazelcastInstance instance = createHazelcastInstance();
MultiMap<String, String> map = instance.getMultiMap("testMultiMapEntryListener");
final CountDownLatch latchAdded = new CountDownLatch(3);
final CountDownLatch latchRemoved = new CountDownLatch(1);
final CountDownLatch latchCleared = new CountDownLatch(1);
final Set<String> expectedValues = new CopyOnWriteArraySet<String>();
expectedValues.add("hello");
expectedValues.add("world");
expectedValues.add("again");
map.addEntryListener(new EntryAdapter<String, String>() {
public void entryAdded(EntryEvent<String, String> event) {
String key = event.getKey();
String value = event.getValue();
if ("2".equals(key)) {
assertEquals("again", value);
} else {
assertEquals("1", key);
}
assertContains(expectedValues, value);
expectedValues.remove(value);
latchAdded.countDown();
}
public void entryRemoved(EntryEvent<String, String> event) {
assertEquals("2", event.getKey());
assertEquals("again", event.getOldValue());
latchRemoved.countDown();
}
public void entryUpdated(EntryEvent<String, String> event) {
throw new AssertionError("MultiMap cannot get update event!");
}
public void entryEvicted(EntryEvent<String, String> event) {
entryRemoved(event);
}
@Override
public void mapEvicted(MapEvent event) {
}
@Override
public void mapCleared(MapEvent event) {
latchCleared.countDown();
}
}, true);
map.put("1", "hello");
map.put("1", "world");
map.put("2", "again");
Collection<String> values = map.get("1");
assertEquals(2, values.size());
assertContains(values, "hello");
assertContains(values, "world");
assertEquals(1, map.get("2").size());
assertEquals(3, map.size());
map.remove("2");
assertEquals(2, map.size());
map.clear();
try {
assertTrue(latchAdded.await(5, TimeUnit.SECONDS));
assertTrue(latchRemoved.await(5, TimeUnit.SECONDS));
assertTrue(latchCleared.await(5, TimeUnit.SECONDS));
} catch (InterruptedException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of java.util.concurrent.CopyOnWriteArraySet in project RxBus by ViTess.
the class BusProxy method mount.
protected void mount(Map<String, Set<BusProcessor>> map) {
for (Iterator iter = SubjectMap.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, Set<BusProcessor>> entry = (Map.Entry<String, Set<BusProcessor>>) iter.next();
String tag = entry.getKey();
Set<BusProcessor> bPros = entry.getValue();
Set<BusProcessor> allBPros = map.get(tag);
if (allBPros == null) {
allBPros = new CopyOnWriteArraySet<>();
map.put(tag, allBPros);
}
allBPros.addAll(bPros);
}
}
use of java.util.concurrent.CopyOnWriteArraySet in project karaf by apache.
the class Activator method start.
@Override
public void start(final BundleContext context) throws Exception {
threadIO = new ThreadIOImpl();
threadIO.start();
sessionFactory = new SecuredSessionFactoryImpl(context, threadIO);
sessionFactory.getCommandProcessor().addConverter(new Converters(context));
sessionFactory.getCommandProcessor().addConstant(".context", context.getBundle(0).getBundleContext());
final CopyOnWriteArraySet<CommandLoggingFilter> listeners = new CopyOnWriteArraySet<>();
filterTracker = new ServiceTracker<>(context, CommandLoggingFilter.class, new ServiceTrackerCustomizer<CommandLoggingFilter, CommandLoggingFilter>() {
@Override
public CommandLoggingFilter addingService(ServiceReference<CommandLoggingFilter> reference) {
CommandLoggingFilter service = context.getService(reference);
listeners.add(service);
return service;
}
@Override
public void modifiedService(ServiceReference<CommandLoggingFilter> reference, CommandLoggingFilter service) {
}
@Override
public void removedService(ServiceReference<CommandLoggingFilter> reference, CommandLoggingFilter service) {
listeners.remove(service);
context.ungetService(reference);
}
});
filterTracker.open();
LoggingCommandSessionListener loggingCommandSessionListener = new LoggingCommandSessionListener();
loggingCommandSessionListener.setFilters(listeners);
sessionFactory.getCommandProcessor().addListener(loggingCommandSessionListener);
try {
EventAdminListener listener = new EventAdminListener(context);
sessionFactory.getCommandProcessor().addListener(listener);
eventAdminListener = listener;
} catch (NoClassDefFoundError error) {
// Ignore the listener if EventAdmin package isn't present
}
sessionFactory.register(new ManagerImpl(sessionFactory, sessionFactory));
sessionFactoryRegistration = context.registerService(SessionFactory.class, sessionFactory, null);
actionExtender = new CommandExtender(sessionFactory);
actionExtender.start(context);
commandTracker = new CommandTracker(sessionFactory, context);
commandTracker.open();
if (Boolean.parseBoolean(context.getProperty(START_CONSOLE))) {
localConsoleManager = new LocalConsoleManager(context, sessionFactory);
localConsoleManager.start();
} else {
LOGGER.info("Not starting local console. To activate set " + START_CONSOLE + "=true");
}
}
use of java.util.concurrent.CopyOnWriteArraySet in project wildfly by wildfly.
the class ServiceContainerEndpointRegistry method getEndpoints.
@Override
public Set<ObjectName> getEndpoints() {
Set<ObjectName> endpoints = new CopyOnWriteArraySet<ObjectName>();
for (ServiceName sname : currentServiceContainer().getServiceNames()) {
if (sname.getCanonicalName().startsWith(endpointPrefix)) {
String contextPath = sname.getParent().getSimpleName().substring(8);
String endpointName = sname.getSimpleName();
final StringBuilder name = new StringBuilder(Endpoint.SEPID_DOMAIN + ":");
name.append(Endpoint.SEPID_PROPERTY_CONTEXT + "=").append(contextPath).append(",");
name.append(Endpoint.SEPID_PROPERTY_ENDPOINT + "=").append(endpointName);
endpoints.add(ObjectNameFactory.create(name.toString()));
}
}
return endpoints;
}
use of java.util.concurrent.CopyOnWriteArraySet in project bnd by bndtools.
the class Processor method getPlugins.
/**
* Return a list of plugins. Plugins are defined with the -plugin command.
* They are class names, optionally associated with attributes. Plugins can
* implement the Plugin interface to see these attributes. Any object can be
* a plugin.
*/
public Set<Object> getPlugins() {
Set<Object> p;
synchronized (this) {
p = plugins;
if (p != null)
return p;
plugins = p = new CopyOnWriteArraySet<>();
missingCommand = new HashSet<String>();
}
// We only use plugins now when they are defined on our level
// and not if it is in our parent. We inherit from our parent
// through the previous block.
String spe = getProperty(PLUGIN);
if (NONE.equals(spe))
return p;
// The owner of the plugin is always in there.
p.add(this);
setTypeSpecificPlugins(p);
if (parent != null)
p.addAll(parent.getPlugins());
//
// Look only local
//
spe = mergeLocalProperties(PLUGIN);
String pluginPath = mergeProperties(PLUGINPATH);
loadPlugins(p, spe, pluginPath);
addExtensions(p);
for (RegistryDonePlugin rdp : getPlugins(RegistryDonePlugin.class)) {
try {
rdp.done();
} catch (Exception e) {
error("Calling done on %s, gives an exception %s", rdp, e);
}
}
return p;
}
Aggregations