use of com.netflix.zuul.passport.CurrentPassport in project zuul by Netflix.
the class ZuulFilterChainRunner method filter.
@Override
public void filter(T inMesg, HttpContent chunk) {
String filterName = "-";
try (TaskCloseable ignored = PerfMark.traceTask(this, s -> s.getClass().getSimpleName() + ".filterChunk")) {
addPerfMarkTags(inMesg);
Preconditions.checkNotNull(inMesg, "input message");
final AtomicInteger runningFilterIdx = getRunningFilterIndex(inMesg);
final int limit = runningFilterIdx.get();
for (int i = 0; i < limit; i++) {
final ZuulFilter<T, T> filter = filters[i];
filterName = filter.filterName();
if ((!filter.isDisabled()) && (!shouldSkipFilter(inMesg, filter))) {
final HttpContent newChunk = filter.processContentChunk(inMesg, chunk);
if (newChunk == null) {
// Filter wants to break the chain and stop propagating this chunk any further
return;
}
// deallocate original chunk if necessary
if ((newChunk != chunk) && (chunk.refCnt() > 0)) {
chunk.release(chunk.refCnt());
}
chunk = newChunk;
}
}
if (limit >= filters.length) {
// Filter chain has run to end, pass down the channel pipeline
invokeNextStage(inMesg, chunk);
} else {
inMesg.bufferBodyContents(chunk);
boolean isAwaitingBody = isFilterAwaitingBody(inMesg);
// Record passport states for start and end of buffering bodies.
if (isAwaitingBody) {
CurrentPassport passport = CurrentPassport.fromSessionContext(inMesg.getContext());
if (inMesg.hasCompleteBody()) {
if (inMesg instanceof HttpRequestMessage) {
passport.addIfNotAlready(PassportState.FILTERS_INBOUND_BUF_END);
} else if (inMesg instanceof HttpResponseMessage) {
passport.addIfNotAlready(PassportState.FILTERS_OUTBOUND_BUF_END);
}
} else {
if (inMesg instanceof HttpRequestMessage) {
passport.addIfNotAlready(PassportState.FILTERS_INBOUND_BUF_START);
} else if (inMesg instanceof HttpResponseMessage) {
passport.addIfNotAlready(PassportState.FILTERS_OUTBOUND_BUF_START);
}
}
}
if (isAwaitingBody && inMesg.hasCompleteBody()) {
// whole body has arrived, resume filter chain
runFilters(inMesg, runningFilterIdx);
}
}
} catch (Exception ex) {
handleException(inMesg, filterName, ex);
}
}
use of com.netflix.zuul.passport.CurrentPassport in project zuul by Netflix.
the class PooledConnection method release.
public void release() {
if (released) {
return;
}
if (isActive()) {
if (connectionState != ConnectionState.WRITE_READY) {
closeWrtBusyConnCounter.increment();
}
}
if (!isShouldClose() && connectionState != ConnectionState.WRITE_READY) {
CurrentPassport passport = CurrentPassport.fromChannel(channel);
LOG.info("Error - Attempt to put busy connection into the pool = " + this.toString() + ", " + String.valueOf(passport));
this.shouldClose = true;
}
// reset the connectionState
connectionState = ConnectionState.WRITE_READY;
released = true;
channelManager.release(this);
}
use of com.netflix.zuul.passport.CurrentPassport in project zuul by Netflix.
the class PerServerConnectionPool method release.
@Override
public boolean release(PooledConnection conn) {
if (conn == null) {
return false;
}
if (conn.isInPool()) {
return false;
}
// Get the eventloop for this channel.
EventLoop eventLoop = conn.getChannel().eventLoop();
Deque<PooledConnection> connections = getPoolForEventLoop(eventLoop);
CurrentPassport passport = CurrentPassport.fromChannel(conn.getChannel());
// Discard conn if already at least above waterline in the pool already for this server.
int poolWaterline = config.perServerWaterline();
if (poolWaterline > -1 && connections.size() >= poolWaterline) {
closeAboveHighWaterMarkCounter.increment();
conn.close();
conn.setInPool(false);
return false;
} else // Attempt to return connection to the pool.
if (connections.offer(conn)) {
conn.setInPool(true);
connsInPool.incrementAndGet();
passport.add(PassportState.ORIGIN_CH_POOL_RETURNED);
return true;
} else {
// If the pool is full, then close the conn and discard.
conn.close();
conn.setInPool(false);
return false;
}
}
Aggregations