Java Code Examples for com.google.common.collect.Maps#synchronizedBiMap()

The following examples show how to use com.google.common.collect.Maps#synchronizedBiMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaMetadataCache.java    From registry with Apache License 2.0 6 votes vote down vote up
public SchemaMetadataCache(Long size, Long expiryInSecs, final SchemaMetadataFetcher schemaMetadataFetcher) {
    schemaNameToIdMap = Maps.synchronizedBiMap(HashBiMap.create());
    loadingCache = CacheBuilder.newBuilder()
            .maximumSize(size)
            .expireAfterAccess(expiryInSecs, TimeUnit.SECONDS)
            .build(new CacheLoader<Key, SchemaMetadataInfo>() {
                @Override
                public SchemaMetadataInfo load(Key key) throws Exception {
                    SchemaMetadataInfo schemaMetadataInfo;
                    Key otherKey;
                    if (key.getName() != null) {
                        schemaMetadataInfo = schemaMetadataFetcher.fetch(key.getName());
                        otherKey = Key.of(schemaMetadataInfo.getId());
                        schemaNameToIdMap.put(key.getName(), schemaMetadataInfo.getId());
                    } else if (key.getId() != null) {
                        schemaMetadataInfo = schemaMetadataFetcher.fetch(key.getId());
                        otherKey = Key.of(schemaMetadataInfo.getSchemaMetadata().getName());
                        schemaNameToIdMap.put(schemaMetadataInfo.getSchemaMetadata().getName(), schemaMetadataInfo.getId());
                    } else {
                        throw new RegistryException("Key should have name or id as non null");
                    }
                    loadingCache.put(otherKey, schemaMetadataInfo);
                    return schemaMetadataInfo;
                }
            });
}
 
Example 2
Source File: SchemaBranchCache.java    From registry with Apache License 2.0 6 votes vote down vote up
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
                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;
                }
            });
}
 
Example 3
Source File: GuidDatasetUrnStateStoreNameParser.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
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();
      }
    }
  } else {
    this.version = StateStoreNameVersion.V0;
  }
}
 
Example 4
Source File: EntityIdList.java    From iDisguise with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public static void init() {
	entityUIDs = new ConcurrentHashMap<Integer, UUID>();
	playerNames = Maps.synchronizedBiMap(HashBiMap.<UUID, String>create());
	entityTypes = new ConcurrentHashMap<UUID, EntityType>();
	for(World world : Bukkit.getWorlds()) {
		for(LivingEntity livingEntity : world.getLivingEntities()) {
			addEntity(livingEntity);
		}
	}
}
 
Example 5
Source File: Z3SymbolTable.java    From theta with Apache License 2.0 4 votes vote down vote up
public Z3SymbolTable() {
	constToSymbol = Maps.synchronizedBiMap(HashBiMap.create());
}
 
Example 6
Source File: TestTcpDataSender.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
private <K, V> BiMap<K, V> newSynchronizedBiMap() {
    BiMap<K, V> hashBiMap = HashBiMap.create();
    return Maps.synchronizedBiMap(hashBiMap);
}