protected BaseZuulFilterRunner(FilterType filterType, FilterUsageNotifier usageNotifier, FilterRunner<O, ?> nextStage) { this.usageNotifier = Preconditions.checkNotNull(usageNotifier, "filter usage notifier"); this.nextStage = nextStage; this.RUNNING_FILTER_IDX_SESSION_CTX_KEY = filterType + "RunningFilterIndex"; this.AWAITING_BODY_FLAG_SESSION_CTX_KEY = filterType + "IsAwaitingBody"; }
public void record(long nanoAmount) { if (nanoAmount >= 0) { totalTime.add(nanoAmount); count.increment(); max.max(nanoAmount); } }
@Override public void calcMeasurements(List<Measurement> measurements, long msNow, long secondInterval) { long currentCount = count.longValue(); long currentTotalTime = totalTime.longValue(); measurements.add(newMeasurement(idCount, msNow, (double) (currentCount - lastCount) / secondInterval)); measurements .add(newMeasurement(idTotalTime, msNow, (currentTotalTime - lastTotalTime) / secondInterval * CNV_SECONDS)); measurements.add(newMeasurement(idMax, msNow, max.get() * CNV_SECONDS)); lastCount = currentCount; lastTotalTime = currentTotalTime; // maybe lost some max value, but not so important? max.set(0); } }
private AsciiSet(boolean[] members) { this.members = Preconditions.checkNotNull(members, "members array cannot be null"); this.pattern = toPattern(members); }
/** Create a new instance. */ Regex(String k, String v, boolean ignoreCase, String name) { this.k = Preconditions.checkNotNull(k, "k"); this.v = Preconditions.checkNotNull(v, "v"); if (ignoreCase) { this.pattern = PatternMatcher.compile("^" + v).ignoreCase(); } else { this.pattern = PatternMatcher.compile("^" + v); } this.name = Preconditions.checkNotNull(name, "name"); }
/** * How long to delay before retrying if the request is throttled. This will get doubled * for each attempt that is throttled. Unit is milliseconds. */ public HttpRequestBuilder withInitialRetryDelay(long delay) { Preconditions.checkArg(delay >= 0L, "initial retry delay must be >= 0"); this.initialRetryDelay = delay; return this; }
/** Create a new instance. */ public SwapMeter(Registry registry, Id id, T underlying) { this.registry = registry; this.id = id; this.underlying = unwrap(underlying); }
/** Returns a set that matches no characters. */ public static AsciiSet none() { final boolean[] members = new boolean[128]; return new AsciiSet(members); }
protected BaseZuulFilterRunner(FilterType filterType, FilterUsageNotifier usageNotifier, FilterRunner<O, ?> nextStage) { this.usageNotifier = Preconditions.checkNotNull(usageNotifier, "filter usage notifier"); this.nextStage = nextStage; this.RUNNING_FILTER_IDX_SESSION_CTX_KEY = filterType + "RunningFilterIndex"; this.AWAITING_BODY_FLAG_SESSION_CTX_KEY = filterType + "IsAwaitingBody"; }
private AsciiSet(boolean[] members) { this.members = Preconditions.checkNotNull(members, "members array cannot be null"); this.pattern = toPattern(members); }
protected final AtomicInteger getRunningFilterIndex(I zuulMesg) { final SessionContext ctx = zuulMesg.getContext(); return (AtomicInteger) Preconditions.checkNotNull(ctx.get(RUNNING_FILTER_IDX_SESSION_CTX_KEY), "runningFilterIndex"); }
private final void runFilters(final T mesg, final AtomicInteger runningFilterIdx) { T inMesg = mesg; String filterName = "-"; try { Preconditions.checkNotNull(mesg, "Input message"); int i = runningFilterIdx.get(); while (i < filters.length) { final ZuulFilter<T, T> filter = filters[i]; filterName = filter.filterName(); final T outMesg = filter(filter, inMesg); if (outMesg == null) { return; //either async filter or waiting for the message body to be buffered } inMesg = outMesg; i = runningFilterIdx.incrementAndGet(); } //Filter chain has reached its end, pass result to the next stage invokeNextStage(inMesg); } catch (Exception ex) { handleException(inMesg, filterName, ex); } }
protected final AtomicInteger getRunningFilterIndex(I zuulMesg) { final SessionContext ctx = zuulMesg.getContext(); return (AtomicInteger) Preconditions.checkNotNull(ctx.get(RUNNING_FILTER_IDX_SESSION_CTX_KEY), "runningFilterIndex"); }
private final void runFilters(final T mesg, final AtomicInteger runningFilterIdx) { T inMesg = mesg; String filterName = "-"; try { Preconditions.checkNotNull(mesg, "Input message"); int i = runningFilterIdx.get(); while (i < filters.length) { final ZuulFilter<T, T> filter = filters[i]; filterName = filter.filterName(); final T outMesg = filter(filter, inMesg); if (outMesg == null) { return; //either async filter or waiting for the message body to be buffered } inMesg = outMesg; i = runningFilterIdx.incrementAndGet(); } //Filter chain has reached its end, pass result to the next stage invokeNextStage(inMesg); } catch (Exception ex) { handleException(inMesg, filterName, ex); } }
@Override public void filter(final HttpRequestMessage zuulReq) { if (zuulReq.getContext().isCancelled()) { zuulReq.disposeBufferedBody(); logger.debug("Request was cancelled, UUID {}", zuulReq.getContext().getUUID()); return; } final String endpointName = getEndPointName(zuulReq.getContext()); try { Preconditions.checkNotNull(zuulReq, "input message"); final ZuulFilter<HttpRequestMessage, HttpResponseMessage> endpoint = getEndpoint(endpointName, zuulReq); logger.debug("Got endpoint {}, UUID {}", endpoint.filterName(), zuulReq.getContext().getUUID()); setEndpoint(zuulReq, endpoint); final HttpResponseMessage zuulResp = filter(endpoint, zuulReq); if ((zuulResp != null)&&(! (endpoint instanceof ProxyEndpoint))) { //EdgeProxyEndpoint calls invokeNextStage internally logger.debug("Endpoint calling invokeNextStage, UUID {}", zuulReq.getContext().getUUID()); invokeNextStage(zuulResp); } } catch (Exception ex) { handleException(zuulReq, endpointName, ex); } }
@Override public void filter(final HttpRequestMessage zuulReq, final HttpContent chunk) { if (zuulReq.getContext().isCancelled()) { chunk.release(); return; } String endpointName = "-"; try { ZuulFilter<HttpRequestMessage, HttpResponseMessage> endpoint = Preconditions.checkNotNull( getEndpoint(zuulReq), "endpoint"); endpointName = endpoint.filterName(); final HttpContent newChunk = endpoint.processContentChunk(zuulReq, chunk); if (newChunk != null) { //Endpoints do not directly forward content chunks to next stage in the filter chain. zuulReq.bufferBodyContents(newChunk); //deallocate original chunk if necessary if (newChunk != chunk) { chunk.release(); } if (isFilterAwaitingBody(zuulReq) && zuulReq.hasCompleteBody() && !(endpoint instanceof ProxyEndpoint)) { //whole body has arrived, resume filter chain invokeNextStage(filter(endpoint, zuulReq)); } } } catch (Exception ex) { handleException(zuulReq, endpointName, ex); } }
@Override public void filter(final HttpRequestMessage zuulReq) { if (zuulReq.getContext().isCancelled()) { zuulReq.disposeBufferedBody(); logger.debug("Request was cancelled, UUID {}", zuulReq.getContext().getUUID()); return; } final String endpointName = getEndPointName(zuulReq.getContext()); try { Preconditions.checkNotNull(zuulReq, "input message"); final ZuulFilter<HttpRequestMessage, HttpResponseMessage> endpoint = getEndpoint(endpointName, zuulReq); logger.debug("Got endpoint {}, UUID {}", endpoint.filterName(), zuulReq.getContext().getUUID()); setEndpoint(zuulReq, endpoint); final HttpResponseMessage zuulResp = filter(endpoint, zuulReq); if ((zuulResp != null)&&(! (endpoint instanceof ProxyEndpoint))) { //EdgeProxyEndpoint calls invokeNextStage internally logger.debug("Endpoint calling invokeNextStage, UUID {}", zuulReq.getContext().getUUID()); invokeNextStage(zuulResp); } } catch (Exception ex) { handleException(zuulReq, endpointName, ex); } }
String filterName = "-"; try { Preconditions.checkNotNull(inMesg, "input message");
@Override public void filter(final HttpRequestMessage zuulReq, final HttpContent chunk) { if (zuulReq.getContext().isCancelled()) { chunk.release(); return; } String endpointName = "-"; try { ZuulFilter<HttpRequestMessage, HttpResponseMessage> endpoint = Preconditions.checkNotNull( getEndpoint(zuulReq), "endpoint"); endpointName = endpoint.filterName(); final HttpContent newChunk = endpoint.processContentChunk(zuulReq, chunk); if (newChunk != null) { //Endpoints do not directly forward content chunks to next stage in the filter chain. zuulReq.bufferBodyContents(newChunk); //deallocate original chunk if necessary if (newChunk != chunk) { chunk.release(); } if (isFilterAwaitingBody(zuulReq) && zuulReq.hasCompleteBody() && !(endpoint instanceof ProxyEndpoint)) { //whole body has arrived, resume filter chain invokeNextStage(filter(endpoint, zuulReq)); } } } catch (Exception ex) { handleException(zuulReq, endpointName, ex); } }
String filterName = "-"; try { Preconditions.checkNotNull(inMesg, "input message");