Example usage for com.google.common.collect Maps newConcurrentMap

List of usage examples for com.google.common.collect Maps newConcurrentMap

Introduction

In this page you can find the example usage for com.google.common.collect Maps newConcurrentMap.

Prototype

public static <K, V> ConcurrentMap<K, V> newConcurrentMap() 

Source Link

Document

Returns a general-purpose instance of ConcurrentMap , which supports all optional operations of the ConcurrentMap interface.

Usage

From source file:org.ros.android.android_acm_serial.UsbRequestPool.java

public UsbRequestPool(UsbDeviceConnection connection) {
    this.connection = connection;
    usbRequestQueues = Maps.newConcurrentMap();
    requestWaitThread = new RequestWaitThread();
}

From source file:org.obm.imap.archive.services.ScheduledArchivingTracker.java

@VisibleForTesting
ScheduledArchivingTracker() {
    this.scheduledTasks = Maps.newConcurrentMap();
}

From source file:de.cosmocode.palava.util.qa.UnusedFilter.java

@Inject
public UnusedFilter(@Named(UnusedConfig.PACKAGES) List<String> packageNames,
        @Background ScheduledExecutorService scheduler) {

    final Classpath classpath = Reflection.defaultClasspath();
    final Packages packages = classpath.restrictTo(packageNames);
    final Iterable<Class<? extends IpcCommand>> all = packages.subclassesOf(IpcCommand.class);
    final ConcurrentMap<Class<? extends IpcCommand>, Boolean> map = Maps.newConcurrentMap();

    for (Class<? extends IpcCommand> type : all) {
        map.put(type, Boolean.TRUE);
    }//from   w ww. j  av  a 2s . c  o  m

    this.commands = Collections.newSetFromMap(map);
    this.scheduler = Preconditions.checkNotNull(scheduler, "Scheduler");
}

From source file:org.apache.drill.exec.cache.LocalCache.java

@Override
public void run() throws DrillbitStartupException {
    handles = Maps.newConcurrentMap();
    maps = Maps.newConcurrentMap();/*from   w  w  w.ja v a 2  s  .  c o m*/
    multiMaps = Maps.newConcurrentMap();
    counters = Maps.newConcurrentMap();
}

From source file:com.facebook.buck.distributed.build_slave.MinionHealthTracker.java

public MinionHealthTracker(Clock clock, long maxMinionSilenceMillis, int maxConsecutiveSlowDeadMinionChecks,
        long expectedHeartbeatIntervalMillis, long slowHeartbeatWarningThresholdMillis,
        HealthCheckStatsTracker healthCheckStatsTracker) {
    this.healthCheckStatsTracker = healthCheckStatsTracker;
    Preconditions.checkArgument(slowHeartbeatWarningThresholdMillis > expectedHeartbeatIntervalMillis,
            "slow_heartbeat_warning_threshold_millis must be higher than heartbeat_service_interval_millis");
    Preconditions.checkArgument(maxMinionSilenceMillis > 0,
            "The maxMinionSilenceMillis value needs to be positive. Found [%d] instead.",
            maxMinionSilenceMillis);//from w  w w.  jav a2s.co  m
    this.maxMinionSilenceMillis = maxMinionSilenceMillis;
    this.maxConsecutiveSlowDeadMinionChecks = maxConsecutiveSlowDeadMinionChecks;
    this.slowHeartbeatWarningThresholdMillis = slowHeartbeatWarningThresholdMillis;
    this.minions = Maps.newConcurrentMap();
    this.untrackedMinions = Sets.newConcurrentHashSet();
    this.clock = clock;
}

From source file:ratpack.sep.exec.Parallel.java

/**
 * Executes {@code Params.actions} in parallel.
 * <p>//from w  w  w  . j a v a  2  s . c o  m
 * The result of each {@code action} execution is added to {@link ActionResults}.
 * <p>
 * if {@code action} throws an exception it is equivalent to error result.
 *
 * @param execControl an execution control
 * @param registry the server registry
 * @param actions the collections of actions to execute in parallel
 * @return a promise for the results
 * @throws Exception any
 */
