當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。