2012-09-03 14:12:09 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
|
|
|
*
|
2020-10-23 14:44:18 +02:00
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
2012-09-03 14:12:09 +02:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2013-01-13 17:41:15 +01:00
|
|
|
package io.netty.channel.sctp;
|
2012-09-03 14:12:09 +02:00
|
|
|
|
2019-02-04 10:32:25 +01:00
|
|
|
import static java.util.Objects.requireNonNull;
|
|
|
|
|
2012-09-03 14:12:09 +02:00
|
|
|
import com.sun.nio.sctp.AbstractNotificationHandler;
|
|
|
|
import com.sun.nio.sctp.AssociationChangeNotification;
|
|
|
|
import com.sun.nio.sctp.HandlerResult;
|
|
|
|
import com.sun.nio.sctp.Notification;
|
|
|
|
import com.sun.nio.sctp.PeerAddressChangeNotification;
|
|
|
|
import com.sun.nio.sctp.SendFailedNotification;
|
|
|
|
import com.sun.nio.sctp.ShutdownNotification;
|
|
|
|
|
2012-12-27 22:46:46 +01:00
|
|
|
import io.netty.channel.ChannelPipeline;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@link AbstractNotificationHandler} implementation which will handle all {@link Notification}s by trigger a
|
2013-06-17 21:35:17 +02:00
|
|
|
* {@link Notification} user event in the {@link ChannelPipeline} of a {@link SctpChannel}.
|
2012-12-27 22:46:46 +01:00
|
|
|
*/
|
|
|
|
public final class SctpNotificationHandler extends AbstractNotificationHandler<Object> {
|
2012-09-03 14:12:09 +02:00
|
|
|
|
|
|
|
private final SctpChannel sctpChannel;
|
|
|
|
|
|
|
|
public SctpNotificationHandler(SctpChannel sctpChannel) {
|
2019-02-04 10:32:25 +01:00
|
|
|
requireNonNull(sctpChannel, "sctpChannel");
|
2012-09-03 14:12:09 +02:00
|
|
|
this.sctpChannel = sctpChannel;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public HandlerResult handleNotification(AssociationChangeNotification notification, Object o) {
|
2013-06-17 21:35:17 +02:00
|
|
|
fireEvent(notification);
|
2012-09-03 14:12:09 +02:00
|
|
|
return HandlerResult.CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public HandlerResult handleNotification(PeerAddressChangeNotification notification, Object o) {
|
2013-06-17 21:35:17 +02:00
|
|
|
fireEvent(notification);
|
2012-09-03 14:12:09 +02:00
|
|
|
return HandlerResult.CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public HandlerResult handleNotification(SendFailedNotification notification, Object o) {
|
2013-06-17 21:35:17 +02:00
|
|
|
fireEvent(notification);
|
2012-09-03 14:12:09 +02:00
|
|
|
return HandlerResult.CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public HandlerResult handleNotification(ShutdownNotification notification, Object o) {
|
2013-06-17 21:35:17 +02:00
|
|
|
fireEvent(notification);
|
2012-09-03 14:12:09 +02:00
|
|
|
sctpChannel.close();
|
|
|
|
return HandlerResult.RETURN;
|
|
|
|
}
|
|
|
|
|
2013-06-17 21:35:17 +02:00
|
|
|
private void fireEvent(Notification notification) {
|
|
|
|
sctpChannel.pipeline().fireUserEventTriggered(notification);
|
2012-09-03 14:12:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|