package org.opendaylight.ovsdb.lib.impl;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.netty.channel.Channel;
-
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
import org.opendaylight.ovsdb.lib.EchoServiceCallbackFilters;
import org.opendaylight.ovsdb.lib.LockAquisitionCallback;
import org.opendaylight.ovsdb.lib.LockStolenCallback;
import org.opendaylight.ovsdb.lib.OvsdbClient;
import org.opendaylight.ovsdb.lib.OvsdbConnectionInfo;
import org.opendaylight.ovsdb.lib.OvsdbConnectionInfo.ConnectionType;
+import org.opendaylight.ovsdb.lib.OvsdbConnectionInfo.SocketConnectionType;
import org.opendaylight.ovsdb.lib.jsonrpc.Params;
import org.opendaylight.ovsdb.lib.message.MonitorRequest;
import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.SettableFuture;
-
public class OvsdbClientImpl implements OvsdbClient {
private OvsdbRPC.Callback rpcCallback;
private OvsdbConnectionInfo connectionInfo;
private Channel channel;
+ private static final ThreadFactory threadFactorySSL =
+ new ThreadFactoryBuilder().setNameFormat("OVSDB-PassiveConnection-SSL-%d").build();
+ private static final ThreadFactory threadFactoryNonSSL =
+ new ThreadFactoryBuilder().setNameFormat("OVSDB-PassiveConnection-Non-SSL-%d").build();
- public OvsdbClientImpl(OvsdbRPC rpc, Channel channel, ConnectionType type, ExecutorService executorService) {
+ public OvsdbClientImpl(OvsdbRPC rpc, Channel channel, ConnectionType type,
+ SocketConnectionType socketConnType) {
this.rpc = rpc;
- this.executorService = executorService;
+ ThreadFactory threadFactory =
+ getThreadFactory(type, socketConnType, channel.remoteAddress().toString());
+ this.executorService = Executors.newCachedThreadPool(threadFactory);
this.channel = channel;
-
this.connectionInfo = new OvsdbConnectionInfo(channel, type);
}
+ /**
+ * Genereate the threadFactory based on ACTIVE, PASSIVE (SSL/NON-SSL) connection type.
+ * @param type ACTIVE or PASSIVE {@link ConnectionType}
+ * @param socketConnType SSL or NON-SSL {@link SocketConnectionType}
+ * @param executorNameArgs Additional args to append to thread name format
+ * @return {@link ThreadFactory}
+ */
+ private ThreadFactory getThreadFactory(ConnectionType type,
+ SocketConnectionType socketConnType, String executorNameArgs) {
+ if (type == ConnectionType.PASSIVE) {
+ switch (socketConnType) {
+ case SSL:
+ return threadFactorySSL;
+ case NON_SSL:
+ return threadFactoryNonSSL;
+ default:
+ return Executors.defaultThreadFactory();
+ }
+ } else if (type == ConnectionType.ACTIVE) {
+ ThreadFactory threadFactorySSL =
+ new ThreadFactoryBuilder().setNameFormat("OVSDB-ActiveConnection-" + executorNameArgs + "-%d")
+ .build();
+ return threadFactorySSL;
+ }
+ // Default case
+ return Executors.defaultThreadFactory();
+ }
+
OvsdbClientImpl() {
}
}
}
+ @Override
+ public ListenableFuture<List<String>> echo() {
+ return rpc.echo();
+ }
+
@Override
public void lock(String lockId, LockAquisitionCallback lockedCallBack, LockStolenCallback stolenCallback) {
throw new UnsupportedOperationException("not yet implemented");
/**
* User friendly convenient method that make use of TyperUtils.getTypedRowWrapper to create a Typed Row Proxy
- * given the Typed Table Class
+ * given the Typed Table Class.
*
* @param klazz Typed Interface
* @return Proxy wrapper for the actual raw Row class.
@Override
public void disconnect() {
channel.disconnect();
+ executorService.shutdown();
}
}