コード例 #1
0
  @Override
  public void unsubscribe(String arn) throws Exception {

    CNSSubscription s = getSubscription(arn);

    if (s != null) {

      deleteIndexes(arn, s.getUserId(), s.getToken());
      CmbComposite columnName =
          cassandraHandler.getCmbComposite(s.getEndpoint(), s.getProtocol().name());
      cassandraHandler.delete(
          AbstractDurablePersistence.CNS_KEYSPACE,
          columnFamilySubscriptions,
          Util.getCnsTopicArn(arn),
          columnName,
          CMB_SERIALIZER.STRING_SERIALIZER,
          CMB_SERIALIZER.COMPOSITE_SERIALIZER);

      if (s.isConfirmed()) {
        cassandraHandler.decrementCounter(
            AbstractDurablePersistence.CNS_KEYSPACE,
            columnFamilyTopicStats,
            s.getTopicArn(),
            "subscriptionConfirmed",
            1,
            CMB_SERIALIZER.STRING_SERIALIZER,
            CMB_SERIALIZER.STRING_SERIALIZER);
      } else {
        cassandraHandler.decrementCounter(
            AbstractDurablePersistence.CNS_KEYSPACE,
            columnFamilyTopicStats,
            s.getTopicArn(),
            "subscriptionPending",
            1,
            CMB_SERIALIZER.STRING_SERIALIZER,
            CMB_SERIALIZER.STRING_SERIALIZER);
      }

      cassandraHandler.incrementCounter(
          AbstractDurablePersistence.CNS_KEYSPACE,
          columnFamilyTopicStats,
          s.getTopicArn(),
          "subscriptionDeleted",
          1,
          CMB_SERIALIZER.STRING_SERIALIZER,
          CMB_SERIALIZER.STRING_SERIALIZER);
    }
  }
コード例 #2
0
  @Override
  public CNSSubscription confirmSubscription(
      boolean authenticateOnUnsubscribe, String token, String topicArn) throws Exception {

    // get Sub-arn given token
    CmbColumnSlice<String, String> slice =
        cassandraHandler.readColumnSlice(
            AbstractDurablePersistence.CNS_KEYSPACE,
            columnFamilySubscriptionsTokenIndex,
            token,
            null,
            null,
            1,
            CMB_SERIALIZER.STRING_SERIALIZER,
            CMB_SERIALIZER.STRING_SERIALIZER,
            CMB_SERIALIZER.STRING_SERIALIZER);

    if (slice == null) {
      throw new CMBException(CMBErrorCodes.NotFound, "Resource not found.");
    }

    // get Column from main table
    String subArn = slice.getColumns().get(0).getName();

    // get Subscription given subArn
    final CNSSubscription s = getSubscription(subArn);

    if (s == null) {
      throw new SubscriberNotFoundException(
          "Could not find subscription given subscription arn " + subArn);
    }

    s.setAuthenticateOnUnsubscribe(authenticateOnUnsubscribe);
    s.setConfirmed(true);
    s.setConfirmDate(new Date());

    // re-insert with no TTL. will clobber the old one which had ttl
    insertOrUpdateSubsAndIndexes(s, null);

    cassandraHandler.decrementCounter(
        AbstractDurablePersistence.CNS_KEYSPACE,
        columnFamilyTopicStats,
        s.getTopicArn(),
        "subscriptionPending",
        1,
        CMB_SERIALIZER.STRING_SERIALIZER,
        CMB_SERIALIZER.STRING_SERIALIZER);
    cassandraHandler.incrementCounter(
        AbstractDurablePersistence.CNS_KEYSPACE,
        columnFamilyTopicStats,
        s.getTopicArn(),
        "subscriptionConfirmed",
        1,
        CMB_SERIALIZER.STRING_SERIALIZER,
        CMB_SERIALIZER.STRING_SERIALIZER);

    return s;
  }
コード例 #3
0
  @Override
  public void unsubscribeAll(String topicArn) throws Exception {

    int pageSize = 1000;

    String nextToken = null;
    List<CNSSubscription> subs =
        listSubscriptionsByTopic(nextToken, topicArn, null, pageSize, false);

    // Note: for pagination to work we need the nextToken's corresponding sub to not be deleted.
    CNSSubscription nextTokenSub = null;
    while (subs.size() > 0) {
      // if retrieve subscription is less than page size, delete all index.
      if (subs.size() < pageSize) {
        deleteIndexesAll(subs);
        break;
      } else {
        // keep the last subscription for pagination purpose.
        nextTokenSub = subs.get(subs.size() - 1);
        nextToken = nextTokenSub.getArn();
        subs.remove(subs.size() - 1);
        deleteIndexesAll(subs);
        subs = listSubscriptionsByTopic(nextToken, topicArn, null, pageSize, false);
        deleteIndexes(nextTokenSub.getArn(), nextTokenSub.getUserId(), nextTokenSub.getToken());
      }
    }

    // int subscriptionConfirmedNum = (int)cassandraHandler.getCounter(CNS_KEYSPACE,
    // columnFamilyTopicStats, topicArn, "subscriptionConfirmed", CMB_SERIALIZER.STRING_SERIALIZER,
    // CMB_SERIALIZER.STRING_SERIALIZER);
    // int subscriptionPendingNum = (int)cassandraHandler.getCounter(CNS_KEYSPACE,
    // columnFamilyTopicStats, topicArn, "subscriptionPending", CMB_SERIALIZER.STRING_SERIALIZER,
    // CMB_SERIALIZER.STRING_SERIALIZER);

    cassandraHandler.incrementCounter(
        AbstractDurablePersistence.CNS_KEYSPACE,
        columnFamilyTopicStats,
        topicArn,
        "subscriptionDeleted",
        1,
        CMB_SERIALIZER.STRING_SERIALIZER,
        CMB_SERIALIZER.STRING_SERIALIZER);
    cassandraHandler.decrementCounter(
        AbstractDurablePersistence.CNS_KEYSPACE,
        columnFamilyTopicStats,
        topicArn,
        "subscriptionConfirmed",
        1,
        CMB_SERIALIZER.STRING_SERIALIZER,
        CMB_SERIALIZER.STRING_SERIALIZER);
    cassandraHandler.decrementCounter(
        AbstractDurablePersistence.CNS_KEYSPACE,
        columnFamilyTopicStats,
        topicArn,
        "subscriptionPending",
        1,
        CMB_SERIALIZER.STRING_SERIALIZER,
        CMB_SERIALIZER.STRING_SERIALIZER);

    cassandraHandler.delete(
        AbstractDurablePersistence.CNS_KEYSPACE,
        columnFamilySubscriptions,
        topicArn,
        null,
        CMB_SERIALIZER.STRING_SERIALIZER,
        CMB_SERIALIZER.STRING_SERIALIZER);
  }