List of usage examples for java.util.concurrent CopyOnWriteArraySet CopyOnWriteArraySet
public CopyOnWriteArraySet()
From source file:org.springframework.data.redis.listener.RedisMessageListenerContainer.java
private void addListener(MessageListener listener, Collection<? extends Topic> topics) { Assert.notNull(listener, "a valid listener is required"); Assert.notEmpty(topics, "at least one topic is required"); List<byte[]> channels = new ArrayList<byte[]>(topics.size()); List<byte[]> patterns = new ArrayList<byte[]>(topics.size()); boolean trace = logger.isTraceEnabled(); // add listener mapping Set<Topic> set = listenerTopics.get(listener); if (set == null) { set = new CopyOnWriteArraySet<Topic>(); listenerTopics.put(listener, set); }//from w w w. j ava 2s . com set.addAll(topics); for (Topic topic : topics) { ByteArrayWrapper holder = new ByteArrayWrapper(serializer.serialize(topic.getTopic())); if (topic instanceof ChannelTopic) { Collection<MessageListener> collection = channelMapping.get(holder); if (collection == null) { collection = new CopyOnWriteArraySet<MessageListener>(); channelMapping.put(holder, collection); } collection.add(listener); channels.add(holder.getArray()); if (trace) logger.trace("Adding listener '" + listener + "' on channel '" + topic.getTopic() + "'"); } else if (topic instanceof PatternTopic) { Collection<MessageListener> collection = patternMapping.get(holder); if (collection == null) { collection = new CopyOnWriteArraySet<MessageListener>(); patternMapping.put(holder, collection); } collection.add(listener); patterns.add(holder.getArray()); if (trace) logger.trace("Adding listener '" + listener + "' for pattern '" + topic.getTopic() + "'"); } else { throw new IllegalArgumentException("Unknown topic type '" + topic.getClass() + "'"); } } // check the current listening state if (listening) { subscriptionTask.subscribeChannel(channels.toArray(new byte[channels.size()][])); subscriptionTask.subscribePattern(patterns.toArray(new byte[patterns.size()][])); } }
From source file:org.opendaylight.netvirt.dhcpservice.DhcpExternalTunnelManager.java
public void updateExistingVMTunnelIPCache(IpAddress tunnelIp, String elanInstanceName, String vmMacAddress) { Pair<IpAddress, String> tunnelIpElanName = new ImmutablePair<>(tunnelIp, elanInstanceName); Set<String> listExistingVmMacAddress; listExistingVmMacAddress = availableVMCache.get(tunnelIpElanName); if (listExistingVmMacAddress == null) { listExistingVmMacAddress = new CopyOnWriteArraySet<>(); }/*from w w w .ja v a 2 s .com*/ listExistingVmMacAddress.add(vmMacAddress); LOG.trace("Updating availableVMCache for tunnelIpElanName {} value {}", tunnelIpElanName, listExistingVmMacAddress); availableVMCache.put(tunnelIpElanName, listExistingVmMacAddress); }
From source file:de.cubeisland.engine.core.webapi.ApiServer.java
public void subscribe(String event, WebSocketRequestHandler requestHandler) { expectNotNull(event, "The event name must not be null!"); expectNotNull(requestHandler, "The request handler must not be null!"); event = event.toLowerCase(ENGLISH);/*from ww w.j a v a 2 s. com*/ Set<WebSocketRequestHandler> subscribedHandlers = this.subscriptions.get(event); if (subscribedHandlers == null) { this.subscriptions.put(event, subscribedHandlers = new CopyOnWriteArraySet<>()); } subscribedHandlers.add(requestHandler); }
From source file:com.linkedin.helix.store.file.FilePropertyStore.java
@Override public void subscribeForPropertyChange(String prefix, PropertyChangeListener<T> listener) throws PropertyStoreException { if (null != listener) { String path = getPath(prefix); synchronized (_fileChangeListeners) { CopyOnWriteArraySet<PropertyChangeListener<T>> listeners = _fileChangeListeners.get(path); if (listeners == null) { listeners = new CopyOnWriteArraySet<PropertyChangeListener<T>>(); _fileChangeListeners.put(path, listeners); }//from w ww .j a va2 s. com listeners.add(listener); } } }
From source file:org.springsource.ide.eclipse.dashboard.internal.ui.editors.DashboardMainPage.java
@Override protected void createFormContent(IManagedForm managedForm) { toolkit = managedForm.getToolkit();//from ww w. ja v a 2 s . c o m form = managedForm.getForm(); unfinishedJobs = new CopyOnWriteArraySet<AggregateFeedJob>(); // get dark gray color as FormText display it lighter as other widgets feedColor = new Color(Display.getDefault(), 70, 70, 70); // getHeaderForm().setText(null);// "SpringSource Tool Suite"); toolkit.decorateFormHeading(form.getForm()); prefStore = IdeUiPlugin.getDefault().getPreferenceStore(); GridLayout compositeLayout = new GridLayout(2, true); compositeLayout.marginHeight = 0; compositeLayout.marginTop = 5; compositeLayout.verticalSpacing = 0; Composite body = form.getBody(); body.setLayout(compositeLayout); Composite leftComposite = toolkit.createComposite(body); leftComposite.setLayout(new GridLayout()); GridDataFactory.fillDefaults().grab(true, true).applyTo(leftComposite); Composite rightComposite = toolkit.createComposite(body); rightComposite.setLayout(new GridLayout()); GridDataFactory.fillDefaults().grab(true, true).applyTo(rightComposite); createHeader(); createNewProjectsSection(leftComposite); createUpdateSection(leftComposite); parts = contributeParts(leftComposite, AbstractDashboardPart.ID_PATH_DOC); for (AbstractDashboardPart part : parts) { if (part.getControl() instanceof Section) { String expansionProp = getExpansionPropertyId(part); Section section = (Section) part.getControl(); GridDataFactory.fillDefaults().grab(false, getStoredExpandedState(expansionProp, false)) .applyTo(section); setUpExpandableSection(section, expansionProp, false); } } createHelpSection(leftComposite); createFeedsSection(rightComposite, "Feeds", FeedType.BLOG, "blog"); searchBox.setFocus(); ResourceProvider.getInstance().addPropertyChangeListener(this); }
From source file:org.sakaiproject.content.tool.FilePickerAction.java
/** * get/init state attribute STATE_EXPANDED_COLLECTIONS * @param state The tool session to get the object from or create it in. * @return An {@link ExpandedCollections} but never <code>null</code>. *//*from w w w . ja va 2 s .c om*/ private static Set<String> getExpandedCollections(ToolSession session) { Set<String> current = (Set<String>) session.getAttribute(STATE_EXPANDED_COLLECTIONS); if (current == null) { current = new CopyOnWriteArraySet<String>(); session.setAttribute(STATE_EXPANDED_COLLECTIONS, current); } return current; }
From source file:lineage2.gameserver.model.Creature.java
/** * Method addTrigger./*from ww w .j av a 2 s. c o m*/ * @param t TriggerInfo */ public void addTrigger(TriggerInfo t) { if (_triggers == null) { _triggers = new ConcurrentHashMap<TriggerType, Set<TriggerInfo>>(); } Set<TriggerInfo> hs = _triggers.get(t.getType()); if (hs == null) { hs = new CopyOnWriteArraySet<TriggerInfo>(); _triggers.put(t.getType(), hs); } hs.add(t); if (t.getType() == TriggerType.ADD) { useTriggerSkill(this, null, t, null, 0); } }
From source file:org.sakaiproject.content.tool.ResourcesAction.java
/** * get/init state attribute STATE_EXPANDED_COLLECTIONS * @param state// ww w . j a va 2 s . c o m * @return An {@link Set} but never <code>null</code>. */ private static Set<String> getExpandedCollections(SessionState state) { Set<String> current = (Set<String>) state.getAttribute(STATE_EXPANDED_COLLECTIONS); if (current == null) { // We use a CopyOnWrite Set so that we don't have to do any sychronization when iterating over it. // Switching to HashSet results in runaway threads and concurrentmodificationsexceptions (from iterating). current = new CopyOnWriteArraySet<String>(); state.setAttribute(STATE_EXPANDED_COLLECTIONS, current); } return current; }