You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2006/07/23 22:35:12 UTC

svn commit: r424807 - in /webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core: ResourceManager.java SimpleResourceManager.java

Author: danj
Date: Sun Jul 23 13:35:12 2006
New Revision: 424807

URL: http://svn.apache.org/viewvc?rev=424807&view=rev
Log:
ResourceManager is no longer responsbile for creating resources at startup - the RouterPersistence layer handles this.

Modified:
    webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core/ResourceManager.java
    webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core/SimpleResourceManager.java

Modified: webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core/ResourceManager.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core/ResourceManager.java?rev=424807&r1=424806&r2=424807&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core/ResourceManager.java (original)
+++ webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core/ResourceManager.java Sun Jul 23 13:35:12 2006
@@ -1,187 +1,178 @@
-/*=============================================================================*
- *  Copyright 2006 The Apache Software Foundation
- *
- *  Licensed 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.muse.core;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.apache.muse.ws.addressing.EndpointReference;
-import org.apache.muse.ws.addressing.soap.SoapFault;
-
-/**
- * ResourceManager defines the interface for creating and storing resources 
- * that can be targeted by other resources (internal and external to a 
- * Muse-derived application). The resources' endpoint references (EPRs) are 
- * used to differentiate between resources in concrete implementations.
- * <br><br>
- * Note that ResourceManager does not initiate any lifecycle events - the 
- * add() operation does not create a resource, and the remove() operation 
- * does not destroy a resource. Other components can use the create() 
- * method to instantiate a resource and add() to make it visible to remote 
- * clients, but the ResourceManager will not start this process as part of 
- * its lifecycle.
- * 
- * @author Dan Jemiolo (danj)
- * 
- * @see Resource#shutdown()
- * 
- */
-
-public interface ResourceManager
-{
-    /**
-     * 
-     * @param listener
-     *        A listener that will be fired whenever a resource is added 
-     *        or removed from the resource. 
-     *
-     */
-    void addListener(ResourceManagerListener listener);
-    
-    /**
-     * 
-     * Add a resource to the manager, associated with the given EPR.
-     * 
-     * @param epr
-     *        The unique EPR identifying the resource instance.
-     *        
-     * @param resource
-     *  
-     * @throws SoapFault
-     *         <ul>
-     *         <li>If there is already a resource with the same EPR.</li>
-     *         </ul>
-     * 
-     * @see #getResource(EndpointReference)
-     * 
-     */
-    void addResource(EndpointReference epr, Resource resource)
-        throws SoapFault;
-    
-    /**
-     * 
-     * @param definitions
-     *        The ResourceDefinition objects that will be used to generate new 
-     *        resource instances. There must be at least one factory in the 
-     *        given array, because each application must define at least one 
-     *        resource type.
-     * 
-     * @see org.apache.muse.core.descriptor.DeploymentDescriptor#getResourceDefinitions()
-     *
-     */
-    void addResourceDefinitions(Collection definitions);
-    
-    Resource createResource(String contextPath)
-        throws SoapFault;
-    
-    /**
-     * 
-     * Creates all of the resources that were specified using the 
-     * resource-type/@instances-at-startup attribute in muse.xml.
-     *
-     */
-    void createStartupResources() 
-        throws SoapFault;
-    
-    Environment getEnvironment();
-    
-    /**
-     *
-     * @return The number of resources stored by the manager.
-     *
-     */
-    int getNumberOfResources();
-    
-    /**
-     * 
-     * @param epr
-     *        The unique EPR that is associated with the desired resource.
-     * 
-     * @return The resource associated with the given key, or null if no 
-     *         such resource exists.
-     *
-     */
-    Resource getResource(EndpointReference epr);
-    
-    /**
-     * 
-     * This method allows you to find a resource type's endpoint URI given 
-     * the Java interface or concrete class of one of its capabilities.
-     * 
-     * @param capabilityClass
-     *        An interface or concrete class for one of the capabilities in 
-     *        the application's resource types. This value may be defined in 
-     *        <em>resource-type/capability/java-capability-class</em> in muse.xml.
-     * 
-     * @return A unique URL for the resource type that is partially-defined by 
-     *         the given capability's interface or class, or null if no such 
-     *         type exists.
-     *
-     */
-    String getResourceContextPath(Class capabilityClass);
-    
-    Collection getResourceContextPaths(Class capabilityClass);
-
-    /**
-     * 
-     * @return A collection containing all of the ResourceDefinition objects, 
-     *         one for each resource type defined in the application's 
-     *         deployment descriptor(s). The collection may be empty.
-     *
-     */
-    Collection getResourceContextPaths();
-    
-    /**
-     *
-     * @return An iterator over a <b>copy</b> of the resource EPR collection.
-     *
-     */
-    Iterator getResourceEPRs();
-
-    void removeListener(ResourceManagerListener listener);
-
-    /**
-     * 
-     * Removes the EPR-resource pair from the manager. This does <b>not</b> 
-     * destroy the resource - it merely removes it from the external view. 
-     * This method should not require WS-RL support on the part of resources.
-     *
-     * @param epr
-     *        The unique EPR that maps to the resource being removed.
-     * 
-     * @throws SoapFault
-     *         <ul>
-     *         <li>If the key does not map to a resource.</li>
-     *         </ul>
-     *
-     */
-    void removeResource(EndpointReference epr)
-        throws SoapFault;
-
-    /**
-     * 
-     * Removes each ResourceDefinition in the given Collection. After this method 
-     * has returned, the application will no longer service requests for the 
-     * given resource types. It will be as though they were never deployed.
-     * 
-     * @param definitions
-     *
-     */
-    void removeResourceDefinitions(Collection definitions);
-
-    void setEnvironment(Environment env);
-}
+/*=============================================================================*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.muse.core;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+
+/**
+ * ResourceManager defines the interface for creating and storing resources 
+ * that can be targeted by other resources (internal and external to a 
+ * Muse-derived application). The resources' endpoint references (EPRs) are 
+ * used to differentiate between resources in concrete implementations.
+ * <br><br>
+ * Note that ResourceManager does not initiate any lifecycle events - the 
+ * add() operation does not create a resource, and the remove() operation 
+ * does not destroy a resource. Other components can use the create() 
+ * method to instantiate a resource and add() to make it visible to remote 
+ * clients, but the ResourceManager will not start this process as part of 
+ * its lifecycle.
+ * 
+ * @author Dan Jemiolo (danj)
+ * 
+ * @see Resource#shutdown()
+ * 
+ */
+
+public interface ResourceManager extends Initialization, Shutdown
+{
+    /**
+     * 
+     * @param listener
+     *        A listener that will be fired whenever a resource is added 
+     *        or removed from the resource. 
+     *
+     */
+    void addListener(ResourceManagerListener listener);
+    
+    /**
+     * 
+     * Add a resource to the manager, associated with the given EPR.
+     * 
+     * @param epr
+     *        The unique EPR identifying the resource instance.
+     *        
+     * @param resource
+     *  
+     * @throws SoapFault
+     *         <ul>
+     *         <li>If there is already a resource with the same EPR.</li>
+     *         </ul>
+     * 
+     * @see #getResource(EndpointReference)
+     * 
+     */
+    void addResource(EndpointReference epr, Resource resource)
+        throws SoapFault;
+    
+    /**
+     * 
+     * @param definitions
+     *        The ResourceDefinition objects that will be used to generate new 
+     *        resource instances. There must be at least one factory in the 
+     *        given array, because each application must define at least one 
+     *        resource type.
+     * 
+     * @see org.apache.muse.core.descriptor.DeploymentDescriptor#getResourceDefinitions()
+     *
+     */
+    void addResourceDefinitions(Collection definitions);
+    
+    Resource createResource(String contextPath)
+        throws SoapFault;
+    
+    Environment getEnvironment();
+    
+    /**
+     *
+     * @return The number of resources stored by the manager.
+     *
+     */
+    int getNumberOfResources();
+    
+    /**
+     * 
+     * @param epr
+     *        The unique EPR that is associated with the desired resource.
+     * 
+     * @return The resource associated with the given key, or null if no 
+     *         such resource exists.
+     *
+     */
+    Resource getResource(EndpointReference epr);
+    
+    /**
+     * 
+     * This method allows you to find a resource type's endpoint URI given 
+     * the Java interface or concrete class of one of its capabilities.
+     * 
+     * @param capabilityClass
+     *        An interface or concrete class for one of the capabilities in 
+     *        the application's resource types. This value may be defined in 
+     *        <em>resource-type/capability/java-capability-class</em> in muse.xml.
+     * 
+     * @return A unique URL for the resource type that is partially-defined by 
+     *         the given capability's interface or class, or null if no such 
+     *         type exists.
+     *
+     */
+    String getResourceContextPath(Class capabilityClass);
+    
+    Collection getResourceContextPaths(Class capabilityClass);
+
+    /**
+     * 
+     * @return A collection containing all of the ResourceDefinition objects, 
+     *         one for each resource type defined in the application's 
+     *         deployment descriptor(s). The collection may be empty.
+     *
+     */
+    Collection getResourceContextPaths();
+    
+    /**
+     *
+     * @return An iterator over a <b>copy</b> of the resource EPR collection.
+     *
+     */
+    Iterator getResourceEPRs();
+
+    void removeListener(ResourceManagerListener listener);
+
+    /**
+     * 
+     * Removes the EPR-resource pair from the manager. This does <b>not</b> 
+     * destroy the resource - it merely removes it from the external view. 
+     * This method should not require WS-RL support on the part of resources.
+     *
+     * @param epr
+     *        The unique EPR that maps to the resource being removed.
+     * 
+     * @throws SoapFault
+     *         <ul>
+     *         <li>If the key does not map to a resource.</li>
+     *         </ul>
+     *
+     */
+    void removeResource(EndpointReference epr)
+        throws SoapFault;
+
+    /**
+     * 
+     * Removes each ResourceDefinition in the given Collection. After this method 
+     * has returned, the application will no longer service requests for the 
+     * given resource types. It will be as though they were never deployed.
+     * 
+     * @param definitions
+     *
+     */
+    void removeResourceDefinitions(Collection definitions);
+
+    void setEnvironment(Environment env);
+}

