我正在使用 mobicents-jainslee-2.7.0.FINAL-jboss-5.1.0.GA ,我尝试部署简单的onTimerEvent服务。 JBoss正确检测所有组件,但单击激活时控制台中没有日志。另一方面onStartedEventSbb效果很好。
为什么服务器不运行此服务和Sbb?
我有一个TimerSbb.java:
public class TimerSbb implements Sbb {
private Tracer tracer;
private SbbContext sbbContext;
private TimerFacility timerFacility;
private NullActivityContextInterfaceFactory nullActivityContextFactory;
private NullActivityFactory nullActivityFactory;
private final int TIMER_PERIOD_IN_MILISECONDS = 500;
public void onTimerEvent(TimerEvent timerEvent, ActivityContextInterface activityContextInterface) {
tracer.info("onTimerEvent");
}
public void setSbbContext(SbbContext context) {
this.sbbContext = context;
tracer = this.sbbContext.getTracer(getClass().getSimpleName());
tracer.info("setSbbContext");
try {
Context initialContext = new InitialContext();
timerFacility = (TimerFacility) initialContext.lookup(TimerFacility.JNDI_NAME);
nullActivityContextFactory = (NullActivityContextInterfaceFactory) initialContext.lookup(NullActivityContextInterfaceFactory.JNDI_NAME);
nullActivityFactory = (NullActivityFactory) initialContext.lookup(NullActivityFactory.JNDI_NAME);
} catch (NamingException e) {
tracer.warning("NamingException", e);
}
setupTimer();
}
private void setupTimer() {
ActivityContextInterface nullActivityContext = nullActivityContextFactory.getActivityContextInterface(nullActivityFactory.createNullActivity());
timerFacility.setTimer(nullActivityContext, null, System.currentTimeMillis(), TIMER_PERIOD_IN_MILISECONDS, 0, new TimerOptions());
nullActivityContext.attach(sbbContext.getSbbLocalObject());
tracer.info("Timer set up. Period = " + TIMER_PERIOD_IN_MILISECONDS + " ms");
}
public void unsetSbbContext() {
tracer.info("unsetSbbContext");
}
public void sbbCreate() throws CreateException {
tracer.info("sbbCreate");
}
public void sbbPostCreate() throws CreateException {
tracer.info("sbbPostCreate");
}
public void sbbActivate() {
tracer.info("sbbActivate");
}
public void sbbPassivate() {
tracer.info("sbbPassivate");
}
public void sbbLoad() {
tracer.info("sbbLoad");
}
public void sbbStore() {
tracer.info("sbbStore");
}
public void sbbRemove() {
tracer.info("sbbRemove");
}
public void sbbExceptionThrown(Exception e, Object o, ActivityContextInterface activityContextInterface) {
tracer.info("sbbExceptionThrown");
}
public void sbbRolledBack(RolledBackContext rolledBackContext) {
tracer.info("sbbRolledBack");
}
}
SBB-jar.xml中:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE sbb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD JAIN SLEE SBB 1.1//EN"
"http://java.sun.com/dtd/slee-sbb-jar_1_1.dtd">
<sbb-jar>
<sbb>
<sbb-name>TimerSbb</sbb-name>
<sbb-vendor>com.example</sbb-vendor>
<sbb-version>1.0</sbb-version>
<sbb-classes>
<sbb-abstract-class>
<sbb-abstract-class-name>
com.example.slee.TimerSbb
</sbb-abstract-class-name>
</sbb-abstract-class>
</sbb-classes>
<event event-direction="Receive">
<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>
</sbb>
</sbb-jar>
定时器service.xml中:
<service-xml>
<service>
<service-name>Timer Service</service-name>
<service-vendor>com.example</service-vendor>
<service-version>1.0</service-version>
<root-sbb>
<sbb-name>TimerSbb</sbb-name>
<sbb-vendor>com.example</sbb-vendor>
<sbb-version>1.0</sbb-version>
</root-sbb>
<default-priority>0</default-priority>
</service>
展开-unit.xml:
<deployable-unit>
<jar>lib/timer-sbb-1.0-SNAPSHOT.jar</jar>
<service-xml>timer-service.xml</service-xml>
</deployable-unit>
我正在用Maven构建jar:Jar结构是:
example.jar:
- lib/timer-sbb-1.0-SNAPSHOT.jar
- timer-service.xml
- META-INF/deployable-unit.xml
timer-sbb-1.0-SNAPSHOT.jar:
- com.example.slee.TimerSbb
- META-INF/sbb-jar.xml
答案 0 :(得分:1)
答案 1 :(得分:1)
问题在于setFacility在setSbbContext方法中创建计时器。这可能太早了,如果我将方法setupTimer()移动到onServiceStartedEvent(),它就可以工作了。