example Service
| import java.util.Properties;
|
| import javax.management.Notification;
| import javax.management.NotificationFilterSupport;
| import javax.management.NotificationListener;
| import javax.management.ObjectName;
| import javax.naming.InitialContext;
| import javax.transaction.SystemException;
| import javax.transaction.TransactionManager;
|
| import org.apache.commons.logging.Log;
| import org.apache.commons.logging.LogFactory;
| import org.jboss.cache.Fqn;
| import org.jboss.cache.PropertyConfigurator;
| import org.jboss.cache.TreeCache;
|
| import
com.esri.infoservices.j2ee.jbosscache.exceptions.InvalidArgumentException;
| import com.ibm.websphere.management.AdminServiceFactory;
| import com.ibm.websphere.management.NotificationConstants;
| import com.ibm.websphere.runtime.CustomService;
|
| public class JCacheWAS51Service implements CustomService,
NotificationListener {
|
| public final static String NODE_PATH = "/GlobalCache";
|
| private final static String CACHE_INITIALIZED_KEY = "CacheInitialized";
|
| private TreeCache treeCache = null;
|
| private Log logger = LogFactory.getLog(getClass());
|
| private String jndiName = null;
|
| public void initialize(Properties configuration) throws Exception {
| String configFile = null;
| logger.info("JCacheWAS51Service.initialize(): starting up.");
| if (configuration != null && !configuration.isEmpty()) {
| if (logger.isDebugEnabled()) {
| configuration.list(System.out);
| }
| configFile = configuration.getProperty("configFile");
| if (configFile == null || configFile.trim().length() ==
0) {
| throw new InvalidArgumentException(
| "JCacheWAS51Service: configFile
configuration property is required.");
| }
| logger
|
.debug("JCacheWAS51Service.initialize(): Starting up TreeCache.");
| treeCache = new TreeCache();
| PropertyConfigurator configurator = new
PropertyConfigurator();
| configurator.configure(treeCache, configFile);
| treeCache.createService();
| treeCache.startService();
| logger
|
.debug("JCacheWAS51Service.initialize(): setting up filters to wait for WAS
startup.");
| NotificationFilterSupport filter = new
NotificationFilterSupport();
|
filter.enableType(NotificationConstants.TYPE_J2EE_STATE_RUNNING);
| ObjectName target = new
ObjectName("WebSphere:*,type=Server");
| AdminServiceFactory
| .getAdminService()
|
.addNotificationListenerExtended(target, this, filter, null);
| logger.info("JCacheWAS51Service.initialize():
waiting.");
| } else {
| logger.debug("JCacheWAS51Service.initialize(): not
configured.");
| }
|
| }
|
| public void shutdown() throws Exception {
| logger
| .info("JCacheWAS51Service.shutdown(): server is
stopping, shutting down cache.");
| if (treeCache != null) {
| treeCache.stopService();
| treeCache.destroyService();
| }
| }
|
| public void handleNotification(Notification arg0, Object arg1) {
| TransactionManager transaction = null;
| logger
| .info("JCacheWAS51Service.initialize(): server
has started, creating node.");
| try {
| logger
|
.info("JCacheWAS51Service.handleNotification(): TreeCache, creating initial
NODE_PATH ["
| + NODE_PATH + "].");
| transaction = treeCache.getTransactionManager();
| transaction.begin();
| Fqn nodeName = new Fqn(NODE_PATH);
| Boolean initialized = (Boolean) treeCache.get(nodeName,
| CACHE_INITIALIZED_KEY);
| if (initialized == null || initialized ==
Boolean.FALSE) {
| treeCache.put(nodeName, CACHE_INITIALIZED_KEY,
Boolean.TRUE);
| }
| transaction.commit();
| logger
|
.debug("JCacheWAS51Service.handleNotification: done with cache handling.");
| } catch (Exception error) {
| logger
|
.error("JCacheWAS51Service.handleNotification: error handling transaction,
message="
| + error.getMessage());
| try {
| transaction.rollback();
| } catch (SystemException warn) {
| logger.warn(warn);
| }
| }
| }
| }
|
|
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3880840#3880840
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3880840
-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user