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

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

Introduction

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

Prototype

public static <K, V> BiMap<K, V> synchronizedBiMap(BiMap<K, V> bimap) 

Source Link

Document

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

Usage

From source file:rapture.repo.jdbc.TransactionAwareDataSource.java

public TransactionAwareDataSource(DataSource dataSource) {
    this.underlyingDataSource = dataSource;
    connections = Maps.synchronizedBiMap(HashBiMap.<String, Connection>create());
}

From source file:de.uniulm.omi.cloudiator.visor.monitoring.ServerRegistryImpl.java

@Inject
public ServerRegistryImpl(ServerFactory serverFactory) {
    this.serverFactory = serverFactory;
    servers = Maps.synchronizedBiMap(HashBiMap.create(new HashMap<>()));
}

From source file:me.lucko.luckperms.core.UuidCache.java

public UuidCache(boolean onlineMode) {
    this.onlineMode = onlineMode;

    if (!onlineMode) {
        cache = Maps.synchronizedBiMap(HashBiMap.create());
    }
}

From source file:net.holmes.core.business.media.dao.index.MediaIndexDaoImpl.java

/**
 * Instantiates a new media index dao implementation.
 *//*  www . j  a  v a  2 s  . c  o  m*/
public MediaIndexDaoImpl() {
    this.elements = Maps.synchronizedBiMap(HashBiMap.<String, MediaIndexElement>create());
}

From source file:com.hortonworks.registries.schemaregistry.cache.SchemaBranchCache.java

public SchemaBranchCache(Integer size, Long expiryInSecs, final SchemaBranchFetcher schemaBranchFetcher) {
    schemaBranchNameToIdMap = Maps.synchronizedBiMap(HashBiMap.create());
    loadingCache = CacheBuilder.newBuilder().maximumSize(size).expireAfterAccess(expiryInSecs, TimeUnit.SECONDS)
            .build(new CacheLoader<Key, SchemaBranch>() {
                @Override//from ww  w .ja  v a 2  s  .  co m
                public SchemaBranch load(Key key) throws Exception {
                    SchemaBranch schemaBranch;
                    Key otherKey;
                    if (key.getSchemaBranchKey() != null) {
                        schemaBranch = schemaBranchFetcher.getSchemaBranch(key.getSchemaBranchKey());
                        otherKey = Key.of(schemaBranch.getId());
                        schemaBranchNameToIdMap.put(key.getSchemaBranchKey(), schemaBranch.getId());
                    } else if (key.getId() != null) {
                        schemaBranch = schemaBranchFetcher.getSchemaBranch(key.getId());
                        otherKey = Key.of(new SchemaBranchKey(schemaBranch.getName(),
                                schemaBranch.getSchemaMetadataName()));
                        schemaBranchNameToIdMap.put(otherKey.schemaBranchKey, schemaBranch.getId());
                    } else {
                        throw new IllegalArgumentException("Given argument is not valid: " + key);
                    }
                    loadingCache.put(otherKey, schemaBranch);
                    return schemaBranch;
                }
            });
}

From source file:org.jboss.weld.serialization.ContextualStoreImpl.java

public ContextualStoreImpl() {
    this.idGenerator = new AtomicInteger(0);
    BiMap<Contextual<?>, String> map = HashBiMap.create();
    // TODO Somehow remove this sync if it shows bad in a profiler
    this.contextuals = Maps.synchronizedBiMap(map);
    this.passivationCapableContextuals = new ConcurrentHashMap<String, Contextual<?>>();
}

From source file:org.apache.gobblin.metastore.nameParser.GuidDatasetUrnStateStoreNameParser.java

public GuidDatasetUrnStateStoreNameParser(FileSystem fs, Path jobStatestoreRootDir) throws IOException {
    this.fs = fs;
    this.sanitizedNameToDatasetURNMap = Maps.synchronizedBiMap(HashBiMap.<String, String>create());
    this.versionIdentifier = new Path(jobStatestoreRootDir,
            StateStoreNameVersion.V1.getDatasetUrnNameMapFile());
    if (this.fs.exists(versionIdentifier)) {
        this.version = StateStoreNameVersion.V1;
        try (InputStream in = this.fs.open(versionIdentifier)) {
            LineReader lineReader = new LineReader(new InputStreamReader(in, Charsets.UTF_8));
            String shortenName = lineReader.readLine();
            while (shortenName != null) {
                String datasetUrn = lineReader.readLine();
                this.sanitizedNameToDatasetURNMap.put(shortenName, datasetUrn);
                shortenName = lineReader.readLine();
            }//from ww w  . j  a  va  2  s .  c  o m
        }
    } else {
        this.version = StateStoreNameVersion.V0;
    }
}

From source file:org.geoserver.gwc.layer.DefaultTileLayerCatalog.java

DefaultTileLayerCatalog(GeoServerResourceLoader resourceLoader, XStream configuredXstream) throws IOException {

    this.resourceLoader = resourceLoader;
    this.serializer = configuredXstream;
    this.baseDirectory = LAYERINFO_DIRECTORY;

    BiMap<String, String> baseBiMap = HashBiMap.create();
    this.layersById = Maps.synchronizedBiMap(baseBiMap);
    this.layersByName = layersById.inverse();
    this.initialized = false;
}

From source file:com.yahoo.storm.yarn.StormAMRMClient.java

public StormAMRMClient(ApplicationAttemptId appAttemptId, @SuppressWarnings("rawtypes") Map storm_conf,
        YarnConfiguration hadoopConf) {//from www  . ja  va2s.co  m
    this.appAttemptId = appAttemptId;
    this.storm_conf = storm_conf;
    this.hadoopConf = hadoopConf;
    Integer pri = Utils.getInt(storm_conf.get(Config.MASTER_CONTAINER_PRIORITY));
    this.DEFAULT_PRIORITY.setPriority(pri);
    numSupervisors = new AtomicInteger(0);
    runningSupervisors = Maps.synchronizedBiMap(HashBiMap.<NodeId, ContainerId>create());

    // start am nm client
    nmClient = (NMClientImpl) NMClient.createNMClient();
    nmClient.init(hadoopConf);
    nmClient.start();

    //get number of slots for supervisor
    int numWorkersPerSupervisor = Util.getNumWorkers(storm_conf);
    int supervisorSizeMB = Util.getSupervisorSizeMB(storm_conf);
    //add 1 for the supervisor itself
    supervisorResource = Resource.newInstance(supervisorSizeMB, numWorkersPerSupervisor + 1);
    LOG.info("Supervisors will allocate Yarn Resource[" + supervisorResource + "]");
}

From source file:org.ros.node.DefaultNodeMainExecutor.java

/**
 * @param nodeFactory/*from  w  ww  . ja va 2s .  co m*/
 *          {@link NodeFactory} to use for node creation.
 * @param scheduledExecutorService
 *          {@link NodeMain}s will be executed using this
 */
private DefaultNodeMainExecutor(NodeFactory nodeFactory, ScheduledExecutorService scheduledExecutorService) {
    this.nodeFactory = nodeFactory;
    this.scheduledExecutorService = scheduledExecutorService;
    connectedNodes = Multimaps.synchronizedMultimap(HashMultimap.<GraphName, ConnectedNode>create());
    nodeMains = Maps.synchronizedBiMap(HashBiMap.<Node, NodeMain>create());
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            DefaultNodeMainExecutor.this.shutdown();
        }
    }));
}