Example usage for com.google.common.collect Sets newConcurrentHashSet

List of usage examples for com.google.common.collect Sets newConcurrentHashSet

Introduction

In this page you can find the example usage for com.google.common.collect Sets newConcurrentHashSet.

Prototype

public static <E> Set<E> newConcurrentHashSet() 

Source Link

Document

Creates a thread-safe set backed by a hash map.

Usage

From source file:org.attribyte.relay.FilesSupplier.java

/**
 * Creates an uninitialized supplier.
 */
public FilesSupplier() {
    this.processedSet = Sets.newConcurrentHashSet();
}

From source file:org.restcomm.media.control.mgcp.transaction.SubMgcpTransactionManager.java

public SubMgcpTransactionManager(MgcpTransactionNumberspace numberspace, ListeningExecutorService executor) {
    // Concurrency Components
    this.executor = executor;

    // MGCP Components
    this.numberspace = numberspace;

    // MGCP Transaction Manager
    this.transactions = new ConcurrentHashMap<>(500);

    // Observers/*from w  w w  .j  a va2 s.c o  m*/
    this.observers = Sets.newConcurrentHashSet();
}

From source file:org.apache.druid.curator.inventory.CuratorInventoryManager.java

public CuratorInventoryManager(CuratorFramework curatorFramework, InventoryManagerConfig config,
        ExecutorService exec, CuratorInventoryManagerStrategy<ContainerClass, InventoryClass> strategy) {
    this.curatorFramework = curatorFramework;
    this.config = config;
    this.strategy = strategy;

    this.containers = new ConcurrentHashMap<>();
    this.uninitializedInventory = Sets.newConcurrentHashSet();

    this.pathChildrenCacheExecutor = exec;
    this.cacheFactory = new PathChildrenCacheFactory.Builder()
            //NOTE: cacheData is temporarily set to false and we get data directly from ZK on each event.
            //this is a workaround to solve curator's out-of-order events problem
            //https://issues.apache.org/jira/browse/CURATOR-191
            .withCacheData(false).withCompressed(true).withExecutorService(pathChildrenCacheExecutor)
            .withShutdownExecutorOnClose(false).build();
}

From source file:org.locationtech.geogig.rocksdb.RocksdbObjectDatabase.java

protected @Override void putAll(Stream<RevObject> stream, BulkOpListener listener) {
    // collect all ids of commits being inserted
    Set<ObjectId> visitedCommits = Sets.newConcurrentHashSet();
    Consumer<RevObject> trackCommits = (o) -> {
        if (TYPE.COMMIT == o.getType()) {
            visitedCommits.add(o.getId());
        }//w  ww.  ja  va2 s  .com
    };
    // the stream will call trackCommits for each object as they're consumed
    stream = stream.peek(trackCommits);
    try {
        super.putAll(stream, listener);
    } finally {
        // insert the mappings for all the commits that tried to be inserted and can be found in
        // the objects db. It is ok to call graphdb.put with a commit that already exists, and
        // this way we don't have to keep a potentially huge collection of RevCommits in memory
        if (!visitedCommits.isEmpty()) {
            Iterator<RevCommit> inserted = super.getAll(visitedCommits, BulkOpListener.NOOP_LISTENER,
                    RevCommit.class);
            graph.putAll(() -> inserted);
        }
    }
}

From source file:org.onosproject.net.intent.impl.compiler.PathCompiler.java

/**
 * Creates the flow rules for the path intent using VLAN
 * encapsulation./*from w  w  w . j  a va 2 s .  c o  m*/
 *
 * @param creator the flowrules creator
 * @param flows the list of flows to fill
 * @param devices the devices on the path
 * @param intent the PathIntent to compile
 */