Modified: webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core/SimpleResourceManager.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core/SimpleResourceManager.java?rev=424807&r1=424806&r2=424807&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core/SimpleResourceManager.java (original)
+++ webservices/muse/trunk/modules/muse-core/src/org/apache/muse/core/SimpleResourceManager.java Sun Jul 23 13:35:12 2006
@@ -32,7 +32,6 @@
 import org.apache.muse.util.messages.Messages;
 import org.apache.muse.util.messages.MessagesFactory;
 import org.apache.muse.ws.addressing.EndpointReference;
-import org.apache.muse.ws.addressing.MessageHeaders;
 import org.apache.muse.ws.addressing.soap.SoapFault;
 
 /**
@@ -62,8 +61,12 @@
     
     private Environment _environment = null;
     
-    private List _listeners = new LinkedList();
+    private boolean _hasBeenInitialized = false;
     
+    private boolean _hasBeenShutdown = false;
+
+    private List _listeners = new LinkedList();
+
     //
     // All instances of a resource type currently alive on the system
     //
@@ -150,59 +153,6 @@
         return resource;
     }
     
-    public void createStartupResources()
-        throws SoapFault
-    {
-        Environment env = getEnvironment();
-        
-        EndpointReference epr = env.getDeploymentEPR();
-        MessageHeaders context = new MessageHeaders(epr, null);
-        
-        //
-        // add a "fake" context based on the default EPR. we need 
-        // some basic WS-A data to create these resources.
-        //
-        env.addAddressingContext(context);
-        
-        Iterator i = getResourceContextPaths().iterator();
-        
-        try
-        {
-            //
-            // for every resource type deployed in this application...
-            //
-            while (i.hasNext())
-            {
-                String path = (String)i.next();
-                ResourceDefinition next = getResourceDefinition(path);
-                int numToCreate = next.getInstancesAtStartup();
-                
-                //
-                // create/initialize the type and make it available
-                //
-                for (int n = 0; n < numToCreate; ++n)
-                {
-                    Resource resource = next.newInstance();
-                    resource.setResourceManager(this);
-                    
-                    fixLocalEPR(resource);
-                    
-                    resource.initialize();
-                    
-                    addResource(resource.getEndpointReference(), resource);
-                }
-            }
-        }
-        
-        //
-        // just like a normal request - don't forget to clean house!
-        //
-        finally
-        {
-            env.removeAddressingContext();
-        }
-    }
-    
     /**
      * 
      * This method addresses the fact that all new resources have 
@@ -279,6 +229,11 @@
         return matches.isEmpty() ? null : (String)matches.iterator().next();
     }
     
+    public Collection getResourceContextPaths()
+    {
+        return _definitionsByPath.keySet();
+    }
+    
     public Collection getResourceContextPaths(Class capabilityClass)
     {
         if (capabilityClass == null)
@@ -314,11 +269,6 @@
         return matches;
     }
     
-    public Collection getResourceContextPaths()
-    {
-        return _definitionsByPath.keySet();
-    }
-    
     /**
      * 
      * @param contextPath
@@ -358,11 +308,27 @@
         return copy.iterator();
     }
     
+    public boolean hasBeenInitialized()
+    {
+        return _hasBeenInitialized;
+    }
+    
+    public boolean hasBeenShutdown()
+    {
+        return _hasBeenShutdown;
+    }
+    
+    public void initialize() 
+        throws SoapFault
+    {
+        _hasBeenInitialized = true;
+    }
+    
     public synchronized void removeListener(ResourceManagerListener listener)
     {
         _listeners.remove(listener);
     }
-    
+
     public void removeResource(EndpointReference epr)
         throws SoapFault
     {        
@@ -398,7 +364,7 @@
             next.resourceRemoved(epr);
         }
     }
-    
+
     public void removeResourceDefinitions(Collection definitions)
     {
         if (definitions == null)
@@ -413,12 +379,26 @@
             _definitionsByPath.remove(path);
         }
     }
-    
+
     public void setEnvironment(Environment environment)
     {
         if (environment == null)
             throw new NullPointerException(_MESSAGES.get("NullEnvironment"));
         
         _environment = environment;
+    }
+
+    public void shutdown() 
+        throws SoapFault
+    {
+        Iterator i = getResourceEPRs();
+        
+        while (i.hasNext())
+        {
+            Resource next = getResource((EndpointReference)i.next());
+            next.shutdown();
+        }
+        
+        _hasBeenShutdown = true;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org