You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Romain Manni-Bucau <rm...@gmail.com> on 2016/02/08 13:22:26 UTC

Fwd: [2/2] tomee git commit: Refactor + spacing

If it can help - didnt investigate if it was 100% valid - 7.x branch
probably solved it with https://issues.apache.org/jira/browse/TOMEE-1548
(isInitialized() method in lazy resource)

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

---------- Forwarded message ----------
From: <jg...@apache.org>
Date: 2016-02-08 13:19 GMT+01:00
Subject: [2/2] tomee git commit: Refactor + spacing
To: commits@tomee.apache.org


Refactor + spacing


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

Branch: refs/heads/tomee-1.7.x
Commit: a2bbedf12d33d887116761b90df6ae7f3cf9d06e
Parents: 2631d5a
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Mon Feb 8 11:04:40 2016 +0000
Committer: Jonathan Gallimore <jo...@jrg.me.uk>
Committed: Mon Feb 8 11:04:40 2016 +0000

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


http://git-wip-us.apache.org/repos/asf/tomee/blob/a2bbedf1/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 d00b470..91b4f7a 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
@@ -1782,6 +1782,10 @@ public class Assembler extends AssemblerTool
implements org.apache.openejb.spi.A
             logger.debug("Not processing resource on destroy: " +
className);
         }

+        removeResourceInfo(name);
+    }
+
+    public void removeResourceInfo(final String name) {
         try {
             //Ensure ResourceInfo for this resource is removed
             final OpenEjbConfiguration configuration =
SystemInstance.get().getComponent(OpenEjbConfiguration.class);
@@ -2197,45 +2201,33 @@ 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 {
-
-       Object object = null;
-
-       try {
-                       object = globalContext.lookup(name);
-               } catch (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
(!LazyObjectReference.class.isInstance(binding.getObject())) continue;
-
-                               final LazyObjectReference<?> ref =
LazyObjectReference.class.cast(binding.getObject());
-                               if (! ref.isInitialized()) {
-                                       globalContext.unbind(name);
-
-                                       // TODO: refactor this method out
-                                       //Ensure ResourceInfo for this
resource is removed
-                           final OpenEjbConfiguration configuration =
SystemInstance.get().getComponent(OpenEjbConfiguration.class);
-                           final Iterator<ResourceInfo> iterator =
configuration.facilities.resources.iterator();
-                           while (iterator.hasNext()) {
-                               final ResourceInfo info = iterator.next();
-                               if
(name.equals(OPENEJB_RESOURCE_JNDI_PREFIX + info.id)) {
-                                   iterator.remove();
-                                   break;
-                               }
-                           }
-
-                                       return;
-                               }
-                       }
-
-                       throw e;
-               }
-
-               final String clazz;
+
+        Object object = null;
+
+        try {
+            object = globalContext.lookup(name);
+        } catch (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
(!LazyObjectReference.class.isInstance(binding.getObject())) continue;
+
+                final LazyObjectReference<?> ref =
LazyObjectReference.class.cast(binding.getObject());
+                if (! ref.isInitialized()) {
+                    globalContext.unbind(name);
+                    removeResourceInfo(name);
+                    return;
+                }
+            }
+
+            throw e;
+        }
+
+        final String clazz;
         if (object == null) { // should it be possible?
             clazz = "?";
         } else {