MemcacheClientHandler Class — netty Architecture
Architecture documentation for the MemcacheClientHandler class in MemcacheClientHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 195df439_d81f_4adb_8295_7597222f7652["MemcacheClientHandler"] 94d9bc6e_6531_484f_54dc_a17f314789d0["MemcacheClientHandler.java"] 195df439_d81f_4adb_8295_7597222f7652 -->|defined in| 94d9bc6e_6531_484f_54dc_a17f314789d0 e9018d62_aaf2_c99b_6087_c7593fa971bf["write()"] 195df439_d81f_4adb_8295_7597222f7652 -->|method| e9018d62_aaf2_c99b_6087_c7593fa971bf d08b1867_7487_c12b_db6f_e90385a59120["channelRead()"] 195df439_d81f_4adb_8295_7597222f7652 -->|method| d08b1867_7487_c12b_db6f_e90385a59120 da17aae7_1ee0_5cdb_2208_48700a728643["exceptionCaught()"] 195df439_d81f_4adb_8295_7597222f7652 -->|method| da17aae7_1ee0_5cdb_2208_48700a728643
Relationship Graph
Source Code
example/src/main/java/io/netty/example/memcache/binary/MemcacheClientHandler.java lines 30–80
public class MemcacheClientHandler extends ChannelDuplexHandler {
/**
* Transforms basic string requests to binary memcache requests
*/
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
String command = (String) msg;
if (command.startsWith("get ")) {
String keyString = command.substring("get ".length());
ByteBuf key = Unpooled.wrappedBuffer(keyString.getBytes(CharsetUtil.UTF_8));
BinaryMemcacheRequest req = new DefaultBinaryMemcacheRequest(key);
req.setOpcode(BinaryMemcacheOpcodes.GET);
ctx.write(req, promise);
} else if (command.startsWith("set ")) {
String[] parts = command.split(" ", 3);
if (parts.length < 3) {
throw new IllegalArgumentException("Malformed Command: " + command);
}
String keyString = parts[1];
String value = parts[2];
ByteBuf key = Unpooled.wrappedBuffer(keyString.getBytes(CharsetUtil.UTF_8));
ByteBuf content = Unpooled.wrappedBuffer(value.getBytes(CharsetUtil.UTF_8));
ByteBuf extras = ctx.alloc().buffer(8);
extras.writeZero(8);
BinaryMemcacheRequest req = new DefaultFullBinaryMemcacheRequest(key, extras, content);
req.setOpcode(BinaryMemcacheOpcodes.SET);
ctx.write(req, promise);
} else {
throw new IllegalStateException("Unknown Message: " + msg);
}
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
FullBinaryMemcacheResponse res = (FullBinaryMemcacheResponse) msg;
System.out.println(res.content().toString(CharsetUtil.UTF_8));
res.release();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
}
Source
Frequently Asked Questions
What is the MemcacheClientHandler class?
MemcacheClientHandler is a class in the netty codebase, defined in example/src/main/java/io/netty/example/memcache/binary/MemcacheClientHandler.java.
Where is MemcacheClientHandler defined?
MemcacheClientHandler is defined in example/src/main/java/io/netty/example/memcache/binary/MemcacheClientHandler.java at line 30.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free