@Override public FetchResponse fetch(FetchRequest request) { scala.collection.Traversable<Tuple2<TopicAndPartition, PartitionFetchInfo>> requestInfo = request.requestInfo(); java.util.Map<TopicAndPartition, Short> errorMap = new HashMap<>(); while (requestInfo.headOption().isDefined()) { // jfim: IntelliJ erroneously thinks the following line is an incompatible type error, but it's only because // it doesn't understand scala covariance when called from Java (ie. it thinks head() is of type A even though // it's really of type Tuple2[TopicAndPartition, PartitionFetchInfo]) Tuple2<TopicAndPartition, PartitionFetchInfo> t2 = requestInfo.head(); TopicAndPartition topicAndPartition = t2._1(); PartitionFetchInfo partitionFetchInfo = t2._2(); if (!topicAndPartition.topic().equals(topicName)) { errorMap.put(topicAndPartition, Errors.UNKNOWN_TOPIC_OR_PARTITION.code()); } else if (partitionLeaderIndices.length < topicAndPartition.partition()) { errorMap.put(topicAndPartition, Errors.UNKNOWN_TOPIC_OR_PARTITION.code()); } else if (partitionLeaderIndices[topicAndPartition.partition()] != index) { errorMap.put(topicAndPartition, Errors.NOT_LEADER_FOR_PARTITION.code()); } else { // Do nothing, we'll generate a fake message } requestInfo = requestInfo.tail(); } return new MockFetchResponse(errorMap); }
/** * Unsafely gets the HTTP/2 endpoint from the given ServerEndpoints. * * If no HTTP/2 endpoint exists this throws an IllegalArgumentException. */ public static ServerEndpoint getHttp2Endpoint(final ServerEndpoints serverEndpoints) { final scala.collection.Traversable<ServerEndpoint> possibleEndpoints = serverEndpoints.endpoints().filter(func(e -> e.expectedHttpVersions().contains("2"))); if (possibleEndpoints.size() == 0) { throw new IllegalArgumentException(String.format( "gRPC client can't automatically find HTTP/2 connection: " + "no valid endpoints available. %s", serverEndpoints )); } else if (possibleEndpoints.size() == 1) { return possibleEndpoints.head(); } else { // TODO: the decision on which HTTP/2 endpoint to use should be based on config (e.g. maybe the user set // `akka.grpc.client."".use-tls` to false for gRPC so this should return the non-TLS HTTP/2 endpoint on the list. return possibleEndpoints.filter(endpoint -> endpoint.ssl().isDefined()).head(); } }
Production p = (Production) s; if (p.items().size() == 3) { Terminal t = (Terminal) p.items().tail().head(); ul.separator = t.value(); ul.klabel = p.klabel().get();
/** * Unsafely gets the HTTP/2 endpoint from the given ServerEndpoints. * * If no HTTP/2 endpoint exists this throws an IllegalArgumentException. */ public static ServerEndpoint getHttp2Endpoint(final ServerEndpoints serverEndpoints) { final scala.collection.Traversable<ServerEndpoint> possibleEndpoints = serverEndpoints.endpoints().filter(func(e->e.expectedHttpVersions().contains("2"))); if (possibleEndpoints.size() != 1) { throw new IllegalArgumentException(String.format( "gRPC client can't automatically find HTTP/2 connection: " + "%s valid endpoints available: %s", possibleEndpoints.size(), serverEndpoints )); } return possibleEndpoints.head(); }
@Override public void incrementMessagesDropped(Throwable cause) { if (cause instanceof FinagleSender.WrappedException) cause = cause.getCause(); Seq<Traversable<String>> paths = Throwables.mkString(cause).inits().toSeq(); for (Iterator<Traversable<String>> i = paths.iterator(); i.hasNext();) { messagesDropped.counter(i.next().toSeq()).incr(); } }
public static StructType subsetSchema(StructType schema, final List<String> fieldNames) { Seq<StructField> fieldSeq = schema.toTraversable().filter(new AbstractFunction1<StructField, Object>() { @Override public Object apply(StructField field) { return fieldNames.contains(field.name()); } }).toSeq(); StructType subset = DataTypes.createStructType(JavaConversions.seqAsJavaList(fieldSeq)); return subset; }
@Override public Integer getValue() { return pool.queued().size(); } });
Production p = (Production) s; if (p.items().size() == 3) { Terminal t = (Terminal) p.items().tail().head(); ul.separator = t.value(); ul.klabel = p.klabel().get().name();
@Override public void incrementMessagesDropped(Throwable cause) { if (cause instanceof FinagleSender.WrappedException) cause = cause.getCause(); Seq<Traversable<String>> paths = Throwables.mkString(cause).inits().toSeq(); for (Iterator<Traversable<String>> i = paths.iterator(); i.hasNext();) { messagesDropped.counter(i.next().toSeq()).incr(); } }
@Override public Integer getValue() { return pool.inUse().size(); } });
final ProductionItem body; if (cfgInfo.isLeafCell(p.sort())) { body = p.items().tail().head(); } else { body = NonTerminal(Sorts.Bag());
@Override public void incrementMessagesDropped(Throwable cause) { Seq<Traversable<String>> paths = Throwables.mkString(cause).inits().toSeq(); for (Iterator<Traversable<String>> i = paths.iterator(); i.hasNext();) { messagesDropped.counter(i.next().toSeq()).incr(); } }
@Override public Integer getValue() { return pool.availables().size(); } });
MySqlConnectionPool(final MySQLConnectionFactory connFactory, final PoolConfiguration poolConfiguration, final MetricFactory metricFactory) { _pool = new ConnectionPool<>(connFactory, poolConfiguration, ScalaFutureHelper.ctx); this.metricFactory = metricFactory; if (metricFactory != null) { metricFactory.registerGauge("old_MysqlAsyncConnectionPool", "available", () -> _pool.availables().size()); metricFactory.registerGauge("old_MysqlAsyncConnectionPool", "waiting", () -> _pool.queued().size()); metricFactory.registerGauge("old_MysqlAsyncConnectionPool", "inUse", () -> _pool.inUse().size()); sendQueryCounter = metricFactory.createCounter("old_MysqlAsyncConnectionPool", "sendQueryCounter"); sendQueryTimer = metricFactory.createTimer("old_MysqlAsyncConnectionPool", "sendQueryTimer"); preparedStatementCounter = metricFactory.createCounter("old_MysqlAsyncConnectionPool", "preparedStatementCounter"); preparedStatementTimer = metricFactory.createTimer("old_MysqlAsyncConnectionPool", "preparedStatementTimer"); } else { sendQueryCounter = null; sendQueryTimer = null; preparedStatementCounter = null; preparedStatementTimer = null; } }