下面列出了com.google.common.collect.LinkedListMultimap#put ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
*
* @param sid
* @param serverType
* @param sequence
* @param localSession
* @return
*/
public LocalSession addSession(String serverId,String serverType,int sessionId,LocalSession localSession) {
if (localSession == null) {
return null;
}
localSession.setServerId(serverId);
localSession.setServerType(serverType);
localSession.setId(sessionId);
localSession.setlistener(this.closeListener);
localSession.setStatus(ISession.STATUS_WORKING);
sessionBySid.put(serverId, localSession);
synchronized(sessionByStype) {
LinkedListMultimap<String, LocalSession> multimap = sessionByStype.get(serverType);
if (multimap == null) {
multimap = LinkedListMultimap.create();
sessionByStype.put(serverType, multimap);
}
multimap.put(serverId, localSession);
}
return localSession;
}
/**
* Builds a classpath from the transitive dependency graph of a list of artifacts.
* When there are multiple versions of an artifact in
* the dependency tree, the closest to the root in breadth-first order is picked up. This "pick
* closest" strategy follows Maven's dependency mediation.
*
* @param artifacts the first artifacts that appear in the classpath, in order
*/
public ClassPathResult resolve(List<Artifact> artifacts) {
LinkedListMultimap<ClassPathEntry, DependencyPath> multimap = LinkedListMultimap.create();
if (artifacts.isEmpty()) {
return new ClassPathResult(multimap, ImmutableList.of());
}
// dependencyGraph holds multiple versions for one artifact key (groupId:artifactId)
DependencyGraph result = dependencyGraphBuilder.buildFullDependencyGraph(artifacts);
List<DependencyPath> dependencyPaths = result.list();
// TODO should DependencyGraphResult have a mediate() method that returns a ClassPathResult?
// To remove duplicates on (groupId:artifactId) for dependency mediation
MavenDependencyMediation mediation = new MavenDependencyMediation();
for (DependencyPath dependencyPath : dependencyPaths) {
Artifact artifact = dependencyPath.getLeaf();
mediation.put(dependencyPath);
if (mediation.selects(artifact)) {
// We include multiple dependency paths to the first version of an artifact we see,
// but not paths to other versions of that artifact.
multimap.put(new ClassPathEntry(artifact), dependencyPath);
}
}
return new ClassPathResult(multimap, result.getUnresolvedArtifacts());
}
/**
* Get multimap of fq method names to fully qualified names of API calls
*
* @param namespace
* API namespace (e.g. org.apache.hadoop), "" for all namespaces
*/
public LinkedListMultimap<String, String> getAPINames(final String namespace) {
final LinkedListMultimap<String, String> fqAPICalls = LinkedListMultimap.create();
// Get scopes for variables
final Table<ASTNode, String, String> variableScopeNameTypes = HashBasedTable.create();
for (final ASTNode parent : variableNames.keySet()) {
final ASTNode scope = ASTVisitors.getCoveringBlock(rootNode, parent);
for (final Entry<String, Integer> entry : variableNames.get(parent).entrySet())
variableScopeNameTypes.put(scope, entry.getKey(), box(variableTypes.get(entry.getValue())));
}
for (final MethodDeclaration method : apiCalls.keySet()) {
for (final Expression exp : apiCalls.get(method)) {
final String fqCallingMethod = methodNames.get(method);
final String parentClassName = fqCallingMethod.substring(0, fqCallingMethod.lastIndexOf("."));
final String fqMethodCall = getFullyQualifiedMethodNameFor(exp, parentClassName,
variableScopeNameTypes);
if (fqMethodCall.startsWith(namespace))
fqAPICalls.put(fqCallingMethod, fqMethodCall);
}
}
for (final String className : unresClasses)
System.out.println("+++++ INFO: Unable to resolve class " + className);
for (final String name : unresMethods)
System.out.println("+++++ INFO: Unable to resolve method " + name);
return fqAPICalls;
}
public LinkedListMultimap<String, String> headerArray2MultiValuedMap(Header[] headers) {
LinkedListMultimap<String, String> m = LinkedListMultimap.create();
if (headers != null) for (Header h : headers) {
m.put(h.getName(), h.getValue());
}
return m;
}
FDSObjectListing getObjectListing(ListObjectsResult result) {
FDSObjectListing listing = null;
if (result != null) {
listing = new FDSObjectListing();
listing.setBucketName(result.getName());
listing.setPrefix(result.getPrefix());
listing.setDelimiter(result.getDelimiter());
listing.setMarker(result.getMarker());
listing.setNextMarker(result.getNextMarker());
listing.setMaxKeys(result.getMaxKeys());
listing.setTruncated(result.isTruncated());
listing.setReverse(result.isReverse());
listing.setWithMetaData(result.isWithMetaData());
List<FDSObjectSummary> summaries = new ArrayList<FDSObjectSummary>(
result.getObjects().size());
for (ObjectBean o : result.getObjects()) {
FDSObjectSummary summary = new FDSObjectSummary();
summary.setBucketName(result.getName());
summary.setObjectName(o.getName());
summary.setSize(o.getSize());
summary.setOwner(new Owner(o.getOwner().getId(), o.getOwner().getDisplayName()));
summary.setUploadTime(o.getUploadTime());
if (o.getMetadataBean() != null) {
Map<String, String> meta = o.getMetadataBean().getRawMeta();
LinkedListMultimap<String, String> linkedListMultimap = LinkedListMultimap.create();
for (Map.Entry<String, String> e : meta.entrySet()) {
linkedListMultimap.put(e.getKey(), e.getValue());
}
summary.setMetadata(FDSObjectMetadata.parseObjectMetadata(linkedListMultimap));
}
summaries.add(summary);
}
listing.setObjectSummaries(summaries);
listing.setCommonPrefixes(result.getCommonPrefixes());
}
return listing;
}
private LinkedListMultimap<String, String> headerArray2MultiValuedMap(Header[] headers) {
LinkedListMultimap<String, String> m = LinkedListMultimap.create();
if (headers != null) for (Header h : headers) {
m.put(h.getName(), h.getValue());
}
return m;
}
public static LinkedListMultimap<String, String> parseUriParameters(URI uri) {
LinkedListMultimap<String, String> params = LinkedListMultimap.create();
String query = uri.getQuery();
if (query != null) {
for (String param : query.split("&")) {
String[] kv = param.split("=");
if (kv.length >= 2) {
params.put(kv[0], param.substring(kv[0].length() + 1));
} else {
params.put(kv[0], "");
}
}
}
return params;
}
private static LinkedListMultimap<String, String> parseUriParameters(URI uri) {
LinkedListMultimap<String, String> params = LinkedListMultimap.create();
String query = uri.getQuery();
if (query != null) {
for (String param : query.split("&")) {
String[] kv = param.split("=");
if (kv.length >= 2) {
params.put(kv[0], param.substring(kv[0].length() + 1));
} else {
params.put(kv[0], "");
}
}
}
return params;
}
/**
* Set signature related headers when credential is properly set
*/
private MetricsHttpClient setAuthenticationHeaders(HttpPost post, byte[] data) {
if (this.client != null && credential != null) {
if (credential.getSecretKeyId() != null) {
String host = this.host.toHostString();
host = host.split(":")[0];
post.setHeader(AuthenticationConstants.HK_HOST, host);
// timestamp
String timestamp = Long.toString(clock.getCurrentEpoch());
post.setHeader(AuthenticationConstants.HK_TIMESTAMP, timestamp);
post.setHeader(HttpKeys.MI_DATE, HttpUtils.getGMTDatetime(new Date()));
// content md5
String md5 = BytesUtil
.bytesToHex(DigestUtil.digest(DigestUtil.DigestAlgorithm.MD5, data));
post.setHeader(com.xiaomi.infra.galaxy.sds.thrift.AuthenticationConstants.HK_CONTENT_MD5, md5);
LinkedListMultimap<String, String> headers = LinkedListMultimap.create();
for (Header header : post.getAllHeaders()) {
headers.put(header.getName().toLowerCase(), header.getValue());
}
try {
String authString = "Galaxy-V3 "
+ credential.getSecretKeyId()
+ ":"
+ Signer.signToBase64(HttpMethod.POST, post.getURI(), headers,
credential.getSecretKey(), SignAlgorithm.HmacSHA1);
post.setHeader(AuthenticationConstants.HK_AUTHORIZATION, authString);
} catch (Exception e) {
throw new RuntimeException("Failed to sign", e);
}
} else {
throw new RuntimeException("SecretKeyId must not be null");
}
}
return this;
}
private LinkedListMultimap<String, String> multimap(String... contents) {
LinkedListMultimap<String, String> result = LinkedListMultimap.create(contents.length / 2);
for (int i = 0; i < contents.length; i += 2) {
result.put(contents[i], contents[i+1]);
}
return result;
}
@Override
@SuppressWarnings("unchecked")
public Iterator<MarkerRange> iterator() {
// this should be part of PartitionStrategy
final LinkedListMultimap<String, FieldPartitioner> partitioners =
LinkedListMultimap.create();
for (FieldPartitioner fp : Accessor.getDefault().getFieldPartitioners(strategy)) {
partitioners.put(fp.getSourceName(), fp);
}
Iterator<MarkerRange.Builder> current = start(new MarkerRange.Builder(cmp));
// primarily loop over sources because the logical constraints are there
for (String source : partitioners.keySet()) {
Predicate constraint = predicates.get(source);
List<FieldPartitioner> fps = partitioners.get(source);
FieldPartitioner first = fps.get(0);
if (first instanceof CalendarFieldPartitioner) {
current = TimeDomain.get(strategy, source)
.addStackedIterator(constraint, current);
} else if (constraint instanceof In) {
current = add((In) constraint, fps, current);
} else if (constraint instanceof Range) {
current = add((Range) constraint, fps, current);
}
}
return Iterators.transform(current, new ToMarkerRangeFunction());
}
/**
* Set signature related headers when credential is properly set
*/
private GalaxyHttpClient setAuthenticationHeaders(HttpPost post, byte[] data, boolean supportAccountKey) {
if (this.client != null && credential != null) {
HttpAuthorizationHeader authHeader = null;
if (credential.getType() != null && credential.getSecretKeyId() != null) {
// signature is supported
if (AuthenticationConstants.SIGNATURE_SUPPORT.get(credential.getType())) {
// host
String host = this.host.toHostString();
host = host.split(":")[0];
post.setHeader(AuthenticationConstants.HK_HOST, host);
// timestamp
String timestamp = Long.toString(clock.getCurrentEpoch());
post.setHeader(AuthenticationConstants.HK_TIMESTAMP, timestamp);
post.setHeader(HttpKeys.MI_DATE, HttpUtils.getGMTDatetime(new Date()));
// content md5
String md5 = BytesUtil
.bytesToHex(DigestUtil.digest(DigestUtil.DigestAlgorithm.MD5, data));
post.setHeader(AuthenticationConstants.HK_CONTENT_MD5, md5);
// signature
LinkedListMultimap<String, String> headers = LinkedListMultimap.create();
for (Header header : post.getAllHeaders()) {
headers.put(header.getName().toLowerCase(), header.getValue());
}
try {
String authString = "Galaxy-V2 " + credential.getSecretKeyId() + ":" +
Signer.signToBase64(HttpMethod.POST, post.getURI(), headers,
credential.getSecretKey(), SignAlgorithm.HmacSHA1);
post.setHeader(AuthenticationConstants.HK_AUTHORIZATION, authString);
} catch (Exception e) {
throw new RuntimeException("Failed to sign", e);
}
} else {
authHeader = createSecretKeyHeader();
if (authHeader != null) {
authHeader.setSupportAccountKey(supportAccountKey);
post.setHeader(AuthenticationConstants.HK_AUTHORIZATION,
encodeAuthorizationHeader(authHeader));
}
}
}
}
return this;
}
private HttpRequest parseRequest(Element element, Evaluator evaluator, ResultRecorder resultRecorder) {
String contents = getTextAndRemoveIndent(element);
contents = replaceVariableReferences(evaluator, contents, resultRecorder);
SessionInputBufferImpl buffer = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), contents.length());
buffer.bind(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8)));
DefaultHttpRequestParser defaultHttpRequestParser = new DefaultHttpRequestParser(buffer);
LinkedListMultimap<String, String> queryParameters = LinkedListMultimap.create();
String method = "";
String url = "";
LinkedListMultimap<String, String> headers = LinkedListMultimap.create();
String body = null;
String server = null;
try {
org.apache.http.HttpRequest httpRequest = defaultHttpRequestParser.parse();
method = httpRequest.getRequestLine().getMethod();
url = httpRequest.getRequestLine().getUri();
if (url.startsWith("#")) {
url = "" + evaluator.evaluate(url);
}
Matcher matcher = Pattern.compile("(https?://[^/]+)(/.*)").matcher(url);
if (matcher.matches()) {
server = matcher.group(1);
url = matcher.group(2);
}
if (url.contains("?")) {
String[] urlAndQueryParameters = url.split("\\?");
url = urlAndQueryParameters[0];
for (String queryParameter : urlAndQueryParameters[1].split("&")) {
String[] parameter = queryParameter.split("=");
queryParameters.put(parameter[0], parameter[1]);
}
}
for (Header header : httpRequest.getAllHeaders()) {
headers.put(header.getName(), header.getValue());
}
if (buffer.hasBufferedData()) {
body = "";
while (buffer.hasBufferedData()) {
body += (char) buffer.read();
}
}
} catch (IOException | HttpException e) {
e.printStackTrace();
}
return new HttpRequest(method, url, headers, body, server, queryParameters);
}