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:edu.umn.msi.tropix.proteomics.itraqquantitation.impl.ITraqMatchBuilderImpl.java

private Map<ScanIndex, ITraqScanSummary> parseScans(final Iterable<File> mzxmlInputs,
        final ITraqMatchBuilderOptions options, final boolean useScanNumber) {
    final Map<ScanIndex, ITraqScanSummary> scanMap = Maps.newConcurrentMap();

    // Loop through the mzxml files
    final List<InputSource> inputSources = getInputSources(mzxmlInputs);

    if (options.getThreads() == 1) {
        for (final InputSource inputSource : inputSources) {
            addSummariesForFile(inputSource.getFile(), inputSource.getIndex(), scanMap, options, useScanNumber);
        }// www. j av  a  2  s.co  m
    } else {
        final Closure<InputSource> sourceReader = new Closure<InputSource>() {
            public void apply(final InputSource inputSource) {
                addSummariesForFile(inputSource.getFile(), inputSource.getIndex(), scanMap, options,
                        useScanNumber);
            }
        };
        if (!Concurrent.processInNThreads(options.getThreads(), sourceReader, inputSources)) {
            throw new RuntimeException("Failed to produce scan map");
        }
    }
    return scanMap;
}

From source file:org.sonatype.nexus.repository.search.SearchServiceImpl.java

@Inject
public SearchServiceImpl(final Provider<Client> client, final RepositoryManager repositoryManager,
        final SecurityHelper securityHelper, final List<IndexSettingsContributor> indexSettingsContributors,
        @Named("${nexus.elasticsearch.profile:-false}") final boolean profile) {
    this.client = checkNotNull(client);
    this.repositoryManager = checkNotNull(repositoryManager);
    this.securityHelper = checkNotNull(securityHelper);
    this.indexSettingsContributors = checkNotNull(indexSettingsContributors);
    this.repositoryNameMapping = Maps.newConcurrentMap();
    this.profile = checkNotNull(profile);
}

From source file:org.syncany.operations.daemon.WebServer.java

public WebServer(DaemonConfigTO daemonConfig) throws Exception {
    this.webSocketChannelRequestFormatMap = Maps.newConcurrentMap();

    initCaches();//from  w w  w  .  ja va 2s. c om
    initEventBus();
    initServer(daemonConfig);
}

From source file:org.apache.hive.spark.client.rpc.RpcServer.java

public RpcServer(Map<String, String> mapConf) throws IOException, InterruptedException {
    this.config = new RpcConfiguration(mapConf);
    this.group = new NioEventLoopGroup(this.config.getRpcThreadCount(),
            new ThreadFactoryBuilder().setNameFormat("RPC-Handler-%d").setDaemon(true).build());
    ServerBootstrap serverBootstrap = new ServerBootstrap().group(group).channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override/*from  ww w.j ava 2s  .  c om*/
                public void initChannel(SocketChannel ch) throws Exception {
                    SaslServerHandler saslHandler = new SaslServerHandler(config);
                    final Rpc newRpc = Rpc.createServer(saslHandler, config, ch, group);
                    saslHandler.rpc = newRpc;

                    Runnable cancelTask = new Runnable() {
                        @Override
                        public void run() {
                            LOG.warn("Timed out waiting for hello from client.");
                            newRpc.close();
                        }
                    };
                    saslHandler.cancelTask = group.schedule(cancelTask,
                            RpcServer.this.config.getConnectTimeoutMs(), TimeUnit.MILLISECONDS);

                }
            }).option(ChannelOption.SO_REUSEADDR, true).childOption(ChannelOption.SO_KEEPALIVE, true);

    this.channel = bindServerPort(serverBootstrap).channel();
    this.port = ((InetSocketAddress) channel.localAddress()).getPort();
    this.pendingClients = Maps.newConcurrentMap();
    this.address = this.config.getServerAddress();
}

From source file:org.apache.drill.exec.expr.fn.registry.FunctionRegistryHolder.java

public FunctionRegistryHolder() {
    this.functions = Maps.newConcurrentMap();
    this.jars = Maps.newConcurrentMap();
}

From source file:uk.ac.cam.cl.dtg.segue.dao.content.ContentMapper.java

/**
 * Creates a new content mapper initialized with a set of types.
 * //  w  w w  . j  a  va2s. c  om
 * @param additionalTypes
 *            - types to add to our look up map.
 * @param mapOfDOsToDTOs
 *            - map of DOs To DTOs.
 */
public ContentMapper(final Map<String, Class<? extends Content>> additionalTypes,
        final Map<Class<? extends Content>, Class<? extends ContentDTO>> mapOfDOsToDTOs) {
    Validate.notNull(additionalTypes);

    this.jsonTypes = new ConcurrentHashMap<String, Class<? extends Content>>();
    jsonTypes.putAll(additionalTypes);

    this.mapOfDOsToDTOs = Maps.newConcurrentMap();

    if (mapOfDOsToDTOs != null) {
        this.mapOfDOsToDTOs.putAll(mapOfDOsToDTOs);
    }
}