private void manageVlanEncap(PathCompilerCreateFlow<T> creator, List<T> flows, List<DeviceId> devices,
        PathIntent intent) {

    Set<Link> linksSet = Sets.newConcurrentHashSet();
    for (int i = 1; i <= intent.path().links().size() - 2; i++) {
        linksSet.add(intent.path().links().get(i));
    }

    Map<LinkKey, Identifier<?>> vlanIds = labelAllocator.assignLabelToLinks(linksSet, intent.id(),
            EncapsulationType.VLAN);

    Iterator<Link> links = intent.path().links().iterator();
    Link srcLink = links.next();

    Link link = links.next();

    // Ingress traffic
    VlanId vlanId = (VlanId) vlanIds.get(linkKey(link));
    if (vlanId == null) {
        throw new IntentCompilationException(ERROR_VLAN + link);
    }
    VlanId prevVlanId = vlanId;

    Optional<VlanIdCriterion> vlanCriterion = intent.selector().criteria().stream()
            .filter(criterion -> criterion.type() == Criterion.Type.VLAN_VID)
            .map(criterion -> (VlanIdCriterion) criterion).findAny();

    //Push VLAN if selector does not include VLAN
    TrafficTreatment.Builder treatBuilder = DefaultTrafficTreatment.builder();
    if (!vlanCriterion.isPresent()) {
        treatBuilder.pushVlan();
    }
    //Tag the traffic with the new encapsulation VLAN
    treatBuilder.setVlanId(vlanId);
    creator.createFlow(intent.selector(), treatBuilder.build(), srcLink.dst(), link.src(), intent.priority(),
            true, flows, devices);

    ConnectPoint prev = link.dst();

    while (links.hasNext()) {

        link = links.next();

        if (links.hasNext()) {
            // Transit traffic
            VlanId egressVlanId = (VlanId) vlanIds.get(linkKey(link));
            if (egressVlanId == null) {
                throw new IntentCompilationException(ERROR_VLAN + link);
            }

            TrafficSelector transitSelector = DefaultTrafficSelector.builder().matchInPort(prev.port())
                    .matchVlanId(prevVlanId).build();

            TrafficTreatment.Builder transitTreat = DefaultTrafficTreatment.builder();

            // Set the new vlanId only if the previous one is different
            if (!prevVlanId.equals(egressVlanId)) {
                transitTreat.setVlanId(egressVlanId);
            }
            creator.createFlow(transitSelector, transitTreat.build(), prev, link.src(), intent.priority(), true,
                    flows, devices);
            /* For the next hop we have to remember
             * the previous egress VLAN id and the egress
             * node
             */
            prevVlanId = egressVlanId;
            prev = link.dst();
        } else {
            // Egress traffic
            TrafficSelector egressSelector = DefaultTrafficSelector.builder().matchInPort(prev.port())
                    .matchVlanId(prevVlanId).build();
            TrafficTreatment.Builder egressTreat = DefaultTrafficTreatment.builder(intent.treatment());

            Optional<L2ModificationInstruction.ModVlanIdInstruction> modVlanIdInstruction = intent.treatment()
                    .allInstructions().stream()
                    .filter(instruction -> instruction instanceof L2ModificationInstruction.ModVlanIdInstruction)
                    .map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).findAny();

            Optional<L2ModificationInstruction.ModVlanHeaderInstruction> popVlanInstruction = intent.treatment()
                    .allInstructions().stream()
                    .filter(instruction -> instruction instanceof L2ModificationInstruction.ModVlanHeaderInstruction)
                    .map(x -> (L2ModificationInstruction.ModVlanHeaderInstruction) x).findAny();

            if (!modVlanIdInstruction.isPresent() && !popVlanInstruction.isPresent()) {
                if (vlanCriterion.isPresent()) {
                    egressTreat.setVlanId(vlanCriterion.get().vlanId());
                } else {
                    egressTreat.popVlan();
                }
            }

            creator.createFlow(egressSelector, egressTreat.build(), prev, link.src(), intent.priority(), true,
                    flows, devices);
        }
    }
}

From source file:com.facebook.buck.parser.PerBuildState.java

public PerBuildState(Parser parser, BuckEventBus eventBus, ListeningExecutorService executorService,
        Cell rootCell, boolean enableProfiling, SpeculativeParsing speculativeParsing,
        boolean ignoreBuckAutodepsFiles) {

    this.parser = parser;
    this.eventBus = eventBus;
    this.enableProfiling = enableProfiling;
    this.ignoreBuckAutodepsFiles = ignoreBuckAutodepsFiles;

    this.cells = new ConcurrentHashMap<>();
    this.cellSymlinkAllowability = new ConcurrentHashMap<>();
    this.buildInputPathsUnderSymlink = Sets.newConcurrentHashSet();
    this.symlinkExistenceCache = new ConcurrentHashMap<>();

    this.stdout = new PrintStream(ByteStreams.nullOutputStream());
    this.stderr = new PrintStream(ByteStreams.nullOutputStream());
    this.console = new Console(Verbosity.STANDARD_INFORMATION, stdout, stderr, Ansi.withoutTty());

    TargetNodeListener<TargetNode<?, ?>> symlinkCheckers = this::registerInputsUnderSymlinks;
    ParserConfig parserConfig = rootCell.getBuckConfig().getView(ParserConfig.class);
    int numParsingThreads = parserConfig.getNumParsingThreads();
    this.projectBuildFileParserPool = new ProjectBuildFileParserPool(numParsingThreads, // Max parsers to create per cell.
            input -> createBuildFileParser(input, PerBuildState.this.ignoreBuckAutodepsFiles));

    this.rawNodeParsePipeline = new RawNodeParsePipeline(parser.getPermState().getRawNodeCache(),
            projectBuildFileParserPool, executorService);
    this.targetNodeParsePipeline = new TargetNodeParsePipeline(
            parser.getPermState().getOrCreateNodeCache(TargetNode.class),
            DefaultParserTargetNodeFactory.createForParser(parser.getMarshaller(),
                    parser.getPermState().getBuildFileTrees(), symlinkCheckers,
                    new TargetNodeFactory(parser.getPermState().getTypeCoercerFactory())),
            parserConfig.getEnableParallelParsing() ? executorService
                    : MoreExecutors.newDirectExecutorService(),
            eventBus, parserConfig.getEnableParallelParsing() && speculativeParsing.value(),
            rawNodeParsePipeline);/*w ww  . j  a  v a2 s.co m*/
    this.targetGroupParsePipeline = new TargetGroupParsePipeline(
            parser.getPermState().getOrCreateNodeCache(TargetGroup.class),
            new DefaultParserTargetGroupFactory(parser.getMarshaller()),
            parserConfig.getEnableParallelParsing() ? executorService
                    : MoreExecutors.newDirectExecutorService(),
            eventBus, rawNodeParsePipeline);

    register(rootCell);
}

