Example usage for java.util Collections synchronizedSet

List of usage examples for java.util Collections synchronizedSet

Introduction

In this page you can find the example usage for java.util Collections synchronizedSet.

Prototype

public static <T> Set<T> synchronizedSet(Set<T> s) 

Source Link

Document

Returns a synchronized (thread-safe) set backed by the specified set.

Usage

From source file:edu.cuny.cat.ui.ProfitPlotPanel.java

public ProfitPlotPanel() {

    shoutSet = Collections.synchronizedSet(new HashSet<Shout>());

    registry = GameController.getInstance().getRegistry();

    setTitledBorder("Income and Expenses");

    dataset = new DefaultCategoryDataset();

    final JFreeChart chart = ChartFactory.createStackedBarChart("", "", "", dataset, PlotOrientation.HORIZONTAL,
            true, true, false);/* w w w.  j av  a2s .co  m*/
    // chart.setAntiAlias(false);
    chart.setBackgroundPaint(getBackground());
    final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    final StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    UIUtils.setDefaultBarRendererStyle(stackedbarrenderer);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    final ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:strat.mining.multipool.stats.service.impl.coinshift.RequestStatsLoggingServiceImpl.java

public RequestStatsLoggingServiceImpl() {
    nbAllGlobal = new AtomicInteger(0);
    nbLastGlobal = new AtomicInteger(0);
    nbAllAddress = new AtomicInteger(0);
    nbLastAddress = new AtomicInteger(0);
    nbPaidout = new AtomicInteger(0);
    nbSuggestion = new AtomicInteger(0);
    nbInitialization = new AtomicInteger(0);

    uniqueAddressesAllStats = Collections.synchronizedSet(new HashSet<String>());
    uniqueAddressesLastStats = Collections.synchronizedSet(new HashSet<String>());
    uniqueAddressesPaidout = Collections.synchronizedSet(new HashSet<String>());
}

From source file:org.schedulesdirect.grabber.ProgramCache.java

private ProgramCache(FileSystem vfs) throws IOException {
    this.vfs = vfs;
    dirtyIds = Collections.synchronizedSet(new HashSet<String>());
}

From source file:dk.netarkivet.monitor.registry.MonitorRegistry.java

/**
 * Register a new JMX host entry./*from   w w w .java 2 s  .co m*/
 * @param hostEntry The entry to add
 *
 * @throws ArgumentNotValid if hostEntry is null.
 */
public synchronized void register(HostEntry hostEntry) {
    ArgumentNotValid.checkNotNull(hostEntry, "HostEntry hostEntry");
    Set<HostEntry> set = hostEntries.get(hostEntry.getName());
    if (set == null) {
        set = Collections.synchronizedSet(new HashSet<HostEntry>());
        hostEntries.put(hostEntry.getName(), set);
    }
    if (set.add(hostEntry)) {
        log.info("Added host '" + hostEntry.getName() + "' port " + hostEntry.getJmxPort() + "/"
                + hostEntry.getRmiPort());
    } else {
        set.remove(hostEntry);
        set.add(hostEntry);
        log.trace("Updated time for '" + hostEntry.getName() + "' port " + hostEntry.getJmxPort() + "/"
                + hostEntry.getRmiPort() + " to " + hostEntry.getTime());
    }
}

From source file:org.fao.geonet.kernel.SelectionManager.java

private SelectionManager() {
    selections = new Hashtable<String, Set<String>>(0);

    Set<String> MDSelection = Collections.synchronizedSet(new HashSet<String>(0));
    selections.put(SELECTION_METADATA, MDSelection);
}

From source file:strat.mining.multipool.stats.builder.MiddlecoinStatsBuilder.java

public MiddlecoinStatsBuilder() {
    currentAddresses = Collections.synchronizedSet(new HashSet<String>());
}

From source file:org.lable.oss.uniqueid.UniqueIDGeneratorThreadSafetyIT.java

@Test
public void moreThanOneGeneratorClusterIDTest() throws InterruptedException {
    final Set<String> ids = Collections.synchronizedSet(new HashSet<String>());
    // {generatorId, clusterId}
    final int[][] profiles = { { 0, 0 }, { 1, 1 }, { 1, 2 }, { 1, 3 }, { 1, 15 }, { 2, 0 }, { 3, 0 }, { 4, 0 },
            { 5, 0 }, { 63, 0 } };// w w w  .  j  a  v a2s. com
    final int iterationCount = 10000;
    final CountDownLatch latch = new CountDownLatch(profiles.length);

    // Generate IDs for different generator-IDs and cluster-IDs in multiple threads.
    // Collision of IDs is almost guaranteed if the generator doesn't handle multi-threading gracefully.

    for (final int[] profile : profiles) {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                IDGenerator generator = LocalUniqueIDGeneratorFactory.generatorFor(profile[0], profile[1]);
                try {
                    for (int i = 0; i < iterationCount; i++) {
                        byte[] id = generator.generate();
                        String asHex = Hex.encodeHexString(id);
                        ids.add(asHex);
                    }
                } catch (GeneratorException e) {
                    // Test will fail due to missing IDs.
                    e.printStackTrace();
                }
                latch.countDown();
            }
        });
        t.start();
    }

    // Wait for all the threads to finish, or timeout.
    boolean successfullyUnlatched = latch.await(20, TimeUnit.SECONDS);
    assertThat(successfullyUnlatched, is(true));

    // If the set holds fewer items than this, duplicates were generated.
    assertThat(ids.size(), is(profiles.length * iterationCount));
}

