forked from eclipse-ee4j/grizzly
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved Http2 OutputQueueRecord into separate class.
- Loading branch information
1 parent
84a2385
commit 688ee7c
Showing
2 changed files
with
99 additions
and
97 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
modules/http2/src/main/java/org/glassfish/grizzly/http2/Http2OutputQueueRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package org.glassfish.grizzly.http2; | ||
|
||
import java.util.List; | ||
|
||
import org.glassfish.grizzly.Buffer; | ||
import org.glassfish.grizzly.CompletionHandler; | ||
import org.glassfish.grizzly.WriteResult; | ||
import org.glassfish.grizzly.asyncqueue.AsyncQueueRecord; | ||
import org.glassfish.grizzly.http2.frames.DataFrame; | ||
import org.glassfish.grizzly.http2.frames.Http2Frame; | ||
import org.glassfish.grizzly.http2.utils.ChunkedCompletionHandler; | ||
|
||
public class Http2OutputQueueRecord extends AsyncQueueRecord<WriteResult> { | ||
|
||
private final int streamId; | ||
|
||
private ChunkedCompletionHandler chunkedCompletionHandler; | ||
private final CompletionHandler<WriteResult> originalCompletionHandler; | ||
private Buffer buffer; | ||
private final boolean isLast; | ||
|
||
private final boolean isZeroSizeData; | ||
|
||
Http2OutputQueueRecord(final int streamId, final Buffer buffer, | ||
final CompletionHandler<WriteResult> completionHandler, final boolean isLast) { | ||
super(null, null, null); | ||
|
||
this.streamId = streamId; | ||
this.buffer = buffer; | ||
this.isZeroSizeData = !buffer.hasRemaining(); | ||
this.originalCompletionHandler = completionHandler; | ||
this.isLast = isLast; | ||
} | ||
|
||
@Override | ||
public void notifyFailure(final Throwable e) { | ||
final CompletionHandler<WriteResult> chLocal = getCompletionHandler(); | ||
if (chLocal != null) { | ||
chLocal.failed(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void recycle() { | ||
} | ||
|
||
@Override | ||
public WriteResult getCurrentResult() { | ||
return null; | ||
} | ||
|
||
CompletionHandler<WriteResult> getCompletionHandler() { | ||
return chunkedCompletionHandler != null ? chunkedCompletionHandler : originalCompletionHandler; | ||
} | ||
|
||
boolean isZeroSizeData() { | ||
return isZeroSizeData; | ||
} | ||
|
||
boolean isFinished() { | ||
return buffer == null; | ||
} | ||
|
||
int serializeTo(final List<Http2Frame> frames, final int maxDataSize) { | ||
|
||
final int recordSize = buffer.remaining(); | ||
|
||
if (recordSize <= maxDataSize) { | ||
final DataFrame dataFrame = DataFrame.builder().streamId(streamId).data(buffer).endStream(isLast).build(); | ||
|
||
frames.add(dataFrame); | ||
|
||
buffer = null; | ||
|
||
return recordSize; | ||
} else { | ||
if (originalCompletionHandler != null && chunkedCompletionHandler == null) { | ||
chunkedCompletionHandler = new ChunkedCompletionHandler(originalCompletionHandler); | ||
} | ||
|
||
if (chunkedCompletionHandler != null) { | ||
chunkedCompletionHandler.incChunks(); | ||
} | ||
|
||
final Buffer remainder = buffer.split(buffer.position() + maxDataSize); | ||
|
||
final DataFrame dataFrame = DataFrame.builder().streamId(streamId).data(buffer).endStream(false).build(); | ||
|
||
frames.add(dataFrame); | ||
|
||
buffer = remainder; | ||
|
||
return maxDataSize; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters