未在相应的SBB实体

时间:2017-09-07 10:31:08

标签: restcomm jain-sip mobicents jain-slee

现在我按照this示例来实现所描述的确切内容。

我想要什么

  1. 从资源接收活动
  2. 使用timerFacility.setTimer方法睡眠固定5秒
  3. 通过5秒后,服务需要将消息发送回资源​​(在onTimerEvent上)
  4. 问题出在哪里

    上述操作完全适用于一次触发一个事件,但是当事件以小于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 个答案:

答案 0 :(得分:0)

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

this.setRefId(message);

您可以使用地图将计时器ID与收到的邮件相关联,然后在处理onTimerEvent时检索它。