本文整理汇总了Java中io.netty.handler.codec.http.websocketx.WebSocketFrame.isFinalFragment方法的典型用法代码示例。如果您正苦于以下问题:Java WebSocketFrame.isFinalFragment方法的具体用法?Java WebSocketFrame.isFinalFragment怎么用?Java WebSocketFrame.isFinalFragment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.handler.codec.http.websocketx.WebSocketFrame
的用法示例。
在下文中一共展示了WebSocketFrame.isFinalFragment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import io.netty.handler.codec.http.websocketx.WebSocketFrame; //导入方法依赖的package包/类
@Override
protected void decode(final ChannelHandlerContext ctx, final WebSocketFrame msg, final List<Object> out)
throws Exception {
if (msg instanceof BinaryWebSocketFrame) {
ByteBuf content = msg.content();
// the content is passed to other handlers so they need to be retained.
content.retain();
fragments.add(content);
if (msg.isFinalFragment()) {
if (fragments.size() == 1) {
out.add(fragments.get(0));
} else {
ByteBuf[] array = fragments.toArray(BYTE_BUF_TYPE);
out.add(Unpooled.wrappedBuffer(array));
}
fragments.clear();
}
} else if (msg instanceof TextWebSocketFrame) {
LOG.warn("Recieved a Websocket text frame. This was not expected. Ignoring it.");
}
}
示例2: handleWebSocketFrame
import io.netty.handler.codec.http.websocketx.WebSocketFrame; //导入方法依赖的package包/类
protected void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
logger.debug("Received incoming frame [{}]", frame.getClass().getName());
// Check for closing frame
if (frame instanceof CloseWebSocketFrame) {
if (frameBuffer != null) {
handleMessageCompleted(ctx, frameBuffer.toString());
}
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
return;
}
if (frame instanceof PingWebSocketFrame) {
ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content().retain()));
return;
}
if (frame instanceof PongWebSocketFrame) {
logger.info("Pong frame received");
return;
}
if (frame instanceof TextWebSocketFrame) {
frameBuffer = new StringBuilder();
frameBuffer.append(((TextWebSocketFrame)frame).text());
} else if (frame instanceof ContinuationWebSocketFrame) {
if (frameBuffer != null) {
frameBuffer.append(((ContinuationWebSocketFrame)frame).text());
} else {
logger.warn("Continuation frame received without initial frame.");
}
} else {
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass().getName()));
}
// Check if Text or Continuation Frame is final fragment and handle if needed.
if (frame.isFinalFragment()) {
handleMessageCompleted(ctx, frameBuffer.toString());
frameBuffer = null;
}
}
示例3: handleWebSocketFrame
import io.netty.handler.codec.http.websocketx.WebSocketFrame; //导入方法依赖的package包/类
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
// Check for closing frame
if (frame instanceof CloseWebSocketFrame) {
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
return;
}
if (frame instanceof PingWebSocketFrame) {
ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
return;
}
//pfdm.getToPronghornPipe(pipeIdx)
Attribute<ContentToPronghornPipe> attrib = ctx.channel().attr(PRONGHORN_KEY);
Pipe toPronghornPipe = pfdm.getToPronghornPipe(attrib.get().pipeId);
MemberHolder subscriptionHolder = pfdm.getMemberHolder(attrib.get().pipeId);
if (!frame.isFinalFragment()) {
attrib.get().partialSendToPipe(frame.content(), continuationInProgress, toPronghornPipe, subscriptionHolder);
continuationInProgress = true;
} else {
attrib.get().sendToPipe(frame.content(), continuationDataPos, continuationInProgress, toPronghornPipe, subscriptionHolder);
//finished final fragment so capture this now
continuationDataPos = Pipe.getBlobWorkingHeadPosition( toPronghornPipe);
continuationInProgress = false;
}
}
示例4: handleWebSocketFrame
import io.netty.handler.codec.http.websocketx.WebSocketFrame; //导入方法依赖的package包/类
protected void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame)
{
logger.debug("Received incoming frame [{}]", frame.getClass().getName());
// Check for closing frame
if ( frame instanceof CloseWebSocketFrame) {
if ( frameBuffer != null) {
handleMessageCompleted( ctx, frameBuffer.toString());
}
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
return;
}
if (frame instanceof PingWebSocketFrame) {
ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content().retain()));
return;
}
if (frame instanceof PongWebSocketFrame) {
logger.info("Pong frame received");
return;
}
if (frame instanceof TextWebSocketFrame) {
frameBuffer = new StringBuilder();
frameBuffer.append(((TextWebSocketFrame)frame).text());
}
else if (frame instanceof ContinuationWebSocketFrame) {
if (frameBuffer != null) {
frameBuffer.append(((ContinuationWebSocketFrame)frame).text());
}
else {
logger.warn("Continuation frame received without initial frame.");
}
}
else {
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass().getName()));
}
// Check if Text or Continuation Frame is final fragment and handle if needed.
if (frame.isFinalFragment()) {
handleMessageCompleted(ctx, frameBuffer.toString());
frameBuffer = null;
}
}
示例5: handleWebSocketFrame
import io.netty.handler.codec.http.websocketx.WebSocketFrame; //导入方法依赖的package包/类
/**
* Handle web socket frame.
*
* @param ctx the ctx
* @param frame the frame
*/
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
try{
// Check for closing frame
if (frame instanceof CloseWebSocketFrame) {
dominoServer.onClose(this.newWrapper(ctx));
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
return;
}
if (frame instanceof PingWebSocketFrame) {
ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
return;
}
if(frame instanceof PongWebSocketFrame){
return;//do nothing.
}
if(frame instanceof TextWebSocketFrame){
String message = ((TextWebSocketFrame) frame).text();
textBuffer.append(message);
}else if(frame instanceof ContinuationWebSocketFrame){
textBuffer.append(((ContinuationWebSocketFrame) frame).text());
}
if(frame.isFinalFragment()){
dominoServer.onMessage(this.newWrapper(ctx), textBuffer.toString());
textBuffer = new StringBuilder();
}
}catch(Exception e){
e.printStackTrace();
}
}