Package org.cipango.kaleo.event

Examples of org.cipango.kaleo.event.Subscription


    });
    JSON.getDefault().addConvertor(Subscription.class, new Convertor()
    {
      public void toJSON(Object obj, Output out)
      {
        Subscription subscription = (Subscription) obj;
        out.add("uri", subscription.getUri());
        out.add("state", subscription.getState().toString());
        out.add("authorized", subscription.isAuthorized());
      }
      public Object fromJSON(Map object)  { return null; }
    });
   
    JSON.getDefault().addConvertor(Registration.class, new Convertor()
View Full Code Here


   
    RegResource regResource = _regEventPackage.get(uri);
   
    try
    {
      Subscription subscription = null;
     
      if (expires == 0)
      {
        subscription = regResource.removeSubscription(session.getId());
       
        if (subscription == null)
        {
          subscription = new Subscription(regResource, session, -1);
        }
        else
        {
          subscription.setExpirationTime(System.currentTimeMillis());
          if (_log.isDebugEnabled())
            _log.debug("removed reg subscription {} to registration resource {}",
              subscription.getSession().getId(), regResource.getUri());
       
        subscription.setState(Subscription.State.TERMINATED, Reason.TIMEOUT);
      }
      else
      {
        long now = System.currentTimeMillis();
       
        subscription = regResource.getSubscription(session.getId());
   
        if (subscription == null)
        {
          subscription = new Subscription(regResource, session, now + expires*1000);
          subscription.setState(State.ACTIVE, Reason.SUBSCRIBE);
          regResource.addSubscription(subscription);
         
          session.setAttribute(Constants.SUBSCRIPTION_ATTRIBUTE, uri);
         
          if (_log.isDebugEnabled())
            _log.debug("added reg subscription {} to registration resource {}",
                subscription.getSession().getId(), regResource.getUri());
        }
        else
        {
          subscription.setExpirationTime(now + expires * 1000);
         
          if (_log.isDebugEnabled())
            _log.debug("refreshed reg subscription {} to registration resource {}",
                subscription.getSession().getId(), regResource.getUri());
        }
      }
     
      int code = (subscription.getState() != Subscription.State.PENDING) ?
          SipServletResponse.SC_OK : SipServletResponse.SC_ACCEPTED;
     
      SipServletResponse response = subscribe.createResponse(code);
      response.setExpires(expires);
      response.send();
View Full Code Here

        SipServletResponse response = subscribe.createResponse(SipServletResponse.SC_FORBIDDEN);
        response.send();
        return;
      }
     
      Subscription subscription = null;
     
      if (expires == 0)
      {
        subscription = presentity.removeSubscription(session.getId());
       
        if (subscription == null)
        {
          subscription = new Subscription(presentity, session, -1, subscriberUri);
          subscription.addListener(_watcherInfo.getSubscriptionListener());
        }
        else
        {
          subscription.setExpirationTime(System.currentTimeMillis());
          if (_log.isDebugEnabled())
            _log.debug("removed presence subscription {} to presentity {}",
              subscription.getSession().getId(), presentity.getUri());
       
        if (subHandling == SubHandling.CONFIRM)
          subscription.setState(Subscription.State.WAITING, Reason.TIMEOUT, subHandling == SubHandling.ALLOW);
        else
          subscription.setState(Subscription.State.TERMINATED, Reason.TIMEOUT, subHandling == SubHandling.ALLOW);
      }
      else
      {
        long now = System.currentTimeMillis();
       
        subscription = presentity.getSubscription(session.getId());
   
        if (subscription == null)
        {
          subscription = new Subscription(presentity, session, now + expires*1000, subscriberUri);
          subscription.addListener(_watcherInfo.getSubscriptionListener());
          presentity.addSubscription(subscription);
         
          switch (subHandling)
          {
          case ALLOW:
            subscription.setState(State.ACTIVE, Reason.SUBSCRIBE, true);
            break;
          case CONFIRM:
            subscription.setState(State.PENDING, Reason.SUBSCRIBE, false);
            break;
          case POLITE_BLOCK:
            subscription.setState(State.ACTIVE, Reason.SUBSCRIBE, false);
            break;
          default:
            break;
          }
         
          session.setAttribute(Constants.SUBSCRIPTION_ATTRIBUTE, uri);
         
          if (_log.isDebugEnabled())
            _log.debug("added presence subscription {} to presentity {}",
                subscription.getId(), presentity.getUri());
        }
        else
        {
          subscription.setExpirationTime(now + expires * 1000);
         
          if (_log.isDebugEnabled())
            _log.debug("refreshed presence subscription {} to presentity {}",
                subscription.getSession().getId(), presentity.getUri());
        }
      }
     
      int code = (subscription.getState() != Subscription.State.PENDING) ?
          SipServletResponse.SC_OK : SipServletResponse.SC_ACCEPTED;
     
      SipServletResponse response = subscribe.createResponse(code);
      response.setExpires(expires);
      response.send();
View Full Code Here

    else
      subscriberUri = URIUtil.toCanonical(subscribe.getFrom().getURI());
   
    try
    {
      Subscription subscription = null;
     
      if (expires == 0)
      {
        subscription = resource.removeSubscription(session.getId());
       
        if (subscription == null)
          subscription = new Subscription(resource, session, -1, subscriberUri);
        else
        {
          subscription.setExpirationTime(System.currentTimeMillis());
          if (_log.isDebugEnabled())
            _log.debug("removed presence.winfo subscription {} to resource {}",
              subscription.getSession().getId(), resource.getUri());
       
        subscription.setState(Subscription.State.TERMINATED, Reason.TIMEOUT);
      }
      else
      {
        long now = System.currentTimeMillis();
       
        subscription = resource.getSubscription(session.getId());
   
        if (subscription == null)
        {
          subscription = new Subscription(resource, session, now + expires*1000, subscriberUri);
          subscription.setState(State.ACTIVE, Reason.SUBSCRIBE);
          resource.addSubscription(subscription);
         
          session.setAttribute(Constants.SUBSCRIPTION_ATTRIBUTE, uri);
         
          if (_log.isDebugEnabled())
            _log.debug("added presence.winfo subscription {} to resource {}",
                subscription.getSession().getId(), resource.getUri());
        }
        else
        {
          subscription.setExpirationTime(now + expires * 1000);
         
          if (_log.isDebugEnabled())
            _log.debug("refreshed presence.winfo subscription {} to resource {}",
                subscription.getSession().getId(), resource.getUri());
        }
      }
     
      int code = (subscription.getState() != Subscription.State.PENDING) ?
          SipServletResponse.SC_OK : SipServletResponse.SC_ACCEPTED;
     
      SipServletResponse response = subscribe.createResponse(code);
      response.setExpires(expires);
      response.send();
View Full Code Here

      try
      {
        Iterator<Subscription> it = presentity.getSubscriptions().iterator();
        while (it.hasNext())
        {
          Subscription subscription = it.next();
          SubHandling subHandling = policy.getPolicy(subscription.getUri());
         
          State state = subscription.getState();
          boolean authorised = subscription.isAuthorized();
          switch (subHandling)
          {
          case ALLOW:
            subscription.setState(State.ACTIVE, Reason.APPROVED, true);
            break;
          case CONFIRM:
            subscription.setState(State.PENDING, Reason.SUBSCRIBE, true);
            break;
          case POLITE_BLOCK:
            subscription.setState(State.ACTIVE, Reason.SUBSCRIBE, false);
            break;
          case BLOCK:
            subscription.setState(State.TERMINATED, Reason.REJECTED, false);
            break;
          default:
            break;
          }
         
          // send NOTIFY if state has changed.
          if (state != subscription.getState() || authorised != subscription.isAuthorized())
          {
            PresenceEventPackage.this.notify(subscription);
          }
        }
      }
View Full Code Here

    WatcherList watcherList = watcherinfo.getWatcherListArray(0);
    assertEquals(AOR, watcherList.getResource());
    assertEquals(PresenceEventPackage.NAME, watcherList.getPackage());
    assertEquals(0, watcherList.getWatcherArray().length);
   
    Subscription subscription = new Subscription(presentity, null, 100, SUBSCRIBER_AOR);
    subscription.addListener(resource);
    subscription.setState(Subscription.State.PENDING, Reason.SUBSCRIBE);
    //System.out.println(resource.getState().getContent());
    assertEquals(1, eventListener._nbNotif);
   
    subscription.setState(Subscription.State.ACTIVE, Reason.APPROVED);
    assertEquals(2, eventListener._nbNotif);
   
    subscription.setState(Subscription.State.TERMINATED, Reason.TIMEOUT);
    assertEquals(3, eventListener._nbNotif);
    assertEquals(0, watcherList.getWatcherArray().length);
  }
View Full Code Here

TOP

Related Classes of org.cipango.kaleo.event.Subscription

Copyright © 2018 www.massapicom. 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.