public Promise<ActionResults<O>> apply(ExecControl execControl, Registry registry,
        Iterable<Action<T, O>> actions) throws Exception {
    Iterator<Action<T, O>> iterator = actions.iterator();
    if (!iterator.hasNext()) {
        return execControl.promiseOf(new ActionResults<>(ImmutableMap.of()));
    }

    return execControl.<Map<String, ActionResult<O>>>promise(fulfiller -> {
        AtomicInteger counter = new AtomicInteger();
        Map<String, ActionResult<O>> results = Maps.newConcurrentMap();
        while (iterator.hasNext()) {
            counter.incrementAndGet();
            Action<T, O> action = iterator.next();
            if (action == null || action.getName() == null) {
                int i = counter.decrementAndGet();
                results.put("ACTION_NULL_IDX_" + i, ActionResult.error(new NullPointerException()));
                if (i == 0 && !iterator.hasNext()) {
                    fulfiller.success(results);
                    return;
                }
                continue;
            }
            execControl.exec()
                    .start(execution -> apply(execution, action).defer(Runnable::run).wiretap(result -> {

                    }).then(result -> {
                        results.put(action.getName(), result);
                        if (counter.decrementAndGet() == 0 && !iterator.hasNext()) {
                            fulfiller.success(results);
                        }
                    }));
        }
    }).map(ImmutableMap::copyOf).map(map -> new ActionResults<O>(map));
}

From source file:com.facebook.buck.distributed.build_client.RemoteExecutionBuildTargetsQueue.java

public RemoteExecutionBuildTargetsQueue() {
    this.targetsWaitingToBeBuilt = Queues.newArrayDeque();
    this.targetsBuilding = Maps.newConcurrentMap();
    this.haveRemoteMachinesConnected = false;
    this.totalTargetsEnqueued = 0;
    this.totalTargetsBuilt = 0;
}

From source file:com.netflix.genie.web.tasks.leader.AgentJobCleanupTask.java

/**
 * Constructor.//from  w ww  . ja va  2  s . c o  m
 *
 * @param jobSearchService      the job search service
 * @param jobPersistenceService the job persistence service
 * @param properties            the task properties
 * @param registry              the metrics registry
 */
public AgentJobCleanupTask(final JobSearchService jobSearchService,
        final JobPersistenceService jobPersistenceService, final AgentCleanupProperties properties,
        final MeterRegistry registry) {
    this.jobSearchService = jobSearchService;
    this.jobPersistenceService = jobPersistenceService;
    this.properties = properties;
    this.registry = registry;
    this.awolJobDeadlines = Maps.newConcurrentMap();

    // Auto-publish number of jobs tracked for shutdown due to agent not being connected.
    this.registry.gaugeMapSize(DISCONNECTED_GAUGE_METRIC_NAME, Sets.newHashSet(), this.awolJobDeadlines);
}

From source file:org.onosproject.store.primitives.impl.DefaultDatabaseState.java

@Initializer
@Override/*w ww .  j a va  2 s. com*/
public void init(StateContext<DatabaseState<String, byte[]>> context) {
    counters = context.get("counters");
    if (counters == null) {
        counters = Maps.newConcurrentMap();
        context.put("counters", counters);
    }
    maps = context.get("maps");
    if (maps == null) {
        maps = Maps.newConcurrentMap();
        context.put("maps", maps);
    }
    locks = context.get("locks");
    if (locks == null) {
        locks = Maps.newConcurrentMap();
        context.put("locks", locks);
    }
    queues = context.get("queues");
    if (queues == null) {
        queues = Maps.newConcurrentMap();
        context.put("queues", queues);
    }
    nextVersion = context.get("nextVersion");
    if (nextVersion == null) {
        nextVersion = 0L;
        context.put("nextVersion", nextVersion);
    }
}

From source file:com.continuuity.loom.store.tenant.SQLTenantStore.java

@Inject
SQLTenantStore(DBConnectionPool dbConnectionPool, DBQueryExecutor dbQueryExecutor)
        throws SQLException, ClassNotFoundException {
    this.dbConnectionPool = dbConnectionPool;
    this.dbQueryExecutor = dbQueryExecutor;
    this.idToNameMap = Maps.newConcurrentMap();
}