tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject [2/9] tomee git commit: Check the binding for LazyResources and Destroyable resources first
Date Wed, 02 Aug 2017 23:06:13 GMT
Check the binding for LazyResources and Destroyable resources first


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/96973e9a
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/96973e9a
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/96973e9a

Branch: refs/heads/master
Commit: 96973e9ac09f96b9fea13b97380a2f82cb157f61
Parents: cce266a
Author: Jonathan Gallimore <jon@jrg.me.uk>
Authored: Thu Jul 13 09:50:34 2017 +0100
Committer: Jonathan Gallimore <jon@jrg.me.uk>
Committed: Thu Jul 13 09:50:34 2017 +0100

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java    | 59 ++++++++++----------
 1 file changed, 28 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/96973e9a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index d0c0958..13c27e6 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -2469,43 +2469,40 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
     }
 
     private void destroyLookedUpResource(final Context globalContext, final String id, final
String name) throws NamingException {
+        // check to see if the resource is a LazyObjectReference that has not been initialized
+        // if it is, we'll remove the LazyObjectReference, rather than do a lookup causing
it
+        // to be instantiated
+        final String ctx = name.substring(0, name.lastIndexOf("/"));
+        final String objName = name.substring(ctx.length() + 1);
+
+        final NamingEnumeration<Binding> bindings = globalContext.listBindings(ctx);
+        while (bindings.hasMoreElements()) {
+            final Binding binding = bindings.nextElement();
+            if (!binding.getName().equals(objName)) {
+                continue;
+            }
 
-        final Object object;
-
-        try {
-            object = globalContext.lookup(name);
-        } catch (final NamingException e) {
-            // if we catch a NamingException, check to see if the resource is a LaztObjectReference
that has not been initialized correctly
-            final String ctx = name.substring(0, name.lastIndexOf("/"));
-            final String objName = name.substring(ctx.length() + 1);
-            final NamingEnumeration<Binding> bindings = globalContext.listBindings(ctx);
-            while (bindings.hasMoreElements()) {
-                final Binding binding = bindings.nextElement();
-                if (!binding.getName().equals(objName)) {
-                    continue;
-                }
-                if (DestroyableResource.class.isInstance(binding.getObject())) {
-                    final DestroyableResource destroyableResource = DestroyableResource.class.cast(binding.getObject());
-                    destroyableResource.destroyResource();
-                    globalContext.unbind(name);
-                    return;
-                }
-
-                if (!LazyObjectReference.class.isInstance(binding.getObject())) {
-                    continue;
-                }
+            if (DestroyableResource.class.isInstance(binding.getObject())) {
+                final DestroyableResource destroyableResource = DestroyableResource.class.cast(binding.getObject());
+                destroyableResource.destroyResource();
+                globalContext.unbind(name);
+                return;
+            }
 
-                final LazyObjectReference<?> ref = LazyObjectReference.class.cast(binding.getObject());
-                if (! ref.isInitialized()) {
-                    globalContext.unbind(name);
-                    removeResourceInfo(name);
-                    return;
-                }
+            if (!LazyObjectReference.class.isInstance(binding.getObject())) {
+                continue;
             }
 
-            throw e;
+            final LazyObjectReference<?> ref = LazyObjectReference.class.cast(binding.getObject());
+            if (!ref.isInitialized()) {
+                globalContext.unbind(name);
+                removeResourceInfo(id);
+                return;
+            }
         }
 
+        // otherwise, look the object up and remove it
+        final Object object = globalContext.lookup(name);
         final String clazz;
         if (object == null) { // should it be possible?
             clazz = "?";


Mime
View raw message