Esempio n. 1
0
  protected void advanceInitializers(IOFSwitchExt sw) {
    CopyOnWriteArrayList<IOFInitializerListener> initializers = initializerMap.get(sw);

    // Remove first initializer if it exists
    Iterator<IOFInitializerListener> it = initializers.iterator();
    if (it.hasNext()) {
      IOFInitializerListener initializer = it.next();
      initializers.remove(initializer);
      log.debug("Remaining initializers for switch {}: {}", sw, initializers);
    }

    if (it.hasNext()) {
      IOFInitializerListener initializer = it.next();
      queueInitializer(sw, initializer);
    } else {
      /**
       * Must synchronize here to ensure we don't transition into active while simultaneously being
       * disconnected.
       */
      synchronized (sw) {
        if (!OFSwitchState.DISCONNECTED.equals(sw.getState())) {
          sw.transitionToState(OFSwitchState.ACTIVE);
          // Add switch to active list
          addActiveSwitch(sw);
        }
        initializerMap.remove(sw);
      }
    }
  }
Esempio n. 2
0
 /** Disconnect the switch from Beacon */
 protected void disconnectSwitch(SelectionKey key, IOFSwitchExt sw) {
   /**
    * Must synchronize here to ensure we don't transition into active while simultaneously being
    * disconnected.
    */
   synchronized (sw) {
     key.cancel();
     OFStream stream = (OFStream) sw.getInputStream();
     stream.getIOLoop().removeStream(stream);
     removeSwitch(sw);
     try {
       sw.getSocketChannel().socket().close();
     } catch (IOException e1) {
     }
     this.initializerMap.remove(sw);
     if (!OFSwitchState.DISCONNECTED.equals(sw.getState())) {
       sw.transitionToState(OFSwitchState.DISCONNECTED);
     }
     log.info("Switch disconnected {}", sw);
   }
 }