@Override public RecordMetadata get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { try { FutureUtils.result(dlsnFuture, Duration.apply(timeout, unit)); // TODO: align the DLSN concepts with kafka concepts return new RecordMetadata(new TopicPartition(topic, 0), -1L, -1L); } catch (DLInterruptedException e) { throw new InterruptedException("Interrupted on waiting for response"); } catch (IOException e) { throw new ExecutionException("Error on waiting for response", e); } } }
public MovingAverageRateFactory(Timer timer) { this.avgs = new CopyOnWriteArrayList<SampledMovingAverageRate>(); this.timer = timer; Function0<BoxedUnit> sampleTask = new Function0<BoxedUnit>() { public BoxedUnit apply() { sampleAll(); return null; } }; this.timerTask = timer.schedulePeriodically( Time.now(), Duration.fromSeconds(DEFAULT_INTERVAL_SECS), sampleTask); }
private ClientBuilder getDefaultClientBuilder() { return ClientBuilder.get() .hostConnectionLimit(1) .tcpConnectTimeout(Duration.fromMilliseconds(200)) .connectTimeout(Duration.fromMilliseconds(200)) .requestTimeout(Duration.fromSeconds(1)); }
@Override public void unlock() { Future<BoxedUnit> unlockResult = asyncUnlock(); try { Await.result(unlockResult, Duration.fromMilliseconds(lockOpTimeout)); } catch (TimeoutException toe) { // This shouldn't happen unless we lose a watch, and may result in a leaked lock. LOG.error("Timeout unlocking {} owned by {} : ", new Object[] { lockPath, lockId, toe }); } catch (Exception e) { LOG.warn("{} failed to unlock {} : ", new Object[] { lockId, lockPath, e }); } }
/** * Await for the transmit to be complete * * @param timeout * wait timeout * @param unit * wait timeout unit */ int awaitTransmitComplete(long timeout, TimeUnit unit) throws Exception { return Await.result(transmitComplete, Duration.fromTimeUnit(timeout, unit)); }
closeWaitDuration = Duration.Top(); } else { closeWaitDuration = Duration.fromMilliseconds(writerCloseTimeoutMs);
@Test public void flushesIncompleteSpans() throws Exception { advanceAndRecord(0, root, new Annotation.Rpc("GET")); advanceAndRecord(15, root, new Annotation.ServiceName("frontend")); advanceAndRecord(0, root, Annotation.ServerRecv$.MODULE$); // Note: there's no ServerSend() which would complete the span. time.advance(recorder.ttl.plus(Duration.fromMilliseconds(1))); // advance timer timer.tick(); // invokes a flush Span span = spansSent.take(); assertThat(span.id()).isEqualTo(root.spanId().toString()); assertThat(span.name()).isEqualTo("get"); assertThat(span.kind()).isEqualTo(Span.Kind.SERVER); assertThat(span.annotations()).extracting(zipkin2.Annotation::value).containsExactly( "finagle.flush" ); assertThat(span.duration()).isNull(); }
/** * Wait for the result until it completes. * * @param result result to wait * @return the result * @throws IOException when encountered exceptions on the result */ public static <T> T result(Future<T> result) throws IOException { return result(result, Duration.Top()); }
synchronized String sendNextWrite() { long elapsedMs = stopwatch.elapsed(TimeUnit.MILLISECONDS); if (elapsedMs > requestTimeoutMs || numTriedStreams >= numStreams) { fail(new IndividualRequestTimeoutException(Duration.fromMilliseconds(elapsedMs))); return null; } try { return sendWriteToStream(nextStream); } finally { nextStream = (nextStream + 1) % numStreams; ++numTriedStreams; } }
logger.info("Waiting for closing all streams ..."); try { Await.result(closeResult, Duration.fromTimeUnit(5, TimeUnit.MINUTES)); logger.info("Closed all streams in {} millis.", closeStreamsStopwatch.elapsed(TimeUnit.MILLISECONDS));
logger.info("Using thriftmux."); Tuple2<Transport.Liveness, Stack.Param<Transport.Liveness>> livenessParam = new Transport.Liveness( Duration.Top(), Duration.Top(), Option.apply((Object) Boolean.valueOf(true))).mk(); serverBuilder = serverBuilder.stack(ThriftMuxServer$.MODULE$.configured(livenessParam._1(), livenessParam._2()));
public void start() { Duration[] defaultLatchIntervals = {Duration.apply(1, TimeUnit.MINUTES)}; @SuppressWarnings("deprecation") AdminServiceFactory adminServiceFactory = new AdminServiceFactory( this.mPort, 20, List$.MODULE$.<StatsFactory>empty(), Option.<String>empty(), List$.MODULE$.<Regex>empty(), Map$.MODULE$.<String, CustomHttpHandler>empty(), JavaConversions .asScalaBuffer(Arrays.asList(defaultLatchIntervals)).toList() ); RuntimeEnvironment runtimeEnvironment = new RuntimeEnvironment(this); adminServiceFactory.apply(runtimeEnvironment); try { Properties properties = new Properties(); properties.load(this.getClass().getResource("build.properties").openStream()); String buildRevision = properties.getProperty("build_revision", "unknown"); LOG.info("build.properties build_revision: {}", properties.getProperty("build_revision", "unknown")); StatsUtil.setLabel("secor.build_revision", buildRevision); } catch (Throwable t) { LOG.error("Failed to load properties from build.properties", t); } } }
public static <T> T validateFutureSucceededAndGetResult(Future<T> future) throws Exception { try { return Await.result(future, Duration.fromSeconds(10)); } catch (Exception ex) { fail("unexpected exception " + ex.getClass().getName()); throw ex; } } }
private ClientBuilder getDefaultClientBuilder() { return ClientBuilder.get() .hostConnectionLimit(1) .tcpConnectTimeout(Duration.fromMilliseconds(200)) .connectTimeout(Duration.fromMilliseconds(200)) .requestTimeout(Duration.fromSeconds(1)); }
private void advance(TimeControl time, MockTimer timer, int timeMs) { Duration duration = Duration.fromMilliseconds(timeMs); time.advance(duration); timer.tick(); }
@Override protected final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final int profileDurationSecs = HttpServletRequestParams.getInt(req, "seconds", 10); final int profilePollRate = HttpServletRequestParams.getInt(req, "hz", 100); LOG.info("Collecting CPU profile for " + profileDurationSecs + " seconds at " + profilePollRate + " Hz"); Duration sampleDuration = Duration.fromTimeUnit(profileDurationSecs, TimeUnit.SECONDS); CpuProfile profile = CpuProfile.recordInThread(sampleDuration, profilePollRate, stateToProfile).get(); resp.setHeader("Content-Type", "pprof/raw"); resp.setStatus(HttpServletResponse.SC_OK); OutputStream responseBody = resp.getOutputStream(); try { profile.writeGoogleProfile(responseBody); } finally { Closeables.close(responseBody, /* swallowIOException */ true); } } }
logger.info("Using thriftmux."); Tuple2<Transport.Liveness, Stack.Param<Transport.Liveness>> livenessParam = new Transport.Liveness( Duration.Top(), Duration.Top(), Option.apply((Object) Boolean.valueOf(true))).mk(); serverBuilder = serverBuilder.stack( ThriftMuxServer$.MODULE$.configured(livenessParam._1(), livenessParam._2()));