portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry HybridRegistryService.java CastorRegistryService.java
Date Tue, 13 Jul 2004 22:53:44 GMT
taylor      2004/07/13 15:53:44

  Modified:    src/java/org/apache/jetspeed/services/registry
                        CastorRegistryService.java
  Added:       src/java/org/apache/jetspeed/services/registry
                        HybridRegistryService.java
  Log:
  new HybridRegistryService combines Database and Castor into one service
  with this service, you can store some registries in the database, and other registries on
the local file system
  For example, your security and portlet regs could go in the database, and the others on
the file system
  Thus far I have only implemented storing the security registry
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.39      +31 -25    jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/CastorRegistryService.java
  
  Index: CastorRegistryService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/CastorRegistryService.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- CastorRegistryService.java	23 May 2004 00:35:11 -0000	1.38
  +++ CastorRegistryService.java	13 Jul 2004 22:53:44 -0000	1.39
  @@ -125,7 +125,7 @@
   
       /** the extension for registry files */
       private String extension = null;
  -
  +    
       /**
        * Returns a Registry object for further manipulation
        *
  @@ -156,7 +156,7 @@
        */
       public RegistryEntry createEntry(String regName)
       {
  -                RegistryEntry entry = null;
  +        RegistryEntry entry = null;
           Registry registry = (Registry) registries.get(regName);
   
           if (registry != null)
  @@ -323,7 +323,7 @@
           String mapFile = null;
           Vector names = new Vector();
           int refreshRate = 0;
  -
  +        
           // read the configuration keys
           try
           {
  @@ -339,7 +339,7 @@
           {
               throw new InitializationException("Unable to initialize CastorRegistryService,
missing config keys");
           }
  -
  +        
           // build the map of default fragments, eahc registry must be associated
           // with at least one fragment
           try
  @@ -432,26 +432,7 @@
   
               if (registry == null)
               {
  -                String registryClass = null;
  -                try
  -                {
  -                    registryClass =
  -                        "org.apache.jetspeed.om.registry.base.Base"
  -                        + name
  -                        + "Registry";
  -
  -                    registry = (Registry) Class.forName(registryClass).newInstance();
  -                }
  -                catch (Exception e)
  -                {
  -                    if (logger.isWarnEnabled())
  -                    {
  -                        logger.warn("RegistryService: Class "
  -                                    + registryClass
  -                                    + " not found, reverting to default Registry");
  -                    }
  -                    registry = new BaseRegistry();
  -                }
  +                registry = createRegistry(name);
   
                   registries.put(name, registry);
               }
  @@ -473,7 +454,32 @@
   
       }
   
  +    protected Registry createRegistry(String name)
  +    {
  +        Registry registry = null;
  +        String registryClass = null;
  +        try
  +        {
  +            registryClass =
  +                "org.apache.jetspeed.om.registry.base.Base"
  +                + name
  +                + "Registry";
   
  +            registry = (Registry) Class.forName(registryClass).newInstance();
  +        }
  +        catch (Exception e)
  +        {
  +            if (logger.isWarnEnabled())
  +            {
  +                logger.warn("RegistryService: Class "
  +                            + registryClass
  +                            + " not found, reverting to default Registry");
  +            }
  +            registry = new BaseRegistry();
  +        }
  +        return registry;
  +    }
  +    
       /** Late init method from Turbine Service model */
       public void init() throws InitializationException
       {
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/HybridRegistryService.java
  
  Index: HybridRegistryService.java
  ===================================================================
  /*
   * Copyright 2000-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 org.apache.jetspeed.services.registry;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Enumeration;
  import java.util.Hashtable;
  import java.util.Iterator;
  
  import javax.servlet.ServletConfig;
  
  import org.apache.jetspeed.om.dbregistry.SecurityDbEntryPeer;
  import org.apache.jetspeed.om.registry.Registry;
  import org.apache.jetspeed.om.registry.RegistryEntry;
  import org.apache.jetspeed.om.registry.RegistryException;
  import org.apache.jetspeed.om.registry.SecurityEntry;
  import org.apache.jetspeed.om.registry.base.LocalRegistry;
  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
  import org.apache.jetspeed.services.logging.JetspeedLogger;
  import org.apache.turbine.services.InitializationException;
  import org.apache.turbine.services.TurbineServices;
  import org.apache.turbine.services.resources.ResourceService;
  
  /**
   * Implements the Jetspeed Registry Service interface, with a hybrid of Database and File-based
(Castor)
   * Registry storage. Allows user to store some registries in the database, and others on
the file system.
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: HybridRegistryService.java,v 1.1 2004/07/13 22:53:44 taylor Exp $
   */
  public class HybridRegistryService extends CastorRegistryService
  {
      /** regsitry type keyed list of entries */
      private Hashtable dbRegistries = new Hashtable();
      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(HybridRegistryService.class.getName());
          
          
      /**
       * This is the early initialization method called by the
       * Turbine <code>Service</code> framework
       */
      public synchronized void init(ServletConfig conf) throws InitializationException
      {
          super.init(conf);
  
          try
          {
              // get the list of managed Registries in the Database
              ResourceService serviceConf = ((TurbineServices) 
                      TurbineServices.getInstance()).getResources(RegistryService.SERVICE_NAME);
              ResourceService rs = serviceConf.getResources("database.default");
              
              if (rs != null)
              {
                  Iterator iterator = rs.getKeys();                
                  while (iterator.hasNext())
                  {
                      String name = (String)iterator.next();
                      Registry registry = createRegistry(name);
                      dbRegistries.put(name, registry);
                      loadCache(name, registry);
                  }                
              }
  
  
              
          }
          catch (Throwable t)
          {
              throw new InitializationException("Unable to initialize HybridRegistryService,
missing config keys");
          }
          
      }
      
      private void loadCache(String registryName, Registry registry)
      {
          LocalRegistry local = (LocalRegistry)registry;
          try
          {
              if (registryName.equals(org.apache.jetspeed.services.Registry.SECURITY))
              {
                  Iterator extent = SecurityDbEntryPeer.fetchExtent().iterator();
                  while (extent.hasNext())
                  {
                      SecurityEntry se = (SecurityEntry)extent.next();
                      System.out.println("Caching ... " + se.getName());
                      local.addLocalEntry((RegistryEntry)se);                    
                  }
              }
          }
          catch (Exception e)
          {
              logger.error("Failed to load cache for registry: " + registryName, e);
          }
      }
      
      public Enumeration getNames()
      {
          ArrayList result = new ArrayList();
          Enumeration names = super.getNames();
          if (names != null)
          {
              result.addAll(Collections.list(names));            
          }        
          result.addAll(dbRegistries.keySet());
          return Collections.enumeration(result);        
      }
  
      public Registry get(String registryName)
      {
          Registry registry = (Registry)dbRegistries.get(registryName);
          if (null == registry)
          {
              return super.get(registryName);
          }        
          return registry;
      }
      
      public RegistryEntry createEntry(String registryName)
      {
          Registry registry = (Registry)dbRegistries.get(registryName);
          if (null == registry)
          {
              return super.createEntry(registryName);
          }            
          
          return registry.createEntry();
      }
      
      public RegistryEntry getEntry(String registryName, String entryName)
      {        
          RegistryEntry entry = null;
          Registry registry = (Registry)dbRegistries.get(registryName);
          if (null == registry)
          {            
              return super.getEntry(registryName, entryName);
          }            
                  
          try
          {
              entry = registry.getEntry(entryName);
          }
          catch (RegistryException iee)
          {
              if (logger.isInfoEnabled())
              {
                  logger.info("HybridRegistryService: Failed to lookup " + entryName + " from
" + registryName);
              }            
          }
          if (null == entry)
          {            
              if (registryName.equals(org.apache.jetspeed.services.Registry.SECURITY))
              {                                         
                  entry = (RegistryEntry)SecurityDbEntryPeer.lookupSecurityEntry(entryName);
                  if (entry != null)
                  {
                      LocalRegistry local = (LocalRegistry)registry;
                      try
                      {
                          local.addEntry(entry);
                      }
                      catch (RegistryException e)
                      {
                          if (logger.isInfoEnabled())
                          {
                              logger.info("HybridRegistryService: Failed to add to local cache
" + entryName + " from " + registryName);
                          }                                    
                      }
                  }
              }
          }
          else
          {
              // System.out.println(" +++ Getting from cache");                
          }
          return entry;        
      }
      
      public void addEntry(String registryName, RegistryEntry entry)
      throws RegistryException
      {
          LocalRegistry registry = (LocalRegistry)dbRegistries.get(registryName);
          if (null == registry)
          {
              super.addEntry(registryName, entry);            
              return;
          }            
          if (entry == null)
          {
              return;
          }        
          
          save(registry, entry);
      }
      
      public void removeEntry(String registryName, String entryName)
      {
          LocalRegistry registry = (LocalRegistry)dbRegistries.get(registryName);
          if (null == registry)
          {
              super.removeEntry(registryName, entryName);            
              return;
          }                    
          if (entryName == null)
          {
              return;
          }        
          SecurityDbEntryPeer.removeSecurityEntry(entryName);        
          registry.removeLocalEntry(entryName);
      }
  
      public void saveEntry(String registryName, RegistryEntry entry) throws RegistryException
      {
          LocalRegistry registry = (LocalRegistry)dbRegistries.get(registryName);
          if (null == registry)
          {
              super.saveEntry(registryName, entry);            
              return;
          }
          if (entry == null)
          {
              return;
          }                
          save(registry, entry);
      }
      
      private void save(LocalRegistry registry, RegistryEntry entry) throws RegistryException
      {
          if (entry instanceof SecurityEntry)
          {
              SecurityEntry se = (SecurityEntry)entry;
              
              SecurityDbEntryPeer.storeSecurityEntry(se);
              se = SecurityDbEntryPeer.lookupSecurityEntry(se.getName());        
              if (registry.hasEntry(entry.getName()))
              {
                  registry.setLocalEntry((RegistryEntry)se);
              }
              else
              {
                  registry.addLocalEntry((RegistryEntry)se);
              }
          }
          
      }
      
  }
  
  
  

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


Mime
View raw message