From source file:org.apache.bookkeeper.stream.storage.impl.sc.ZkStorageContainerManager.java

public ZkStorageContainerManager(Endpoint myEndpoint, StorageConfiguration conf,
        ClusterMetadataStore clusterMetadataStore, StorageContainerRegistry registry, StatsLogger statsLogger) {
    super("zk-storage-container-manager", conf, statsLogger);
    this.endpoint = myEndpoint;
    this.metadataStore = clusterMetadataStore;
    this.registry = registry;
    this.executor = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("zk-storage-container-manager").build());
    this.liveContainers = Collections.synchronizedMap(Maps.newConcurrentMap());
    this.pendingStartStopContainers = Collections.synchronizedSet(Sets.newConcurrentHashSet());
    this.containerAssignmentMap = new ConcurrentLongHashMap<>();
    this.clusterAssignmentMap = Maps.newHashMap();
    // probe the containers every 1/2 of controller scheduling interval. this ensures the manager
    // can attempt to start containers before controller reassign them.
    this.probeInterval = Duration.ofMillis(conf.getClusterControllerScheduleIntervalMs() / 2);
}

From source file:nl.knaw.huygens.timbuctoo.storage.graph.tinkerpop.conversion.ElementConverterFactory.java

@SuppressWarnings("unchecked")
private <T extends Entity> Collection<PropertyConverter> createPropertyConverters(Class<T> type) {
    Set<PropertyConverter> propertyConverters = Sets.newConcurrentHashSet();
    for (Class<? extends Entity> typeToGetFieldsFrom = type; isEntity(
            typeToGetFieldsFrom); typeToGetFieldsFrom = (Class<? extends Entity>) typeToGetFieldsFrom
                    .getSuperclass()) {/*from  www.  j a va2  s .  com*/

        for (Field field : typeToGetFieldsFrom.getDeclaredFields()) {
            propertyConverters.add(propertyConverterFactory.createPropertyConverter(type, field));
        }
    }
    return propertyConverters;
}

From source file:org.obm.servlet.filter.qos.handlers.TransactionalKeyRequestsInfoStore.java

@Inject
@VisibleForTesting
TransactionalKeyRequestsInfoStore() {
    references = Sets.newConcurrentHashSet();
    map = new MapMaker().weakValues().makeMap();
    count = new AtomicInteger();
}

From source file:com.netflix.genie.agent.execution.services.impl.grpc.GRpcAgentFileStreamServiceImpl.java

GRpcAgentFileStreamServiceImpl(final FileStreamServiceGrpc.FileStreamServiceStub fileStreamServiceStub,
        final TaskScheduler taskScheduler, final JobDirectoryManifestProtoConverter manifestProtoConverter) {
    this.fileStreamServiceStub = fileStreamServiceStub;
    this.taskScheduler = taskScheduler;
    this.manifestProtoConverter = manifestProtoConverter;
    this.trigger = new ExponentialBackOffTrigger(
            ExponentialBackOffTrigger.DelayType.FROM_PREVIOUS_EXECUTION_BEGIN, 1000, //TODO make configurable
            10000, //TODO make configurable
            1.1f //TODO make configurable
    );/*  ww w .j a  v a  2s  .  com*/
    this.responseObserver = new ServerControlStreamObserver(this);
    this.concurrentTransfersSemaphore = new Semaphore(MAX_CONCURRENT_TRANSMIT_STREAMS);
    this.activeFileTransfers = Sets.newConcurrentHashSet();
}