本文整理匯總了Java中io.netty.handler.codec.DelimiterBasedFrameDecoder類的典型用法代碼示例。如果您正苦於以下問題:Java DelimiterBasedFrameDecoder類的具體用法?Java DelimiterBasedFrameDecoder怎麽用?Java DelimiterBasedFrameDecoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DelimiterBasedFrameDecoder類屬於io.netty.handler.codec包,在下文中一共展示了DelimiterBasedFrameDecoder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: switchToBinary
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
private void switchToBinary(ChannelHandlerContext ctx) {
ChannelPipeline p = ctx.pipeline();
p.addLast(new DelimiterBasedFrameDecoder(maxFrameLength, Delimiters.lineDelimiter()));
p.addLast(new StringDecoder(Charset.forName(charset)));
p.addLast(new NetoJsonToMessageDecoder(opcodeMap));
NetoMessageToJsonEncoder netoMessageToJsonEncoder = new NetoMessageToJsonEncoder();
netoMessageToJsonEncoder.setOpcodeMap(opcodeMap);
p.addLast(netoMessageToJsonEncoder);
p.addLast(new MessageHandler(redisService));
p.remove(this);
// 핸들러를 다시 등록 했으므로 이벤트를 전파
ctx.fireChannelActive();
}
示例2: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
NetoJsonToMessageDecoder decoder = new NetoJsonToMessageDecoder(opcodeMap);
NetoMessageToJsonEncoder encoder = new NetoMessageToJsonEncoder();
if (opcodeMap instanceof BiMap) {
encoder.setOpcodeMap((BiMap<Integer, Class<? extends NetoJsonMessage>>) opcodeMap);
}
MessageHandler handler = new MessageHandler(redisService);
ChannelPipeline p = ch.pipeline();
p.addLast(new DelimiterBasedFrameDecoder(maxFrameLength, Delimiters.lineDelimiter()));
p.addLast(new StringDecoder(Charset.forName(charset)));
p.addLast(decoder);
p.addLast(encoder);
p.addLast(handler);
}
示例3: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new LoggingHandler());
// Add SSL handler first to encrypt and decrypt everything.
// In this example, we use a bogus certificate in the server side
// and accept any invalid certificates in the client side.
// You will need something more complicated to identify both
// and server in the real world.
if (sslCtx != null)
pipeline.addLast(sslCtx.newHandler(ch.alloc(), SecureChatClient.HOST, SecureChatClient.PORT));
// On top of the SSL handler, add the text line codec.
pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast(new StringDecoder());
pipeline.addLast(new StringEncoder());
// and then business logic.
pipeline.addLast(new SecureChatClientHandler());
}
示例4: initChannel_configuresSerialChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Test
public void initChannel_configuresSerialChannel() throws Exception {
when(channel.config()).thenReturn(config);
when(config.getBaudrate()).thenReturn(19200);
when(config.getDatabits()).thenReturn(DATABITS_8);
when(config.getStopbits()).thenReturn(STOPBITS_1);
when(config.getParitybit()).thenReturn(NONE);
when(channel.pipeline()).thenReturn(pipeline);
initializer.setRxTxSerialHandler(handler);
initializer.initChannel(channel);
// Check if serial config is correct:
verify(config, times(1)).setBaudrate(19200);
verify(config, times(1)).setDatabits(DATABITS_8);
verify(config, times(1)).setStopbits(STOPBITS_1);
verify(config, times(1)).setParitybit(NONE);
// Check if encoders, decoders and handlers are set:
verify(pipeline, times(1)).addLast(eq("framer"), any(DelimiterBasedFrameDecoder.class));
verify(pipeline, times(1)).addLast(eq("decoder"), any(RxtxMessageFrameDecoder.class));
verify(pipeline, times(1)).addLast(eq("encoder"), any(RxtxMessageFrameEncoder.class));
verify(pipeline, times(1)).addLast(eq("handler"), eq(handler));
}
示例5: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.config().setAllowHalfClosure(true);
ChannelPipeline pipeline = ch.pipeline();
//IdleStateHandler 與客戶端鏈接後,根據超出配置的時間自動觸發userEventTriggered
//readerIdleTime服務端長時間沒有讀到數據,則為讀空閑,觸發讀空閑監聽,並自動關閉鏈路連接,周期性按readerIdleTime的超時間觸發空閑監聽方法
//writerIdleTime服務端長時間沒有發送寫請求,則為空閑,觸發寫空閑監聽,空閑期間,周期性按writerIdleTime的超時間觸發空閑監聽方法
//allIdleTime 服務端在allIdleTime時間內未接收到客戶端消息,或者,也未去向客戶端發送消息,則觸發周期性操作
pipeline.addLast("ping", new IdleStateHandler(10, 20, 35, TimeUnit.SECONDS));
// 以("\n")為結尾分割的 解碼器
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
// 字符串解碼 和 編碼
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
// 自己的邏輯Handler
pipeline.addLast("handler", new DataServerHandler(nodeInfo));
}
示例6: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()))
.addLast("decoder", new StringDecoder())
.addLast("encoder", new StringEncoder())
.addLast("json_to_ob",new JsonToObjectHandler())
.addLast("register",new RegisterHandler())
.addLast("authority", new AuthorityHandler())
.addLast("enterGroup",new EnterGroupHandler())
.addLast("channelManager", new ChannelManagerHandler())
.addLast("createGroup", new CreateGroupHandler())
.addLast("addGroup", new AddGroupHandler())
.addLast("deleteGroup",new DeleteGroupHandler())
.addLast("Limiter", new LimiterHandler())
.addLast("log", new LoggerHandler())
.addLast("response", new Responser());
}
示例7: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
/*
* 這個地方的 必須和服務端對應上。否則無法正常解碼和編碼
*
* 解碼和編碼 我將會在下一張為大家詳細的講解。再次暫時不做詳細的描述
*/
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
Delimiters.lineDelimiter()));
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
// 客戶端的邏輯
pipeline.addLast("handler", new HelloClientHandler());
}
示例8: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Add SSL handler first to encrypt and decrypt everything.
// In this example, we use a bogus certificate in the server side
// and accept any invalid certificates in the client side.
// You will need something more complicated to identify both
// and server in the real world.
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
// On top of the SSL handler, add the text line codec.
pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast(new StringDecoder());
pipeline.addLast(new StringEncoder());
// and then business logic.
pipeline.addLast(new SecureChatServerHandler());
}
示例9: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Add SSL handler first to encrypt and decrypt everything.
// In this example, we use a bogus certificate in the server side
// and accept any invalid certificates in the client side.
// You will need something more complicated to identify both
// and server in the real world.
pipeline.addLast(sslCtx.newHandler(ch.alloc(), SecureChatClient.HOST, SecureChatClient.PORT));
// On top of the SSL handler, add the text line codec.
pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast(new StringDecoder());
pipeline.addLast(new StringEncoder());
// and then business logic.
pipeline.addLast(new SecureChatClientHandler());
}
示例10: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
}
// Add the text line codec combination first,
pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
// the encoder and decoder are static as these are sharable
pipeline.addLast(DECODER);
pipeline.addLast(ENCODER);
// and then business logic.
pipeline.addLast(SERVER_HANDLER);
}
示例11: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc(), TelnetClient.HOST, TelnetClient.PORT));
}
// Add the text line codec combination first,
pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast(DECODER);
pipeline.addLast(ENCODER);
// and then business logic.
pipeline.addLast(CLIENT_HANDLER);
}
示例12: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
protected void initChannel(final SocketChannel ch) throws Exception {
final ChannelPipeline pipeline = ch.pipeline();
// decoders
// Add the text line codec combination first,
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast("stringDecoder", stringDecoder);
pipeline.addLast("requestDecoder", requestDecoder);
// encoders
pipeline.addLast("stringEncoder", stringEncoder);
pipeline.addLast("responseEncoder", responseEncoder);
// business logic handler
pipeline.addLast(group, "serverHandler", serverHandler);
pipeline.addLast("exceptionHandler", exceptionHandler);
}
示例13: testFailSlowTooLongFrameRecovery
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Test
public void testFailSlowTooLongFrameRecovery() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(
new DelimiterBasedFrameDecoder(1, true, false, Delimiters.nulDelimiter()));
for (int i = 0; i < 2; i ++) {
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 }));
try {
assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0 })));
fail(DecoderException.class.getSimpleName() + " must be raised.");
} catch (TooLongFrameException e) {
// Expected
}
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A', 0 }));
ByteBuf buf = releaseLater((ByteBuf) ch.readInbound());
assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
}
}
示例14: testFailFastTooLongFrameRecovery
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Test
public void testFailFastTooLongFrameRecovery() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(
new DelimiterBasedFrameDecoder(1, Delimiters.nulDelimiter()));
for (int i = 0; i < 2; i ++) {
try {
assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 1, 2 })));
fail(DecoderException.class.getSimpleName() + " must be raised.");
} catch (TooLongFrameException e) {
// Expected
}
ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 0, 'A', 0 }));
ByteBuf buf = releaseLater((ByteBuf) ch.readInbound());
assertEquals("A", buf.toString(CharsetUtil.ISO_8859_1));
}
}
示例15: initChannel
import io.netty.handler.codec.DelimiterBasedFrameDecoder; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Add SSL handler first to encrypt and decrypt everything.
// In this example, we use a bogus certificate in the server side
// and accept any invalid certificates in the client side.
// You will need something more complicated to identify both
// and server in the real world.
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
// On top of the SSL handler, add the text line codec.
pipeline.addLast(new DelimiterBasedFrameDecoder(8*8192, Delimiters.lineDelimiter()));
pipeline.addLast(new StringDecoder());
pipeline.addLast(new StringEncoder());
// and then business logic.
pipeline.addLast(new NettySpoutServerHandler(spout));
}