Added support for switch idle state
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / connection / ConnectionAdapterImpl.java
index f2e5fdcaf553e5123da807ba37890dfdb832797b..0658b7146d4bbb11a48f70a3134dc587256df0fa 100644 (file)
@@ -51,6 +51,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.Notification;
@@ -96,19 +97,10 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
         responseCache = CacheBuilder.newBuilder()
                 .concurrencyLevel(1)
                 .expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
-                .removalListener(new RemovalListener<RpcResponseKey, SettableFuture<?>>() {
-
-                    @Override
-                    public void onRemoval(
-                            RemovalNotification<RpcResponseKey, SettableFuture<?>> notification) {
-                        SettableFuture<?> future = notification.getValue();
-                        if (!future.isDone()) {
-                            LOG.warn("rpc response discarded: " + notification.getKey());
-                               future.cancel(true);
-                        }
-                    }
-                }).build();
+                .removalListener(new ResponseRemovalListener()).build();
         LOG.info("ConnectionAdapter created");
+    
+    
     }
     
     /**
@@ -252,7 +244,9 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
                 systemListener.onDisconnectEvent((DisconnectEvent) message);
                 responseCache.invalidateAll();
                 disconnectOccured = true;
-            } 
+            } else if (message instanceof SwitchIdleEvent) {
+                systemListener.onSwitchIdleEvent((SwitchIdleEvent) message);
+            }
             // OpenFlow messages
               else if (message instanceof EchoRequestMessage) {
                 messageListener.onEchoRequestMessage((EchoRequestMessage) message);
@@ -515,5 +509,18 @@ public class ConnectionAdapterImpl implements ConnectionFacade {
             throw new IllegalStateException("Missing listeners: " + buffer.toString());
         }
     }
+    
+    static class ResponseRemovalListener implements RemovalListener<RpcResponseKey, SettableFuture<?>> {
+
+        @Override
+        public void onRemoval(
+                RemovalNotification<RpcResponseKey, SettableFuture<?>> notification) {
+            SettableFuture<?> future = notification.getValue();
+            if (!future.isDone()) {
+                LOG.warn("rpc response discarded: " + notification.getKey());
+                future.cancel(true);
+            }
+        }
+    }
 
 }