import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import java.text.SimpleDateFormat;
private Date loginTime;
private long inRpcSuccess, inRpcFail, outRpcError;
+ private volatile boolean delayedClose;
public NetconfServerSession(final NetconfServerSessionListener sessionListener, final Channel channel, final long sessionId,
final NetconfHelloMessageAdditionalHeader header) {
super.sessionUp();
}
+ /**
+ * Close this session after next message is sent.
+ * Suitable for close rpc that needs to send ok response before the session is closed.
+ */
+ public void delayedClose() {
+ this.delayedClose = true;
+ }
+
+ @Override
+ public ChannelFuture sendMessage(final NetconfMessage netconfMessage) {
+ final ChannelFuture channelFuture = super.sendMessage(netconfMessage);
+ // delayed close was set, close after the message was sent
+ if(delayedClose) {
+ channelFuture.addListener(new ChannelFutureListener() {
+ @Override
+ public void operationComplete(final ChannelFuture future) throws Exception {
+ close();
+ }
+ });
+ }
+ return channelFuture;
+ }
+
public void onIncommingRpcSuccess() {
inRpcSuccess++;
}
return builder.build();
}
- private Class<? extends Transport> getTransportForString(final String transport) {
+ private static Class<? extends Transport> getTransportForString(final String transport) {
switch(transport) {
case "ssh" :
return NetconfSsh.class;
}
}
- private String formatDateTime(final Date loginTime) {
+ private static String formatDateTime(final Date loginTime) {
+ // FIXME: thread-local cache?
SimpleDateFormat dateFormat = new SimpleDateFormat(ISO_DATE_FORMAT);
return dateFormat.format(loginTime);
}