package org.glassfish.grizzly.http;
import org.glassfish.grizzly.Closeable;
import org.glassfish.grizzly.OutputSink;
import org.glassfish.grizzly.attributes.Attribute;
import org.glassfish.grizzly.attributes.AttributeBuilder;
import org.glassfish.grizzly.attributes.AttributeHolder;
import org.glassfish.grizzly.attributes.AttributeStorage;
import org.glassfish.grizzly.filterchain.FilterChainContext;
public class HttpContext implements AttributeStorage {
private static final Attribute<HttpContext> HTTP_CONTEXT_ATTR =
AttributeBuilder.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(HttpContext.class.getName());
private final AttributeStorage contextStorage;
private final OutputSink outputSink;
private final Closeable closeable;
private final HttpRequestPacket request;
protected HttpContext(final AttributeStorage attributeStorage,
final OutputSink outputSink, final Closeable closeable,
final HttpRequestPacket request) {
this.contextStorage = attributeStorage;
this.closeable = closeable;
this.outputSink = outputSink;
this.request = request;
}
public HttpRequestPacket getRequest() {
return request;
}
public HttpContext attach(final FilterChainContext ctx) {
HTTP_CONTEXT_ATTR.set(ctx, this);
return this;
}
@Override
public final AttributeHolder getAttributes() {
return contextStorage.getAttributes();
}
public AttributeStorage getContextStorage() {
return contextStorage;
}
public OutputSink getOutputSink() {
return outputSink;
}
public Closeable getCloseable() {
return closeable;
}
public void close() {
closeable.closeSilently();
}
public static HttpContext newInstance(
final AttributeStorage attributeStorage,
final OutputSink outputSink,
final Closeable closeable,
final HttpRequestPacket request) {
return new HttpContext(attributeStorage,
outputSink, closeable, request);
}
public static HttpContext get(final FilterChainContext ctx) {
return HTTP_CONTEXT_ATTR.get(ctx);
}
}