locked
Custom subscription not caught by handler RRS feed

  • Question

  • Hi,

     

    I am trying to implement the Custom Subscriptions pattern as found in Robotics Tutorial 6.  My code is very similar to that in the example but I'm having some problems with it.  I seem to be able to subscribe to the Custom Subscription fine, but when I post the notify message to the selected subscribers, nothing is received (the handler is never called).  My code follows.  I'm sure I'm doing something stupid, but I'm just too close to it and can't see it.  Any help will be appreciated.

     

    Dogulas

     

    Code Snippet

    //---------------------------

    // From UmbilicalTypes.cs

    //---------------------------

     

    public class UmbilicalOperations : PortSet<

    DsspDefaultLookup,

    DsspDefaultDrop,

    Get,

    SensorSubscribe,

    Subscribe>

    {

    }

    // ...

    public class Subscribe : Subscribe<

    SubscribeRequestType,

    PortSet<SubscribeResponseType, Fault>>

    {

    }

    public class SensorSubscribe : Subscribe<

    SensorSubscribeRequestType,

    PortSet<SubscribeResponseType, Fault>>

    {

    }

    [DataContract]

    public class SensorSubscribeRequestType : SubscribeRequestType

    {

    //The list of sensors to subscribe to

    [DataMember]

    public List<string> Sensors;

    }

     

    //---------------------------

    // From Umbilical.cs

    //---------------------------

     

    // Normal Subscription Handler

    [ServiceHandler(ServiceHandlerBehavior.Concurrent)]

    public IEnumerator<ITask> SubscribeHandler(Subscribe subscribe)

    {

    SubscribeRequestType request = subscribe.Body;

    yield return Arbiter.Choice(

    SubscribeHelper(

    _submgrPort,

    request,

    subscribe.ResponsePort),

    delegate(SuccessResult success)

    {

    // synchronize subscriber

    base.SendNotification<Replace>(

    _submgrPort,

    request.Subscriber,

    _state);

    },

    delegate(Exception e)

    {

    LogError(null, "Subscribe failed for: "

    + request.Subscriber, e);

    }

    );

    yield break;

    }

    // ...

    // Custom Subscription Handler

    [ServiceHandler(ServiceHandlerBehavior.Concurrent)]

    public IEnumerator<ITask> SensorSubscribeHandler(

    SensorSubscribe sensorSubscribe)

    {

    submgr.InsertSubscription selectiveSubscription

    = new submgr.InsertSubscription(

    new submgr.InsertSubscriptionMessage(

    sensorSubscribe.Body.Subscriber,

    sensorSubscribe.Body.Expiration,

    0

    )

    );

    //

    selectiveSubscription.Body.NotificationCount

    = sensorSubscribe.Body.NotificationCount;

    //

    List<submgr.QueryType> subscribeFilter

    = new List<submgr.QueryType>();

    //items in this loop are OR'ed together

    foreach (string s in sensorSubscribe.Body.Sensors)

    {

    //you can achieve an AND behavior by adding ...

    subscribeFilter.Add(new submgr.QueryType(s.ToUpper()));

    }

    //

    selectiveSubscription.Body.QueryList

    = subscribeFilter.ToArray();

    _submgrPort.Post(selectiveSubscription);

    //

    yield return Arbiter.Choice(

    selectiveSubscription.ResponsePort,

    delegate(SubscribeResponseType response)

    {

    sensorSubscribe.ResponsePort.Post(response);

    },

    delegate(Fault fault)

    {

    sensorSubscribe.ResponsePort.Post(fault);

    }

    );

    yield break;

    }

    // ...

    // Posting Update Notifications

    public IEnumerator<ITask> AMessageHandler(AMessage aMessage)

    {

    //Build notification list

    List<string> notify;

    // The following populates 'notify'

    if (!helper.UpdateState(_state, out notify))

    {

    LogError("Could not update the state");

    }

    // notify general subscribers

    _submgrPort.Post(

    new submgr.Submit(

    _state,

    DsspActions.ReplaceRequest

    )

    );

    // notify selective subscribers

    _submgrPort.Post(

    new submgr.Submit(

    _state,

    DsspActions.ReplaceRequest,

    notify.ToArray()

    )

    );

    // ...

    yield break;

    }

     

    //---------------------------

    // From Dashboard.cs

    //---------------------------

     

    private umbilical.UmbilicalOperations _umbilicalPort

    = new umbilical.UmbilicalOperations();

    private umbilical.UmbilicalOperations _umbilicalNotifyPort

    = new umbilical.UmbilicalOperations();

    // ...

    // Subscribe to the Custom Subscription

    private void SubscribeToSensors()

    {

    umbilical.SensorSubscribeRequestType sensorSubscribeRequest

    = new umbilical.SensorSubscribeRequestType();

    sensorSubscribeRequest.Sensors = new List<string>();

    sensorSubscribeRequest.Sensors.Add("bckBumper");

    // ...

    Activate(

    Arbiter.Choice(

    _umbilicalPort.SensorSubscribe(

    sensorSubscribeRequest,

    _umbilicalNotifyPort),

    delegate(SubscribeResponseType Rsp)

    {

    Activate<ITask>(

    Arbiter.Receive<umbilical.Replace>(

    true,

    _umbilicalNotifyPort,

    SensorNotificationHandler

    )

    );

    },

    delegate(Fault F)

    {

    LogError("subscription failed");

    }

    )

    );

    }

    // ...

    // Handle Notification Messages

    private void SensorNotificationHandler(umbilical.Replace notify)

    {

    Console.WriteLine("got here");  // not happening !!!

    }

     

    Friday, April 11, 2008 8:59 PM

Answers

  •  

    All i can think of, is that when you send the notification in your AMessageHandler(), the list of taks that notify.ToArray() returns, does not match the tags when you subscribed.

     

    Do a GET on your subMgr instance that is managing this subscriptiona nd verify the proper subscriber is present.

     

    Also please review the DSS user guide, the SubMgr section for how keyed subscriptions work.

     

    thanx

    g

     

     

    • Marked as answer by Dogulas Thursday, April 9, 2009 6:48 PM
    Wednesday, April 16, 2008 4:11 AM

All replies

  • I am not completely sure, but i believe if you add a Replace type message you your UmbilicalOperations, that will solve it.  This is one sticky point in MSRS.  Even though your service does not expect to receive a Replace message, it does send one out, so it must be in your main port operations.
    Tuesday, April 15, 2008 1:29 AM
  • Thanks for the reply Ben.

     

    I actually already had the "Replace" message in my umbilical operations with no effect.  This is the way it looks:

     

    Code Snippet

    [ServicePort()]

    public class UmbilicalOperations : PortSet<

    DsspDefaultLookup,

    DsspDefaultDrop,

    Get,

    HttpGet,

    Replace,

    Connect,

    Disconnect,

    SensorUpdate,

    SensorSubscribe,

    Subscribe>

    {

    }

     

    Any other suggestions?  I must still be missing something.

     

    Thanks,

    Dogulas

     

    Tuesday, April 15, 2008 7:10 PM
  •  

    All i can think of, is that when you send the notification in your AMessageHandler(), the list of taks that notify.ToArray() returns, does not match the tags when you subscribed.

     

    Do a GET on your subMgr instance that is managing this subscriptiona nd verify the proper subscriber is present.

     

    Also please review the DSS user guide, the SubMgr section for how keyed subscriptions work.

     

    thanx

    g

     

     

    • Marked as answer by Dogulas Thursday, April 9, 2009 6:48 PM
    Wednesday, April 16, 2008 4:11 AM