本文整理汇总了Java中com.google.common.collect.Multimaps.synchronizedMultimap方法的典型用法代码示例。如果您正苦于以下问题:Java Multimaps.synchronizedMultimap方法的具体用法?Java Multimaps.synchronizedMultimap怎么用?Java Multimaps.synchronizedMultimap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Multimaps
的用法示例。
在下文中一共展示了Multimaps.synchronizedMultimap方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessage
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public void sendMessage(String userEmail, String message) {
Multimap<String, WebSocketSession> syncMap = Multimaps.synchronizedMultimap(userPagesMap);
Collection<WebSocketSession> mis = syncMap.get(userEmail);
synchronized (syncMap) {
if (mis != null) {
Iterator<WebSocketSession> it = mis.iterator();
while (it.hasNext()) {
WebSocketSession session = it.next();
try {
session.sendMessage(new TextMessage(message));
} catch (Exception e) {
logger.info("The WebSocket connection has been closed: " + session.toString());
}
}
}
}
}
示例2: broadcastOne
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
@Override
public void broadcastOne(String user, String message) {
Multimap<String, MessageInbound> syncMap = Multimaps.synchronizedMultimap(userPagesMap);
Collection<MessageInbound> mis = syncMap.get(user);
synchronized (syncMap) {
if (mis != null) {
Iterator<MessageInbound> it = mis.iterator();
while (it.hasNext()) {
MessageInbound inbound = it.next();
try {
sendToPage(inbound, message);
} catch (IOException e) {
// userPagesMap.remove(user, inbound);
logger.info("The WebSocket connection has been closed: " + inbound.toString());
}
}
}
}
}
示例3: lazyInitCacheIfNeeded
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
private void lazyInitCacheIfNeeded() {
if (!initialized) {
synchronized (this) {
if (!initialized) {
if (watchersCache == null) {
watchersCache = HashMultimap.create();
watchersCache = Multimaps.synchronizedMultimap(watchersCache);
}
try {
//TODO: [by YS] consider using single query to get watch + repo path
List<Watch> nodeWatches = watchesDao.getWatches();
for (Watch nodeWatch : nodeWatches) {
RepoPath repoPath = fileService.loadItem(nodeWatch.getNodeId()).getRepoPath();
watchersCache.put(repoPath, nodeWatch);
}
initialized = true;
} catch (SQLException e) {
throw new StorageException("Failed to load watches", e);
}
}
}
}
}
示例4: train
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public TrainingResults train(String name, int numberOfTrees, List<LabeledItem<Integer>> trainingData, List<String> attributes, int defaultLabel) {
int featuresToUse = (int) Math.sqrt(attributes.size());
Multimap<LabeledItem<Integer>, Tree<Integer>> treesForItem = Multimaps.synchronizedMultimap(ArrayListMultimap.create());
Matrix itemProximities = new Basic2DMatrix(trainingData.size(), trainingData.size());
IdentityHashMap<Tree<Integer>, Set<LabeledItem<Integer>>> outOfBagItemsByTree = new IdentityHashMap<>();
Collection<Tree<Integer>> trees = Functional.timesParallel(numberOfTrees, () -> {
List<LabeledItem<Integer>> bootstrappedData = pickTrainingData(trainingData);
Set<LabeledItem<Integer>> outOfBagItems = Sets.difference(new HashSet<>(trainingData), new HashSet<>(bootstrappedData));
Tree<Integer> tree = decisionTreeTrainer.train(name, bootstrappedData, attributes, featuresToUse, defaultLabel);
outOfBagItems.forEach(item -> treesForItem.put(item, tree));
outOfBagItemsByTree.put(tree, outOfBagItems);
System.out.print(".");
return tree;
});
System.out.println("\n calculating proximities...");
calculateProximities(trainingData, itemProximities, trees);
return new TrainingResults(new RandomForest(trees, defaultLabel), treesForItem, itemProximities, trainingData, outOfBagItemsByTree);
}
示例5: DynamicPartitionObserver
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
* Instantiates a new Dynamic partition observer.
*/
public DynamicPartitionObserver() {
mapping = Collections.synchronizedMap(new HashMap<>());
mappingReverse = Multimaps.synchronizedMultimap(ArrayListMultimap.create());
filters = Collections.synchronizedSet(new LinkedHashSet<>());
listeners = Collections.synchronizedSet(new HashSet<>());
listenerExecutor = Executors.newSingleThreadExecutor();
}
示例6:
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/********************** constructors **********************************/
DatarouterNodes(){
this.topLevelNodes = new ConcurrentSkipListSet<>();
this.nodeByName = new ConcurrentSkipListMap<>();
this.topLevelNodesByRouterName = Multimaps.synchronizedMultimap(TreeMultimap.create());
this.routerNameByNode = new ConcurrentSkipListMap<>();
this.clientIdsByRouterName = new ConcurrentSkipListMap<>();
this.physicalNodeByTableNameByClientName = new ConcurrentSkipListMap<>();
}
示例7: PackageInventory
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
* No argument constructor.
*/
PackageInventory(){
packagesByIdMap = new ConcurrentHashMap<PID, MovingCodePackage>();
// multimap for packageName -> packageId LUT
Multimap<String, MovingCodePackage> delegate1 = ArrayListMultimap.create();
packagesByNameMap = Multimaps.synchronizedMultimap(delegate1);
// multimap for functionId -> packageId LUT
Multimap<String, MovingCodePackage> delegate2 = ArrayListMultimap.create();
packagesByFunctionIdMap = Multimaps.synchronizedMultimap(delegate2);
}
示例8: TopologyImpl
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
/**
* Create an empty Topology.
*/
public TopologyImpl() {
mastership = new HashMap<>();
// TODO: Does these object need to be stored in Concurrent Collection?
switches = new ConcurrentHashMap<>();
ports = new ConcurrentHashMap<>();
hosts = Multimaps.synchronizedMultimap(
HashMultimap.<SwitchPort, HostData>create());
mac2Host = new ConcurrentHashMap<>();
outgoingLinks = new ConcurrentHashMap<>();
incomingLinks = new ConcurrentHashMap<>();
}
示例9: ConfigurationManager
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
@Inject
public ConfigurationManager(ServiceProperties props) {
this.serviceProps = props;
this.callbackListeners = Multimaps.synchronizedMultimap(ArrayListMultimap.create());
this.lastProperties = new HashMap<>(props.getAllProperties());
}
示例10: ElectionRegistry
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public ElectionRegistry(ZKClient zkClient) {
this.zkClient = zkClient;
Multimap<String, LeaderElection> multimap = HashMultimap.create();
this.registry = Multimaps.synchronizedMultimap(multimap);
}
示例11: WebSocketRegistryImpl
import com.google.common.collect.Multimaps; //导入方法依赖的package包/类
public WebSocketRegistryImpl()
{
this.idToSession = Maps.newConcurrentMap();
this.groupToId = Multimaps.synchronizedMultimap( HashMultimap.create() );
}