private Tuple2<Integer, Double> maxAndMean(List<QueryRatePerSecond> l) { int max = Integer.MIN_VALUE; double sum = 0.0d; if (l.size() == 0) { return new Tuple2<>(Integer.valueOf(0), Double.valueOf(0.0)); } for (QueryRatePerSecond qps : l) { sum += (double) qps.howMany; if (qps.howMany > max) { max = qps.howMany; } } return new Tuple2<>(Integer.valueOf(max), Double.valueOf(sum / (double) l.size())); }
/** * Wait for up to "timeout" milliseconds for an incoming message. This hides * spurious wakeup, but InterruptedException will be propagated. * * @param timeout * maximum time to wait for message in milliseconds * @return a Pair instance containing the reason for returning and the * message possible received * @throws InterruptedException if the waiting thread is interrupted */ public Tuple2<MessageState, T> get(long timeout) throws InterruptedException { long barrier = System.currentTimeMillis() + timeout; synchronized (lock) { while (!received) { long t = System.currentTimeMillis(); if (t >= barrier) { return new Tuple2<>(MessageState.TIMEOUT, null); } lock.wait(barrier - t); } return new Tuple2<>(MessageState.VALID, message); } }
private static List<Tuple2<String, Double>> buildPercentileList(DoubleHistogram histogram) { List<Tuple2<String, Double>> prefixAndValues = new ArrayList<>(2); prefixAndValues.add(new Tuple2<>("95", histogram.getValueAtPercentile(95.0d))); prefixAndValues.add(new Tuple2<>("99", histogram.getValueAtPercentile(99.0d))); return prefixAndValues; }
private static Tuple2<String[], Value[]> buildParameters(Map<String, ?> properties) { String[] dimensions = properties.keySet().toArray(new String[0]); Arrays.sort(dimensions); Value[] location = new Value[dimensions.length]; for (int i = 0; i < dimensions.length; ++i) { location[i] = Value.of(String.valueOf(properties.get(dimensions[i]))); } return new Tuple2<>(dimensions, location); }
private Tuple2<File, String> createTuple(String name) { return new Tuple2<>(file(name), name); }
private void validateRouting(SchemaValidator validator, Tuple2<File, String> directory) throws IOException { File dir = directory.first; if ( ! dir.isDirectory()) return; String directoryName = directory.second; for (File f : dir.listFiles(xmlFilter)) { if (f.isDirectory()) validateRouting(validator, new Tuple2<>(f, directoryName + File.separator + f.getName())); else validator.validate(f, directoryName + File.separator + f.getName()); } }
private static Tuple2<Boolean, Integer> chooseStatusFromError(ErrorMessage error) { Tuple2<Boolean, Integer> webServiceStatus = chooseWebServiceStatus(error); if (webServiceStatus.first) { return webServiceStatus; } if (error.getCode() == NO_BACKENDS_IN_SERVICE.code) return new Tuple2<>(true, Response.Status.SERVICE_UNAVAILABLE); if (error.getCode() == TIMEOUT.code) return new Tuple2<>(true, Response.Status.GATEWAY_TIMEOUT); if (error.getCode() == BACKEND_COMMUNICATION_ERROR.code) return new Tuple2<>(true, Response.Status.SERVICE_UNAVAILABLE); if (error.getCode() == ILLEGAL_QUERY.code) return new Tuple2<>(true, Response.Status.BAD_REQUEST); if (error.getCode() == INVALID_QUERY_PARAMETER.code) return new Tuple2<>(true, Response.Status.BAD_REQUEST); return NO_MATCH; }
private static Tuple2<Boolean, Integer> chooseWebServiceStatus(ErrorMessage error) { if (isHttpStatusCode(error.getCode())) return new Tuple2<>(true, error.getCode()); if (error.getCode() == FORBIDDEN.code) return new Tuple2<>(true, Response.Status.FORBIDDEN); if (error.getCode() == UNAUTHORIZED.code) return new Tuple2<>(true, Response.Status.UNAUTHORIZED); if (error.getCode() == NOT_FOUND.code) return new Tuple2<>(true, Response.Status.NOT_FOUND); if (error.getCode() == BAD_REQUEST.code) return new Tuple2<>(true, Response.Status.BAD_REQUEST); if (error.getCode() == INTERNAL_SERVER_ERROR.code) return new Tuple2<>(true, Response.Status.INTERNAL_SERVER_ERROR); if (error.getCode() == INSUFFICIENT_STORAGE.code) return new Tuple2<>(true, Response.Status.INSUFFICIENT_STORAGE); return NO_MATCH; }
private Tuple2<String, Chain<Searcher>> resolveChain(String explicitChainName) { String chainName = explicitChainName; if (chainName == null) { chainName = defaultSearchChainName; } Chain<Searcher> searchChain = searchChainRegistry.getChain(chainName); if (searchChain == null && explicitChainName == null) { // explicit chain not found should cause error chainName = fallbackSearchChain; searchChain = searchChainRegistry.getChain(chainName); } return new Tuple2<>(chainName, searchChain); }
private Tuple2<Integer, Reply> createEmptyReplyResult() { return new Tuple2<>(null, (Reply)new EmptyReply()); }
static Tuple2<HttpResponse, Integer> doCheckProtocolVersion(List<String> clientSupportedVersions) { List<String> washedClientVersions = splitVersions(clientSupportedVersions); if (washedClientVersions == null || washedClientVersions.isEmpty()) { return new Tuple2<>(new ErrorHttpResponse( Headers.HTTP_NOT_ACCEPTABLE, "Request did not contain " + Headers.VERSION + "header. Server supports protocol versions " + serverSupportedVersions), -1); } //select the highest version supported by both parties //this could be extended when we support a gazillion versions - but right now: keep it simple. int version; if (washedClientVersions.contains("3")) { version = 3; } else { return new Tuple2<>(new ErrorHttpResponse( Headers.HTTP_NOT_ACCEPTABLE, "Could not parse " + Headers.VERSION + "header of request (values: " + washedClientVersions + "). Server supports protocol versions " + serverSupportedVersions), -1); } return new Tuple2<>(null, version); }
public Tuple2<Integer, Reply> mergedReply() { if (shouldReturnErrorReply()) { return createMergedErrorReplyResult(); } else if (!successfullyMergedAtLeastOneReply()) { return createEmptyReplyResult(); } return new Tuple2<>(successIndex, successReply); }
public AppSubDirs(File root) { this.root = new Tuple2<>(root, root.getName()); rules = createTuple(ApplicationPackage.RULES_DIR.getRelative()); searchchains = createTuple(ApplicationPackage.SEARCHCHAINS_DIR); docprocchains = createTuple(ApplicationPackage.DOCPROCCHAINS_DIR); routingtables = createTuple(ApplicationPackage.ROUTINGTABLES_DIR); configDefs = createTuple(ApplicationPackage.CONFIG_DEFINITIONS_DIR); searchdefinitions = createTuple(ApplicationPackage.SEARCH_DEFINITIONS_DIR.getRelative()); }
later.add(new Tuple2<>(progress, processing)); } else if (DocumentProcessor.Progress.DONE.equals(progress)) { processingsDone.add(processing);
for (int i=0; i<numberOfFields; ++i) { fieldIdsAndLengths.add(new Tuple2<>(getInt1_4Bytes(null), getInt2_4_8Bytes(null)));
for (int i=0; i<numberOfFields; ++i) { fieldIdsAndLengths.add(new Tuple2<>(getInt1_4Bytes(null), getInt2_4_8Bytes(null)));
for (int i=0; i<numberOfFields; ++i) { fieldIdsAndLengths.add(new Tuple2<>(getInt1_4Bytes(null), getInt2_4_8Bytes(null)));
for (int i=0; i<numberOfFields; ++i) { fieldIdsAndLengths.add(new Tuple2<>(getInt1_4Bytes(null), getInt2_4_8Bytes(null)));