Exemplo n.º 1
0
  /**
   * Uninstalls a single intent by Id.
   *
   * @param appId the Application ID
   * @param keyString the Intent key value to look up
   */
  @DELETE
  @Path("{appId}/{key}")
  public void deleteIntentById(
      @PathParam("appId") String appId, @PathParam("key") String keyString) {
    final ApplicationId app = get(CoreService.class).getAppId(appId);

    Intent intent = get(IntentService.class).getIntent(Key.of(keyString, app));
    IntentService service = get(IntentService.class);

    if (intent == null) {
      intent = service.getIntent(Key.of(Long.decode(keyString), app));
    }
    if (intent == null) {
      // No such intent.  REST standards recommend a positive status code
      // in this case.
      return;
    }

    Key key = intent.key();

    // set up latch and listener to track uninstall progress
    CountDownLatch latch = new CountDownLatch(1);

    IntentListener listener = new DeleteListener(key, latch);
    service.addListener(listener);

    try {
      // request the withdraw
      service.withdraw(intent);

      try {
        latch.await(WITHDRAW_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
      } catch (InterruptedException e) {
        log.info("REST Delete operation timed out waiting for intent {}", key);
      }
      // double check the state
      IntentState state = service.getIntentState(key);
      if (state == WITHDRAWN || state == FAILED) {
        service.purge(intent);
      }

    } finally {
      // clean up the listener
      service.removeListener(listener);
    }
  }
Exemplo n.º 2
0
  @Override
  protected void execute() {
    IntentService intentService = get(IntentService.class);
    CoreService coreService = get(CoreService.class);

    ApplicationId appId = appId();
    if (!isNullOrEmpty(applicationIdString)) {
      appId = coreService.getAppId(applicationIdString);
      if (appId == null) {
        print("Cannot find application Id %s", applicationIdString);
        return;
      }
    }

    if (isNullOrEmpty(keyString)) {
      for (Intent intent : intentService.getIntents()) {
        if (intent.appId().equals(appId)) {
          removeIntent(intentService, intent);
        }
      }

    } else {
      final Key key;
      if (keyString.startsWith("0x")) {
        // The intent uses a LongKey
        keyString = keyString.replaceFirst("0x", "");
        key = Key.of(new BigInteger(keyString, 16).longValue(), appId);
      } else {
        // The intent uses a StringKey
        key = Key.of(keyString, appId);
      }

      Intent intent = intentService.getIntent(key);
      if (intent != null) {
        removeIntent(intentService, intent);
      }
    }
  }