import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.local.LocalAddress;
-import io.netty.channel.local.LocalChannel;
import io.netty.channel.local.LocalServerChannel;
-import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.Promise;
import java.net.InetSocketAddress;
import org.opendaylight.netconf.api.NetconfServerDispatcher;
@Override
public ChannelFuture createServer(InetSocketAddress address) {
- return super.createServer(address, new PipelineInitializer<NetconfServerSession>() {
- @Override
- public void initializeChannel(final SocketChannel ch, final Promise<NetconfServerSession> promise) {
- initializer.initialize(ch, promise);
- }
- });
+ return super.createServer(address, initializer::initialize);
}
@Override
public ChannelFuture createLocalServer(LocalAddress address) {
- return super.createServer(address, LocalServerChannel.class, new ChannelPipelineInitializer<LocalChannel,
- NetconfServerSession>() {
- @Override
- public void initializeChannel(final LocalChannel ch, final Promise<NetconfServerSession> promise) {
- initializer.initialize(ch, promise);
- }
- });
+ return super.createServer(address, LocalServerChannel.class, initializer::initialize);
}
public static class ServerChannelInitializer extends AbstractChannelInitializer<NetconfServerSession> {
}
final String currentModuleName = cap.getModuleName().get();
- Map<String, String> revisionMap = mappedModulesToRevisionToSchema.get(currentModuleName);
- if (revisionMap == null) {
- revisionMap = Maps.newHashMap();
- mappedModulesToRevisionToSchema.put(currentModuleName, revisionMap);
- }
+ Map<String, String> revisionMap =
+ mappedModulesToRevisionToSchema.computeIfAbsent(currentModuleName, k -> Maps.newHashMap());
final String currentRevision = cap.getRevision().get();
revisionMap.put(currentRevision, cap.getCapabilitySchema().get());
if (!running) {
startUpdateSessionStats();
}
- return new AutoCloseable() {
- @Override
- public void close() {
- listeners.remove(listener);
- }
- };
+ return () -> listeners.remove(listener);
}
@Override
import io.netty.util.Timeout;
import io.netty.util.Timer;
import io.netty.util.TimerTask;
-import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import io.netty.util.concurrent.Promise;
import java.util.concurrent.TimeUnit;
} else {
final Optional<SslHandler> sslHandler = getSslHandler(channel);
if (sslHandler.isPresent()) {
- Future<Channel> future = sslHandler.get().handshakeFuture();
- future.addListener(new GenericFutureListener<Future<? super Channel>>() {
- @Override
- public void operationComplete(final Future<? super Channel> future) {
- Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful");
- LOG.debug("Ssl handshake complete");
- start();
- }
+ sslHandler.get().handshakeFuture().addListener(future -> {
+ Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful");
+ LOG.debug("Ssl handshake complete");
+ start();
});
} else {
start();
LOG.warn("Netconf session was not established after {}", connectionTimeoutMillis);
changeState(State.FAILED);
- channel.close().addListener(new GenericFutureListener<ChannelFuture>() {
- @Override
- public void operationComplete(final ChannelFuture future) {
- if (future.isSuccess()) {
- LOG.debug("Channel {} closed: success", future.channel());
- } else {
- LOG.warn("Channel {} closed: fail", future.channel());
- }
+ channel.close().addListener((GenericFutureListener<ChannelFuture>) future -> {
+ if (future.isSuccess()) {
+ LOG.debug("Channel {} closed: success", future.channel());
+ } else {
+ LOG.warn("Channel {} closed: fail", future.channel());
}
});
}
* OpenEXI does not allow us to directly prevent resolution of external entities. In order
* to prevent XXE attacks, we reuse a single no-op entity resolver.
*/
- private static final EntityResolver ENTITY_RESOLVER = new EntityResolver() {
- @Override
- public InputSource resolveEntity(final String publicId, final String systemId) {
- return new InputSource();
- }
- };
+ private static final EntityResolver ENTITY_RESOLVER = (publicId, systemId) -> new InputSource();
/**
* Since we have a limited number of options we can have, instantiating a weak cache
ClientChannel localChannel = channel;
sshReadAsyncListener = new AsyncSshHandlerReader(() -> AsyncSshHandler.this.disconnect(ctx, ctx.newPromise()),
- msg -> ctx.fireChannelRead(msg), localChannel.toString(), localChannel.getAsyncOut());
+ ctx::fireChannelRead, localChannel.toString(), localChannel.getAsyncOut());
// if readAsyncListener receives immediate close,
// it will close this handler and closing this handler sets channel variable to null
import io.netty.channel.EventLoopGroup;
import io.netty.channel.local.LocalAddress;
import io.netty.channel.local.LocalChannel;
-import io.netty.util.concurrent.GenericFutureListener;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
}
});
clientChannelFuture = clientBootstrap.connect(localAddress);
- clientChannelFuture.addListener(new GenericFutureListener<ChannelFuture>() {
-
- @Override
- public void operationComplete(final ChannelFuture future) {
- if (future.isSuccess()) {
- clientChannel = clientChannelFuture.channel();
- } else {
- LOG.warn("Unable to establish internal connection to netconf server for client: {}",
- getClientAddress());
- Preconditions.checkNotNull(callback, "Exit callback must be set");
- callback.onExit(1, "Unable to establish internal connection to netconf server for client: "
- + getClientAddress());
- }
+ clientChannelFuture.addListener(future -> {
+ if (future.isSuccess()) {
+ clientChannel = clientChannelFuture.channel();
+ } else {
+ LOG.warn("Unable to establish internal connection to netconf server for client: {}",
+ getClientAddress());
+ Preconditions.checkNotNull(callback, "Exit callback must be set");
+ callback.onExit(1, "Unable to establish internal connection to netconf server for client: "
+ + getClientAddress());
}
});
}
clientChannelFuture.cancel(true);
if (clientChannel != null) {
- clientChannel.close().addListener(new GenericFutureListener<ChannelFuture>() {
-
- @Override
- public void operationComplete(final ChannelFuture future) {
- if (!future.isSuccess()) {
- LOG.warn("Unable to release internal connection to netconf server on channel: {}",
- clientChannel);
- }
+ clientChannel.close().addListener(future -> {
+ if (!future.isSuccess()) {
+ LOG.warn("Unable to release internal connection to netconf server on channel: {}",
+ clientChannel);
}
});
}
dataChangeListenerRegistration = null;
}
- contexts.values().forEach(netconfTopologyContext -> close(netconfTopologyContext));
-
- clusterRegistrations.values().forEach(
- clusterSingletonServiceRegistration -> close(clusterSingletonServiceRegistration));
+ contexts.values().forEach(NetconfTopologyManager::close);
+ clusterRegistrations.values().forEach(NetconfTopologyManager::close);
contexts.clear();
clusterRegistrations.clear();
import java.util.function.Consumer;
import javax.annotation.concurrent.GuardedBy;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
return false;
}
- processTransactionOperation(facade -> facade.cancel());
+ processTransactionOperation(AsyncWriteTransaction::cancel);
return true;
}
import com.google.common.collect.ImmutableSet;
import java.io.File;
-import java.security.PublicKey;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
-import org.apache.sshd.server.session.ServerSession;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.auth.AuthProvider;
import org.opendaylight.netconf.test.tool.operations.OperationsCreator;
return true;
};
- public static final PublickeyAuthenticator DEFAULT_PUBLIC_KEY_AUTHENTICATOR = new PublickeyAuthenticator() {
- @Override
- public boolean authenticate(final String username, final PublicKey key, final ServerSession session) {
- LOG.info("Auth with public key: {}", key);
- return true;
- }
+ public static final PublickeyAuthenticator DEFAULT_PUBLIC_KEY_AUTHENTICATOR = (username, key, session) -> {
+ LOG.info("Auth with public key: {}", key);
+ return true;
};
private int generateConfigsTimeout = (int) TimeUnit.MINUTES.toMillis(30);
}
private List<V> getValues(K key) {
- List<V> list = store.get(key);
- if (list == null) {
- list = new LinkedList<>();
- store.put(key, list);
- }
-
- return list;
+ return store.computeIfAbsent(key, k -> new LinkedList<>());
}
}
final URI namespace = node.getQName().getNamespace();
final Optional<Revision> revision = node.getQName().getRevision();
- Map<Optional<Revision>, Module> revisionToModule = NAMESPACE_AND_REVISION_TO_MODULE.get(namespace);
- if (revisionToModule == null) {
- revisionToModule = new HashMap<>();
- NAMESPACE_AND_REVISION_TO_MODULE.put(namespace, revisionToModule);
- }
- Module module = revisionToModule.get(revision);
- if (module == null) {
- module = schemaContext.findModule(namespace, revision).orElse(null);
- revisionToModule.put(revision, module);
- }
+ Map<Optional<Revision>, Module> revisionToModule =
+ NAMESPACE_AND_REVISION_TO_MODULE.computeIfAbsent(namespace, k -> new HashMap<>());
+ Module module =
+ revisionToModule.computeIfAbsent(revision, k -> schemaContext.findModule(namespace, k).orElse(null));
if (module != null) {
return module.getName() + ":" + node.getQName().getLocalName();
}