Example #1
0
  @Override
  public void onSessionUp(final NetconfClientSession session) {
    sessionLock.lock();
    try {
      logger.debug("{}: Session established", id);
      this.session = session;

      NetconfSessionCapabilities netconfSessionCapabilities =
          NetconfSessionCapabilities.fromNetconfSession(session);
      logger.trace("{}: Session advertised capabilities: {}", id, netconfSessionCapabilities);

      if (overrideNetconfCapabilities.isPresent()) {
        netconfSessionCapabilities =
            netconfSessionCapabilities.replaceModuleCaps(overrideNetconfCapabilities.get());
        logger.debug(
            "{}: Session capabilities overridden, capabilities that will be used: {}",
            id,
            netconfSessionCapabilities);
      }

      remoteDevice.onRemoteSessionUp(netconfSessionCapabilities, this);
    } finally {
      sessionLock.unlock();
    }
  }
Example #2
0
  private void processNotification(final NetconfMessage notification) {
    logger.debug("{}: Notification received: {}", id, notification);

    if (logger.isTraceEnabled()) {
      logger.trace("{}: Notification received: {}", id, msgToS(notification));
    }

    remoteDevice.onNotification(notification);
  }
Example #3
0
  private void tearDown(String reason) {
    List<UncancellableFuture<RpcResult<NetconfMessage>>> futuresToCancel = Lists.newArrayList();
    sessionLock.lock();
    try {
      if (session != null) {
        session = null;

        /*
         * Walk all requests, check if they have been executing
         * or cancelled and remove them from the queue.
         */
        final Iterator<Request> it = requests.iterator();
        while (it.hasNext()) {
          final Request r = it.next();
          if (r.future.isUncancellable()) {
            futuresToCancel.add(r.future);
            it.remove();
          } else if (r.future.isCancelled()) {
            // This just does some house-cleaning
            it.remove();
          }
        }

        remoteDevice.onRemoteSessionDown();
      }
    } finally {
      sessionLock.unlock();
    }

    // Notify pending request futures outside of the sessionLock to avoid unnecessarily
    // blocking the caller.
    for (UncancellableFuture<RpcResult<NetconfMessage>> future : futuresToCancel) {
      if (Strings.isNullOrEmpty(reason)) {
        future.set(createSessionDownRpcResult());
      } else {
        future.set(createErrorRpcResult(RpcError.ErrorType.TRANSPORT, reason));
      }
    }
  }