StompChatHandler Class — netty Architecture
Architecture documentation for the StompChatHandler class in StompChatHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD f937e446_8aba_2036_93fc_8020adb1953f["StompChatHandler"] ce7f0b14_707f_4254_e5c9_e53c56144d8f["StompChatHandler.java"] f937e446_8aba_2036_93fc_8020adb1953f -->|defined in| ce7f0b14_707f_4254_e5c9_e53c56144d8f 5ef12430_b789_c7f8_301d_8283d302e997["channelRead0()"] f937e446_8aba_2036_93fc_8020adb1953f -->|method| 5ef12430_b789_c7f8_301d_8283d302e997 91529c34_98b8_0877_0e3c_4566c29cc41c["onSubscribe()"] f937e446_8aba_2036_93fc_8020adb1953f -->|method| 91529c34_98b8_0877_0e3c_4566c29cc41c e7e2a1ff_4014_45fc_319b_33586aa4f65b["onSend()"] f937e446_8aba_2036_93fc_8020adb1953f -->|method| e7e2a1ff_4014_45fc_319b_33586aa4f65b 300a2492_839b_f301_5856_263dc6251275["onUnsubscribe()"] f937e446_8aba_2036_93fc_8020adb1953f -->|method| 300a2492_839b_f301_5856_263dc6251275 79a0cee0_3fe1_bbec_8430_245727dc0633["onConnect()"] f937e446_8aba_2036_93fc_8020adb1953f -->|method| 79a0cee0_3fe1_bbec_8430_245727dc0633 81e01bd7_15ff_1fba_87da_191986d1898d["onDisconnect()"] f937e446_8aba_2036_93fc_8020adb1953f -->|method| 81e01bd7_15ff_1fba_87da_191986d1898d f5104c6e_035e_0b9d_444a_4cc359d713bf["sendErrorFrame()"] f937e446_8aba_2036_93fc_8020adb1953f -->|method| f5104c6e_035e_0b9d_444a_4cc359d713bf 044018ea_46d1_75d7_13e0_1ebec8aaf9c9["StompFrame()"] f937e446_8aba_2036_93fc_8020adb1953f -->|method| 044018ea_46d1_75d7_13e0_1ebec8aaf9c9
Relationship Graph
Source Code
example/src/main/java/io/netty/example/stomp/websocket/StompChatHandler.java lines 39–195
@Sharable
public class StompChatHandler extends SimpleChannelInboundHandler<StompFrame> {
private final ConcurrentMap<String, Set<StompSubscription>> chatDestinations =
new ConcurrentHashMap<String, Set<StompSubscription>>();
@Override
protected void channelRead0(ChannelHandlerContext ctx, StompFrame inboundFrame) throws Exception {
DecoderResult decoderResult = inboundFrame.decoderResult();
if (decoderResult.isFailure()) {
sendErrorFrame("rejected frame", decoderResult.toString(), ctx);
return;
}
switch (inboundFrame.command()) {
case STOMP:
case CONNECT:
onConnect(ctx, inboundFrame);
break;
case SUBSCRIBE:
onSubscribe(ctx, inboundFrame);
break;
case SEND:
onSend(ctx, inboundFrame);
break;
case UNSUBSCRIBE:
onUnsubscribe(ctx, inboundFrame);
break;
case DISCONNECT:
onDisconnect(ctx, inboundFrame);
break;
default:
sendErrorFrame("unsupported command",
"Received unsupported command " + inboundFrame.command(), ctx);
}
}
private void onSubscribe(ChannelHandlerContext ctx, StompFrame inboundFrame) {
String destination = inboundFrame.headers().getAsString(DESTINATION);
String subscriptionId = inboundFrame.headers().getAsString(ID);
if (destination == null || subscriptionId == null) {
sendErrorFrame("missed header", "Required 'destination' or 'id' header missed", ctx);
return;
}
Set<StompSubscription> subscriptions = chatDestinations.get(destination);
if (subscriptions == null) {
subscriptions = new HashSet<StompSubscription>();
Set<StompSubscription> previousSubscriptions = chatDestinations.putIfAbsent(destination, subscriptions);
if (previousSubscriptions != null) {
subscriptions = previousSubscriptions;
}
}
final StompSubscription subscription = new StompSubscription(subscriptionId, destination, ctx.channel());
if (subscriptions.contains(subscription)) {
sendErrorFrame("duplicate subscription",
"Received duplicate subscription id=" + subscriptionId, ctx);
return;
}
subscriptions.add(subscription);
ctx.channel().closeFuture().addListener(f ->
chatDestinations.get(subscription.destination()).remove(subscription));
String receiptId = inboundFrame.headers().getAsString(RECEIPT);
if (receiptId != null) {
StompFrame receiptFrame = new DefaultStompFrame(StompCommand.RECEIPT);
receiptFrame.headers().set(RECEIPT_ID, receiptId);
ctx.writeAndFlush(receiptFrame);
}
}
private void onSend(ChannelHandlerContext ctx, StompFrame inboundFrame) {
String destination = inboundFrame.headers().getAsString(DESTINATION);
if (destination == null) {
sendErrorFrame("missed header", "required 'destination' header missed", ctx);
return;
}
Source
Frequently Asked Questions
What is the StompChatHandler class?
StompChatHandler is a class in the netty codebase, defined in example/src/main/java/io/netty/example/stomp/websocket/StompChatHandler.java.
Where is StompChatHandler defined?
StompChatHandler is defined in example/src/main/java/io/netty/example/stomp/websocket/StompChatHandler.java at line 39.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free