<!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;">
EJB 3.1 @Singleton remote access
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/RET">Christian Tre</a> in <i>JNDI and Naming</i> - <a href="http://community.jboss.org/message/542570#542570">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hello!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>While testing the new @Singleton-Annotation almost completely implemented in JBoss AS 6 M3 i encountered several problems during deploying or getting the right<span style="color: #333333;"> In</span>terface.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>My Remote Interface:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">@Remote
@RemoteBinding(jndiBinding=ParameterHolder.JNDI_BINDING)
<font color="navy"><b>public</b></font> <font color="navy"><b>interface</b></font> ParameterHolder <font color="navy">{</font>
 
    <font color="navy"><b>public</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> String JNDI_BINDING = JNDI_PREFIX + <font color="red">"core/ParameterHolder"</font>;
 
    <font color="navy"><b>public</b></font> <font color="navy"><b>abstract</b></font> <font color="navy"><b>void</b></font> reloadAll();
 
    <font color="darkgreen">/**
     * Methode für Interceptoren, um bestimmte Parameter
     * nach einem Create / Update / Delete neu zu laden
     * @param oid
     */</font>
    <font color="navy"><b>public</b></font> <font color="navy"><b>abstract</b></font> <font color="navy"><b>void</b></font> reload(Parameter param);
 
    <font color="navy"><b>public</b></font> <font color="navy"><b>abstract</b></font> <font color="navy"><b>void</b></font> unload(Parameter param);
 
    <font color="navy"><b>public</b></font> <font color="navy"><b>abstract</b></font> Parameter get(String name, Company company);
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>my Local Interface:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">@Local
@LocalBinding(jndiBinding=ParameterHolderLocal.JNDI_BINDING)
<font color="navy"><b>public</b></font> <font color="navy"><b>interface</b></font> ParameterHolderLocal <font color="navy">{</font>
 
    <font color="navy"><b>public</b></font> <font color="navy"><b>static</b></font> <font color="navy"><b>final</b></font> String JNDI_BINDING = ParameterHolder.JNDI_BINDING + JNDI_SUFFIX_LOCAL;
   
    <font color="navy"><b>public</b></font> <font color="navy"><b>abstract</b></font> <font color="navy"><b>void</b></font> reloadAll();
 
    <font color="darkgreen">/**
     * Methode für Interceptoren, um bestimmte Parameter
     * nach einem Create / Update / Delete neu zu laden
     * @param oid
     */</font>
    <font color="navy"><b>public</b></font> <font color="navy"><b>abstract</b></font> <font color="navy"><b>void</b></font> reload(Parameter param);
 
    <font color="navy"><b>public</b></font> <font color="navy"><b>abstract</b></font> <font color="navy"><b>void</b></font> unload(Parameter param);
 
    <font color="navy"><b>public</b></font> <font color="navy"><b>abstract</b></font> Parameter get(String name, Company company);
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>my BeanImplementation:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">@Singleton
@Startup
@DependsOn(ParameterServiceLocal.JNDI_BINDING)
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> ParameterHolderImpl <font color="navy"><b>implements</b></font> ParameterHolder, ParameterHolderLocal <font color="navy">{</font>
    <font color="navy"><b>private</b></font> <font color="navy"><b>static</b></font> Set<Parameter> params = <font color="navy"><b>new</b></font> HashSet<Parameter>();
   
    <font color="navy"><b>private</b></font> Log LOG = LogFactory.getLog(this.getClass());
   
    @EJB(mappedName=ParameterServiceLocal.JNDI_BINDING)
    <font color="navy"><b>private</b></font> ParameterServiceLocal parameterservice;
   
    @PostConstruct
    <font color="navy"><b>private</b></font> <font color="navy"><b>void</b></font> init() <font color="navy">{</font>
        params.clear();
        params.addAll(parameterservice.findAll());
    <font color="navy">}</font>
   
    @SuppressWarnings(<font color="red">"unused"</font>)
    @PreDestroy
    <font color="navy"><b>private</b></font> <font color="navy"><b>void</b></font> destroy() <font color="navy">{</font>
        params.clear();
    <font color="navy">}</font>
   
    @Lock(LockType.WRITE)
    <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> reloadAll() <font color="navy">{</font>
        init();
    <font color="navy">}</font>
   
    <font color="darkgreen">/**
     * Methode für Interceptoren, um bestimmte Parameter
     * nach einem Create / Update / Delete neu zu laden
     * @param oid
     */</font>
    @Lock(LockType.WRITE)
    <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> reload(Parameter param) <font color="navy">{</font>
        <font color="navy"><b>if</b></font> (param == <font color="navy"><b>null</b></font>) <font color="navy">{</font>
            <font color="navy"><b>return</b></font>;
        <font color="navy">}</font>
        <font color="navy"><b>if</b></font> (LOG.isTraceEnabled()) <font color="navy">{</font>
            LOG.trace(<font color="red">"reload \""</font> + param.getName() + <font color="red">"\" from Company "</font> + param.getCompany());
        <font color="navy">}</font>
        <font color="darkgreen">// da es sein kann, dass der Parameter neu erstellt wurde, muss er nochmal nachgeladen werden</font>
        param = parameterservice.findByName(param.getName(), param.getCompany());
        <font color="darkgreen">// wenn der param nicht null ist und entweder nicht in der Liste ist (also neu angelegt)</font>
        <font color="darkgreen">// oder in der Liste ist und gelöscht werden konnte</font>
        <font color="navy"><b>if</b></font> (param != <font color="navy"><b>null</b></font> && (!params.contains(param) || params.remove(param))) <font color="navy">{</font>
            params.add(param);
        <font color="navy">}</font> <font color="navy"><b>else</b></font> <font color="navy">{</font>
            <font color="navy"><b>if</b></font> (LOG.isWarnEnabled()) <font color="navy">{</font>
                LOG.warn(<font color="red">"cannot reload Parameter: "</font> + param);
            <font color="navy">}</font>
        <font color="navy">}</font>
    <font color="navy">}</font>
   
    @Lock(LockType.WRITE)
    <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> unload(Parameter param) <font color="navy">{</font>
        <font color="navy"><b>if</b></font> (param == <font color="navy"><b>null</b></font>) <font color="navy">{</font>
            <font color="navy"><b>return</b></font>;
        <font color="navy">}</font>
        <font color="navy"><b>if</b></font> (LOG.isTraceEnabled()) <font color="navy">{</font>
            LOG.trace(<font color="red">"unload \""</font> + param.getName() + <font color="red">"\" from Company "</font> + param.getCompany());
        <font color="navy">}</font>
        params.remove(param);
    <font color="navy">}</font>
   
    @Lock(LockType.READ)
    <font color="navy"><b>public</b></font> Parameter get(String name, Company company) <font color="navy">{</font>
        Iterator<Parameter> iter = params.iterator();
        <font color="navy"><b>while</b></font> (iter.hasNext()) <font color="navy">{</font>
            Parameter p = iter.next();
            <font color="navy"><b>if</b></font> (p.getCompany().equals(company) && p.getName().equals(name)) <font color="navy">{</font>
                <font color="navy"><b>return</b></font> p;
            <font color="navy">}</font>
        <font color="navy">}</font>
        <font color="navy"><b>return</b></font> <font color="navy"><b>null</b></font>;
    <font color="navy">}</font>
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>At my ParameterServiceImpl i added Interceptors to the write / update / delete-Methods to renew these one Parameter in the global Cache (this Singleton)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>in my serverlog this line appeared on deploying my app:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">2010-05-12 13:12:08,040 WARN  [org.jboss.ejb3.session.SessionContainer] (HDScanner) No JndiSessionRegistrarBase was found; byassing binding of Proxies to jboss.j2ee:service=EJB3,name=ParameterHolderImpl in Global JNDI.
</code></pre><p>(yes, its byassing instead of bypassing <span> ;) </span>)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>in my junittest</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </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> CoreServicesRemoteTest <font color="navy"><b>extends</b></font> TestCase <font color="navy">{</font>
 
    <font color="navy"><b>private</b></font> Context ctx;
    <font color="navy"><b>private</b></font> CompanyService cs;
    <font color="navy"><b>private</b></font> ParameterService ps;
    <font color="navy"><b>private</b></font> ParameterHolder ph;
   
    <font color="navy"><b>protected</b></font> <font color="navy"><b>void</b></font> setUp() <font color="navy"><b>throws</b></font> Exception <font color="navy">{</font>
        super.setUp();
        ctx = <font color="navy"><b>new</b></font> JndiConnection().getInitialContext();
        assertNotNull(ctx);
        cs = (CompanyService) ctx.lookup(CompanyService.JNDI_BINDING);
        assertNotNull(cs);
        ps = (ParameterService) ctx.lookup(ParameterService.JNDI_BINDING);
        assertNotNull(ps);
        ph = (ParameterHolder) ctx.lookup(ParameterHolder.JNDI_BINDING);
        assertNotNull(ph);
    <font color="navy">}</font>
 
    <font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> testCompanyCreate() <font color="navy"><b>throws</b></font> Exception <font color="navy">{</font>
        Company c = cs.create(1, <font color="red">"my Company"</font>);
        assertNotNull(c);
        Parameter p = ps.create(<font color="red">"mein Param"</font>,<font color="red">"Wert"</font>, c);
        assertNotNull(ps.find(p.getOid()));
        assertNotNull(ph.get(<font color="red">"mein Param"</font>, c));
        assertTrue(ps.delete(p));
        assertNull(ph.get(<font color="red">"mein param"</font>, c));
        assertTrue(cs.delete(c));
    <font color="navy">}</font>
<font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>i get an Communication-Exception at the lookup for Parameterholder:</p><pre class="jive-pre"><code class="jive-code jive-java">javax.naming.CommunicationException [Root exception is java.lang.ClassNotFoundException: org.jboss.ejb3.singleton.proxy.impl.invocationhandler.SingletonBeanRemoteInvocationHandler (no security manager: RMI <font color="navy"><b>class</b></font> loader disabled)]
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:847)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at de.neutrasoft.portal.test.CoreServicesRemoteTest.setUp(CoreServicesRemoteTest.java:28)
    at junit.framework.TestCase.runBare(TestCase.java:128)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.jboss.ejb3.singleton.proxy.impl.invocationhandler.SingletonBeanRemoteInvocationHandler (no security manager: RMI <font color="navy"><b>class</b></font> loader disabled)
    at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
    at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
    at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
    at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
    at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at java.rmi.MarshalledObject.get(Unknown Source)
    at org.jnp.interfaces.MarshalledValuePair.get(MarshalledValuePair.java:72)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:771)
    ... 16 more
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>my second try: make ParameterHolder stateless and with static HashMap, but that fails too, i guess because the Bean is destroyed between 1st Instance + Parameter stuffed and first get-Call on the Map.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Whats the Problem here? Any Classes still missing in M3?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>regards, Chris</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/542570#542570">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JNDI and Naming at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>