本文整理汇总了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;
}
示例2: RedisRestChannel
import org.elasticsearch.common.netty.channel.Channel; //导入依赖的package包/类
public RedisRestChannel(Channel channel, RedisRestRequest request) {
this.channel = channel;
this.request = request;
}
示例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;
}