users@glassfish.java.net

[gf-users] Recommendation

From: Matt S <mlcs05_at_hotmail.com>
Date: Thu, 24 Apr 2014 02:40:03 +0000

Alcon:


Have some home projects that involve Glassfish 4.0 (b89) when I made an observation. I’ve an EAR project with some non-persistent EJB timers and was getting an odd error when I attempted to deploy it after I created a cluster. Stack trace looks like this:


[2014-04-23T19:31:20.242-0700] [glassfish 4.0] [SEVERE] [NCLS-CORE-00026] [javax.enterprise.system.core] [tid: _ThreadID=35 _ThreadName=admin-listener(3)] [timeMillis: 1398306680242] [levelValue: 1000] [[
  Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: Failed to create automatic timers for FileScanner -- n must be positive
 at java.util.Random.nextInt(Random.java:300)
 at org.glassfish.ejb.startup.EjbDeployer.getOwnerId(EjbDeployer.java:583)
 at org.glassfish.ejb.startup.EjbDeployer.createAutomaticPersistentTimersForEJB(EjbDeployer.java:560)
 at org.glassfish.ejb.startup.EjbDeployer.checkEjbBundleForTimers(EjbDeployer.java:535)
 at org.glassfish.ejb.startup.EjbDeployer.event(EjbDeployer.java:508)
 at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
 at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:484)
 at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
 at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
 at java.security.AccessController.doPrivileged(Native Method)
 at javax.security.auth.Subject.doAs(Subject.java:356)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
 at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:235)
 at org.glassfish.admin.rest.utils.ResourceUtil.runCommand(ResourceUtil.java:257)
 at org.glassfish.admin.rest.resources.TemplateListOfResource.createResource(TemplateListOfResource.java:134)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)


etc…




I had a datasource setup in the EJB Timers area of the Admin console so this puzzled me a bit. I dove into the code and found this:


org.glassfish.ejb.startup.EjbDeployer


private String More ...getOwnerId(String target) {
    // If target is a cluster, replace it with the instance
    ReferenceContainer ref = domain.getReferenceContainerNamed(target);


    if(ref != null && ref.isCluster()) {
        Cluster cluster = (Cluster) ref; // guaranteed safe cast!!
        List<Server> instances = cluster.getInstances();


        // Try a random instance in a cluster
        int useInstance = random.nextInt(instances.size());
        Server s0 = instances.get(useInstance);
        if (s0.isRunning()) {
            return s0.getName();
        } else {
            // Pick the first running instead
            for (Server s : instances) {
                if (s.isRunning()) {
                    return s.getName();
                }
            }
        }
    }
    return target;
}


I had accidentally not added any instances to my cluster yet when I deployed it. When there’s time and not much going on, recommend at least some logging or an instances.empty() check.


Thanks,

Matt