private Consultant(ScheduledExecutorService executor, ObjectMapper mapper, URI consulUri,
ServiceIdentifier identifier, SetMultimap<String, SettingListener> settingListeners,
Set<ConfigListener> configListeners, ConfigValidator validator, CloseableHttpClient http,
boolean pullConfig, String healthEndpoint, String kvPrefix) {
this.registered = new AtomicBoolean();
this.settingListeners = Multimaps.synchronizedSetMultimap(settingListeners);
this.configListeners = Sets.newConcurrentHashSet(configListeners);
this.serviceInstanceBackend = new ServiceInstanceBackend(identifier.getDatacenter(), consulUri, mapper, http);
this.mapper = mapper;
this.validator = validator;
this.executor = executor;
this.consulUri = consulUri;
this.id = identifier;
this.pullConfig = pullConfig;
this.validated = new Properties();
this.healthEndpoint = healthEndpoint;
this.http = http;
this.kvPrefix = kvPrefix;
}
java类com.google.common.collect.Multimaps的实例源码
Consultant.java 文件源码
项目:consultant
阅读 43
收藏 0
点赞 0
评论 0
GuavaTest.java 文件源码
项目:onetwo
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void testGroupBy(){
List<UserEntity> all = LangUtils.newArrayList();
List<UserEntity> aa = createUserList("aa", 3);
List<UserEntity> bb = createUserList("bb", 1);
List<UserEntity> cc = createUserList("cc", 2);
all.addAll(aa);
all.addAll(bb);
all.addAll(cc);
ImmutableListMultimap<String, UserEntity> groups = Multimaps.index(all, new Function<UserEntity, String>() {
@Override
public String apply(UserEntity input) {
return input.getUserName();
}
});
System.out.println("groups:" + groups);
Assert.assertEquals(3, groups.get("aa").size());
Assert.assertEquals(1, groups.get("bb").size());
Assert.assertEquals(2, groups.get("cc").size());
}
IntMultimap.java 文件源码
项目:jklol
阅读 17
收藏 0
点赞 0
评论 0
/**
* Creates a new multimap that reverses the keys and values in {@code map}.
*
* @param map
* @return
*/
public static IntMultimap invertFrom(Multimap<? extends Integer, ? extends Integer> map) {
if (map instanceof IntMultimap) {
IntMultimap other = (IntMultimap) map;
// This is unnecessary, but it makes this method easier to implement.
other.reindexItems();
int[] newSortedKeys = Arrays.copyOf(other.sortedValues, other.sortedValues.length);
int[] newSortedValues = Arrays.copyOf(other.sortedKeys, other.sortedKeys.length);
ArrayUtils.sortKeyValuePairs(newSortedKeys, newSortedValues, 0, newSortedKeys.length);
return new IntMultimap(newSortedKeys, newSortedValues);
} else {
IntMultimap inverse = IntMultimap.create();
Multimaps.invertFrom(map, inverse);
return inverse;
}
}
FunctionRegistry.java 文件源码
项目:presto
阅读 24
收藏 0
点赞 0
评论 0
public FunctionMap(FunctionMap map, Iterable<? extends SqlFunction> functions)
{
this.functions = ImmutableListMultimap.<QualifiedName, SqlFunction>builder()
.putAll(map.functions)
.putAll(Multimaps.index(functions, function -> QualifiedName.of(function.getSignature().getName())))
.build();
// Make sure all functions with the same name are aggregations or none of them are
for (Map.Entry<QualifiedName, Collection<SqlFunction>> entry : this.functions.asMap().entrySet()) {
Collection<SqlFunction> values = entry.getValue();
long aggregations = values.stream()
.map(function -> function.getSignature().getKind())
.filter(kind -> kind == AGGREGATE || kind == APPROXIMATE_AGGREGATE)
.count();
checkState(aggregations == 0 || aggregations == values.size(), "'%s' is both an aggregation and a scalar function", entry.getKey());
}
}
PartitionUpdate.java 文件源码
项目:presto
阅读 16
收藏 0
点赞 0
评论 0
public static List<PartitionUpdate> mergePartitionUpdates(List<PartitionUpdate> unMergedUpdates)
{
ImmutableList.Builder<PartitionUpdate> partitionUpdates = ImmutableList.builder();
for (Collection<PartitionUpdate> partitionGroup : Multimaps.index(unMergedUpdates, PartitionUpdate::getName).asMap().values()) {
PartitionUpdate firstPartition = partitionGroup.iterator().next();
ImmutableList.Builder<String> allFileNames = ImmutableList.builder();
for (PartitionUpdate partition : partitionGroup) {
// verify partitions have the same new flag, write path and target path
// this shouldn't happen but could if another user added a partition during the write
if (partition.isNew() != firstPartition.isNew() ||
!partition.getWritePath().equals(firstPartition.getWritePath()) ||
!partition.getTargetPath().equals(firstPartition.getTargetPath())) {
throw new PrestoException(HIVE_WRITER_ERROR, format("Partition %s was added or modified during INSERT", firstPartition.getName()));
}
allFileNames.addAll(partition.getFileNames());
}
partitionUpdates.add(new PartitionUpdate(firstPartition.getName(),
firstPartition.isNew(),
firstPartition.getWritePath(),
firstPartition.getTargetPath(),
allFileNames.build()));
}
return partitionUpdates.build();
}
WebsocketHandler.java 文件源码
项目:onboard
阅读 26
收藏 0
点赞 0
评论 0
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());
}
}
}
}
}
WebSocketServiceImpl.java 文件源码
项目:onboard
阅读 21
收藏 0
点赞 0
评论 0
@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());
}
}
}
}
}
WorkspacePlugin.java 文件源码
项目:gradle-workspace-plugin
阅读 23
收藏 0
点赞 0
评论 0
/**
* Get the configurations that export an artifact
*
* @param projects Projects to search
* @return Exporting configurations
*/
protected Multimap<@NonNull String, @NonNull ExportingConfiguration> getExportingConfigurations(
Collection<@NonNull Project> projects) {
Multimap<@NonNull String, @NonNull ExportingConfiguration> exports = Multimaps.newSetMultimap(new HashMap<>(),
() -> new TreeSet<>(CONFIGURATION_INFO_COMPARATOR));
for (Project project : projects) {
Set<String> configurationNames = ImmutableSet.of("default");
WorkspaceConfig workspaceConfig = project.getExtensions().findByType(WorkspaceConfig.class);
if (workspaceConfig != null) {
configurationNames = workspaceConfig.getExportedConfigurations();
}
for (String configurationName : configurationNames) {
Configuration configuration = project.getConfigurations().findByName(configurationName);
if (configuration != null) {
getExportingConfigurations(project, configuration, exports);
}
}
}
return exports;
}
WatchesServiceImpl.java 文件源码
项目:artifactory
阅读 19
收藏 0
点赞 0
评论 0
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);
}
}
}
}
}
BilingualEntryMerger.java 文件源码
项目:metadict
阅读 18
收藏 0
点赞 0
评论 0
@NotNull
@Override
protected Collection<Collection<BilingualEntry>> findCandidates(@NotNull Collection<BilingualEntry> normalizedInput) {
Multimap<MergeCandidateIdentifier, BilingualEntry> candidatesMap = buildMergeCandidateMultimap(normalizedInput);
Multimap<MergeCandidateIdentifier, BilingualEntry> knownMap = Multimaps.filterEntries(candidatesMap, this::toNullIfUnknown);
Multimap<MergeCandidateIdentifier, BilingualEntry> unknownMap = Multimaps.filterEntries(candidatesMap, this::toNullIfKnown);
Collection<Collection<BilingualEntry>> candidates = new ArrayList<>(candidatesMap.keys().size());
identifyUnknownEntryTypeCandidates(candidatesMap, knownMap, unknownMap, candidates);
mergeSingleDialectLanguages(candidatesMap);
for (MergeCandidateIdentifier key : knownMap.asMap().keySet()) {
candidates.add(candidatesMap.get(key));
}
return candidates;
}