List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList
public CopyOnWriteArrayList()
From source file:org.smartfrog.services.anubis.Node.java
public Node(AnnotationConfigApplicationContext context, int c, CountDownLatch launchLatch, CountDownLatch startLatch, CountDownLatch endLatch, int maxSleep, int messageCount) throws Exception { this.context = context; cardinality = c;/*from w ww . jav a 2s . c o m*/ this.launchLatch = launchLatch; this.startLatch = startLatch; this.endLatch = endLatch; this.maxSleep = maxSleep; messagesToSend = messageCount; for (int i = 0; i < cardinality; i++) { receiveHistory.put(i, new CopyOnWriteArrayList<ValueHistory>()); msgReceivedLatches.put(i, new CountDownLatch(messageCount)); } identity = context.getBean(Identity.class).id; partition = context.getBean(Partition.class); partition.register(new PartitionNotification() { @Override public void objectNotification(Object obj, int sender, long time) { receiveHistory.get(sender).add(new ValueHistory(sender, obj, time, Action.NEW)); msgReceivedLatches.get(sender).countDown(); } @Override public void partitionNotification(View view, int leader) { Node.this.view = view; if (view.isStable() && view.cardinality() == cardinality) { // System.out.println("Launching: " + view + " : " + instance); Node.this.launchLatch.countDown(); } else { // System.out.println("Not launching: " + view + " : " + instance); } } }); }
From source file:voldemort.store.cachestore.impl.SortedCacheStore.java
/** * * @param path//from ww w. j a va 2 s.c o m * @param blockSize * @param curIndex * @param filename * @param delayWrite * @param mode */ public SortedCacheStore(String path, BlockSize blockSize, int curIndex, String filename, boolean delayWrite, int mode) { this.delayWrite = delayWrite; if (delayWrite) { delayWriteQueue = new LinkedBlockingQueue<DelayBlock>(QUEUE_SIZE); } this.mode = mode; checkPath(path); this.path = path; this.blockSize = blockSize; this.curIndex = curIndex; this.overflow = new AtomicLong(0); this.list = new CopyOnWriteArrayList<ChannelStore>(); this.namePrefix = filename; this.map = new ConcurrentSkipListMap<Key, CacheBlock>(); //check to see if more file 0 / 1 if (curIndex <= 1) { list.add(0, open(getPath(path) + filename + curIndex, map, false, 0, delayWrite, mode)); deleted += list.get(0).getDeleted(); if (ChannelStore.isChannelExist(getPath(path) + filename + 1 + ".ndx")) { // close channel 0 list.get(0).close(delayWriteQueue); list.add(1, open(getPath(path) + filename + 1, map, false, 1, delayWrite, mode)); this.curIndex = 1; deleted += list.get(1).getDeleted(); } } else { throw new StoreException("not support for index " + curIndex + " > 1 "); } initMetaDataStore(); serverState = State.Active; }
From source file:org.goko.tools.serial.jssc.service.JsscSerialConnectionService.java
/** (inheritDoc) * @see org.goko.core.common.service.IGokoService#start() *//*from w w w . ja v a 2s . c om*/ @Override public void startService() throws GkException { this.inputListeners = new CopyOnWriteArrayList<WeakReference<IConnectionDataListener>>(); this.outputListeners = new CopyOnWriteArrayList<WeakReference<IConnectionDataListener>>(); this.connectionListeners = new ArrayList<WeakReference<IConnectionListener>>(); }
From source file:org.mariotaku.twidere.loader.support.TwitterAPIStatusesLoader.java
@SuppressWarnings("unchecked") @Override/*from www .j a va2 s . c o m*/ public final List<ParcelableStatus> loadInBackground() { final File serializationFile = getSerializationFile(); List<ParcelableStatus> data = getData(); if (data == null) { data = new CopyOnWriteArrayList<>(); } if (isFirstLoad() && getTabPosition() >= 0 && serializationFile != null) { final List<ParcelableStatus> cached = getCachedData(serializationFile); if (cached != null) { data.addAll(cached); if (mComparator != null) { Collections.sort(data, mComparator); } else { Collections.sort(data); } return new CopyOnWriteArrayList<>(data); } } if (!isFromUser()) return data; final Twitter twitter = getTwitter(); if (twitter == null) return null; final List<Status> statuses; final boolean truncated; final Context context = getContext(); final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final int loadItemLimit = prefs.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT); final boolean noItemsBefore = data.isEmpty(); try { final Paging paging = new Paging(); paging.setCount(loadItemLimit); if (mMaxId > 0) { paging.setMaxId(mMaxId); } if (mSinceId > 0) { paging.setSinceId(mSinceId - 1); } statuses = new ArrayList<>(); truncated = Utils.truncateStatuses(getStatuses(twitter, paging), statuses, mSinceId); if (!Utils.isOfficialTwitterInstance(context, twitter)) { TwitterContentUtils.getStatusesWithQuoteData(twitter, statuses); } } catch (final TwitterException e) { // mHandler.post(new ShowErrorRunnable(e)); Log.w(LOGTAG, e); return new CopyOnWriteArrayList<>(data); } final long[] statusIds = new long[statuses.size()]; long minId = -1; int minIdx = -1; int rowsDeleted = 0; for (int i = 0, j = statuses.size(); i < j; i++) { final Status status = statuses.get(i); final long id = status.getId(); if (minId == -1 || id < minId) { minId = id; minIdx = i; } statusIds[i] = id; if (deleteStatus(data, status.getId())) { rowsDeleted++; } } // Insert a gap. final boolean deletedOldGap = rowsDeleted > 0 && ArrayUtils.contains(statusIds, mMaxId); final boolean noRowsDeleted = rowsDeleted == 0; final boolean insertGap = minId > 0 && (noRowsDeleted || deletedOldGap) && !truncated && !noItemsBefore && statuses.size() > 1; for (int i = 0, j = statuses.size(); i < j; i++) { final Status status = statuses.get(i); data.add(new ParcelableStatus(status, mAccountId, insertGap && isGapEnabled() && minIdx == i)); } final SQLiteDatabase db = TwidereApplication.getInstance(context).getSQLiteDatabase(); final ParcelableStatus[] array = data.toArray(new ParcelableStatus[data.size()]); for (int i = 0, size = array.length; i < size; i++) { final ParcelableStatus status = array[i]; if (shouldFilterStatus(db, status) && !status.is_gap && i != size - 1) { deleteStatus(data, status.id); } } if (mComparator != null) { Collections.sort(data, mComparator); } else { Collections.sort(data); } saveCachedData(serializationFile, data); return new CopyOnWriteArrayList<>(data); }
From source file:de.dfki.asr.compass.model.PrefabSet.java
public PrefabSet() { name = ""; children = new CopyOnWriteArrayList<>(); prefabs = new CopyOnWriteArrayList<>(); }
From source file:org.lz1aq.lzhfqrp.RadioController.java
/** * Before being able to use this class you need to call the following methods: * 1. loadProtocolParser()/* ww w. j a va 2 s .co m*/ * 2. connect() */ public RadioController() { eventListeners = new CopyOnWriteArrayList<>(); }
From source file:org.rifidi.edge.epcglobal.aleread.wrappers.ReportSender.java
/** * Constructor./* www . java 2 s. c om*/ */ public ReportSender(Collection<RifidiReport> reports, String specName, ECSpec spec) { rifidiReports = new ArrayList<RifidiReport>(); rifidiReports.addAll(reports); subscriptionURIs = new CopyOnWriteArrayList<String>(); resultQueue = new LinkedBlockingQueue<ResultContainer>(); this.specName = specName; this.spec = spec; try { cont = JAXBContext.newInstance(ReportAnswer.class, ECReports.class); marsh = cont.createMarshaller(); } catch (JAXBException e) { logger.fatal("Unabel to create JAXB marshaller: " + e); throw new RuntimeException(e); } }
From source file:de.taimos.httputils.HTTPRequest.java
/** * @param name the name of the header//from ww w .ja va 2 s .com * @param value the value of the header * @return this */ public HTTPRequest header(final String name, final String value) { if (!this.headers.containsKey(name)) { this.headers.put(name, new CopyOnWriteArrayList<String>()); } this.headers.get(name).add(value); return this; }
From source file:ExpiringMap.java
/** * Creates a new instance of ExpiringMap using the supplied values and * a {@link ConcurrentHashMap} for the internal data structure. * * @param timeToLive/*from w w w . ja v a2s . c o m*/ * The time-to-live value (seconds) * @param expirationInterval * The time between checks to see if a value should be removed (seconds) */ public ExpiringMap(int timeToLive, int expirationInterval) { this(new ConcurrentHashMap<K, ExpiringObject>(), new CopyOnWriteArrayList<ExpirationListener<V>>(), timeToLive, expirationInterval); }
From source file:org.mule.transport.jms.MultiConsumerJmsMessageReceiver.java
public MultiConsumerJmsMessageReceiver(Connector connector, FlowConstruct flowConstruct, InboundEndpoint endpoint) throws CreateException { super(connector, flowConstruct, endpoint); jmsConnector = (JmsConnector) connector; isTopic = jmsConnector.getTopicResolver().isTopic(endpoint, true); if (isTopic && jmsConnector.getNumberOfConsumers() != 1) { if (logger.isInfoEnabled()) { logger.info("Destination " + getEndpoint().getEndpointURI() + " is a topic, but " + jmsConnector.getNumberOfConsumers() + " receivers have been requested. Will configure only 1."); }//from w w w.j a v a 2 s. c o m receiversCount = 1; } else { receiversCount = jmsConnector.getNumberOfConsumers(); } if (logger.isDebugEnabled()) { logger.debug("Creating " + receiversCount + " sub-receivers for " + endpoint.getEndpointURI()); } consumers = new CopyOnWriteArrayList(); }