jtaylor 02/02/12 18:54:50 Modified: src/java/org/apache/stratum/jcs JCS.java Log: Implementing Dan's suggestion that the static factory methods should be named getInstance(). Also, license, javadoc, extracting duplicate code. Revision Changes Path 1.2 +88 -37 jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/JCS.java Index: JCS.java =================================================================== RCS file: /home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/JCS.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JCS.java 12 Feb 2002 15:47:21 -0000 1.1 +++ JCS.java 13 Feb 2002 02:54:50 -0000 1.2 @@ -1,5 +1,59 @@ package org.apache.stratum.jcs; +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Velocity", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact [EMAIL PROTECTED] + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + */ + import org.apache.stratum.jcs.access.GroupCacheAccess; import org.apache.stratum.jcs.engine.control.Cache; import org.apache.stratum.jcs.engine.control.CacheAttributes; @@ -12,65 +66,67 @@ import org.apache.stratum.jcs.engine.behavior.ICompositeCacheAttributes; /** - * To make using JCS a bit easier. + * To make using JCS a bit easier. * - *@author asmuts - *@created February 12, 2002 + * @author <a href="mailto:[EMAIL PROTECTED]">Aaron Smuts</a> + * @author <a href="mailto:[EMAIL PROTECTED]">James Taylor</a> + * @version $Id: JCS.java,v 1.2 2002/02/13 02:54:50 jtaylor Exp $ */ public class JCS extends GroupCacheAccess { - private static GroupCacheManager cacheMgr; - /////////////////////////////////////////// /** - * Constructor for the JCS object + * Protected constructor for use by the static factory methods. * - *@param cacheControl Description of the Parameter + * @param cacheControl Cache which the instance will provide access to */ protected JCS( Cache cacheControl ) { super( cacheControl ); } - - ///////////////////////////////////////// /** - * Gets the groupAccess attribute of the GroupCacheAccess class + * Get a JCS which accesses the provided region. * - *@param region Description of the Parameter - *@return The groupAccess value - *@exception CacheException Description of the Exception + * @param region Region that return JCS will provide access to + * @return A JCS which provides access to a given region. + * @exception CacheException */ - public static JCS getJCS( String region ) + public static JCS getInstance( String region ) throws CacheException { - if ( cacheMgr == null ) - { - synchronized ( GroupCacheAccess.class ) - { - if ( cacheMgr == null ) - { - cacheMgr = GroupCacheManagerFactory.getInstance(); - } - } - } + ensureCacheManager(); + return new JCS( ( Cache ) cacheMgr.getCache( region ) ); } - - ///////////////////////////////////////// /** - * Gets the groupAccess attribute of the GroupCacheAccess class + * Get a JCS which accesses the provided region. * - *@param region Description of the Parameter - *@param icca Description of the Parameter - *@return The groupAccess value - *@exception CacheException Description of the Exception + * @param region Region that return JCS will provide access to + * @param icca Cache attributes for region + * @return A JCS which provides access to a given region. + * @exception CacheException */ - public static JCS getJCS( String region, ICompositeCacheAttributes icca ) + public static JCS getInstance( String region, + ICompositeCacheAttributes icca ) throws CacheException { + ensureCacheManager(); + + return new JCS( ( Cache ) cacheMgr.getCache( region, icca ) ); + } + + /** + * Gets an instance of GroupCacheManager and stores it in the cacheMgr + * class field, if it is not already set. Unlike the implementation in + * CacheAccess, the cache manager is a GroupCacheManager. + * + * NOTE: This can / will be moved up into GroupCacheAccess. + */ + protected static void ensureCacheManager() + { if ( cacheMgr == null ) { synchronized ( GroupCacheAccess.class ) @@ -81,10 +137,5 @@ } } } - - return new JCS( ( Cache ) cacheMgr.getCache( region, icca ) ); } - - - }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
