geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r637171 - in /geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl: ./ context/ executor/
Date Fri, 14 Mar 2008 17:33:39 GMT
Author: gawor
Date: Fri Mar 14 10:33:37 2008
New Revision: 637171

URL: http://svn.apache.org/viewvc?rev=637171&view=rev
Log:
Throw IllegalStateException if the component that created proxy via ContextServie is not running

Added:
    geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/ModuleContext.java
  (with props)
    geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceModuleFacade.java
  (with props)
Modified:
    geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/GeronimoManagedContextBuilder.java
    geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceGBean.java
    geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/executor/ManagedExecutorServiceModuleFacade.java

Modified: geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/GeronimoManagedContextBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/GeronimoManagedContextBuilder.java?rev=637171&r1=637170&r2=637171&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/GeronimoManagedContextBuilder.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/GeronimoManagedContextBuilder.java
Fri Mar 14 10:33:37 2008
@@ -23,7 +23,6 @@
 
 import org.apache.geronimo.concurrent.ManagedContext;
 import org.apache.geronimo.concurrent.ManagedContextHandler;
-import org.apache.geronimo.concurrent.impl.executor.ManagedExecutorServiceModuleFacade;
 import org.apache.geronimo.concurrent.spi.ManagedContextBuilder;
 import org.apache.geronimo.gbean.AbstractName;
 
@@ -35,7 +34,7 @@
         contextHandler.saveContext(capturedContext);
         
         // determine module name
-        AbstractName moduleID = ManagedExecutorServiceModuleFacade.getCurrentModule();
+        AbstractName moduleID = ModuleContext.getCurrentModule();
         
         return new GeronimoManagedContext(contextHandler, capturedContext, moduleID);
     }

Added: geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/ModuleContext.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/ModuleContext.java?rev=637171&view=auto
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/ModuleContext.java
(added)
+++ geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/ModuleContext.java
Fri Mar 14 10:33:37 2008
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.concurrent.impl;
+
+import org.apache.geronimo.gbean.AbstractName;
+
+public class ModuleContext {
+
+    private static ThreadLocal<AbstractName> moduleThreadLocal = new ThreadLocal<AbstractName>();
+    
+    public static AbstractName getCurrentModule() {
+        return moduleThreadLocal.get();
+    }
+    
+    public static AbstractName setCurrentModule(AbstractName module) {
+        AbstractName current = moduleThreadLocal.get();
+        moduleThreadLocal.set(module);
+        return current;
+    }
+
+}

Propchange: geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/ModuleContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceGBean.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceGBean.java?rev=637171&r1=637170&r2=637171&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceGBean.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceGBean.java
Fri Mar 14 10:33:37 2008
@@ -33,6 +33,7 @@
     public static final GBeanInfo GBEAN_INFO;
     
     private ManagedContextHandlerChain mainContextHandler;
+    private BasicContextService contextService;
 
     public ContextServiceGBean(Kernel kernel, 
                                ClassLoader classLoader,
@@ -43,8 +44,15 @@
         this.mainContextHandler = new ManagedContextHandlerChain(handlers);
     }
     
+    private synchronized BasicContextService getContextService() {
+        if (this.contextService == null) {
+            this.contextService = new BasicContextService(this.mainContextHandler);     
      
+        }
+        return this.contextService;
+    }
+    
     public Object $getResource(AbstractName moduleID) {
-        return new BasicContextService(this.mainContextHandler);
+        return new ContextServiceModuleFacade(getContextService(), moduleID);
     }
     
     static {

Added: geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceModuleFacade.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceModuleFacade.java?rev=637171&view=auto
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceModuleFacade.java
(added)
+++ geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceModuleFacade.java
Fri Mar 14 10:33:37 2008
@@ -0,0 +1,71 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.concurrent.impl.context;
+
+import java.util.Map;
+
+import javax.util.concurrent.ContextService;
+
+import org.apache.geronimo.concurrent.impl.ModuleContext;
+import org.apache.geronimo.gbean.AbstractName;
+
+public class ContextServiceModuleFacade implements ContextService {
+    
+    private ContextService contextService;
+    private AbstractName moduleID;
+
+    public ContextServiceModuleFacade(ContextService contextService,
+                                      AbstractName moduleID) {
+        this.contextService = contextService;
+        this.moduleID = moduleID;
+    }
+    
+    protected Object before() {
+        return ModuleContext.setCurrentModule(this.moduleID);
+    }
+    
+    protected void after(Object obj) {
+        ModuleContext.setCurrentModule((AbstractName)obj);
+    }
+           
+    public Object createContextObject(Object arg0, Class<?>[] arg1) {
+        Object rs = before();
+        try {
+            return this.contextService.createContextObject(arg0, arg1);
+        } finally {
+            after(rs);
+        } 
+    }
+
+    public Object createContextObject(Object arg0, Class<?>[] arg1, Map<String,
String> arg2) {
+        Object rs = before();
+        try {
+            return this.contextService.createContextObject(arg0, arg1, arg2);
+        } finally {
+            after(rs);
+        } 
+    }
+
+    public Map<String, String> getProperties(Object arg0) {
+        return this.contextService.getProperties(arg0);
+    }
+
+    public void setProperties(Object arg0, Map<String, String> arg1) {
+        this.contextService.setProperties(arg0, arg1);
+    }
+           
+}

Propchange: geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/context/ContextServiceModuleFacade.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/executor/ManagedExecutorServiceModuleFacade.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/executor/ManagedExecutorServiceModuleFacade.java?rev=637171&r1=637170&r2=637171&view=diff
==============================================================================
--- geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/executor/ManagedExecutorServiceModuleFacade.java
(original)
+++ geronimo/sandbox/concurrent/geronimo-concurrent/src/main/java/org/apache/geronimo/concurrent/impl/executor/ManagedExecutorServiceModuleFacade.java
Fri Mar 14 10:33:37 2008
@@ -28,12 +28,11 @@
 import javax.util.concurrent.ManagedTaskListener;
 
 import org.apache.geronimo.concurrent.executor.ManagedExecutorServiceFacade;
+import org.apache.geronimo.concurrent.impl.ModuleContext;
 import org.apache.geronimo.gbean.AbstractName;
 
 public class ManagedExecutorServiceModuleFacade extends ManagedExecutorServiceFacade {
-    
-    private static ThreadLocal<AbstractName> moduleThreadLocal = new ThreadLocal<AbstractName>();
-    
+            
     private AbstractName moduleID;
 
     public ManagedExecutorServiceModuleFacade(ManagedExecutorService executor,
@@ -43,18 +42,13 @@
     }
     
     protected Object before() {
-        moduleThreadLocal.set(this.moduleID);
-        return null;
+        return ModuleContext.setCurrentModule(this.moduleID);
     }
     
     protected void after(Object obj) {
-        moduleThreadLocal.remove();
+        ModuleContext.setCurrentModule((AbstractName)obj);
     }
-    
-    public static AbstractName getCurrentModule() {
-        return moduleThreadLocal.get();
-    }
-    
+        
     public <T> List<Future<T>> invokeAll(Collection<Callable<T>>
tasks, 
                                          ManagedTaskListener listener)
         throws InterruptedException {



Mime
View raw message