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); }
/** * Enqueue an item with no expiry. * * @param key the queue * @param value the item as a Buf * @return a Future<Reponse> indicating success or failure. */ public Future<Response> set(String key, Buf value) { return this.set(key, value, Time.fromMilliseconds(0)); }
/** This sends off spans after the deadline is hit, no matter if it ended naturally or not. */ void flush(Time deadline) { for (Iterator<MutableSpan> i = spanMap.values().iterator(); i.hasNext(); ) { MutableSpan span = i.next(); if (span.started().$less$eq(deadline)) { i.remove(); span.addAnnotation(deadline, "finagle.flush"); report(span); } } }
@Override public Future<BoxedUnit> close() { return close(Time.Bottom()); }
synchronized MutableSpan addAnnotation(Time timestamp, String value) { if (annotations.isEmpty()) { span.timestamp(timestamp.inMicroseconds()); } if (!isComplete && (value.equals(CLIENT_RECV) || value.equals(SERVER_SEND) || value.equals(TimeoutFilter.TimeoutAnnotation()))) { if (!annotations.isEmpty()) { span.duration(timestamp.inMicroseconds() - annotations.get(0).timestamp); } isComplete = true; } annotations.add(Annotation.create(timestamp.inMicroseconds(), value, endpoint)); return this; }
/** * Enqueue an item with no expiry. * * @param key the queue * @param value the item as a Buf * @return a Future<Reponse> indicating success or failure. */ public Future<Response> set(String key, Buf value) { return this.set(key, value, Time.fromMilliseconds(0)); }
/** This sends off spans after the deadline is hit, no matter if it ended naturally or not. */ void flush(Time deadline) { for (Iterator<MutableSpan> i = spanMap.values().iterator(); i.hasNext(); ) { MutableSpan span = i.next(); if (span.started().$less$eq(deadline)) { i.remove(); span.addAnnotation(deadline, "finagle.flush"); report(span); } } }
@Override public Future<BoxedUnit> close() { return close(Time.Bottom()); }
synchronized MutableSpan addAnnotation(Time timestamp, String value) { if (annotations.isEmpty()) { span.timestamp(timestamp.inMicroseconds()); } if (!isComplete && (value.equals(CLIENT_RECV) || value.equals(SERVER_SEND) || value.equals(TimeoutFilter.TimeoutAnnotation()))) { if (!annotations.isEmpty()) { span.duration(timestamp.inMicroseconds() - annotations.get(0).timestamp()); } isComplete = true; } annotations.add(V1Annotation.create(timestamp.inMicroseconds(), value, endpoint)); return this; }
/** * Performs a put kestrel call with the provided expiration. * * @param queueName * @param exp * @param value */ public void set(String queueName, int exp, String value) { final Time expTime = Time.fromMilliseconds(exp); final ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(value.getBytes(CharsetUtil.UTF_8)); client.set(queueName, buffer, expTime); }
public void start(boolean leader) { logger.info("Starting placement policy"); TreeSet<ServerLoad> emptyServerLoads = new TreeSet<ServerLoad>(); for (String server : getServers()) { emptyServerLoads.add(new ServerLoad(server)); } load(emptyServerLoads); //Pre-Load so streams don't NPE if (leader) { //this is the leader shard logger.info("Shard is leader. Scheduling timed refresh."); placementRefreshTimer = new ScheduledThreadPoolTimer(1, "timer", true); placementRefreshTimer.schedule(Time.now(), refreshInterval, new Function0<BoxedUnit>() { @Override public BoxedUnit apply() { refresh(); return BoxedUnit.UNIT; } }); } else { logger.info("Shard is not leader. Watching for server load changes."); placementStateManager.watch(new PlacementStateManager.PlacementCallback() { @Override public void callback(TreeSet<ServerLoad> serverLoads) { if (!serverLoads.isEmpty()) { load(serverLoads); } } }); } }
/** This sends off spans after the deadline is hit, no matter if it ended naturally or not. */ void flush(Time deadline) { for (Iterator<MutableSpan> i = spanMap.values().iterator(); i.hasNext(); ) { MutableSpan span = i.next(); if (span.started().$less$eq(deadline)) { i.remove(); span.addAnnotation(deadline, "finagle.flush"); reporter.report(span.toSpan()); } } }
@Override public Future<BoxedUnit> close() { return close(Time.Bottom()); }
synchronized MutableSpan addAnnotation(Time timestamp, String value) { if (annotations.isEmpty()) { span.timestamp(timestamp.inMicroseconds()); } if (!isComplete && (value.equals(CLIENT_RECV) || value.equals(SERVER_SEND) || value.equals(TimeoutFilter.TimeoutAnnotation()))) { if (!annotations.isEmpty()) { span.duration(timestamp.inMicroseconds() - annotations.get(0).timestamp()); } isComplete = true; } annotations.add(V1Annotation.create(timestamp.inMicroseconds(), value, endpoint)); return this; }
/** * Performs a put kestrel call with the provided expiration. * * @param queueName * @param exp * @param value */ public void set(String queueName, int exp, String value) { final Time expTime = Time.fromMilliseconds(exp); final ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(value.getBytes(CharsetUtil.UTF_8)); client.set(queueName, buffer, expTime); }
private void advanceAndRecord(int millis, TraceId traceId, Annotation annotation) { time.advance(Duration.fromMilliseconds(millis)); recorder.record(new Record(traceId, Time.now(), annotation, empty())); }
/** * Performs a put with the byte array valye with an expiration * * @param queueName * @param exp * @param value */ public void set(String queueName, int exp, byte[] value) { final Time expTime = Time.fromMilliseconds(exp); final ChannelBuffer buffer = ChannelBufferUtils.bytesToChannelBuffer(value); client.set(queueName, buffer, expTime); }
/** * Performs a put with the byte array valye with an expiration * * @param queueName * @param exp * @param value */ public void set(String queueName, int exp, byte[] value) { final Time expTime = Time.fromMilliseconds(exp); final ChannelBuffer buffer = ChannelBufferUtils.bytesToChannelBuffer(value); client.set(queueName, buffer, expTime); }
@Override public void evaluate() throws Throwable { Time$.MODULE$.withTimeAt(Time.fromMilliseconds(epochMillis), new AbstractFunction1<TimeControl, Object>() { @Override public Object apply(TimeControl tc) { holder.set(tc); try { base.evaluate(); } catch (Throwable t) { throwable.set(t); } return null; } }); Throwable t = throwable.get(); if (t != null) throw t; } };
@Test public void unfinishedSpansArentImplicitlyReported() throws Exception { tracer.record(new Record(root, Time.fromMilliseconds(TODAY), new ServiceName("web"), empty())); tracer.record(new Record(root, Time.fromMilliseconds(TODAY), new Rpc("get"), empty())); tracer.record(new Record(root, Time.fromMilliseconds(TODAY), ClientSend$.MODULE$, empty())); tracer.reporter.flush(); assertThat(spansSent.take()).isEmpty(); }