*/
package org.opendaylight.controller.sal.connect.netconf.sal;
+import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.Collections;
-
import java.util.concurrent.ExecutorService;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Preconditions;
-
final class NetconfDeviceSalProvider implements AutoCloseable, Provider, BindingAwareProvider {
private static final Logger logger = LoggerFactory.getLogger(NetconfDeviceSalProvider.class);
public MountProvisionInstance getMountInstance() {
Preconditions.checkState(mountInstance != null,
- "%s: Sal provider was not initialized by sal. Cannot publish notification", id);
+ "%s: Sal provider was not initialized by sal. Cannot get mount instance", id);
return mountInstance;
}
public NetconfDeviceDatastoreAdapter getDatastoreAdapter() {
Preconditions.checkState(datastoreAdapter != null,
- "%s: Sal provider %s was not initialized by sal. Cannot publish notification", id);
+ "%s: Sal provider %s was not initialized by sal. Cannot get datastore adapter", id);
return datastoreAdapter;
}
}
private State state = State.IDLE;
+ private final Promise<S> promise;
private final Timer timer;
private final long connectionTimeoutMillis;
L sessionListener, long connectionTimeoutMillis) {
super(promise, channel);
this.sessionPreferences = sessionPreferences;
+ this.promise = promise;
this.timer = timer;
this.sessionListener = sessionListener;
this.connectionTimeoutMillis = connectionTimeoutMillis;
channel.pipeline().addLast(NAME_OF_EXCEPTION_HANDLER, new ExceptionHandlingInboundChannelHandler());
+ // FIXME, make sessionPreferences return HelloMessage, move NetconfHelloMessage to API
+ sendMessage((NetconfHelloMessage)helloMessage);
+
+ replaceHelloMessageOutboundHandler();
+ changeState(State.OPEN_WAIT);
+
timeout = this.timer.newTimeout(new TimerTask() {
@Override
public void run(final Timeout timeout) {
synchronized (this) {
if (state != State.ESTABLISHED) {
+
logger.debug("Connection timeout after {}, session is in state {}", timeout, state);
- final IllegalStateException cause = new IllegalStateException(
- "Session was not established after " + timeout);
- negotiationFailed(cause);
+
+ // Do not fail negotiation if promise is done or canceled
+ // It would result in setting result of the promise second time and that throws exception
+ if (isPromiseFinished() == false) {
+ // FIXME BUG-1365 calling "negotiation failed" closes the channel, but the channel does not get closed if data is still being transferred
+ // Loopback connection initiation might
+ negotiationFailed(new IllegalStateException("Session was not established after " + timeout));
+ }
+
changeState(State.FAILED);
} else if(channel.isOpen()) {
channel.pipeline().remove(NAME_OF_EXCEPTION_HANDLER);
}
}
}
- }, connectionTimeoutMillis, TimeUnit.MILLISECONDS);
- // FIXME, make sessionPreferences return HelloMessage, move NetconfHelloMessage to API
- sendMessage((NetconfHelloMessage)helloMessage);
+ private boolean isPromiseFinished() {
+ return promise.isDone() || promise.isCancelled();
+ }
- replaceHelloMessageOutboundHandler();
- changeState(State.OPEN_WAIT);
+ }, connectionTimeoutMillis, TimeUnit.MILLISECONDS);
}
private void cancelTimeout() {