Javadocs added for SCTP stuff
This commit is contained in:
parent
5a4a52a817
commit
6db7250ed9
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<Object> {
|
||||
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<Object> {
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user