On 08/10/2009 01:09 PM, Galder Zamarreno wrote:

On 08/10/2009 12:42 PM, Manik Surtani wrote:

</snip>

Well, I think we need both.

getConfiguration(String name) to retrieve a configuration template and
modify it.
defineCache(String newName, String templateName, Configuration
overrides) to create a new configuration based on an existing one. Maybe
this name should change to something more intuitive? Perhaps instead of
defineCache, we have:

Configuration defineConfiguration(String configurationName,
Configuration overrides) // registers and names a NEW configuration,
based on the default cfg and the overrides passed in

Configuration defineConfiguration(String configurationName, String
templateName, Configuration overrides) // registers and names a NEW
configuration, based on an existing, predefined configuration and the
overrides passed in

WDYT?

That would be a great way to combine the two API requirements. I assume
that the returned Configuration instances returned would have had the
overrides applied to them already.

Let me work on this APIs in parallel to the work I'm doing for ISPN-6 so
that I can fully exercise/test and see if there's anything we'd need to
change.

https://jira.jboss.org/jira/browse/ISPN-152

A quick update on this. I have implemented ISPN-152, integrated it with the cache provider and the tests I have are now passing. Just a heads up on a change of behaviour.

defineConfiguration(*) methods do no longer throw DuplicateCacheNameException since this limits the API a lot disabling any type of configuration redefininitions/overriding. Example:

defineConfiguration("entity", "entity", overrides);

This means, take the configuration for named cache "entity", apply overrides and use that as new "entity" cache name configuration. If we're throwing DuplicateCacheNameException(s), we wouldn't be able to do this and this seems like a valid use case to me.

By the way, I've already noted this in the javadoc but doing the following:

Configuration c = defineConfiguration("entity", new Configuration());

is a way to return "entity" named cache's configuration! (equivalent to doing something like: manager.getConfiguration("entity") if such method existed!) IOW, this defineConfiguration method is saying: "define a configuration, based on "entity" and apply no overrides (cos no setters have been called in the Configuration instance!) and return new configuration instance"

I've detailed all this in CacheManager's javadoc that you can find attached. If you get the chance, have a read to it and let me know if anything is not clear enough.


Cheers
--
Manik Surtani
ma...@jboss.org
Lead, Infinispan
Lead, JBoss Cache
http://www.infinispan.org
http://www.jbosscache.org






--
Galder Zamarreño
Sr. Software Engineer
Infinispan, JBoss Cache
package org.infinispan.manager;

import org.infinispan.Cache;
import org.infinispan.config.Configuration;
import org.infinispan.config.GlobalConfiguration;
import org.infinispan.factories.annotations.NonVolatile;
import org.infinispan.factories.scopes.Scope;
import org.infinispan.factories.scopes.Scopes;
import org.infinispan.lifecycle.ComponentStatus;
import org.infinispan.lifecycle.Lifecycle;
import org.infinispan.notifications.Listenable;
import org.infinispan.remoting.transport.Address;

import java.util.List;

/**
 * A <tt>CacheManager</tt> is the primary mechanism for retrieving a {...@link org.infinispan.Cache} instance, and is often
 * used as a starting point to using the {...@link org.infinispan.Cache}.
 * <p/>
 * <tt>CacheManager</tt>s are heavyweight objects, and we foresee no more than one <tt>CacheManager</tt> being used per
 * JVM (unless specific configuration requirements require more than one; but either way, this would be a minimal and
 * finite number of instances).
 * <p/>
 * Constructing a <tt>CacheManager</tt> is done via one of its constructors, which optionally take in a {...@link
 * org.infinispan.config.Configuration} or a path or URL to a configuration XML file.
 * <p/>
 * Lifecycle - <tt>CacheManager</tt>s have a lifecycle (it implements {...@link org.infinispan.lifecycle.Lifecycle}) and
 * the default constructors also call {...@link #start()}.  Overloaded versions of the constructors are available, that do
 * not start the <tt>CacheManager</tt>, although it must be kept in mind that <tt>CacheManager</tt>s need to be started
 * before they can be used to create <tt>Cache</tt> instances.
 * <p/>
 * Once constructed, <tt>CacheManager</tt>s should be made available to any component that requires a <tt>Cache</tt>,
 * via <a href="http://en.wikipedia.org/wiki/Java_Naming_and_Directory_Interface";>JNDI</a> or via some other mechanism
 * such as an <a href="http://en.wikipedia.org/wiki/Dependency_injection";>dependency injection</a> framework.
 * <p/>
 * You obtain <tt>Cache</tt> instances from the <tt>CacheManager</tt> by using one of the overloaded
 * <tt>getCache()</tt>, methods.  Note that with <tt>getCache()</tt>, there is no guarantee that the instance you get is
 * brand-new and empty, since caches are named and shared.  Because of this, the <tt>CacheManager</tt> also acts as a
 * repository of <tt>Cache</tt>s, and is an effective mechanism of looking up or creating <tt>Cache</tt>s on demand.
 * <p/>
 * When the system shuts down, it should call {...@link #stop()} on the <tt>CacheManager</tt>.  This will ensure all caches
 * within its scope are properly stopped as well.
 * <p/>
 * Sample usage: <code> CacheManager manager = new DefaultCacheManager("my-config-file.xml"); Cache entityCache =
 * manager.getCache("myEntityCache"); entityCache.put("aPerson", new Person());
 * <p/>
 * Configuration myNewConfiguration = new Configuration(); myNewConfiguration.setCacheMode(Configuration.CacheMode.LOCAL);
 * manager.defineCache("myLocalCache", myNewConfiguration); Cache localCache = manager.getCache("myLocalCache");
 * </code>
 *
 * @author Manik Surtani (<a href="mailto:ma...@jboss.org">ma...@jboss.org</a>)
 * @author Galder Zamarreño
 * @since 4.0
 */
