-/**\r
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.openflowplugin.applications.frsync.impl;\r
-\r
-import java.util.concurrent.Callable;\r
-import java.util.concurrent.TimeUnit;\r
-import java.util.concurrent.TimeoutException;\r
-\r
-import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;\r
-import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import com.google.common.util.concurrent.ListenableFuture;\r
-import com.google.common.util.concurrent.ListeningExecutorService;\r
-\r
-/**\r
- * Decorator for running delegate syncup in Future.\r
- */\r
-public class SyncReactorFutureDecorator implements SyncReactor {\r
-\r
- private static final Logger LOG = LoggerFactory.getLogger(SyncReactorFutureDecorator.class);\r
-\r
- private final SyncReactor delegate;\r
- private final ListeningExecutorService executorService;\r
-\r
- public static final String FRM_RPC_CLIENT_PREFIX = "FRM-RPC-client-";\r
-\r
- public SyncReactorFutureDecorator(SyncReactor delegate, ListeningExecutorService executorService) {\r
- this.delegate = delegate;\r
- this.executorService = executorService;\r
- }\r
-\r
- public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,\r
- final FlowCapableNode configTree, final FlowCapableNode operationalTree) throws InterruptedException {\r
- final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);\r
- LOG.trace("syncup {}", nodeId.getValue());\r
-\r
- final ListenableFuture<Boolean> syncup = executorService.submit(new Callable<Boolean>() {\r
- public Boolean call() throws Exception {\r
- final String oldThreadName = updateThreadName(nodeId);\r
-\r
- try {\r
- final Boolean ret = doSyncupInFuture(flowcapableNodePath, configTree, operationalTree)\r
- .get(10000, TimeUnit.MILLISECONDS);\r
- LOG.trace("ret {} {}", nodeId.getValue(), ret);\r
- return true;\r
- } catch (TimeoutException e) {\r
- LOG.error("doSyncupInFuture timeout occured {}", nodeId.getValue(), e);\r
- return false;\r
- } finally {\r
- updateThreadName(oldThreadName);\r
- }\r
- }\r
- });\r
- \r
- return syncup;\r
- }\r
-\r
- protected ListenableFuture<Boolean> doSyncupInFuture(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,\r
- final FlowCapableNode configTree, final FlowCapableNode operationalTree)\r
- throws InterruptedException {\r
- final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);\r
- LOG.trace("doSyncupInFuture {}", nodeId.getValue());\r
-\r
- return delegate.syncup(flowcapableNodePath, configTree, operationalTree);\r
- }\r
-\r
- static String threadName() {\r
- final Thread currentThread = Thread.currentThread();\r
- return currentThread.getName();\r
- }\r
-\r
- protected String updateThreadName(NodeId nodeId) {\r
- final Thread currentThread = Thread.currentThread();\r
- final String oldName = currentThread.getName();\r
- try {\r
- if (oldName.startsWith(SyncReactorFutureDecorator.FRM_RPC_CLIENT_PREFIX)) {\r
- currentThread.setName(oldName + "@" + nodeId.getValue());\r
- } else {\r
- LOG.warn("try to update foreign thread name {} {}", nodeId, oldName);\r
- }\r
- } catch (Exception e) {\r
- LOG.error("failed updating threadName {}", nodeId, e);\r
- }\r
- return oldName;\r
- }\r
-\r
- protected String updateThreadName(String name) {\r
- final Thread currentThread = Thread.currentThread();\r
- final String oldName = currentThread.getName();\r
- try {\r
- if (oldName.startsWith(SyncReactorFutureDecorator.FRM_RPC_CLIENT_PREFIX)) {\r
- currentThread.setName(name);\r
- } else {\r
- LOG.warn("try to update foreign thread name {} {}", oldName, name);\r
- }\r
- } catch (Exception e) {\r
- LOG.error("failed updating threadName {}", name, e);\r
- }\r
- return oldName;\r
- }\r
-}\r
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.applications.frsync.impl;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import org.opendaylight.openflowplugin.applications.frsync.SyncReactor;
+import org.opendaylight.openflowplugin.applications.frsync.util.PathUtil;
+import org.opendaylight.openflowplugin.applications.frsync.util.SyncupEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Decorator for running delegate syncup in Future.
+ */
+public class SyncReactorFutureDecorator implements SyncReactor {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SyncReactorFutureDecorator.class);
+ private final SyncReactor delegate;
+ private final ListeningExecutorService executorService;
+
+ public SyncReactorFutureDecorator(final SyncReactor delegate, final ListeningExecutorService executorService) {
+ this.delegate = delegate;
+ this.executorService = executorService;
+ }
+
+ public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,
+ final SyncupEntry syncupEntry) {
+ final NodeId nodeId = PathUtil.digNodeId(flowcapableNodePath);
+ return executorService.submit(() -> {
+ try {
+ return doSyncupInFuture(flowcapableNodePath, syncupEntry).get(10000, TimeUnit.MILLISECONDS);
+ } catch (TimeoutException e) {
+ LOG.warn("Syncup future timeout occured {}", nodeId.getValue());
+ return Boolean.FALSE;
+ }
+ });
+ }
+
+ protected ListenableFuture<Boolean> doSyncupInFuture(final InstanceIdentifier<FlowCapableNode> flowcapableNodePath,
+ final SyncupEntry syncupEntry) {
+ return delegate.syncup(flowcapableNodePath, syncupEntry);
+ }
+}