[CJ-dev] commonjava-projects/commonjava-config/projects/jboss-config-service/src/java/org/commonjava
Brought to you by:
johnqueso
Update of /cvsroot/commonjava/commonjava-projects/commonjava-config/projects/jboss-config-service/src/java/org/commonjava/config/snapin/jboss In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26482/projects/jboss-config-service/src/java/org/commonjava/config/snapin/jboss Added Files: SnapInService.java LocalSnapInServiceLoader.java SnapInServiceLoader.java SnapInServiceConstants.java Removed Files: JBossSnapInLocalSvcLoader.java SnapInServiceMBean.java JBossSnapInService.java JBossSnapInServiceConstants.java JBossSnapInServiceLoader.java Log Message: added new classes for managing snap-ins via JBoss service. --- NEW FILE: SnapInService.java --- /* Created on Feb 14, 2004 */ package org.commonjava.config.snapin.jboss; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.Name; import javax.naming.NameNotFoundException; import javax.naming.NamingException; import javax.naming.Reference; import javax.naming.StringRefAddr; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.commonjava.config.snapin.SnapInContainer; import org.commonjava.config.snapin.SnapInContainerLoader; import org.commonjava.config.snapin.SnapInLoaderException; import org.commonjava.opl.ParseException; import org.jboss.naming.NonSerializableFactory; import org.jboss.system.ServiceMBeanSupport; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** Service used to expose a snap-in container to the server via JNDI. * * @jmx.mbean description="Server-centric manager for configuration snap-ins" * name="jboss:type=Service,service=SnapInService" * extends="org.jboss.system.ServiceMBean" * * @author John Casey */ public final class SnapInService extends ServiceMBeanSupport implements SnapInServiceMBean{ private static final Log LOG = LogFactory.getLog(SnapInService.class); private SnapInContainer container; private Element configElement; private String configPath; /** * Return the configuration path to load snap-ins from. * @jmx:managed-attribute */ public synchronized String getConfigPath(){ return configPath; } /** Set the configuration path to use in loading the snap-ins. * @jmx.managed-attribute */ public synchronized void setConfigPath(String configPath) throws SnapInLoaderException, ParseException { this.configPath = configPath; if(configPath != null){ System.setProperty(SnapInContainerLoader.LOCATION_SYSPROP, configPath); } SnapInContainer container = loadContainer(); if (LOG.isInfoEnabled()) { LOG.info("SnapInManager's underlying container was reloaded from: " + configPath); } this.container = container; } /** * @jmx.managed-operation * @throws SnapInLoaderException * @throws ParseException */ public void reloadContainer() throws SnapInLoaderException, ParseException{ if (LOG.isInfoEnabled()) { LOG.info("Reloading SnapInManager's underlying container..."); } SnapInContainer container = loadContainer(); this.container = container; if (LOG.isInfoEnabled()) { LOG.info("...SnapInManager container reload complete."); } } /* (non-Javadoc) * @see org.jboss.system.ServiceMBeanSupport#startService() */ protected void startService() throws Exception { bind(); } /* (non-Javadoc) * @see org.jboss.system.ServiceMBeanSupport#stopService() */ protected void stopService() throws Exception { unbind(); // release container. Reload if re-bound. container = null; } private void bind() throws NamingException, SnapInLoaderException, ParseException { this.container = loadContainer(); String bindName = SnapInServiceConstants.JNDI_NAME; NonSerializableFactory.bind(bindName, container); Context ctx = new InitialContext(); try{ Name n = ctx.getNameParser("").parse(bindName); while (n.size() > 1){ String ctxName = n.get(0); try{ ctx = (Context) ctx.lookup(ctxName); } catch (NameNotFoundException e){ ctx = ctx.createSubcontext(ctxName); } n = n.getSuffix(1); } // The helper class NonSerializableFactory uses address type nns, we go on to // use the helper class to bind the javax.mail.Session object in JNDI StringRefAddr addr = new StringRefAddr("nns", bindName); Reference ref = new Reference( SnapInContainer.class.getName(), addr, NonSerializableFactory.class.getName(), null ); ctx.bind(n.get(0), ref); } finally{ ctx.close(); } if (LOG.isInfoEnabled()) { LOG.info("Snap-In Service bound to " + bindName); } } private void unbind() throws NamingException, ParseException { String bindName = SnapInServiceConstants.JNDI_NAME; if (bindName != null) { InitialContext ctx = new InitialContext(); try{ ctx.unbind(bindName); } finally{ ctx.close(); } NonSerializableFactory.unbind(bindName); if (LOG.isInfoEnabled()) { LOG.info("Snap-In service '" + bindName + "' removed from JNDI"); } } } /** * */ private SnapInContainer loadContainer() throws SnapInLoaderException, ParseException { return SnapInContainerLoader.getSnapInContainer(); } } --- NEW FILE: LocalSnapInServiceLoader.java --- /* Created on Feb 14, 2004 */ package org.commonjava.config.snapin.jboss; import javax.naming.NamingException; import org.commonjava.config.snapin.SnapInContainer; import org.commonjava.config.snapin.SnapInContainerLoader; import org.commonjava.config.snapin.SnapInLoaderException; import org.commonjava.j2ee.services.ServiceLocator; import org.commonjava.j2ee.services.config.EnterpriseConfigurationException; /** * @author jdcasey */ public class LocalSnapInServiceLoader extends SnapInContainerLoader { public LocalSnapInServiceLoader(){} public SnapInContainer loadSnapInContainer() throws SnapInLoaderException { try { return (SnapInContainer)ServiceLocator.getLocalService( SnapInServiceConstants.JNDI_NAME, SnapInContainer.class ); } catch(NamingException e){ throw new SnapInLoaderException(e); } catch (EnterpriseConfigurationException e) { throw new SnapInLoaderException(e); } } } --- NEW FILE: SnapInServiceLoader.java --- /* Created on Feb 14, 2004 */ package org.commonjava.config.snapin.jboss; import javax.naming.NamingException; import org.commonjava.config.snapin.GenericSnapInContainerLoader; import org.commonjava.config.snapin.SnapInContainer; import org.commonjava.config.snapin.SnapInContainerLoader; import org.commonjava.config.snapin.SnapInLoaderException; import org.commonjava.config.snapin.StackedSnapInContainer; import org.commonjava.j2ee.services.ServiceLocator; import org.commonjava.j2ee.services.config.EnterpriseConfigurationException; /** * @author jdcasey */ public class SnapInServiceLoader extends SnapInContainerLoader { public SnapInServiceLoader(){} public SnapInContainer loadSnapInContainer() throws SnapInLoaderException { // We're using a pretty complex setup here. We'll stack the local configuration on top of // the proxied one from the JNDI lookup. This way, local settings can override remote ones. StackedSnapInContainer container = new StackedSnapInContainer(); // First, load the local configuration snap-ins. SnapInContainerLoader localLoader = GenericSnapInContainerLoader.getInstance(); SnapInContainer localContainer = localLoader.loadSnapInContainer(); container.prepend(localContainer); try { SnapInContainer remoteContainer = (SnapInContainer)ServiceLocator.getService( SnapInServiceConstants.JNDI_NAME, SnapInContainer.class ); container.append(remoteContainer); } catch (EnterpriseConfigurationException e) { throw new SnapInLoaderException(e); } catch(NamingException e){ throw new SnapInLoaderException(e); } return container; } } --- NEW FILE: SnapInServiceConstants.java --- /* Created on Feb 14, 2004 */ package org.commonjava.config.snapin.jboss; /** * @author jdcasey */ public final class SnapInServiceConstants { public static final String JNDI_NAME = "/services/SnapInService"; private SnapInServiceConstants() { } } --- JBossSnapInLocalSvcLoader.java DELETED --- --- SnapInServiceMBean.java DELETED --- --- JBossSnapInService.java DELETED --- --- JBossSnapInServiceConstants.java DELETED --- --- JBossSnapInServiceLoader.java DELETED --- |