From source file:org.onosproject.tetopology.management.impl.TeMgrUtil.java

/**
 * Returns an instance of network node for a TE node.
 *
 * @param id     value of the network node id
 * @param teNode value of TE node//from w  w  w  . j a v a2 s . c om
 * @return an instance of network node
 */
public static NetworkNode nodeBuilder(KeyId id, TeNode teNode) {
    List<NetworkNodeKey> supportingNodeIds = null;
    if (teNode.supportingTeNodeId() != null) {
        supportingNodeIds = Lists.newArrayList(networkNodeKey(teNode.supportingTeNodeId()));
    }
    Map<KeyId, TerminationPoint> tps = Maps.newConcurrentMap();
    for (Long teTpid : teNode.teTerminationPointIds()) {
        tps.put(KeyId.keyId(Long.toString(teTpid)), tpBuilder(teTpid));
    }
    return new DefaultNetworkNode(id, supportingNodeIds, teNode, tps);
}

From source file:org.onosproject.bmv2.ctl.Bmv2DeviceContextServiceImpl.java

@Activate
public void activate() {
    KryoNamespace kryo = new KryoNamespace.Builder().register(KryoNamespaces.API)
            .register(new BmvDeviceContextSerializer(), Bmv2DeviceContext.class).build();

    this.contexts = storageService.<DeviceId, Bmv2DeviceContext>consistentMapBuilder()
            .withSerializer(Serializer.using(kryo)).withName("onos-bmv2-contexts").build();

    Bmv2Configuration defaultConfiguration = loadDefaultConfiguration();
    Bmv2Interpreter defaultInterpreter = new Bmv2DefaultInterpreterImpl();
    defaultContext = new Bmv2DeviceContext(defaultConfiguration, defaultInterpreter);

    interpreterClassLoaders = Maps.newConcurrentMap();
    registerInterpreterClassLoader(defaultInterpreter.getClass(), this.getClass().getClassLoader());

    contexts.addListener(contextListener, scheduledExecutor);

    if (configChecker != null && configChecker.isCancelled()) {
        configChecker.cancel(false);/*from   w  w w.  j  av a  2s. c om*/
    }
    configChecker = scheduledExecutor.scheduleAtFixedRate(this::checkDevices, 0, CHECK_INTERVAL,
            TimeUnit.MILLISECONDS);

    log.info("Started");
}

From source file:org.eclipse.milo.opcua.stack.client.handlers.UaTcpClientMessageHandler.java

public UaTcpClientMessageHandler(UaTcpStackClient client, ClientSecureChannel secureChannel,
        SerializationQueue serializationQueue, CompletableFuture<ClientSecureChannel> handshakeFuture) {

    this.client = client;
    this.secureChannel = secureChannel;
    this.serializationQueue = serializationQueue;
    this.handshakeFuture = handshakeFuture;

    secureChannel.attr(KEY_PENDING_REQUEST_FUTURES).setIfAbsent(Maps.newConcurrentMap());

    pending = secureChannel.attr(KEY_PENDING_REQUEST_FUTURES).get();

    secureChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE)
            .setIfAbsent(new LongSequence(1L, UInteger.MAX_VALUE));

    requestIdSequence = secureChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).get();

    handshakeFuture.thenAccept(sc -> {
        Channel channel = sc.getChannel();

        channel.eventLoop().execute(() -> {
            List<UaRequestFuture> awaitingHandshake = channel
                    .attr(UaTcpClientAcknowledgeHandler.KEY_AWAITING_HANDSHAKE).get();

            if (awaitingHandshake != null) {
                channel.attr(UaTcpClientAcknowledgeHandler.KEY_AWAITING_HANDSHAKE).remove();

                logger.debug("{} message(s) queued before handshake completed; sending now.",
                        awaitingHandshake.size());
                awaitingHandshake.forEach(channel::writeAndFlush);
            }/*from w  w w. j a  v  a 2 s  .co m*/
        });
    });
}

From source file:org.onosproject.vpls.VplsOperationManager.java

@Activate
public void activate() {
    appId = coreService.registerApplication(VplsManager.VPLS_APP);
    localNodeId = clusterService.getLocalNode().id();

    leadershipEventListener = new InternalLeadershipListener();
    leadershipService.addListener(leadershipEventListener);
    leadershipService.runForLeadership(appId.name());
    pendingVplsOperations = Maps.newConcurrentMap();

    // Thread pool for VplsOperationExecutor
    workerExecutor = newFixedThreadPool(NUM_THREADS, groupedThreads("onos/apps/vpls", "worker-%d", log));
    // A single thread pool for VplsOperationScheduler
    schedulerExecutor = Executors.newScheduledThreadPool(1,
            groupedThreads("onos/apps/vpls", "scheduler-%d", log));
    // Start the scheduler
    schedulerExecutor.scheduleAtFixedRate(new VplsOperationScheduler(), 0, 500, TimeUnit.MILLISECONDS);

}