io.gravitee.gateway.policy.impl.tracing.TracingReadWriteStream Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.gateway.policy.impl.tracing;
import io.gravitee.gateway.api.ExecutionContext;
import io.gravitee.gateway.api.buffer.Buffer;
import io.gravitee.gateway.api.handler.Handler;
import io.gravitee.gateway.api.stream.ReadStream;
import io.gravitee.gateway.api.stream.ReadWriteStream;
import io.gravitee.gateway.api.stream.WriteStream;
import io.gravitee.gateway.policy.Policy;
import io.gravitee.tracing.api.Span;
import io.gravitee.tracing.api.Tracer;
/**
* A traced {@link ReadWriteStream} used to trace beginning and ending of the policy execution.
*
* @author David BRASSELY (david.brassely at graviteesource.com)
* @author GraviteeSource Team
*/
public class TracingReadWriteStream implements ReadWriteStream {
private final Tracer tracer;
private final ReadWriteStream stream;
private final Policy policy;
private Span span;
public TracingReadWriteStream(final ExecutionContext context, final ReadWriteStream stream, final Policy policy) {
this.policy = policy;
this.tracer = context.getTracer();
this.stream = stream;
}
@Override
public ReadStream bodyHandler(Handler bodyHandler) {
span = tracer.span(this.policy.id()).withAttribute(TracingPolicy.SPAN_ATTRIBUTE, this.policy.id());
stream.bodyHandler(bodyHandler);
return this;
}
@Override
public ReadStream endHandler(Handler endHandler) {
stream.endHandler(endHandler);
return this;
}
@Override
public ReadStream pause() {
stream.pause();
return this;
}
@Override
public ReadStream resume() {
stream.resume();
return this;
}
@Override
public WriteStream write(Buffer chunk) {
stream.write(chunk);
return this;
}
@Override
public void end() {
stream.end();
span.end();
}
@Override
public void end(Buffer chunk) {
stream.end(chunk);
span.end();
}
@Override
public WriteStream drainHandler(Handler drainHandler) {
stream.drainHandler(drainHandler);
return this;
}
@Override
public boolean writeQueueFull() {
return stream.writeQueueFull();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy