下面列出了com.google.common.collect.Maps#synchronizedBiMap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
});
}
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;
}
});
}
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;
}
}
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);
}
}
}
public Z3SymbolTable() {
constToSymbol = Maps.synchronizedBiMap(HashBiMap.create());
}
private <K, V> BiMap<K, V> newSynchronizedBiMap() {
BiMap<K, V> hashBiMap = HashBiMap.create();
return Maps.synchronizedBiMap(hashBiMap);
}