我正在maven多模块EAR项目中使用EBJ 3.1在weblogic 12.2.1.2中实现单例服务。
我的单件服务正在集群中注册。
这是注册节点的日志:
<BEA-000189> <The Singleton Service Appscoped_Singleton_Service is now active on this server.>
这是来自其他节点:
<BEA-003130> <Appscoped_Singleton_Service successfully activated on server iss3.>
单件服务正在实施 weblogic.cluster.singleton.SingletonService 界面,但是当节点不调用方法激活和停用开始或关闭。
我正在阅读有关版本化的EAR和MANIFEST文件的内容,但不明白这一点。
我需要一些帮助才能调用激活和停用方法。
这是我的班级:
import java.io.Serializable;
import javax.inject.Inject;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.test.MyTimerLocal;
import weblogic.cluster.singleton.SingletonService;
public class MySingletonServiceClass implements SingletonService, Serializable, MySingletonServiceInterface {
private static final long serialVersionUID = 3966807367110330202L;
private static final String jndiName = "MySingletonServiceClass";
private int myValue;
@Inject
private MyTimerLocal myTimer;
@Override
public int getMyValue() {
return this.myValue;
}
@Override
public synchronized void setMyValue(final int myValue) {
this.myValue = myValue;
}
@Override
public void activate() {
System.out.println("activate triggered");
Context ic = null;
try {
ic = new InitialContext();
ic.bind(MySingletonServiceClass.jndiName, this);
System.out.println("Object now bound in JNDI at " + MySingletonServiceClass.jndiName);
this.myValue = 5;
final String msg = "###################### MySingletonServiceClass.activate():: Fechamento agendado para " + this.myTimer.agendaExecucao() + " ###############";
System.out.println(msg);
} catch (final NamingException e) {
this.myValue = -1;
e.printStackTrace();
} finally {
try {
if (ic != null) {
ic.close();
}
} catch (final NamingException e) {
e.printStackTrace();
}
}
}
@Override
public void deactivate() {
System.out.println("deactivate triggered");
Context ic = null;
try {
ic = new InitialContext();
ic.unbind(MySingletonServiceClass.jndiName);
System.out.println("Context unbound successfully");
} catch (final NamingException e) {
e.printStackTrace();
}
}
}
感谢您的时间。
答案 0 :(得分:0)
我现在正在使用 src \ main \ application \ META-INF \ weblogic-application.xml
<wls:singleton-service>
<wls:class-name>com.test.MySingletonServiceClass</wls:class-name>
<wls:name>Appscoped_Singleton_Service</wls:name>
</wls:singleton-service>