0

现在我正在按照这个例子来实现所描述的确切内容。

我想要的是

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

onTimer事件:

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,请指出我做错了什么?

4

1 回答 1

0

登录两次都会onTimerEvent显示该消息,因为这是您在 Ref id 属性中保存的最后一条消息:[f]

this.setRefId(message);

您可以使用映射将计时器 ID 与收到的消息相关联,然后在处理onTimerEvent.

于 2017-09-21T06:02:11.673 回答