Merge "Conductor RPC registration moved"
[openflowplugin.git] / openflowplugin-api / src / main / java / org / opendaylight / openflowplugin / api / openflow / device / DeviceContext.java
index 413131105b20f17b2c972a0a15f1f410f8118ec6..79b84011b4c720689439c52e73c03cdd65952b36 100644 (file)
@@ -8,17 +8,15 @@
 
 package org.opendaylight.openflowplugin.api.openflow.device;
 
+import com.google.common.util.concurrent.ListenableFuture;
 import io.netty.util.Timeout;
 import java.math.BigInteger;
 import java.util.List;
+import javax.annotation.CheckForNull;
+
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.md.sal.binding.api.NotificationService;
-import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginTimer;
+import org.opendaylight.openflowplugin.api.openflow.OFPContext;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextClosedHandler;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
@@ -26,10 +24,10 @@ import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegi
 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
 
 /**
  * <p>
@@ -46,29 +44,59 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
  * Context can have at any point in time. Should this quota be exceeded, any further attempt to make
  * a request to the switch will fail immediately, with proper error indication.
  * </p>
- * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
  */
 public interface DeviceContext extends AutoCloseable,
-        OpenFlowPluginTimer,
         DeviceReplyProcessor,
-        DeviceDisconnectedHandler,
-        PortNumberCache {
+        PortNumberCache,
+        TxFacade,
+        XidSequencer,
+        OFPContext{
+
+    void setStatisticsRpcEnabled(boolean isStatisticsRpcEnabled);
 
+    /**
+     * distinguished device context states
+     */
+    enum DEVICE_CONTEXT_STATE {
+        /**
+         * initial phase of talking to switch
+         */
+        INITIALIZATION,
+        /**
+         * standard phase - interacting with switch
+         */
+        WORKING,
+        /**
+         * termination phase of talking to switch
+         */
+        TERMINATION
+    }
+
+    /**
+     * Method returns current device context state.
+     *
+     * @return {@link DeviceContext.DEVICE_CONTEXT_STATE}
+     */
+    DEVICE_CONTEXT_STATE getDeviceContextState();
+
+    /**
+     * Method close all auxiliary connections and primary connection.
+     */
+    void shutdownConnection();
 
     /**
      * Method add auxiliary connection contexts to this context representing single device connection.
      *
      * @param connectionContext
      */
-    void addAuxiliaryConenctionContext(ConnectionContext connectionContext);
+    void addAuxiliaryConnectionContext(ConnectionContext connectionContext);
 
     /**
      * Method removes auxiliary connection context from this context representing single device connection.
      *
      * @param connectionContext
      */
-    void removeAuxiliaryConenctionContext(ConnectionContext connectionContext);
-
+    void removeAuxiliaryConnectionContext(ConnectionContext connectionContext);
 
     /**
      * Method provides state of device represented by this device context.
@@ -77,30 +105,34 @@ public interface DeviceContext extends AutoCloseable,
      */
     DeviceState getDeviceState();
 
-    /**
-     * Method creates put operation using provided data in underlying transaction chain.
-     */
-    <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store, final InstanceIdentifier<T> path, final T data);
+    DeviceInfo getDeviceInfo();
 
     /**
-     * Method creates delete operation for provided path in underlying transaction chain.
+     * Method has to activate (MASTER) or deactivate (SLAVE) TransactionChainManager.
+     * TransactionChainManager represents possibility to write or delete Node subtree data
+     * for actual Controller Cluster Node. We are able to have an active TxManager only if
+     * newRole is {@link OfpRole#BECOMESLAVE}.
+     * Parameters are used as marker to be sure it is change to SLAVE from MASTER or from
+     * MASTER to SLAVE and the last parameter "cleanDataStore" is used for validation only.
+     * @param role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER}
+     * @return RoleChangeTxChainManager future for activation/deactivation
+     * @deprecated replaced by method onDeviceTakeClusterLeadership and onDevicLostClusterLeadership
      */
-    <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path);
+    @Deprecated
+    ListenableFuture<Void> onClusterRoleChange(@CheckForNull OfpRole role);
 
     /**
-     * Method submits Transaction to DataStore.
-     * @return transaction is submitted successfully
+     * Method has to activate TransactionChainManager and prepare all Contexts from Device Contects suite
+     * to Taking ClusterLeadership role {@link OfpRole#BECOMEMASTER} (e.g. Routed RPC registration, StatPolling ...)
+     * @return DeviceInitialization furure
      */
-    boolean submitTransaction();
+    ListenableFuture<Void> onDeviceTakeClusterLeadership();
 
     /**
-     * Method exposes transaction created for device
-     * represented by this context. This read only transaction has a fresh dataStore snapshot.
-     * There is a possibility to get different data set from  DataStore
-     * as write transaction in this context.
+     * Method has to close TxManager ASAP we are notified about Closed Connection
+     * @return sync. future for Slave and MD-SAL completition for Master
      */
-    ReadTransaction getReadTransaction();
-
+    ListenableFuture<Void> shuttingDownDataStoreTransactions();
 
     /**
      * Method provides current devices connection context.
@@ -153,26 +185,12 @@ public interface DeviceContext extends AutoCloseable,
      */
     Timeout getBarrierTaskTimeout();
 
-    /**
-     * Sets notification service
-     *
-     * @param notificationService
-     */
-    void setNotificationService(NotificationService notificationService);
-
     void setNotificationPublishService(NotificationPublishService notificationPublishService);
 
     MessageSpy getMessageSpy();
 
-    /**
-     * Method sets reference to handler used for cleanup after device context about to be closed.
-     */
-    void addDeviceContextClosedHandler(DeviceContextClosedHandler deviceContextClosedHandler);
-
     MultiMsgCollector getMultiMsgCollector(final RequestContext<List<MultipartReply>> requestContext);
 
-    Long getReservedXid();
-
     /**
      * indicates that device context is fully published (e.g.: packetIn messages should be passed)
      */
@@ -194,9 +212,11 @@ public interface DeviceContext extends AutoCloseable,
 
     RpcContext getRpcContext();
 
-    /**
-     * Callback when confirmed that device is disconnected from cluster
-      */
-    void onDeviceDisconnectedFromCluster();
+    void setStatisticsContext(StatisticsContext statisticsContext);
+
+    StatisticsContext getStatisticsContext();
+
+    @Override
+    void close();
 }