8 Replies Latest reply on Nov 20, 2007 10:45 AM by adrian.brock

    Status of annotation based configuration

    starksm64

      I'm seeing an NPE currently due to a lookup of an annotation not returning a value in the ejb3 container:

      07:44:30,645 ERROR [AbstractKernelController] Error installing to Start: name=jboss.j2ee:ear=appclient_dep_compat14_50.ear,jar=appclient_dep_compat14_50_ejb.jar,name=TestBean,service=EJB3 state=Create
      java.lang.NullPointerException
       at org.jboss.ejb3.EJBContainer.initializePool(EJBContainer.java:804)
       at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:740)
       at org.jboss.ejb3.session.SessionContainer.start(SessionContainer.java:208)
       at org.jboss.ejb3.stateless.StatelessContainer.start(StatelessContainer.java:124)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      ...
      
       protected void initializePool() throws Exception
       {
       org.jboss.annotation.ejb.Pool poolAnnotation = getAnnotation(org.jboss.annotation.ejb.Pool.class);
       String registeredPoolName = poolAnnotation.value(); // line 804
       int maxSize = poolAnnotation.maxSize();
       long timeout = poolAnnotation.timeout();
       Ejb3Deployer deployer = deployment.getDeployer();
       PoolFactoryRegistry registry = deployer.getPoolFactoryRegistry();
       PoolFactory factory = registry.getPoolFactory(registeredPoolName);
       pool = factory.createPool();
       pool.initialize(this, maxSize, timeout);
       ...
      


      What are we expecting to do with this type of code?


        • 1. Re: Status of annotation based configuration
          anil.saldhana

          Use reasonable defaults for annotations?

          • 2. Re: Status of annotation based configuration

             

            "anil.saldhana@jboss.com" wrote:
            Use reasonable defaults for annotations?


            That doesn't make sense you have to specify the value if you use the annotation
            directly.

            Rather than the normal annotation, I'd guess the problem is the annotation
            created from the xml.

            No default here:

            public class PoolImpl implements Pool
            {
             public String value;
            


            or here:

             private void addPoolAnnotations(EJBContainer container,
             JBossEnterpriseBeanMetaData enterpriseBean) throws Exception
             {
             if (enterpriseBean.getPoolConfig() != null)
             {
             PoolConfigMetaData config = enterpriseBean.getPoolConfig();
            
             PoolImpl poolAnnotation = new PoolImpl();
            
             if (config.getValue() != null && !config.getValue().trim().equals(""))
             poolAnnotation.setValue(config.getValue());
            
             if (config.getMaxSize() != null)
             poolAnnotation.setMaxSize(config.getMaxSize());
            
             if (config.getTimeout() != null)
             poolAnnotation.setTimeout(config.getTimeout());
            
             addClassAnnotation(container, Pool.class, poolAnnotation);
             }
             }
            


            • 3. Re: Status of annotation based configuration
              alrubinger

              There should be compile-time constraints to ensure that @Pool.value is specified; as Adrian notes, this is bypassed when using XML-based configuration.

              http://jira.jboss.com/jira/browse/EJBTHREE-1119

              S,
              ALR

              • 4. Re: Status of annotation based configuration
                alrubinger

                In the case of missing "value" in XML, I'd prefer a Deployment Exception:

                if (config.getValue() != null && !config.getValue().trim().equals(""))
                {
                 poolAnnotation.setValue(config.getValue());
                }
                else
                {
                 throw new RuntimeException("detailed message");
                }
                


                ...instead of a default; let the bean provider know they must specify a registered Pool implementation if they're going to perform an override in jboss.xml.

                S,
                ALR

                • 5. Re: Status of annotation based configuration
                  anil.saldhana

                  Think Adrian said he is going to/has an idea how to get this issue resolved. So verify with him, Andrew. :)

                  • 6. Re: Status of annotation based configuration

                     

                    "ALRubinger" wrote:

                    ...instead of a default; let the bean provider know they must specify a registered Pool implementation if they're going to perform an override in jboss.xml.


                    Why do they have to specify a default pool implementation?
                    Most likely all they want to do is change the pool size?

                    We should define defaults somewhere and reference them
                    from the three places that use.

                    e.g.
                    public interface PoolDefaults
                    {
                     String defaultPool = "ThreadLocalPool";
                     int defaultSize = 30;
                     // etc.
                    }
                    public @interface Pool
                    {
                     String value() default PoolDefaults.defaultPool;
                     int size() default PoolDefaults.defaultSize;
                     // etc.
                    }
                    
                    public class PoolImpl implements Pool
                    {
                     public String value = PoolDefaults.defaultPool;
                     public int maxSize = PoolDefaults.defaultSize;
                     // etc.
                    }
                    



                    • 7. Re: Status of annotation based configuration
                      alrubinger

                       

                      "adrian@jboss.org" wrote:
                      Why do they have to specify a default pool implementation? Most likely all they want to do is change the pool size?


                      A much better point.

                      "adrian@jboss.org" wrote:
                      We should define defaults somewhere and reference them from the three places that use.


                      OK, but if we externalize the defaults into a "constants" class/interface, it'll have to go into ext-api for @Pool to get at it. I don't think this is too implementation-specific to be a problem, but worth noting.

                      S,
                      ALR

                      • 8. Re: Status of annotation based configuration

                         

                        "ALRubinger" wrote:

                        OK, but if we externalize the defaults into a "constants" class/interface, it'll have to go into ext-api for @Pool to get at it. I don't think this is too implementation-specific to be a problem, but worth noting.

                        S,
                        ALR


                        If you don't like the default being in ext-api, make the defaultPool "##Default" or
                        "*Default" then bind that to a real runtime default in your PoolFactoryRegistry config.