use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project dubbo by alibaba.
the class QosProcessHandler method decode.
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() < 1) {
return;
}
// read one byte to guess protocol
final int magic = in.getByte(in.readerIndex());
ChannelPipeline p = ctx.pipeline();
p.addLast(new LocalHostPermitHandler(acceptForeignIp));
if (isHttp(magic)) {
// no welcome output for http protocol
if (welcomeFuture != null && welcomeFuture.isCancellable()) {
welcomeFuture.cancel(false);
}
p.addLast(new HttpServerCodec());
p.addLast(new HttpObjectAggregator(1048576));
p.addLast(new HttpProcessHandler());
p.remove(this);
} else {
p.addLast(new LineBasedFrameDecoder(2048));
p.addLast(new StringDecoder(CharsetUtil.UTF_8));
p.addLast(new StringEncoder(CharsetUtil.UTF_8));
p.addLast(new IdleStateHandler(0, 0, 5 * 60));
p.addLast(new TelnetProcessHandler());
p.remove(this);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project openremote by openremote.
the class TcpStringServer method addDecoders.
@Override
protected void addDecoders(SocketChannel channel) {
// Add delimiter and string decoders to do the work
channel.pipeline().addLast(new DelimiterBasedFrameDecoder(maxFrameLength, stripDelimiter, Unpooled.wrappedBuffer(delimiter.getBytes())));
channel.pipeline().addLast(new StringDecoder());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project alibaba-mom by younfor.
the class DefaultProducer method start.
@Override
public void start() {
SIP = System.getProperty("SIP");
if (SIP == null)
SIP = "127.0.0.1";
System.out.println("connect:" + System.getProperty("SIP"));
group = new NioEventLoopGroup();
bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioSocketChannel.class).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, true).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel channel) throws Exception {
channel.pipeline().addLast(new RpcEncoder()).addLast(new LineBasedFrameDecoder(1024 * 256)).addLast(new StringDecoder()).addLast(new SimpleChannelInboundHandler<Object>() {
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
logger.error("producer失去broker链接");
connect();
}
@Override
protected void channelRead0(ChannelHandlerContext arg0, Object info) throws Exception {
logger.debug("recv ack: " + (String) info);
if (info != null) /*&&info.toString().startsWith("ackGroup"*/
{
String[] id = ((String) info).split("@");
// System.out.println(id.length+":len:"+id[0]+" | "+id[1]);
if (id[0].startsWith("fail")) {
// System.out.println("无人订阅");
SendResult sr = new SendResult();
sr.setMsgId(id[1]);
resultMap.get(id[1]).put(sr);
} else {
for (int i = 1; i < id.length; i++) {
// System.out.println(id[i]);
SendResult sr = new SendResult();
sr.setMsgId(id[i]);
resultMap.get(id[i]).put(sr);
}
}
// synchronized(lock){
// lock.notifyAll();
// }
} else {
// 异步方式接受数据
if (asyncResults.containsKey((String) info)) {
SendResult sr = new SendResult();
sr.setMsgId((String) info);
asyncResults.get((String) info).onResult(sr);
;
} else {
}
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
logger.error("--生产者的异常关闭--" + cause.getMessage());
cause.printStackTrace();
logger.error("重新连接");
ctx.close();
connect();
}
});
}
});
connect();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project java by wavefrontHQ.
the class StringLineIngester method createDecoderList.
/**
* Returns a copy of the given list plus inserts the 2 decoders needed for this specific ingester
* (LineBasedFrameDecoder and StringDecoder)
*
* @param decoders the starting list
* @return copy of the provided list with additional decodiers prepended
*/
private static List<Function<Channel, ChannelHandler>> createDecoderList(@Nullable final List<Function<Channel, ChannelHandler>> decoders) {
final List<Function<Channel, ChannelHandler>> copy;
if (decoders == null) {
copy = new ArrayList<>();
} else {
copy = new ArrayList<>(decoders);
}
copy.add(0, new Function<Channel, ChannelHandler>() {
@Override
public ChannelHandler apply(Channel input) {
return new LineBasedFrameDecoder(4096, true, false);
}
});
copy.add(1, new Function<Channel, ChannelHandler>() {
@Override
public ChannelHandler apply(Channel input) {
return new StringDecoder(Charsets.UTF_8);
}
});
return copy;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder in project java by wavefrontHQ.
the class HistogramLineIngester method initChannel.
@Override
protected void initChannel(Channel ch) throws Exception {
// Round robin channel to handler assignment.
int idx = (int) (Math.abs(connectionId.getAndIncrement()) % handlers.size());
ChannelHandler handler = handlers.get(idx);
// Add decoders and timeout, add handler()
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new LineBasedFrameDecoder(MAXIMUM_FRAME_LENGTH, true, false), new StringDecoder(Charsets.UTF_8), new IdleStateHandler(CHANNEL_IDLE_TIMEOUT_IN_SECS_DEFAULT, 0, 0), new ChannelDuplexHandler() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
logger.warning("terminating connection to histogram client due to inactivity after " + CHANNEL_IDLE_TIMEOUT_IN_SECS_DEFAULT + "s: " + ctx.channel());
ctx.close();
}
}
}
}, handler);
}
Aggregations