From source file:com.sqkj.engine.image.ImageCache.java

private void init(ImageCacheParams cacheParams) {
    mCacheParams = cacheParams;// w ww.j a  v a2s .c  om
    if (mCacheParams.memoryCacheEnabled) {
        WaterDropsLog.v("Memory cache created (size = " + mCacheParams.memCacheSize + ")");
        if (SdkUtils.hasHoneycomb()) {
            mReusableBitmaps = Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
        }
        mMemoryCache = new LruCache<String, BitmapDrawable>(mCacheParams.memCacheSize) {
            @Override
            protected void entryRemoved(boolean evicted, String key, BitmapDrawable oldValue,
                    BitmapDrawable newValue) {
                if (RecyclingBitmapDrawable.class.isInstance(oldValue)) {
                    ((RecyclingBitmapDrawable) oldValue).setIsCached(false);
                } else {
                    if (SdkUtils.hasHoneycomb()) {
                        mReusableBitmaps.add(new SoftReference<Bitmap>(oldValue.getBitmap()));
                    }
                }
            }

            @Override
            protected int sizeOf(String key, BitmapDrawable value) {
                final int bitmapSize = getBitmapSize(value) / 1024;
                WaterDropsLog.d("@@@@@@Bitmap Size==>" + bitmapSize);
                return bitmapSize == 0 ? 1 : bitmapSize;
            }
        };
    }
}

From source file:com.higgses.griffin.cache.ImageCache.java

/**
 * Create a new ImageCache object using the specified parameters. This should not be
 * called directly by other classes, instead use
 *
 * @param cacheParams//from  w  w w .j av  a  2 s . c  o  m
 *         The cache parameters to use to initialize the cache
 *
 * @link com.example.android.displayingbitmaps.util.ImageCache#getInstance(android.support.v4.app.FragmentManager,
 *com.example.android.displayingbitmaps.util.ImageCache.ImageCacheParams)} to fetch an ImageCache
 * instance.
 */
private ImageCache(CacheParams cacheParams) {
    super(cacheParams);
    if (GriUAndroidVersion.hasHoneycomb()) {
        mReusableBitmaps = Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
    }
}

From source file:com.chanlytech.unicorn.cache.ImageCache.java

/**
 * Create a new ImageCache object using the specified parameters. This should not be
 * called directly by other classes, instead use
 *
 * @param cacheParams// w w  w .ja  v a 2s  .  c  om
 *         The cache parameters to use to initialize the cache
 *
 * @link com.example.android.displayingbitmaps.util.ImageCache#getInstance(android.support.v4.app.FragmentManager,
 *com.example.android.displayingbitmaps.util.ImageCache.ImageCacheParams)} to fetch an ImageCache
 * instance.
 */
private ImageCache(CacheParams cacheParams) {
    super(cacheParams);
    if (AndroidVersion.hasHoneycomb()) {
        mReusableBitmaps = Collections.synchronizedSet(new HashSet<SoftReference<Bitmap>>());
    }
}