hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind Registry.java
Date Thu, 19 Aug 2004 13:35:55 GMT
hlship      2004/08/19 06:35:55

  Modified:    .        status.xml
               framework/src/java/org/apache/hivemind/impl
                        RegistryImpl.java
               framework/src/java/org/apache/hivemind Registry.java
  Added:       framework/src/test/hivemind/test TestContains.java
                        contains.xml
  Log:
  [HIVEMIND-37] Add polling methods to Registry.
  
  Revision  Changes    Path
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/TestContains.java
  
  Index: TestContains.java
  ===================================================================
  //Copyright 2004 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 hivemind.test;
  
  import org.apache.hivemind.Registry;
  
  /**
   * Tests Registry.contains functionality.
   * 
   * @author Naresh Sikha
   */
  public class TestContains extends FrameworkTestCase
  {
      private Registry registry;
  
      protected void setUp() throws Exception
      {
          registry = buildFrameworkRegistry("contains.xml");
      }
  
      protected void tearDown() throws Exception
      {
          registry.shutdown();
      }
  
      public void testConfiguration()
      {
          assertTrue(registry.containsConfiguration("hivemind.tests.contains.Simple"));
      }
  
      public void testConfigurationFailure()
      {
          assertTrue(!registry.containsConfiguration("xhivemind.tests.contains.Simple"));
      }
      
      public void testService()
      {
          assertTrue(registry.containsService("hivemind.tests.contains.multipleServiceOne",
IMultipleService.class));
      }
      
      public void testServiceFailure()
      {
          assertTrue(!registry.containsService("hivemind.tests.contains.multipleServiceOne",
IUniqueService.class));
          assertTrue(!registry.containsService("xhivemind.tests.contains.multipleServiceOne",
IMultipleService.class));
      }
  
      public void testUniqueService()
      {
          assertTrue(registry.containsService(IUniqueService.class));
      }
  
      public void testUniqueServiceFailure()
      {
          assertTrue(!registry.containsService(IMultipleService.class));
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/framework/src/test/hivemind/test/contains.xml
  
  Index: contains.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     Copyright 2004 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.
  -->
  
  <module id="hivemind.tests.contains" version="1.0.0">
      <service-point id="uniqueService" interface="hivemind.test.IUniqueService">
          <create-instance class="hivemind.test.UniqueServiceImpl"/>
      </service-point>
      <service-point id="multipleServiceOne" interface="hivemind.test.IMultipleService">
          <create-instance class="hivemind.test.MultipleServiceImpl"/>
      </service-point>
      <service-point id="multipleServiceTwo" interface="hivemind.test.IMultipleService">
          <create-instance class="hivemind.test.MultipleServiceImpl"/>
      </service-point>
  	<configuration-point id="Simple" schema-id="Datum"/>
  		<schema id="Datum">
  			<element name="datum">
  			  <attribute name="key" required="true"/>
  			  <attribute name="value" required="true"/>
  				<rules>
  					<create-object class="hivemind.test.config.impl.Datum"/>
  					<read-attribute property="key" attribute="key"/>
  					<read-attribute property="value" attribute="value"/>
  					<invoke-parent method="addElement"/>
  				</rules>
  			</element>
  		</schema>
  	<contribution configuration-id="Simple">
  	    <datum key="key1" value="value1"/>
  		<datum key="key2" value="value2"/>
  	</contribution>
  </module>
  
  
  
  1.48      +3 -0      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- status.xml	19 Aug 2004 13:25:58 -0000	1.47
  +++ status.xml	19 Aug 2004 13:35:54 -0000	1.48
  @@ -70,6 +70,9 @@
         <action type="fix" dev="HLS" due-to="Luke Blanshard" fixes-bug="HIVEMIND-16">
           Add <code>getCause()</code> method to ApplicationRuntimeException
         </action>
  +      <action type="add" dev="HLS" due-to="Naresh Sikha" fixes-bug="HIVEMIND-37">
  +        Add polling methods to Registry.
  +      </action>
       </release>
     
       <release version="1.0-beta-2" date="Aug 1 2004">
  
  
  
  1.16      +36 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java
  
  Index: RegistryImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- RegistryImpl.java	29 Jul 2004 13:18:49 -0000	1.15
  +++ RegistryImpl.java	19 Aug 2004 13:35:54 -0000	1.16
  @@ -14,6 +14,7 @@
   
   package org.apache.hivemind.impl;
   
  +import java.util.Collection;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.LinkedList;
  @@ -519,6 +520,36 @@
           _threadEventNotifier.fireThreadCleanup();
       }
   
  +    public boolean containsConfiguration(String configurationId)
  +    {
  +        checkShutdown();
  +
  +        return _configurationPoints.containsKey(configurationId);
  +    }
  +
  +    public boolean containsService(Class serviceInterface)
  +    {
  +        boolean contains = false;
  +
  +        List servicePoints = (List) _servicePointsByInterface.get(serviceInterface);
  +
  +        return size(servicePoints) == 1;
  +    }
  +
  +    public boolean containsService(String serviceId, Class serviceInterface)
  +    {
  +        checkShutdown();
  +
  +        boolean contains = false;
  +
  +        ServicePoint point = (ServicePoint) _servicePoints.get(serviceId);
  +
  +        if (point == null)
  +            return false;
  +
  +        return point.getServiceInterface().equals(serviceInterface);
  +    }
  +
       public void setLocale(Locale locale)
       {
           _locale = locale;
  @@ -532,6 +563,11 @@
       public Translator getTranslator(String translator)
       {
           return _translatorManager.getTranslator(translator);
  +    }
  +
  +    private int size(Collection c)
  +    {
  +        return c == null ? 0 : c.size();
       }
   
   }
  
  
  
  1.7       +29 -0     jakarta-hivemind/framework/src/java/org/apache/hivemind/Registry.java
  
  Index: Registry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/Registry.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Registry.java	17 Jul 2004 23:50:39 -0000	1.6
  +++ Registry.java	19 Aug 2004 13:35:55 -0000	1.7
  @@ -32,6 +32,35 @@
   public interface Registry extends SymbolSource
   {
       /**
  +     * Returns true if a configuration for the specified id exists.
  +     * 
  +     * @param configurationId
  +     * @return true if a configuration for the specified id exists
  +     */
  +    public boolean containsConfiguration(String configurationId);
  +    
  +    /**
  +     * Returns true if a single service for the specified service interface
  +     * class exists.
  +     * 
  +     * @param serviceInterface
  +     * @return true if a single service for the specified service interface
  +     *   exists
  +     */
  +    public boolean containsService(Class serviceInterface);
  +    
  +    /**
  +     * Returns true if a service for the specified service id and service
  +     * interface exists.
  +     * 
  +     * @param serviceId
  +     * @param serviceInterface
  +     * @return true if a service for the specified service id and service
  +     *   interface exists
  +     */
  +    public boolean containsService(String serviceId, Class serviceInterface);
  +    
  +    /**
        * Returns a configuration as a List of elements (as defined by the schema
        * for the configuration point, or as {@link Element}s if no configuration point
        * does not define a schema.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message