当前位置: 首页>>代码示例>>Java>>正文


Java Channel类代码示例

本文整理汇总了Java中org.elasticsearch.common.netty.channel.Channel的典型用法代码示例。如果您正苦于以下问题:Java Channel类的具体用法?Java Channel怎么用?Java Channel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Channel类属于org.elasticsearch.common.netty.channel包,在下文中一共展示了Channel类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChannel

import org.elasticsearch.common.netty.channel.Channel; //导入依赖的package包/类
public static Channel getChannel(final RestChannel channel) {
    try {
        if (channelField == null) {
            channelField = channel.getClass().getDeclaredField(
                    CHANNEL_FIELD_NAME);
            channelField.setAccessible(true);
        }
        return (Channel) channelField.get(channel);
    } catch (final Exception e) {
        logger.error("Could not load Netty's channel.", e);
    }
    return null;
}
 
开发者ID:codelibs,项目名称:elasticsearch-util,代码行数:14,代码来源:NettyUtils.java

示例2: RedisRestChannel

import org.elasticsearch.common.netty.channel.Channel; //导入依赖的package包/类
public RedisRestChannel(Channel channel, RedisRestRequest request) {
    this.channel = channel;
    this.request = request;
}
 
开发者ID:kzwang,项目名称:elasticsearch-transport-redis,代码行数:5,代码来源:RedisRestChannel.java

示例3: decode

import org.elasticsearch.common.netty.channel.Channel; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
    int readableBytes = buffer.readableBytes();
    if (readableBytes < 8) {
        return null;
    }

    buffer.resetReaderIndex();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < readableBytes; i++) {
        byte next = buffer.readByte();
        sb.append((char) next);
    }

    String[] command = sb.toString().split("\r\n");

    if (logger.isDebugEnabled()) {
        logger.debug("Received command: {}", sb.toString());
    }

    if (command.length < 2) {
        return null;
    }

    String cmd = command[2];
    String uri = null;
    String data = null;
    RestRequest.Method method;

    if (command.length >= 4) {
        uri = command[4];
    }

    if (command.length >= 6) {
        data = command[6];
    }

    if (cmd.equalsIgnoreCase("set")) {
        if (data != null && (data.startsWith("put") || data.startsWith("PUT"))) {
            data = data.substring(3);  // remove start 'PUT'
            method = RestRequest.Method.PUT;
        } else {
            method = RestRequest.Method.POST;
        }
    } else if (cmd.equalsIgnoreCase("get")) {
        method = RestRequest.Method.GET;
    } else if (cmd.equalsIgnoreCase("del")) {
        method = RestRequest.Method.DELETE;
    } else if (cmd.equalsIgnoreCase("exists")) {
        method = RestRequest.Method.HEAD;
    } else if (cmd.equalsIgnoreCase("quit")) {
        if (channel.isConnected()) {
            channel.disconnect();
        }
        return null;
    } else {
        logger.error("Unsupported command [{}], ignoring", cmd);

        ChannelBuffer writeBuffer = ChannelBuffers.dynamicBuffer(1 + NOT_SUPPORT_STRING.length());
        writeBuffer.writeByte('-');
        writeBuffer.writeBytes(NOT_SUPPORT.duplicate());
        channel.write(writeBuffer);
        return null;
    }

    RedisRestRequest request = new RedisRestRequest(method, uri);
    if (data != null) {
        request.setData(new BytesArray(data));
    }

    return request;

}
 
开发者ID:kzwang,项目名称:elasticsearch-transport-redis,代码行数:74,代码来源:RedisDecoder.java


注:本文中的org.elasticsearch.common.netty.channel.Channel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。