Example #1
0
        private void RemoveNotificatoinsOf(ObserveRelation relation)
        {
            if (log.IsDebugEnabled)
                log.Debug("Remove all remaining NON-notifications of observe relation");

            foreach (Response previous in relation.ClearNotifications())
            {
                // notifications are local MID namespace
                Exchange.KeyID keyId = new Exchange.KeyID(previous.ID, null);
                _exchangesByID.Remove(keyId);
            }
        }
Example #2
0
 /// <inheritdoc/>
 public void AddObserveRelation(ObserveRelation relation)
 {
     if (_observeRelations.AddOrUpdate(relation, false, (k, v) => true))
     {
         if (log.IsDebugEnabled)
             log.Debug("Replacing observe relation between " + relation.Key + " and resource " + Uri);
     }
     else
     {
         if (log.IsDebugEnabled)
             log.Debug("Successfully established observe relation between " + relation.Key + " and resource " + Uri);
     }
 }
Example #3
0
 /// <inheritdoc/>
 public void RemoveObserveRelation(ObserveRelation relation)
 {
     Boolean val;
     _observeRelations.TryRemove(relation, out val);
 }
Example #4
0
 /// <summary>
 /// Adds the specified observe relation.
 /// </summary>
 public void AddObserveRelation(ObserveRelation relation)
 {
     _relations.Add(relation);
 }
Example #5
0
 /// <summary>
 /// Removes the specified observe relation.
 /// </summary>
 public void RemoveObserveRelation(ObserveRelation relation)
 {
     _relations.Remove(relation);
 }
Example #6
0
 /// <inheritdoc/>
 public void RemoveObserveRelation(ObserveRelation relation)
 {
     ((ICollection<KeyValuePair<String, ObserveRelation>>)_observeRelations).Remove(new KeyValuePair<String, ObserveRelation>(relation.Key, relation));
 }
Example #7
0
        /// <inheritdoc/>
        public void AddObserveRelation(ObserveRelation relation)
        {
            ObserveRelation old = null;
            _observeRelations.AddOrUpdate(relation.Key, relation, (k, v) =>
            {
                old = v;
                return relation;
            });

            if (old != null)
            {
                old.Cancel();
                if (log.IsDebugEnabled)
                    log.Debug("Replacing observe relation between " + relation.Key + " and resource " + Uri);
            }
            else
            {
                if (log.IsDebugEnabled)
                    log.Debug("Successfully established observe relation between " + relation.Key + " and resource " + Uri);
            }
        }
Example #8
0
 /// <summary>
 /// Removes the specified observe relation.
 /// </summary>
 public void RemoveObserveRelation(ObserveRelation relation)
 {
     _relations.Remove(relation);
 }
Example #9
0
 /// <summary>
 /// Adds the specified observe relation.
 /// </summary>
 public void AddObserveRelation(ObserveRelation relation)
 {
     _relations.Add(relation);
 }
        private void CheckForObserveOption(Exchange exchange, IResource resource)
        {
            Request request = exchange.Request;
            if (request.Method != Method.GET)
                return;

            System.Net.EndPoint source = request.Source;
            Int32? obs = request.Observe;
            if (obs.HasValue && resource.Observable)
            {
                if (obs == 0)
                {
                    // Requests wants to observe and resource allows it :-)
                    if (log.IsDebugEnabled)
                        log.Debug("Initiate an observe relation between " + source + " and resource " + resource.Uri);
                    ObservingEndpoint remote = _observeManager.FindObservingEndpoint(source);
                    ObserveRelation relation = new ObserveRelation(_config, remote, resource, exchange);
                    remote.AddObserveRelation(relation);
                    exchange.Relation = relation;
                    // all that's left is to add the relation to the resource which
                    // the resource must do itself if the response is successful
                }
                else if (obs == 1)
                {
                    ObserveRelation relation = _observeManager.GetRelation(source, request.Token);
                    if (relation != null)
                        relation.Cancel();
                }
            }
        }