<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    ClassPool bootstrap refactoring
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/kabir.khan%40jboss.com">Kabir Khan</a> in <i>JBoss Microcontainer Development</i> - <a href="http://community.jboss.org/message/539242#539242">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p><span>Following on from </span><a class="jive-link-external-small" href="http://community.jboss.org/message/539041#539041" target="_blank">http://community.jboss.org/message/539041#539041</a><span> I have started refactoring how the ClassPools are initialized during bootstrap and moving code into the classpools project. The following (uncommitted, but working) test in ClassPools demonstrates how I see this working in the bootstrap.</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java">&#160;&#160; <font color="darkgreen">/**
&#160;&#160;&#160; * Simulates the steps to be taken during AS bootstrap
&#160;&#160;&#160; */</font>
&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> testBootstrap() <font color="navy"><b>throws</b></font> Exception
&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">//Initialize the config. This wires together the parts of the system</font>
&#160;&#160;&#160;&#160;&#160; JBossClClassPoolConfig config = JBossClClassPoolConfig.getInstance();
&#160;&#160;&#160;&#160;&#160; assertNotNull(config.getClassPoolFactory());
&#160;&#160;&#160;&#160;&#160; assertNotNull(config.getClassPoolRepository());
&#160;&#160;&#160;&#160;&#160; assertNotNull(config.getDomainRegistry());
&#160;&#160;&#160;&#160;&#160; assertNotNull(config.getRegisterModuleCallback());
&#160;&#160;&#160;&#160;&#160; assertNull(config.getClassLoading());
&#160;
&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">//Check that the classpool factory works before we have deployed the classpool system</font>
&#160;&#160;&#160;&#160;&#160; ClassLoader urlCl = createChildURLLoader(null, JAR_A_URL); 
&#160;&#160;&#160;&#160;&#160; ClassPool urlPool = config.getClassPoolRepository().registerClassLoader(urlCl);
&#160;&#160;&#160;&#160;&#160; assertNotNull(urlPool);
&#160;&#160;&#160;&#160;&#160; CtClass aUrl = urlPool.get(CLASS_A);
&#160;&#160;&#160;&#160;&#160; CtClass stringUrl = urlPool.get(String.class.getName());
&#160;
&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">//Install the bean to get notified when ClassLoading is installed</font>
&#160;&#160;&#160;&#160;&#160; BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(<font color="red">"JBossClClassPoolConfig"</font>, JBossClClassPoolConfig.class.getName());
&#160;&#160;&#160;&#160;&#160; builder.setFactoryClass(JBossClClassPoolConfig.class.getName());
&#160;&#160;&#160;&#160;&#160; builder.setFactoryMethod(<font color="red">"getInstance"</font>);
&#160;&#160;&#160;&#160;&#160; ValueMetaData inject = builder.createContextualInject(null, null, AutowireType.BY_NAME, InjectOption.CALLBACK);
&#160;&#160;&#160;&#160;&#160; ((AbstractInjectionValueMetaData)inject).setValue(<font color="red">"ClassLoading"</font>);
&#160;&#160;&#160;&#160;&#160; builder.addPropertyMetaData(<font color="red">"classLoading"</font>, inject);
&#160;&#160;&#160;&#160;&#160; getDelegate().deploy(builder.getBeanMetaData());
&#160;
&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">//Deploy the ClassLoading. This causes the RegistryModuleCallback</font>
&#160;&#160;&#160;&#160;&#160; <font color="darkgreen">//to get installed as a module registry in ClassLoading</font>
&#160;&#160;&#160;&#160;&#160; getDelegate().deployCommon();
&#160;&#160;&#160;&#160;&#160; assertNotNull(config.getClassLoading());
&#160;
&#160;&#160;&#160;&#160;&#160; testScenario = <font color="navy"><b>new</b></font> ClassPoolTestScenario&lt;CLDeploymentBuilder&gt;(getClassLoaderFactory(), config.getClassPoolRepository());
&#160;
&#160;&#160;&#160;&#160;&#160; ClassPool poolA = testScenario.createLoader(<font color="navy"><b>new</b></font> CLDeploymentBuilder(<font color="red">"A"</font>, JAR_A_URL));
&#160;&#160;&#160;&#160;&#160; CtClass aDomain = poolA.get(CLASS_A);
&#160;&#160;&#160;&#160;&#160; assertNotSame(aUrl, aDomain);
&#160;&#160;&#160;&#160;&#160; assertSame(stringUrl, poolA.get(String.class.getName()));
&#160;
&#160;&#160;&#160;&#160;&#160; ClassPool poolB = testScenario.createLoader(<font color="navy"><b>new</b></font> CLDeploymentBuilder(<font color="red">"B"</font>, JAR_B_URL));
&#160;&#160;&#160;&#160;&#160; assertSame(aDomain, poolB.get(CLASS_A));
&#160;&#160; <font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The JBossClClassPoolConfig singleton wires together a lot of the things that are needed for running this in AS (getters ommitted)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> JBossClClassPoolConfig
<font color="navy">{</font>
&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>volatile</b></font> JBossClClassPoolConfig config;&#160; 
&#160;
&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>final</b></font> DomainRegistry domainRegistry;
&#160;
&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>final</b></font> RegisterModuleCallback registerModuleCallback;
&#160;
&#160;&#160; <font color="navy"><b>private</b></font> ClassLoading classLoading;
&#160;
&#160;&#160; <font color="navy"><b>private</b></font> JBossClDelegatingClassPoolFactory classPoolFactory;
&#160;
&#160;&#160; <font color="navy"><b>private</b></font> ClassPoolRepository classPoolRepository;
&#160;
&#160;&#160; <font color="navy"><b>private</b></font> JBossClClassPoolConfig(DomainRegistry domainRegistry, RegisterModuleCallback registerModuleCallback, JBossClDelegatingClassPoolFactory classPoolFactory)
&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160; this.domainRegistry = domainRegistry;
&#160;&#160;&#160;&#160;&#160; this.registerModuleCallback = registerModuleCallback;
&#160;&#160;&#160;&#160;&#160; this.classPoolFactory = classPoolFactory;
&#160;&#160;&#160;&#160;&#160; classPoolRepository = ClassPoolRepository.getInstance();
&#160;&#160;&#160;&#160;&#160; classPoolRepository.setClassPoolFactory(classPoolFactory);
&#160;&#160; <font color="navy">}</font>
&#160;
&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>static</b></font> JBossClClassPoolConfig getInstance()
&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (config == <font color="navy"><b>null</b></font>)
&#160;&#160;&#160;&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; config = initialize();
&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> config;
&#160;&#160; <font color="navy">}</font>
&#160;&#160; 
&#160;&#160; <font color="navy"><b>private</b></font> <font color="navy"><b>synchronized</b></font> <font color="navy"><b>static</b></font> JBossClClassPoolConfig initialize()
&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (config != <font color="navy"><b>null</b></font>)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> config;
&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160; DomainRegistry domainRegistry = <font color="navy"><b>new</b></font> VFSClassLoaderDomainRegistry();
&#160;&#160;&#160;&#160;&#160; RegisterModuleCallback registerModuleCallback = <font color="navy"><b>new</b></font> RegisterModuleCallback(domainRegistry);
&#160;&#160;&#160;&#160;&#160; JBossClDelegatingClassPoolFactory classPoolFactory = <font color="navy"><b>new</b></font> JBossClDelegatingClassPoolFactory(domainRegistry, registerModuleCallback);
&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>return</b></font> <font color="navy"><b>new</b></font> JBossClClassPoolConfig(domainRegistry, registerModuleCallback, classPoolFactory);
&#160;&#160; <font color="navy">}</font>
&#160;&#160; 
&#160;&#160; <font color="darkgreen">/**
&#160;&#160;&#160; * Set the classLoading. This should be set via a property 
&#160;&#160;&#160; * by the MC
&#160;&#160;&#160; * 
&#160;&#160;&#160; * @param cl the classLoading to set
&#160;&#160;&#160; */</font>
&#160;&#160; <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> setClassLoading(ClassLoading cl)
&#160;&#160; <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (cl != <font color="navy"><b>null</b></font>)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; cl.addModuleRegistry(registerModuleCallback);
&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>else</b></font> <font color="navy"><b>if</b></font> (classLoading != <font color="navy"><b>null</b></font>)
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; classLoading.removeModuleRegistry(registerModuleCallback);
&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160; classLoading = cl;
&#160;&#160; <font color="navy">}</font>
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So basically all the AS bootstrap will need to do is to call JBossClClassPoolConfig.getInstance() to initialize the classpool parts, and then deploy the JBossClClassPoolConfig bean whose purpose is to add the RegisterModuleCallback as a module registry in ClassLoading once that is deployed.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>With this in place and with a few small changes to how the aop classes work, what is in bootstrap/aop.xml will reuse things from JBossClClassPoolConfig where appropriate.</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/539242#539242">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Microcontainer Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2115">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>