Package org.glassfish.jersey.server
Class ChunkedOutput<T>
- java.lang.Object
-
- javax.ws.rs.core.GenericType<T>
-
- org.glassfish.jersey.server.ChunkedOutput<T>
-
- Type Parameters:
T
- chunk type.
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ChunkedOutput<T> extends javax.ws.rs.core.GenericType<T> implements java.io.Closeable
Used for sending messages in "typed" chunks. Useful for long running processes, which needs to produce partial responses.
-
-
Field Summary
Fields Modifier and Type Field Description private AsyncContext
asyncContext
private byte[]
chunkDelimiter
private boolean
closed
private javax.ws.rs.container.ConnectionCallback
connectionCallback
private boolean
flushing
private java.util.concurrent.BlockingDeque<T>
queue
private ContainerRequest
requestContext
private RequestScope
requestScope
private RequestContext
requestScopeContext
private ContainerResponse
responseContext
private java.util.concurrent.atomic.AtomicBoolean
resumed
private static byte[]
ZERO_LENGTH_DELIMITER
-
Constructor Summary
Constructors Modifier Constructor Description protected
ChunkedOutput()
Create newChunkedOutput
.protected
ChunkedOutput(byte[] chunkDelimiter)
Create newChunkedOutput
with a custom chunk delimiter.protected
ChunkedOutput(byte[] chunkDelimiter, javax.inject.Provider<AsyncContext> asyncContextProvider)
Create newChunkedOutput
with a custom chunk delimiter.ChunkedOutput(java.lang.reflect.Type chunkType)
CreateChunkedOutput
with specified type.ChunkedOutput(java.lang.reflect.Type chunkType, byte[] chunkDelimiter)
Create newChunkedOutput
with a custom chunk delimiter.ChunkedOutput(java.lang.reflect.Type chunkType, java.lang.String chunkDelimiter)
Create newChunkedOutput
with a custom chunk delimiter.protected
ChunkedOutput(java.lang.String chunkDelimiter)
Create newChunkedOutput
with a custom chunk delimiter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this response - it will be finalized and underlying connections will be closed or made available for another response.boolean
equals(java.lang.Object obj)
protected void
flushQueue()
int
hashCode()
boolean
isClosed()
Get state information.(package private) void
setContext(RequestScope requestScope, RequestContext requestScopeContext, ContainerRequest requestContext, ContainerResponse responseContext, javax.ws.rs.container.ConnectionCallback connectionCallbackRunner)
Set context used for writing chunks.java.lang.String
toString()
void
write(T chunk)
Write a chunk.
-
-
-
Field Detail
-
ZERO_LENGTH_DELIMITER
private static final byte[] ZERO_LENGTH_DELIMITER
-
queue
private final java.util.concurrent.BlockingDeque<T> queue
-
chunkDelimiter
private final byte[] chunkDelimiter
-
resumed
private final java.util.concurrent.atomic.AtomicBoolean resumed
-
flushing
private boolean flushing
-
closed
private volatile boolean closed
-
asyncContext
private volatile AsyncContext asyncContext
-
requestScope
private volatile RequestScope requestScope
-
requestScopeContext
private volatile RequestContext requestScopeContext
-
requestContext
private volatile ContainerRequest requestContext
-
responseContext
private volatile ContainerResponse responseContext
-
connectionCallback
private volatile javax.ws.rs.container.ConnectionCallback connectionCallback
-
-
Constructor Detail
-
ChunkedOutput
protected ChunkedOutput()
Create newChunkedOutput
.
-
ChunkedOutput
public ChunkedOutput(java.lang.reflect.Type chunkType)
CreateChunkedOutput
with specified type.- Parameters:
chunkType
- chunk type. Must not be {code null}.
-
ChunkedOutput
protected ChunkedOutput(byte[] chunkDelimiter)
Create newChunkedOutput
with a custom chunk delimiter.- Parameters:
chunkDelimiter
- custom chunk delimiter bytes. Must not be {code null}.- Since:
- 2.4.1
-
ChunkedOutput
protected ChunkedOutput(byte[] chunkDelimiter, javax.inject.Provider<AsyncContext> asyncContextProvider)
Create newChunkedOutput
with a custom chunk delimiter.- Parameters:
chunkDelimiter
- custom chunk delimiter bytes. Must not be {code null}.- Since:
- 2.4.1
-
ChunkedOutput
public ChunkedOutput(java.lang.reflect.Type chunkType, byte[] chunkDelimiter)
Create newChunkedOutput
with a custom chunk delimiter.- Parameters:
chunkType
- chunk type. Must not be {code null}.chunkDelimiter
- custom chunk delimiter bytes. Must not be {code null}.- Since:
- 2.4.1
-
ChunkedOutput
protected ChunkedOutput(java.lang.String chunkDelimiter)
Create newChunkedOutput
with a custom chunk delimiter.- Parameters:
chunkDelimiter
- custom chunk delimiter string. Must not be {code null}.- Since:
- 2.4.1
-
ChunkedOutput
public ChunkedOutput(java.lang.reflect.Type chunkType, java.lang.String chunkDelimiter)
Create newChunkedOutput
with a custom chunk delimiter.- Parameters:
chunkType
- chunk type. Must not be {code null}.chunkDelimiter
- custom chunk delimiter string. Must not be {code null}.- Since:
- 2.4.1
-
-
Method Detail
-
write
public void write(T chunk) throws java.io.IOException
Write a chunk.- Parameters:
chunk
- a chunk instance to be written.- Throws:
java.io.IOException
- if this response is closed or when encountered any problem during serializing or writing a chunk.
-
flushQueue
protected void flushQueue() throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
Close this response - it will be finalized and underlying connections will be closed or made available for another response.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
isClosed
public boolean isClosed()
Get state information. Please note thatChunkedOutput
can be closed by the client side - client can close connection from its side.- Returns:
- true when closed, false otherwise.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjavax.ws.rs.core.GenericType<T>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjavax.ws.rs.core.GenericType<T>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjavax.ws.rs.core.GenericType<T>
-
setContext
void setContext(RequestScope requestScope, RequestContext requestScopeContext, ContainerRequest requestContext, ContainerResponse responseContext, javax.ws.rs.container.ConnectionCallback connectionCallbackRunner) throws java.io.IOException
Set context used for writing chunks.- Parameters:
requestScope
- request scope.requestScopeContext
- current request context instance.requestContext
- request context.responseContext
- response context.connectionCallbackRunner
- connection callback.- Throws:
java.io.IOException
- when encountered any problem during serializing or writing a chunk.
-
-