📄 cachesubscriber.java
字号:
package org.artemis.right.jms;
import java.io.Serializable;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.artemis.right.RightDelegateIF;
import com.gsta.eshore.framework.jcf.IState;
import com.gsta.eshore.framework.jcf.StateImpl;
import com.gsta.eshore.framework.jms.AbstractCacheService;
import com.gsta.eshore.framework.jms.ICacheListener;
import com.gsta.eshore.framework.servicerepository.ServiceLocator;
final public class CacheSubscriber implements ICacheListener {
private static Logger logger=Logger.getLogger(CacheSubscriber.class);
private ConstantTableReader ctr = null;
private RightDelegateIF bizDelegate = null;
/**
* Construct
* @param ctr
*/
public CacheSubscriber(){
}
public CacheSubscriber(ConstantTableReader ctr){
this.ctr = ctr;
}
public IState init(){
AbstractCacheService cacheService;
IState state = new StateImpl();
try {
/*
boolean bret = ServiceLocator.getInstance().init("etc/jcf/framework/config/ServiceConfig.xml");
logger.debug("init etc/BizServiceConfig.xml with the result is "+bret);
//得到EJB
System.out.println("ContextServiceLocator.getInstance().getContext() = "+ContextServiceLocator.getInstance().getContext());
bizDelegate = (RightDelegateIF)ContextServiceLocator.getInstance().getBean("RightDelegate");
boolean bretEJB = bizDelegate.init("jcfServerFacade");
logger.debug("init EJB with the result is "+bretEJB);
*/
//以下代码注册一个订阅者
cacheService = AbstractCacheService.createCachService(CachePublisher.JMS_JNDI_NAME, state);
logger.debug("create JMS CachService Success!");
if (!state.isOK()){
logger.fatal("createCachService fail,", state.getThrowable());
return state;
}
cacheService.addCacheListener(this);
} catch (Exception e) {
state.setErrCode("97103");
logger.fatal("JmsCacheServer add listener fail:", e);
}
return state;
}
public void cacheUpdated(IState state) {
// ctr=bizDelegate.getConstantTable(state);
// //更新缓存
// ConstantTableReader.setCtReader(ctr);
logger.debug("cache Update with result is "+state.isOK());
}
public void cacheUpdated(String cacheName, Serializable cacheContent) {
if (!( cacheContent instanceof Properties)){
logger.error("CacheSubscriber cacheUpdated error: cacheContent is not instance of Properties");
return;
}
Properties prop = (Properties)cacheContent;
String className = prop.getProperty(CachePublisher.CLASS_NAME);
if (className == null){
logger.error("CacheSubscriber cacheUpdated error: cacheContent has not class name");
return;
}
logger.debug("Bnet CacheSubscriber recieved:" + prop.toString());
IState state=new StateImpl();
if (className.equals(ConstantTableReader.class.getName()))
cacheUpdated(state);
}
public static void main(String []argv){
ServiceLocator locator = ServiceLocator.getInstance();
locator.init("etc/ServiceConfig.xml");
CacheSubscriber sub = new CacheSubscriber(null);
IState state = sub.init();
System.out.println(state.isOK());
try {
Thread.sleep(9000000l);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public ConstantTableReader getCtr() {
return ctr;
}
public void setCtr(ConstantTableReader ctr) {
this.ctr = ctr;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -