Exemplo n.º 1
0
  @Override
  protected Object doExecute() throws Exception {
    printInitCommand("remove protocol");
    IProtocolManager protocolManager = getProtocolManager();
    IResourceManager manager = getResourceManager();
    String[] argsRouterName = new String[2];
    try {
      argsRouterName = splitResourceName(resourceId);
    } catch (Exception e) {
      printError(e.getMessage());
      printEndCommand();
      return -1;
    }

    IResourceIdentifier resourceIdentifier =
        manager.getIdentifierFromResourceName(argsRouterName[0], argsRouterName[1]);

    IProtocolSessionManager sessionManager =
        protocolManager.getProtocolSessionManager(resourceIdentifier.getId());

    if (!optionAll && (sessionId == null || sessionId.contentEquals(""))) {
      printError("Either specify a session id or --all.");
    }
    if (optionAll) {
      for (String sessionID : sessionManager.getAllProtocolSessionIds()) {
        sessionManager.destroyProtocolSession(sessionID);
      }
    } else sessionManager.destroyProtocolSession(sessionId);
    printEndCommand();
    return null;
  }
  /**
   * If not exists the protocol session manager, it's created and add the session context
   *
   * @param resourceId
   * @throws ProtocolException
   */
  private IProtocolSessionManager addSessionContext(String resourceId) throws ProtocolException {
    ProtocolSessionContext psc = new ProtocolSessionContext();
    IProtocolSessionManager psm = protocolManager.getProtocolSessionManager(resourceId);

    psc.addParameter(ProtocolSessionContext.PROTOCOL_URI, RESOURCE_URI);
    psc.addParameter(ProtocolSessionContext.PROTOCOL, "netconf");
    psc.addParameter(ProtocolSessionContext.AUTH_TYPE, "password");

    psm.registerContext(psc);

    return psm;
  }