From 6db7250ed934accfba0e36f4fce90de2e81008c1 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 27 Dec 2012 22:46:46 +0100 Subject: [PATCH] Javadocs added for SCTP stuff --- .../io/netty/channel/socket/SctpMessage.java | 27 +++++++++++++++++++ .../channel/socket/SctpNotificationEvent.java | 16 +++++++++++ .../socket/SctpNotificationHandler.java | 22 ++++++++++----- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/socket/SctpMessage.java b/transport/src/main/java/io/netty/channel/socket/SctpMessage.java index 99e7aa1c07..d8ad3d73d2 100644 --- a/transport/src/main/java/io/netty/channel/socket/SctpMessage.java +++ b/transport/src/main/java/io/netty/channel/socket/SctpMessage.java @@ -43,21 +43,41 @@ public final class SctpMessage { msgInfo = null; } + /** + * Essential data that is being carried within SCTP Data Chunk + * @param msgInfo the {@link MessageInfo} + * @param payloadBuffer channel buffer + */ public SctpMessage(MessageInfo msgInfo, ByteBuf payloadBuffer) { + if (msgInfo == null) { + throw new NullPointerException("msgInfo"); + } + if (payloadBuffer == null) { + throw new NullPointerException("payloadBuffer"); + } this.msgInfo = msgInfo; streamIdentifier = msgInfo.streamNumber(); protocolIdentifier = msgInfo.payloadProtocolID(); this.payloadBuffer = payloadBuffer; } + /** + * Return the stream-identifier + */ public int getStreamIdentifier() { return streamIdentifier; } + /** + * Return the protocol-identifier + */ public int getProtocolIdentifier() { return protocolIdentifier; } + /** + * Return a view of the readable bytes of the payload. + */ public ByteBuf getPayloadBuffer() { if (payloadBuffer.readable()) { return payloadBuffer.slice(); @@ -66,10 +86,17 @@ public final class SctpMessage { } } + /** + * Return the {@link MessageInfo} for inbound messages or {@code null} for + * outbound messages. + */ public MessageInfo getMessageInfo() { return msgInfo; } + /** + * Return {@code true} if this message is complete. + */ public boolean isComplete() { if (msgInfo != null) { return msgInfo.isComplete(); diff --git a/transport/src/main/java/io/netty/channel/socket/SctpNotificationEvent.java b/transport/src/main/java/io/netty/channel/socket/SctpNotificationEvent.java index aee4d2d29a..6b30cdaadc 100644 --- a/transport/src/main/java/io/netty/channel/socket/SctpNotificationEvent.java +++ b/transport/src/main/java/io/netty/channel/socket/SctpNotificationEvent.java @@ -16,12 +16,28 @@ package io.netty.channel.socket; import com.sun.nio.sctp.Notification; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPipeline; +/** + * Will be passed to {@link ChannelPipeline#fireUserEventTriggered(Object)} method and so forwarded to the added + * {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)} method. + */ public final class SctpNotificationEvent { private final Notification notification; private final Object attachment; + /** + * Create a new instance + * + * @param notification the {@link Notification} which triggered this event + * @param attachment the attachment or {@code null} if non is attached. + */ public SctpNotificationEvent(Notification notification, Object attachment) { + if (notification == null) { + throw new NullPointerException("notification"); + } this.notification = notification; this.attachment = attachment; } diff --git a/transport/src/main/java/io/netty/channel/socket/SctpNotificationHandler.java b/transport/src/main/java/io/netty/channel/socket/SctpNotificationHandler.java index 3ec99d94c1..d4ff3e960e 100644 --- a/transport/src/main/java/io/netty/channel/socket/SctpNotificationHandler.java +++ b/transport/src/main/java/io/netty/channel/socket/SctpNotificationHandler.java @@ -23,40 +23,50 @@ import com.sun.nio.sctp.PeerAddressChangeNotification; import com.sun.nio.sctp.SendFailedNotification; import com.sun.nio.sctp.ShutdownNotification; -public class SctpNotificationHandler extends AbstractNotificationHandler { +import io.netty.channel.ChannelPipeline; + + +/** + * {@link AbstractNotificationHandler} implementation which will handle all {@link Notification}s by trigger a + * {@link SctpNotificationEvent} in the {@link ChannelPipeline} of a {@link SctpChannel}. + */ +public final class SctpNotificationHandler extends AbstractNotificationHandler { private final SctpChannel sctpChannel; public SctpNotificationHandler(SctpChannel sctpChannel) { + if (sctpChannel == null) { + throw new NullPointerException("sctpChannel"); + } this.sctpChannel = sctpChannel; } @Override public HandlerResult handleNotification(AssociationChangeNotification notification, Object o) { - updateInboundBuffer(notification, o); + fireEvent(notification, o); return HandlerResult.CONTINUE; } @Override public HandlerResult handleNotification(PeerAddressChangeNotification notification, Object o) { - updateInboundBuffer(notification, o); + fireEvent(notification, o); return HandlerResult.CONTINUE; } @Override public HandlerResult handleNotification(SendFailedNotification notification, Object o) { - updateInboundBuffer(notification, o); + fireEvent(notification, o); return HandlerResult.CONTINUE; } @Override public HandlerResult handleNotification(ShutdownNotification notification, Object o) { - updateInboundBuffer(notification, o); + fireEvent(notification, o); sctpChannel.close(); return HandlerResult.RETURN; } - private void updateInboundBuffer(Notification notification, Object o) { + private void fireEvent(Notification notification, Object o) { sctpChannel.pipeline().fireUserEventTriggered(new SctpNotificationEvent(notification, o)); } }