List of usage examples for com.google.common.collect Sets newSetFromMap
@Deprecated public static <E> Set<E> newSetFromMap(Map<E, Boolean> map)
From source file:org.jboss.weld.bootstrap.ConcurrentValidator.java
@Override public void validateDecorators(Collection<? extends Decorator<?>> decorators, final BeanManagerImpl manager) { final Set<CommonBean<?>> specializedBeans = Sets .newSetFromMap(new ConcurrentHashMap<CommonBean<?>, Boolean>()); executor.invokeAllAndCheckForExceptions(new IterativeWorkerTaskFactory<Decorator<?>>(decorators) { protected void doWork(Decorator<?> decorator) { validateDecorator(decorator, specializedBeans, manager); }//from w w w . j a v a2s . co m }); }
From source file:com.comphenix.protocol.async.AsyncFilterManager.java
/** * Initialize a asynchronous filter manager. * <p>/*from w ww .j a v a 2s. c o m*/ * <b>Internal method</b>. Retrieve the global asynchronous manager from the protocol manager instead. * @param reporter - desired error reporter. * @param scheduler - task scheduler. */ public AsyncFilterManager(ErrorReporter reporter, BukkitScheduler scheduler) { // Initialize timeout listeners this.serverTimeoutListeners = new SortedPacketListenerList(); this.clientTimeoutListeners = new SortedPacketListenerList(); this.timeoutListeners = Sets.newSetFromMap(new ConcurrentHashMap<PacketListener, Boolean>()); this.playerSendingHandler = new PlayerSendingHandler(reporter, serverTimeoutListeners, clientTimeoutListeners); this.serverProcessingQueue = new PacketProcessingQueue(playerSendingHandler); this.clientProcessingQueue = new PacketProcessingQueue(playerSendingHandler); this.playerSendingHandler.initializeScheduler(); this.scheduler = scheduler; this.reporter = reporter; this.mainThread = Thread.currentThread(); }
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.utils.events.DefaultEventManager.java
@Override public <L> void addListener(final Class<? extends Event<L>> type, final L listener) { Preconditions.checkNotNull(type);//from ww w.j a v a 2 s.co m Preconditions.checkNotNull(listener); @SuppressWarnings("unchecked") final Set<L> listeners = (Set<L>) this.eventsToListeners.get(type); final Set<L> usedListeners; if (Presence.isAbsent(listeners)) { usedListeners = Sets.newSetFromMap(new WeakHashMap<L, Boolean>()); this.eventsToListeners.put(type, usedListeners); } else { usedListeners = listeners; } final boolean fresh = usedListeners.add(listener); Preconditions.checkArgument(fresh); }
From source file:org.eclipse.emf.compare.ide.ui.internal.logical.resolver.SynchronizedResourceSet.java
/** * Constructor.//from www . j a v a2 s. c o m * * @param proxyListener * The listener to notify of proxy creations. */ public SynchronizedResourceSet(IProxyCreationListener proxyListener) { this.uriCache = new ConcurrentHashMap<URI, Resource>(); this.resources = new SynchronizedResourcesEList<Resource>(); this.namespaceURIs = Sets.newSetFromMap(new ConcurrentHashMap<URI, Boolean>()); this.loadedPackages = Sets.newSetFromMap(new ConcurrentHashMap<Resource, Boolean>()); this.packageLoadingLock = new ReentrantLock(true); this.loadOptions = super.getLoadOptions(); /* * This resource set is specifically designed to resolve cross resources links, it thus spends a lot * of time loading resources. The following set of options is what seems to give the most significant * boost in loading performances, though I did not fine-tune what's really needed here. */ final NoNotificationParserPool parserPool = new NoNotificationParserPool(true); parserPool.addProxyListener(proxyListener); parserPool.addNamespaceDeclarationListener(new INamespaceDeclarationListener() { public void schemaLocationDeclared(String key, URI uri) { namespaceURIs.add(uri.trimFragment()); } }); loadOptions.put(XMLResource.OPTION_USE_PARSER_POOL, parserPool); loadOptions.put(XMLResource.OPTION_USE_DEPRECATED_METHODS, Boolean.FALSE); /* * We don't use XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP whereas it could bring performance * improvements because we are loading the resources concurrently and this map could be used (put and * get) by several threads. Passing a ConcurrentMap here is not an option either as EMF sometimes * needs to put "null" values in there. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=403425 for * more details. */ /* * Most of the existing options we are not using from here, since none of them seems to have a single * effect on loading performance, whether we're looking at time or memory. See also * https://www.eclipse.org/forums/index.php/t/929918/ */ }
From source file:com.opengamma.engine.view.compilation.ViewCompilationContext.java
public Set<UniqueId> takeExpiredResolutions() { final Set<UniqueId> result = _expiredResolutions; _expiredResolutions = Sets.newSetFromMap(new ConcurrentHashMap<UniqueId, Boolean>()); return result; }
From source file:com.leacox.dagger.servlet.ManagedFilterPipeline.java
@Override public void destroyPipeline() { //destroy servlets first servletPipeline.destroy();/*from w w w .jav a2 s . c o m*/ //go down chain and destroy all our filters Set<Filter> destroyedSoFar = Sets.newSetFromMap(Maps.<Filter, Boolean>newIdentityHashMap()); for (FilterDefinition filterDefinition : filterDefinitions) { filterDefinition.destroy(destroyedSoFar); } }
From source file:com.arpnetworking.tsdcore.sinks.PeriodicStatisticsSink.java
private Set<String> createConcurrentSet(final Set<String> existingSet) { final int initialCapacity = (int) (existingSet.size() / 0.75); return Sets.newSetFromMap(new ConcurrentHashMap<>(initialCapacity)); }
From source file:com.facebook.buck.rules.CassandraArtifactCache.java
public CassandraArtifactCache(String hosts, int port, int timeoutSeconds, boolean doStore, BuckEventBus buckEventBus) throws ConnectionException { this.doStore = doStore; this.buckEventBus = Preconditions.checkNotNull(buckEventBus); this.numConnectionExceptionReports = new AtomicInteger(0); this.timeoutSeconds = timeoutSeconds; final AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder().forCluster(CLUSTER_NAME) .forKeyspace(KEYSPACE_NAME)//from ww w. j a v a2s .c o m .withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setCqlVersion("3.0.0") .setTargetCassandraVersion("1.2").setDiscoveryType(NodeDiscoveryType.RING_DESCRIBE)) .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl(POOL_NAME).setSeeds(hosts) .setPort(port).setMaxConnsPerHost(1)) .withConnectionPoolMonitor(new CountingConnectionPoolMonitor()) .buildKeyspace(ThriftFamilyFactory.getInstance()); ExecutorService connectionService = MoreExecutors.getExitingExecutorService( (ThreadPoolExecutor) Executors.newFixedThreadPool(1), 0, TimeUnit.SECONDS); this.keyspaceAndTtlFuture = connectionService.submit(new Callable<KeyspaceAndTtl>() { @Override public KeyspaceAndTtl call() throws ConnectionException { context.start(); Keyspace keyspace = context.getClient(); try { verifyMagic(keyspace); int ttl = getTtl(keyspace); return new KeyspaceAndTtl(keyspace, ttl); } catch (ConnectionException e) { reportConnectionFailure("Attempting to get keyspace and ttl from server.", e); throw e; } } }); this.futures = Sets .newSetFromMap(new ConcurrentHashMap<ListenableFuture<OperationResult<Void>>, Boolean>()); this.isWaitingToClose = new AtomicBoolean(false); this.isKilled = new AtomicBoolean(false); }
From source file:org.wicketstuff.datastores.memcached.GuavaMemcachedDataStore.java
@Override public void storeData(final String sessionId, final int pageId, byte[] data) { final String key = makeKey(sessionId, pageId); Set<String> keys; try {//from w w w . j av a2 s . co m keys = keysPerSession.get(sessionId, new Callable<Set<String>>() { @Override public Set<String> call() throws Exception { return Sets.newSetFromMap(createEvictingMap()); } }); } catch (ExecutionException ex) { LOG.warn("An error occurred while creating a new set for the keys in session '{}': {}", sessionId, ex.getMessage()); keys = Sets.newSetFromMap(createEvictingMap()); keysPerSession.put(sessionId, keys); } int expirationTime = settings.getExpirationTime(); client.set(key, expirationTime, data); keys.add(key); LOG.debug("Stored data for session '{}' and page id '{}'", sessionId, pageId); }
From source file:com.cinchapi.concourse.ConnectionPool.java
/** * Construct a new instance./*w w w . java2s .c om*/ * * @param host * @param port * @param username * @param password * @param environment * @param poolSize */ protected ConnectionPool(String host, int port, String username, String password, String environment, int poolSize) { this.available = buildQueue(poolSize); this.leased = Sets.newSetFromMap(Maps.<Concourse, Boolean>newConcurrentMap()); for (int i = 0; i < poolSize; ++i) { available.offer(Concourse.connect(host, port, username, password, environment)); } // Ensure that the client connections are forced closed when the JVM is // shutdown in case the user does not properly close the pool Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { forceClose(); } })); }