@Scope(Scopes.GLOBAL)
@NonVolatile
public interface CacheManager extends Lifecycle, Listenable {
//   /**
//    * Defines a named cache.  Named caches can be defined by using this method, in which case the configuration passed
//    * in is used to override the default configuration used when this cache manager instance was created.
//    * <p/>
//    * The other way to define named caches is declaratively, in the XML file passed in to the cache manager.
//    * <p/>
//    * A combination of approaches may also be used, provided the names do not conflict.
//    *
//    * @param cacheName             name of cache to define
//    * @param configurationOverride configuration overrides to use
//    * @throws DuplicateCacheNameException if the name is already in use.
//    */
//   void defineCache(String cacheName, Configuration configurationOverride) throws DuplicateCacheNameException;

   /**
    * Defines a named cache's configuration using the following algorithm:
    * <p/>
    * If cache name hasn't been defined before, this method creates a clone of the default cache's configuration, 
    * then applies the configuration overrides passed and returns this configuration instance.
    * <p/>
    * If cache name has been previously defined, this method creates a clone of this cache's existing configuration, 
    * applies the overrides and return the configuration instance.
    * <p/>
    * The other way to define named cache's configuration is declaratively, in the XML file passed in to the cache 
    * manager.  This method enables you to override certain properties that have previously been defined via XML.
    * <p/>
    * Passing a brand new Configuration instance as configuration override without having called any of its setters
    * will effectively return the named cache's configuration since no overrides where passed to it.
    *
    * @param cacheName             name of cache whose configuration is being defined
    * @param configurationOverride configuration overrides to use
    * @return a cloned configuration instance
    */   
   Configuration defineConfiguration(String cacheName, Configuration configurationOverride);

   /**
    * Defines a named cache's configuration using the following algorithm:
    * <p/>
    * If cache name hasn't been defined before, this method creates a clone of the configuration of the cache whose 
    * name matches the given template cache name, then applies the configuration overrides passed and returns this 
    * configuration instance.
    * <p/>  
    * If cache name has been previously defined, this method creates a clone of this cache's existing configuration, 
    * applies the overrides and return this configuration instance. 
    * <p/>
    * The other way to define named cache's configuration is declaratively, in the XML file passed in to the cache manager.  
    * This method enables you to override certain properties that have previously been defined via XML.
    * <p/>
    * Passing a brand new Configuration instance as configuration override without having called any of its setters
    * will effectively return the named cache's configuration since no overrides where passed to it.
    * <p/>
    * If templateName is null or there's no named cache with that name, this methods works exactly like 
    * {...@link CacheManager#defineConfiguration(String, Configuration)} in the sense that the base configuration used is the
    * default configuration.
    *
    * @param cacheName             name of cache whose configuration is being defined
    * @param templateName          name of cache to which to which apply overrides if cache name has not been previously 
    *                              defined
    * @param configurationOverride configuration overrides to use
    * @return a cloned configuration instance
    */
   Configuration defineConfiguration(String cacheName, String templateCacheName, Configuration configurationOverride);

   /**
    * Retrieves the default cache associated with this cache manager.
    * <p/>
    * As such, this method is always guaranteed to return the default cache.
    *
    * @return the default cache.
    */
   <K, V> Cache<K, V> getCache();

   /**
    * Retrieves a named cache from the system.  If the cache has been previously created with the same name, the running
    * cache instance is returned.  Otherwise, this method attempts to create the cache first.
    * <p/>
    * When creating a new cache, this method will use the configuration passed in to the CacheManager on construction,
    * as a template, and then optionally apply any overrides previously defined for the named cache using the {...@link
    * #defineCache(String, org.infinispan.config.Configuration)} method, or declared in the configuration file.
    *
    * @param cacheName name of cache to retrieve
    * @return a cache instance identified by cacheName
    */
   <K, V> Cache<K, V> getCache(String cacheName);

   /**
    * @return the name of the cluster.  Null if running in local mode.
    */
   String getClusterName();

   List<Address> getMembers();

   Address getAddress();

   boolean isCoordinator();

   ComponentStatus getStatus();

   /**
    * Returns the global configuration object associated to this CacheManager.
    */
   public GlobalConfiguration getGlobalConfiguration();
}
_______________________________________________
hibernate-dev mailing list
hibernate-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev

Reply via email to