Examples of CNSSubscription


Examples of com.comcast.cns.model.CNSSubscription

            }
           
            for (CmbColumn<String, String> col : cols) {
             
                String subArn = col.getName();
                CNSSubscription subscription = getSubscription(subArn);
               
                if (subscription == null) {
                    throw new IllegalStateException("Subscriptions-user-index contains subscription-arn which doesn't exist in subscriptions-index. subArn:" + subArn);
                }
               
                // ignore invalid subscriptions coming from Cassandra
               
                try {
                  subscription.checkIsValid();
                } catch (CMBException ex) {
                  logger.error("event=invalid_subscription " + subscription.toString(), ex);
                  continue;
                }
               
                if (protocol != null && subscription.getProtocol() != protocol) {
                  continue;
                }
               
                if (hidePendingArn) {
                    if (subscription.isConfirmed()) {
                        l.add(subscription);
                    else {
                        subscription.setArn("PendingConfirmation");
                        l.add(subscription);
                    }
                } else {
                    l.add(subscription);
                }
View Full Code Here

Examples of com.comcast.cns.model.CNSSubscription

            return l;
        }
       
        for (CmbColumn<CmbComposite, String> col : cols.getColumns()) {
         
            CNSSubscription sub = extractSubscriptionFromColumn(col, topicArn);
           
                // ignore invalid subscriptions coming from Cassandra
               
                try {
                  sub.checkIsValid();
                } catch (CMBException ex) {
                  logger.error("event=invalid_subscription " + sub.toString(), ex);
                  continue;
                }
           
            if (protocol != null && protocol != sub.getProtocol()) {
              continue;
            }
           
            if (hidePendingArn) {
                if (sub.isConfirmed()) {
                    l.add(sub);
                } else {
                    sub.setArn("PendingConfirmation");
                    l.add(sub);
                }
            } else {
                l.add(sub);
            }
View Full Code Here

Examples of com.comcast.cns.model.CNSSubscription

     
      //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;
  }
View Full Code Here

Examples of com.comcast.cns.model.CNSSubscription

  }
 
  @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);
    }
  }
View Full Code Here

Examples of com.comcast.cns.model.CNSSubscription

     
    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);
View Full Code Here

Examples of com.comcast.cns.model.CNSSubscription

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

  @Override
  public void setRawMessageDelivery(String subscriptionArn, boolean rawMessageDelivery) throws Exception{
    CNSSubscription sub;
    sub = getSubscription(subscriptionArn);
    if (sub != null) {
      sub.setRawMessageDelivery(rawMessageDelivery);
      insertOrUpdateSubsAndIndexes(sub, null);
    }
  }
View Full Code Here

Examples of com.comcast.cns.model.CNSSubscription

            topicArn = t.getArn();

      ICNSSubscriptionPersistence subscriptionHandler = new CNSSubscriptionCassandraPersistence();
      long beforeSubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionPending");

      CNSSubscription s = subscriptionHandler.subscribe(CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/1234", CnsSubscriptionProtocol.http, t.getArn(), userId1);

      long afterSubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionPending");
     
      // check default delivery policy on topic1
     
      CNSSubscriptionAttributes attributes = attributeHandler.getSubscriptionAttributes(s.getArn());
     
      assertTrue("Expected 3 retries in healthy policy, instead found " + attributes.getEffectiveDeliveryPolicy().getHealthyRetryPolicy().getNumRetries(), attributes.getEffectiveDeliveryPolicy().getHealthyRetryPolicy().getNumRetries() == 3);
     
      List<CNSSubscription> l = subscriptionHandler.listSubscriptions(null, null, userId1);

      assertTrue("Could not verify PendingConfirmation state", l.size() == 1 && l.get(0).getArn().equals("PendingConfirmation"));

      s = subscriptionHandler.confirmSubscription(false, s.getToken(), t.getArn());

      l = subscriptionHandler.listSubscriptions(null, null, userId1);

      assertTrue("Expected 1 subscription, instead found " + l.size(), l.size() == 1);

      l = subscriptionHandler.listSubscriptionsByTopic(null, t.getArn(), null);

      assertTrue("Expected 1 subscription, instead found " + l.size(), l.size() == 1);

      l = subscriptionHandler.listSubscriptionsByTopic(null, t.getArn(), CnsSubscriptionProtocol.http);

      assertTrue("Expected 1 subscription, instead found " + l.size(), l.size() == 1);
     
      l = subscriptionHandler.listSubscriptionsByTopic(null, t.getArn(), CnsSubscriptionProtocol.email);

      assertTrue("Expected 0 subscription, instead found " + l.size(), l.size() == 0);
     
      assertTrue("Wrong number of subscribers", afterSubscribeCount == beforeSubscribeCount+1);

      try {
        l = subscriptionHandler.listSubscriptionsByTopic(null, com.comcast.cns.util.Util.generateCnsTopicArn("xyz", "east", userId1), null);
      } catch (CMBException ex) {
        assertTrue(ex.getCMBCode().equals(CMBErrorCodes.NotFound.getCMBCode()));
      }
     
      CNSSubscription sdup = subscriptionHandler.getSubscription(s.getArn());
     
      assertTrue("Subscriptions are not identical: " + s + "; " + sdup, s.equals(sdup));
     
      long beforeUnsubscribeCount = subscriptionHandler.getCountSubscription(t.getArn(), "subscriptionDeleted");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.