Событие таймера не запускается в соответствующем объекте SBB

Теперь я следую этому примеру, чтобы добиться точного описания.

Что я хочу

  1. Получить событие из ресурса
  2. Используйте метод timerFacility.setTimer, чтобы спать в течение фиксированных 5 секунд.
  3. Через 5 секунд службе необходимо отправить сообщение обратно на ресурс (в onTimerEvent)

Где проблема

Вышеуказанное достигается идеально для события, запускаемого по одному, но когда событие запускается несколько раз с интервалом менее 5, тогда onTimerEvent вызывается с последним контекстом активности для обоих запросов, более новый контекст каким-то образом перезаписывает предыдущий один)

Класс SBB

Декларация:

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

private NullActivityContextInterfaceFactory nullACIFactory;

private NullActivityFactory nullActivityFactory;

Метод setSbbContext:

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;
    }

}

на событие сообщения:

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);
    }
}

Это мой 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>

Это вывод, который я получаю:

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

Последние две строки журнала должны печатать соответственно d и f вместо f и f. Подскажите, пожалуйста, что я делаю не так?

1 ответ

Вход в систему onTimerEvent показывает сообщение [f] оба раза, потому что это последний, который вы сохранили в атрибуте Ref id:

this.setRefId(message);

Вы можете использовать карту, чтобы связать идентификатор таймера с полученным сообщением, а затем получить его при обработке onTimerEvent,

Другие вопросы по тегам