2017-01-31 19 views
0

我正在使用Maven多模块EAR项目中的EBJ 3.1在weblogic 12.2.1.2中实施单例服务。weblogic集群中的单例服务正在注册但未调用激活方法

我的单身服务正在集群中注册。

这是从节点的日志,其中注册:

<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和清单文件的内容,但并未理解这一点。

我需要一些帮助,使方法激活停用被调用。

这是我的课:

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

为什么你认为不调用的方法?由于缺乏日志输出? – slwk

+0

我现在已经在我的src \ main \ application \ META-INF \ weblogic-application.xml中使用了这个工作** ' com.test .MySingletonServiceClass Appscoped_Singleton_Service

回答

0

我得到这个在我的src \主\程序\ 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>