Timer Event not being fired in respective SBB Entity

162 views Asked by At

Now I am following this example to achieve the exact thing described.

What I want

  1. Receive an event from a resource
  2. Use timerFacility.setTimer method to sleep for a fixed 5 secs
  3. After 5 secs pass, the service needs to send a message back to the resource (in on onTimerEvent)

Where the problem is

The above is achieved perfectly for event being fired one at a time, but when event is fired multiple times with interval less than 5, then onTimerEvent is invoked with the latest activity context for both the requests, the newer context somehow seems to overwrite the previous one)

SBB class

Declaration:

// //////////////////////////////////////////////////////////
// Null Activities declaration for the timer event
// ////////////////////////////////////////////////////////

private NullActivityContextInterfaceFactory nullACIFactory;

private NullActivityFactory nullActivityFactory;

setSbbContext method:

public void setSbbContext(SbbContext context) {
    this.sbbContext = (SbbContextExt) context;
    logger = this.sbbContext.getTracer(getClass().getName());
    logger.info("TimerSbb context set");
    // this.timerFacility = this.sbbContext.getTimerFacility();

    try {

        final Context myEnv = (Context) new InitialContext();

        // slee facilities
        this.timerFacility = (TimerFacility) myEnv.lookup(TimerFacility.JNDI_NAME);
        this.nullACIFactory = (NullActivityContextInterfaceFactory) myEnv.lookup(NullActivityContextInterfaceFactory.JNDI_NAME);
        this.nullActivityFactory = (NullActivityFactory) myEnv.lookup(NullActivityFactory.JNDI_NAME);

        // // the sbb interface to interact with SIP resource adaptor
        // this.sipProvider = (SleeSipProvider) myEnv.lookup("java:comp/env/slee/resources/jainsip/1.2/provider");

    } catch (Exception e) {
        logger.severe("Failed to set sbb context", e);
    }
}

onTimerEvent:

public void onTimerEvent(javax.slee.facilities.TimerEvent event, ActivityContextInterface aci) {

    this.logger.info("[" + this.getRefId() + "] new TimerEvent Fired");
    // detaching so the null AC is claimed after the event handling

    aci.detach(sbbContext.getSbbLocalObject());
    this.logger.info("[" + this.getRefId() + "] context detatched");

    try {

        // // create child
        //
        // DataSourceChildSbbLocalInterface child = (DataSourceChildSbbLocalInterface) getLocationChildRelation().create();
        //
        // // request bindings of the message target
        //
        // child.getBindings(getSender().getURI().toString());

    } catch (Exception e) {
        logger.severe("failed to create sip registrar child sbb, to lookup the sender's contacts", e);
        return;
    }

}

on Message Event:

public void onTelnetMessageEvent(com.kalsym.event.MessageEvent event, ActivityContextInterface aci/* , EventContext eventContext */) {

    try {
        // ////////////////////////////////////////////////////////////////

        this.logger.info("onTelnetMessageEvent");
        String message = event.getMessage();
        String refId = event.getRefId();
        this.setRefId(message);
        this.logger.info("[" + this.getRefId() + "] Received onTelnetMessageEvent with message: " + message);

        int timerDurationInSecs = 5;

        ActivityContextInterface timerACI = this.nullACIFactory.getActivityContextInterface(this.nullActivityFactory.createNullActivity());

        timerACI.attach(this.sbbContext.getSbbLocalObject());
        // Have tried all TimerPreserveMised options here
        TimerPreserveMissed tpm = TimerPreserveMissed.LAST;
        // Have tried new TimerOptions() as well
        TimerOptions options = new TimerOptions(5000, tpm);

        this.timerFacility.setTimer(timerACI, null, System.currentTimeMillis() + timerDurationInSecs * 1000, options);

        // ////////////////////////////////////////////////////////////////
    } catch (Exception exp) {
        this.logger.severe("Error in recieving Telent Event", exp);
    }
}

This is my sbb-jar:

  <event event-direction="Receive" initial-event="False">
        <event-name>TimerEvent</event-name>
        <event-type-ref>
            <event-type-name>javax.slee.facilities.TimerEvent</event-type-name>
            <event-type-vendor>javax.slee</event-type-vendor>
            <event-type-version>1.0</event-type-version>
        </event-type-ref>
    </event>
    <event event-direction="Receive" initial-event="True">
        <event-name>TelnetMessageEvent</event-name>
        <event-type-ref>
            <event-type-name>TelnetMessageEvent</event-type-name>
            <event-type-vendor>kalsym</event-type-vendor>
            <event-type-version>1.0</event-type-version>
        </event-type-ref>
    </event>

This is the output I am getting:

2017-09-06 16:14:17,734 INFO  [javax.slee.SbbNotification[service=ServiceID[name=timer,vendor=trangec,version=1.0],sbb=SbbID[name=TimerSbb,vendor=trangec,version=1.0]].trangec.timer.TimerSbbImpl] (SLEE-EventRouterExecutor-0-thread-1) TimerSbb context set

2017-09-06 16:14:17,743 INFO  [javax.slee.SbbNotification[service=ServiceID[name=timer,vendor=trangec,version=1.0],sbb=SbbID[name=TimerSbb,vendor=trangec,version=1.0]].trangec.timer.TimerSbbImpl] (SLEE-EventRouterExecutor-0-thread-1) onTelnetMessageEvent
2017-09-06 16:14:17,745 INFO  [javax.slee.SbbNotification[service=ServiceID[name=timer,vendor=trangec,version=1.0],sbb=SbbID[name=TimerSbb,vendor=trangec,version=1.0]].trangec.timer.TimerSbbImpl] (SLEE-EventRouterExecutor-0-thread-1) [d] Received onTelnetMessageEvent with message: d

2017-09-06 16:14:19,396 INFO  [javax.slee.SbbNotification[service=ServiceID[name=timer,vendor=trangec,version=1.0],sbb=SbbID[name=TimerSbb,vendor=trangec,version=1.0]].trangec.timer.TimerSbbImpl] (SLEE-EventRouterExecutor-2-thread-1) onTelnetMessageEvent
2017-09-06 16:14:19,396 INFO  [javax.slee.SbbNotification[service=ServiceID[name=timer,vendor=trangec,version=1.0],sbb=SbbID[name=TimerSbb,vendor=trangec,version=1.0]].trangec.timer.TimerSbbImpl] (SLEE-EventRouterExecutor-2-thread-1) [f] Received onTelnetMessageEvent with message: f




2017-09-06 16:14:22,750 INFO  [javax.slee.SbbNotification[service=ServiceID[name=timer,vendor=trangec,version=1.0],sbb=SbbID[name=TimerSbb,vendor=trangec,version=1.0]].trangec.timer.TimerSbbImpl] (SLEE-EventRouterExecutor-7-thread-1) [f] new TimerEvent Fired


2017-09-06 16:14:24,398 INFO  [javax.slee.SbbNotification[service=ServiceID[name=timer,vendor=trangec,version=1.0],sbb=SbbID[name=TimerSbb,vendor=trangec,version=1.0]].trangec.timer.TimerSbbImpl] (SLEE-EventRouterExecutor-0-thread-1) [f] new TimerEvent Fired

The last two log lines should print respectively d and f instead of f and f, please suggest what am I doing wrong?

1

There are 1 answers

0
delephin On

The log in onTimerEvent shows the message [f] both times because that's the last one you saved in the Ref id attribute:

this.setRefId(message);

You could use a map to associate the timer ID to the message received, and then retrieve it when processing the onTimerEvent.