jakarta-jcs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r536904 [11/38] - in /jakarta/jcs/trunk: ./ auxiliary-builds/javagroups/ auxiliary-builds/javagroups/src/java/org/apache/jcs/auxiliary/javagroups/ auxiliary-builds/javagroups/src/test/org/apache/jcs/auxiliary/javagroups/ auxiliary-builds/jd...
Date Thu, 10 May 2007 16:04:27 GMT
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/admin/servlet/JCSAdminServletRegionDetail.vm
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/admin/servlet/JCSAdminServletRegionDetail.vm?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/admin/servlet/JCSAdminServletRegionDetail.vm (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/admin/servlet/JCSAdminServletRegionDetail.vm Thu May 10 09:03:42 2007
@@ -1,3 +1,19 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  The ASF licenses this file
+## to you 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.
 <html>
 
 <head><title> JCS Admin Servlet Region Detail </title></head>
@@ -31,4 +47,4 @@
 
 </body>
 
-</html>
\ No newline at end of file
+</html>

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheAttributes.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheAttributes.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheAttributes.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheAttributes.java Thu May 10 09:03:42 2007
@@ -1,12 +1,31 @@
 package org.apache.jcs.auxiliary;
 
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
 import org.apache.jcs.engine.behavior.ICacheEventQueue;
 
 /**
  * This has common attributes used by all auxiliaries.
  * <p>
  * @author aaronsm
- *  
+ *
  */
 public abstract class AbstractAuxiliaryCacheAttributes
     implements AuxiliaryCacheAttributes
@@ -33,7 +52,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.jcs.auxiliary.AuxiliaryCacheAttributes#setCacheName(java.lang.String)
      */
     public void setCacheName( String s )
@@ -43,7 +62,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.jcs.auxiliary.AuxiliaryCacheAttributes#getCacheName()
      */
     public String getCacheName()
@@ -63,7 +82,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.jcs.auxiliary.AuxiliaryCacheAttributes#getName()
      */
     public String getName()
@@ -73,7 +92,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.jcs.auxiliary.AuxiliaryCacheAttributes#setEventQueueType(java.lang.String)
      */
     public void setEventQueueType( String s )
@@ -99,7 +118,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.jcs.auxiliary.AuxiliaryCacheAttributes#getEventQueueType()
      */
     public String getEventQueueType()
@@ -116,7 +135,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.jcs.auxiliary.AuxiliaryCacheAttributes#getEventQueueTypeFactoryCode()
      */
     public int getEventQueueTypeFactoryCode()
@@ -126,7 +145,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.jcs.auxiliary.AuxiliaryCacheAttributes#setEventQueuePoolName(java.lang.String)
      */
     public void setEventQueuePoolName( String s )
@@ -136,7 +155,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.jcs.auxiliary.AuxiliaryCacheAttributes#getEventQueuePoolName()
      */
     public String getEventQueuePoolName()

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java Thu May 10 09:03:42 2007
@@ -1,12 +1,22 @@
 package org.apache.jcs.auxiliary;
 
 /*
- * Copyright 2001-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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
  */
 
 import java.io.IOException;

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheAttributes.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheAttributes.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheAttributes.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheAttributes.java Thu May 10 09:03:42 2007
@@ -1,19 +1,22 @@
 package org.apache.jcs.auxiliary;
 
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
  *
- * 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
  *
- *     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.
+ * 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.
  */
 
 import java.io.Serializable;
@@ -21,7 +24,7 @@
 /**
  * This is a nominal interface that auxiliary cache attributes should
  * implement. This allows the auxiliary mangers to share a common interface.
- *  
+ *
  */
 public interface AuxiliaryCacheAttributes
     extends Cloneable, Serializable
@@ -39,7 +42,7 @@
 
     /**
      * Sets the name of the cache, referenced by the appropriate manager.
-     * 
+     *
      * @param s
      *            The new cacheName value
      */
@@ -47,14 +50,14 @@
 
     /**
      * Gets the cacheName attribute of the AuxiliaryCacheAttributes object
-     * 
+     *
      * @return The cacheName value
      */
     public String getCacheName();
 
     /**
      * Name known by by configurator
-     * 
+     *
      * @param s
      *            The new name value
      */
@@ -62,7 +65,7 @@
 
     /**
      * Gets the name attribute of the AuxiliaryCacheAttributes object
-     * 
+     *
      * @return The name value
      */
     public String getName();
@@ -70,7 +73,7 @@
     /**
      * SINGLE is the default. If you choose POOLED, the value of
      * EventQueuePoolName will be used
-     * 
+     *
      * @param s
      *            SINGLE or POOLED
      * @return
@@ -78,14 +81,14 @@
     public void setEventQueueType( String s );
 
     /**
-     * 
+     *
      * @return SINGLE or POOLED
      */
     public String getEventQueueType();
 
     /**
      * Returns the value used by the factory.
-     * 
+     *
      * @return
      */
     public int getEventQueueTypeFactoryCode();
@@ -93,7 +96,7 @@
     /**
      * If you choose a POOLED event queue type, the value of EventQueuePoolName
      * will be used. This is ignored if the pool type is SINGLE
-     * 
+     *
      * @param s
      *            SINGLE or POOLED
      * @return
@@ -103,14 +106,14 @@
     /**
      * Sets the pool name to use. If a pool is not found by this name, the
      * thread pool manager will return a default configuration.
-     * 
+     *
      * @return name of thread pool to use for this auxiliary
      */
     public String getEventQueuePoolName();
 
     /**
      * Description of the Method
-     * 
+     *
      * @return
      */
     public AuxiliaryCacheAttributes copy();

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheFactory.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheFactory.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheFactory.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheFactory.java Thu May 10 09:03:42 2007
@@ -1,19 +1,22 @@
 package org.apache.jcs.auxiliary;
 
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
  *
- * 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
  *
- *     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.
+ * 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.
  */
 
 import org.apache.jcs.engine.behavior.ICompositeCacheManager;
@@ -21,27 +24,27 @@
 /**
  * All auxiliary caches must have a factory that the cache configurator can use
  * to create instances.
- *  
+ *
  */
 public interface AuxiliaryCacheFactory
 {
 
     /**
-     * 
+     *
      * @param attr
-     * 
+     *
      * @param cacheMgr
      *            This allows auxiliaries to reference the manager without
      *            assuming that it is a singleton. This will allow JCS to be a
      *            nonsingleton. Also, it makes it easier to test.
-     * 
+     *
      * @return AuxiliaryCache
      */
     public AuxiliaryCache createCache( AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr );
 
     /**
      * Sets the name attribute of the AuxiliaryCacheFactory object
-     * 
+     *
      * @param s
      *            The new name value
      */
@@ -49,7 +52,7 @@
 
     /**
      * Gets the name attribute of the AuxiliaryCacheFactory object
-     * 
+     *
      * @return The name value
      */
     public String getName();

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheManager.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheManager.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheManager.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheManager.java Thu May 10 09:03:42 2007
@@ -1,28 +1,31 @@
 package org.apache.jcs.auxiliary;
 
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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
  *
- * 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
  *
- *     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.
+ * 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.
  */
 
 import org.apache.jcs.engine.behavior.ICacheType;
 
 /**
  * AuxiliaryCacheManager
- * 
+ *
  * FIXME: Should not need to extend ICacheType
- *  
+ *
  */
 public interface AuxiliaryCacheManager
     extends ICacheType
@@ -30,7 +33,7 @@
 
     /**
      * Return the appropriate auxiliary cache for this region.
-     * 
+     *
      * @param cacheName
      * @return AuxiliaryCache
      */
@@ -40,7 +43,7 @@
      * This allows the cache manager to be plugged into the auxiliary caches,
      * rather then having them get it themselves. Cache maangers can be mocked
      * out and the auxiliaries will be easier to test.
-     * 
+     *
      * @param cacheName
      * @param cacheManager
      * @return AuxiliaryCache

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java Thu May 10 09:03:42 2007
@@ -1,12 +1,22 @@
 package org.apache.jcs.auxiliary.disk;
 
 /*
- * Copyright 2001-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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
  */
 
 import java.io.IOException;

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java Thu May 10 09:03:42 2007
@@ -1,14 +1,22 @@
 package org.apache.jcs.auxiliary.disk;
 
 /*
- * Copyright 2001-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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
  */
 
 import org.apache.jcs.auxiliary.AbstractAuxiliaryCacheAttributes;
@@ -144,4 +152,4 @@
         str.append( "\n allowRemoveAll   = " + allowRemoveAll );
         return str.toString();
     }
-}
\ No newline at end of file
+}

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/LRUMapJCS.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/LRUMapJCS.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/LRUMapJCS.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/LRUMapJCS.java Thu May 10 09:03:42 2007
@@ -1,5 +1,24 @@
 package org.apache.jcs.auxiliary.disk;
 
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jcs.utils.struct.LRUMap;
@@ -55,4 +74,4 @@
             log.debug( "Key store size [" + this.size() + "]" );
         }
     }
-}
\ No newline at end of file
+}

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java Thu May 10 09:03:42 2007
@@ -1,12 +1,22 @@
 package org.apache.jcs.auxiliary.disk;
 
 /*
- * Copyright 2001-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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
  */
 
 import java.io.Serializable;

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/behavior/IDiskCacheAttributes.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/behavior/IDiskCacheAttributes.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/behavior/IDiskCacheAttributes.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/behavior/IDiskCacheAttributes.java Thu May 10 09:03:42 2007
@@ -1,14 +1,22 @@
 package org.apache.jcs.auxiliary.disk.behavior;
 
 /*
- * Copyright 2001-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.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
  */
 
 import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java Thu May 10 09:03:42 2007
@@ -1,490 +1,500 @@
-package org.apache.jcs.auxiliary.disk.block;
-
-/*
- * Copyright 2001-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.
- */
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.io.Serializable;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.utils.serialization.StandardSerializer;
-import org.apache.jcs.utils.struct.SingleLinkedList;
-
-/**
- * This class manages reading an writing data to disk. When asked to write a value, it returns a
- * block array. It can read an object from the block numbers in a byte array.
- * <p>
- * @author Aaron Smuts
- */
-public class BlockDisk
-{
-    /** The logger */
-    private static final Log log = LogFactory.getLog( BlockDisk.class );
-
-    /** The size of the header that indicates the amount of data stored in an occupied block. */
-    public static final byte HEADER_SIZE_BYTES = 4;
-
-    /** defaults to 4kb */
-    private static final int DEFAULT_BLOCK_SIZE_BYTES = 4 * 1024;
-
-    /** Size of the blocks */
-    private int blockSizeBytes = DEFAULT_BLOCK_SIZE_BYTES;
-
-    /**
-     * the total number of blocks that have been used. If there are no free, we will use this to
-     * calculate the position of the next block.
-     */
-    private int numberOfBlocks = 0;
-
-    /** Empty blocks that can be reused. */
-    private SingleLinkedList emptyBlocks = new SingleLinkedList();
-
-    /** Handles serializing the objects */
-    private static final StandardSerializer SERIALIZER = new StandardSerializer();
-
-    /** Location of the spot on disk */
-    private final String filepath;
-
-    /** The file handle. */
-    private RandomAccessFile raf;
-
-    /** How many bytes have we put to disk */
-    private long putBytes = 0;
-
-    /** How many items have we put to disk */
-    private long putCount = 0;
-
-    /**
-     * Constructor for the Disk object
-     * <p>
-     * @param file
-     * @exception FileNotFoundException
-     */
-    public BlockDisk( File file )
-        throws FileNotFoundException
-    {        
-        this( file, DEFAULT_BLOCK_SIZE_BYTES );
-        if ( log.isInfoEnabled() )
-        {
-            log.info( "Used default block size [" + DEFAULT_BLOCK_SIZE_BYTES + "]" );
-        }
-        
-    }
-
-    /**
-     * Creates the file and set the block size in bytes.
-     * <p>
-     * @param file
-     * @param blockSizeBytes
-     * @throws FileNotFoundException
-     */
-    public BlockDisk( File file, int blockSizeBytes )
-        throws FileNotFoundException
-    {
-        this.filepath = file.getAbsolutePath();
-        raf = new RandomAccessFile( filepath, "rw" );
-
-        if ( log.isInfoEnabled() )
-        {
-            log.info( "Constructing BlockDisk, blockSizeBytes [" + blockSizeBytes + "]" );
-        }
-        this.blockSizeBytes = blockSizeBytes;
-    }
-
-    /**
-     * This writes an object to disk and returns the blocks it was stored in.
-     * <p>
-     * The program flow is as follows:
-     * <ol>
-     * <li>Serialize the object.</li>
-     * <li>Detemine the number of blocks needed.</li>
-     * <li>Look for free blocks in the emptyBlock list.</li>
-     * <li>If there were not enough in the empty list. Take the nextBlock and increment it.</li>
-     * <li>If the data will not fit in one block, create sub arrays.</li>
-     * <li>Write the subarrays to disk.</li>
-     * <li>If the process fails we should decrement the block count if we took from it.</li>
-     * </ol>
-     * @param object
-     * @return the blocks we used.
-     * @throws IOException
-     */
-    protected int[] write( Serializable object )
-        throws IOException
-    {
-        // serialize the object
-        byte[] data = SERIALIZER.serialize( object );
-
-        this.addToPutBytes( data.length );
-        this.incrementPutCount();
-
-        // figure out how many blocks we need.
-        int numBlocksNeeded = calculateTheNumberOfBlocksNeeded( data );
-
-        int[] blocks = new int[numBlocksNeeded];
-
-        // get them from the empty list or take the next one
-        for ( short i = 0; i < numBlocksNeeded; i++ )
-        {
-            Integer emptyBlock = (Integer) emptyBlocks.takeFirst();
-            if ( emptyBlock != null )
-            {
-                blocks[i] = emptyBlock.intValue();
-            }
-            else
-            {
-                blocks[i] = takeNextBlock();
-            }
-        }
-
-        // get the individual sub arrays.
-        byte[][] chunks = getBlockChunks( data, numBlocksNeeded );
-
-        // write the blocks
-        for ( byte i = 0; i < numBlocksNeeded; i++ )
-        {
-            int position = calculateByteOffsetForBlock( blocks[i] );
-            write( position, chunks[i] );
-        }
-
-        return blocks;
-    }
-
-    /**
-     * Return the amount to put in each block. Fill them all the way, minus the header.
-     * <p>
-     * @param complete
-     * @param numBlocksNeeded
-     * @return byte[][]
-     */
-    protected byte[][] getBlockChunks( byte[] complete, int numBlocksNeeded )
-    {
-        byte[][] chunks = new byte[numBlocksNeeded][];
-
-        if ( numBlocksNeeded == 1 )
-        {
-            chunks[0] = complete;
-        }
-        else
-        {
-            int maxChunkSize = this.blockSizeBytes - HEADER_SIZE_BYTES;
-            int totalBytes = complete.length;
-            int totalUsed = 0;
-            for ( short i = 0; i < numBlocksNeeded; i++ )
-            {
-                // use the max that can be written to a block or whatever is left in the original
-                // array
-                int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed );
-                byte[] chunk = new byte[chunkSize];
-                // copy from the used position to the chunk size on the complete array to the chunk
-                // array.
-                System.arraycopy( complete, totalUsed, chunk, 0, chunkSize );
-                chunks[i] = chunk;
-                totalUsed += chunkSize;
-            }
-        }
-
-        return chunks;
-    }
-
-    /**
-     * Writes the given byte array to the Disk at the specified position.
-     * <p>
-     * @param position
-     * @param data
-     * @return true if we wrote successfully
-     * @throws IOException
-     */
-    private boolean write( long position, byte[] data )
-        throws IOException
-    {
-        synchronized ( this )
-        {
-            raf.seek( position );
-            raf.writeInt( data.length );
-            raf.write( data, 0, data.length );
-        }
-        return true;
-    }
-
-    /**
-     * Reads an object that is located in the specified blocks.
-     * <p>
-     * @param blockNumbers
-     * @return Serializable
-     * @throws IOException
-     * @throws ClassNotFoundException
-     */
-    protected Serializable read( int[] blockNumbers )
-        throws IOException, ClassNotFoundException
-    {
-        byte[] data = null;
-
-        if ( blockNumbers.length == 1 )
-        {
-            data = readBlock( blockNumbers[0] );
-        }
-        else
-        {
-            data = new byte[0];
-            // get all the blocks into data
-            for ( short i = 0; i < blockNumbers.length; i++ )
-            {
-                byte[] chunk = readBlock( blockNumbers[i] );
-                byte[] newTotal = new byte[data.length + chunk.length];
-                // copy data into the new array
-                System.arraycopy( data, 0, newTotal, 0, data.length );
-                // copyt the chunk into the new array
-                System.arraycopy( chunk, 0, newTotal, data.length, chunk.length );
-                // swap the new and old.
-                data = newTotal;
-            }
-        }
-
-        return (Serializable) SERIALIZER.deSerialize( data );
-    }
-
-    /**
-     * This reads the occupied data in a block.
-     * <p>
-     * The first four bytes of the record should tell us how long it is. The data is read into a
-     * byte array and then an object is constructed from the byte array.
-     * <p>
-     * @return byte[]
-     * @param block
-     * @throws IOException
-     */
-    private byte[] readBlock( int block )
-        throws IOException
-    {
-        byte[] data = null;
-        int datalen = 0;
-        synchronized ( this )
-        {
-            String message = null;
-            boolean corrupted = false;
-            long fileLength = raf.length();
-
-            int position = calculateByteOffsetForBlock( block );
-            if ( position > fileLength )
-            {
-                corrupted = true;
-                message = "Record " + position + " starts past EOF.";
-            }
-            else
-            {
-                raf.seek( position );
-                datalen = raf.readInt();
-                if ( position + datalen > fileLength )
-                {
-                    corrupted = true;
-                    message = "Record " + position + " exceeds file length.";
-                }
-            }
-
-            if ( corrupted )
-            {
-                log.warn( "\n The file is corrupt: " + "\n " + message );
-                throw new IOException( "The File Is Corrupt, need to reset" );
-            }
-
-            raf.readFully( data = new byte[datalen] );
-        }
-        return data;
-    }
-
-    /**
-     * Add these blocks to the emptyBlock list.
-     * <p>
-     * @param blocksToFree
-     */
-    protected void freeBlocks( int[] blocksToFree )
-    {
-        if ( blocksToFree != null )
-        {
-            for ( short i = 0; i < blocksToFree.length; i++ )
-            {
-                emptyBlocks.addLast( new Integer( blocksToFree[i] ) );
-            }
-        }
-    }
-
-    /**
-     * Add to to total put size.
-     * <p>
-     * @param length
-     */
-    private synchronized void addToPutBytes( long length )
-    {
-        this.putBytes += length;
-    }
-
-    /**
-     * Thread safe increment.
-     */
-    private synchronized void incrementPutCount()
-    {
-        this.putCount++;
-    }
-
-    /**
-     * Returns the current number and adds one.
-     * <p>
-     * @return the block number to use.
-     */
-    private synchronized int takeNextBlock()
-    {
-        return this.numberOfBlocks++;
-    }
-
-    /**
-     * Calcuates the file offset for a particular block.
-     * <p>
-     * @param block
-     * @return the offset for this block
-     */
-    protected int calculateByteOffsetForBlock( int block )
-    {
-        return block * blockSizeBytes;
-    }
-
-    /**
-     * The number of blocks needed.
-     * <p>
-     * @param data
-     * @return the number of blocks needed to store the byte array
-     */
-    protected int calculateTheNumberOfBlocksNeeded( byte[] data )
-    {
-        int dataLength = data.length;
-
-        int oneBlock = blockSizeBytes - HEADER_SIZE_BYTES;
-
-        // takes care of 0 = HEADER_SIZE_BYTES + blockSizeBytes
-        if ( dataLength <= oneBlock )
-        {
-            return 1;
-        }
-
-        int dividend = dataLength / oneBlock;
-
-        if ( dataLength % oneBlock != 0 )
-        {
-            dividend++;
-        }
-        return dividend;
-    }
-
-    /**
-     * Returns the raf length.
-     * <p>
-     * @return the size of the file.
-     * @exception IOException
-     */
-    protected long length()
-        throws IOException
-    {
-        synchronized ( this )
-        {
-            return raf.length();
-        }
-    }
-
-    /**
-     * Closes the raf.
-     * <p>
-     * @exception IOException
-     */
-    protected synchronized void close()
-        throws IOException
-    {
-        raf.close();
-    }
-
-    /**
-     * Returns the serialized form of the given object in a byte array.
-     * <p>
-     * Use the Serilizer abstraction layer.
-     * <p>
-     * @return a byte array of the serialized object.
-     * @param obj
-     * @exception IOException
-     */
-    protected static byte[] serialize( Serializable obj )
-        throws IOException
-    {
-        return SERIALIZER.serialize( obj );
-    }
-
-    /**
-     * @return Returns the numberOfBlocks.
-     */
-    protected int getNumberOfBlocks()
-    {
-        return numberOfBlocks;
-    }
-
-    /**
-     * @return Returns the blockSizeBytes.
-     */
-    protected int getBlockSizeBytes()
-    {
-        return blockSizeBytes;
-    }
-
-    /**
-     * @return Returns the average size of the an element inserted.
-     */
-    protected long getAveragePutSizeBytes()
-    {
-        if ( this.putCount == 0 )
-        {
-            return 0;
-        }
-        return this.putBytes / this.putCount;
-    }
-
-    /**
-     * @return Returns the number of empty blocks.
-     */
-    protected int getEmptyBlocks()
-    {
-        return this.emptyBlocks.size();
-    }
-
-    /**
-     * For debugging only.
-     * <p>
-     * @return String with details.
-     */
-    public String toString()
-    {
-        StringBuffer buf = new StringBuffer();
-        buf.append( "\nBlock Disk " );
-        buf.append( "\n  Filepath [" + filepath + "]" );
-        buf.append( "\n  NumberOfBlocks [" + getNumberOfBlocks() + "]" );
-        buf.append( "\n  BlockSizeBytes [" + getBlockSizeBytes() + "]" );
-        buf.append( "\n  Put Bytes [" + this.putBytes + "]" );
-        buf.append( "\n  Put Count [" + this.putCount + "]" );
-        buf.append( "\n  Average Size [" + getAveragePutSizeBytes() + "]" );
-        buf.append( "\n  Empty Blocks [" + this.getEmptyBlocks() + "]" );
-        try
-        {
-            buf.append( "\n  Length [" + length() + "]" );
-        }
-        catch ( IOException e )
-        {
-            // swallow
-        }
-        return buf.toString();
-    }
-}
+package org.apache.jcs.auxiliary.disk.block;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.io.Serializable;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.utils.serialization.StandardSerializer;
+import org.apache.jcs.utils.struct.SingleLinkedList;
+
+/**
+ * This class manages reading an writing data to disk. When asked to write a value, it returns a
+ * block array. It can read an object from the block numbers in a byte array.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class BlockDisk
+{
+    /** The logger */
+    private static final Log log = LogFactory.getLog( BlockDisk.class );
+
+    /** The size of the header that indicates the amount of data stored in an occupied block. */
+    public static final byte HEADER_SIZE_BYTES = 4;
+
+    /** defaults to 4kb */
+    private static final int DEFAULT_BLOCK_SIZE_BYTES = 4 * 1024;
+
+    /** Size of the blocks */
+    private int blockSizeBytes = DEFAULT_BLOCK_SIZE_BYTES;
+
+    /**
+     * the total number of blocks that have been used. If there are no free, we will use this to
+     * calculate the position of the next block.
+     */
+    private int numberOfBlocks = 0;
+
+    /** Empty blocks that can be reused. */
+    private SingleLinkedList emptyBlocks = new SingleLinkedList();
+
+    /** Handles serializing the objects */
+    private static final StandardSerializer SERIALIZER = new StandardSerializer();
+
+    /** Location of the spot on disk */
+    private final String filepath;
+
+    /** The file handle. */
+    private RandomAccessFile raf;
+
+    /** How many bytes have we put to disk */
+    private long putBytes = 0;
+
+    /** How many items have we put to disk */
+    private long putCount = 0;
+
+    /**
+     * Constructor for the Disk object
+     * <p>
+     * @param file
+     * @exception FileNotFoundException
+     */
+    public BlockDisk( File file )
+        throws FileNotFoundException
+    {
+        this( file, DEFAULT_BLOCK_SIZE_BYTES );
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "Used default block size [" + DEFAULT_BLOCK_SIZE_BYTES + "]" );
+        }
+
+    }
+
+    /**
+     * Creates the file and set the block size in bytes.
+     * <p>
+     * @param file
+     * @param blockSizeBytes
+     * @throws FileNotFoundException
+     */
+    public BlockDisk( File file, int blockSizeBytes )
+        throws FileNotFoundException
+    {
+        this.filepath = file.getAbsolutePath();
+        raf = new RandomAccessFile( filepath, "rw" );
+
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "Constructing BlockDisk, blockSizeBytes [" + blockSizeBytes + "]" );
+        }
+        this.blockSizeBytes = blockSizeBytes;
+    }
+
+    /**
+     * This writes an object to disk and returns the blocks it was stored in.
+     * <p>
+     * The program flow is as follows:
+     * <ol>
+     * <li>Serialize the object.</li>
+     * <li>Detemine the number of blocks needed.</li>
+     * <li>Look for free blocks in the emptyBlock list.</li>
+     * <li>If there were not enough in the empty list. Take the nextBlock and increment it.</li>
+     * <li>If the data will not fit in one block, create sub arrays.</li>
+     * <li>Write the subarrays to disk.</li>
+     * <li>If the process fails we should decrement the block count if we took from it.</li>
+     * </ol>
+     * @param object
+     * @return the blocks we used.
+     * @throws IOException
+     */
+    protected int[] write( Serializable object )
+        throws IOException
+    {
+        // serialize the object
+        byte[] data = SERIALIZER.serialize( object );
+
+        this.addToPutBytes( data.length );
+        this.incrementPutCount();
+
+        // figure out how many blocks we need.
+        int numBlocksNeeded = calculateTheNumberOfBlocksNeeded( data );
+
+        int[] blocks = new int[numBlocksNeeded];
+
+        // get them from the empty list or take the next one
+        for ( short i = 0; i < numBlocksNeeded; i++ )
+        {
+            Integer emptyBlock = (Integer) emptyBlocks.takeFirst();
+            if ( emptyBlock != null )
+            {
+                blocks[i] = emptyBlock.intValue();
+            }
+            else
+            {
+                blocks[i] = takeNextBlock();
+            }
+        }
+
+        // get the individual sub arrays.
+        byte[][] chunks = getBlockChunks( data, numBlocksNeeded );
+
+        // write the blocks
+        for ( byte i = 0; i < numBlocksNeeded; i++ )
+        {
+            int position = calculateByteOffsetForBlock( blocks[i] );
+            write( position, chunks[i] );
+        }
+
+        return blocks;
+    }
+
+    /**
+     * Return the amount to put in each block. Fill them all the way, minus the header.
+     * <p>
+     * @param complete
+     * @param numBlocksNeeded
+     * @return byte[][]
+     */
+    protected byte[][] getBlockChunks( byte[] complete, int numBlocksNeeded )
+    {
+        byte[][] chunks = new byte[numBlocksNeeded][];
+
+        if ( numBlocksNeeded == 1 )
+        {
+            chunks[0] = complete;
+        }
+        else
+        {
+            int maxChunkSize = this.blockSizeBytes - HEADER_SIZE_BYTES;
+            int totalBytes = complete.length;
+            int totalUsed = 0;
+            for ( short i = 0; i < numBlocksNeeded; i++ )
+            {
+                // use the max that can be written to a block or whatever is left in the original
+                // array
+                int chunkSize = Math.min( totalUsed + maxChunkSize, totalBytes - totalUsed );
+                byte[] chunk = new byte[chunkSize];
+                // copy from the used position to the chunk size on the complete array to the chunk
+                // array.
+                System.arraycopy( complete, totalUsed, chunk, 0, chunkSize );
+                chunks[i] = chunk;
+                totalUsed += chunkSize;
+            }
+        }
+
+        return chunks;
+    }
+
+    /**
+     * Writes the given byte array to the Disk at the specified position.
+     * <p>
+     * @param position
+     * @param data
+     * @return true if we wrote successfully
+     * @throws IOException
+     */
+    private boolean write( long position, byte[] data )
+        throws IOException
+    {
+        synchronized ( this )
+        {
+            raf.seek( position );
+            raf.writeInt( data.length );
+            raf.write( data, 0, data.length );
+        }
+        return true;
+    }
+
+    /**
+     * Reads an object that is located in the specified blocks.
+     * <p>
+     * @param blockNumbers
+     * @return Serializable
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    protected Serializable read( int[] blockNumbers )
+        throws IOException, ClassNotFoundException
+    {
+        byte[] data = null;
+
+        if ( blockNumbers.length == 1 )
+        {
+            data = readBlock( blockNumbers[0] );
+        }
+        else
+        {
+            data = new byte[0];
+            // get all the blocks into data
+            for ( short i = 0; i < blockNumbers.length; i++ )
+            {
+                byte[] chunk = readBlock( blockNumbers[i] );
+                byte[] newTotal = new byte[data.length + chunk.length];
+                // copy data into the new array
+                System.arraycopy( data, 0, newTotal, 0, data.length );
+                // copyt the chunk into the new array
+                System.arraycopy( chunk, 0, newTotal, data.length, chunk.length );
+                // swap the new and old.
+                data = newTotal;
+            }
+        }
+
+        return (Serializable) SERIALIZER.deSerialize( data );
+    }
+
+    /**
+     * This reads the occupied data in a block.
+     * <p>
+     * The first four bytes of the record should tell us how long it is. The data is read into a
+     * byte array and then an object is constructed from the byte array.
+     * <p>
+     * @return byte[]
+     * @param block
+     * @throws IOException
+     */
+    private byte[] readBlock( int block )
+        throws IOException
+    {
+        byte[] data = null;
+        int datalen = 0;
+        synchronized ( this )
+        {
+            String message = null;
+            boolean corrupted = false;
+            long fileLength = raf.length();
+
+            int position = calculateByteOffsetForBlock( block );
+            if ( position > fileLength )
+            {
+                corrupted = true;
+                message = "Record " + position + " starts past EOF.";
+            }
+            else
+            {
+                raf.seek( position );
+                datalen = raf.readInt();
+                if ( position + datalen > fileLength )
+                {
+                    corrupted = true;
+                    message = "Record " + position + " exceeds file length.";
+                }
+            }
+
+            if ( corrupted )
+            {
+                log.warn( "\n The file is corrupt: " + "\n " + message );
+                throw new IOException( "The File Is Corrupt, need to reset" );
+            }
+
+            raf.readFully( data = new byte[datalen] );
+        }
+        return data;
+    }
+
+    /**
+     * Add these blocks to the emptyBlock list.
+     * <p>
+     * @param blocksToFree
+     */
+    protected void freeBlocks( int[] blocksToFree )
+    {
+        if ( blocksToFree != null )
+        {
+            for ( short i = 0; i < blocksToFree.length; i++ )
+            {
+                emptyBlocks.addLast( new Integer( blocksToFree[i] ) );
+            }
+        }
+    }
+
+    /**
+     * Add to to total put size.
+     * <p>
+     * @param length
+     */
+    private synchronized void addToPutBytes( long length )
+    {
+        this.putBytes += length;
+    }
+
+    /**
+     * Thread safe increment.
+     */
+    private synchronized void incrementPutCount()
+    {
+        this.putCount++;
+    }
+
+    /**
+     * Returns the current number and adds one.
+     * <p>
+     * @return the block number to use.
+     */
+    private synchronized int takeNextBlock()
+    {
+        return this.numberOfBlocks++;
+    }
+
+    /**
+     * Calcuates the file offset for a particular block.
+     * <p>
+     * @param block
+     * @return the offset for this block
+     */
+    protected int calculateByteOffsetForBlock( int block )
+    {
+        return block * blockSizeBytes;
+    }
+
+    /**
+     * The number of blocks needed.
+     * <p>
+     * @param data
+     * @return the number of blocks needed to store the byte array
+     */
+    protected int calculateTheNumberOfBlocksNeeded( byte[] data )
+    {
+        int dataLength = data.length;
+
+        int oneBlock = blockSizeBytes - HEADER_SIZE_BYTES;
+
+        // takes care of 0 = HEADER_SIZE_BYTES + blockSizeBytes
+        if ( dataLength <= oneBlock )
+        {
+            return 1;
+        }
+
+        int dividend = dataLength / oneBlock;
+
+        if ( dataLength % oneBlock != 0 )
+        {
+            dividend++;
+        }
+        return dividend;
+    }
+
+    /**
+     * Returns the raf length.
+     * <p>
+     * @return the size of the file.
+     * @exception IOException
+     */
+    protected long length()
+        throws IOException
+    {
+        synchronized ( this )
+        {
+            return raf.length();
+        }
+    }
+
+    /**
+     * Closes the raf.
+     * <p>
+     * @exception IOException
+     */
+    protected synchronized void close()
+        throws IOException
+    {
+        raf.close();
+    }
+
+    /**
+     * Returns the serialized form of the given object in a byte array.
+     * <p>
+     * Use the Serilizer abstraction layer.
+     * <p>
+     * @return a byte array of the serialized object.
+     * @param obj
+     * @exception IOException
+     */
+    protected static byte[] serialize( Serializable obj )
+        throws IOException
+    {
+        return SERIALIZER.serialize( obj );
+    }
+
+    /**
+     * @return Returns the numberOfBlocks.
+     */
+    protected int getNumberOfBlocks()
+    {
+        return numberOfBlocks;
+    }
+
+    /**
+     * @return Returns the blockSizeBytes.
+     */
+    protected int getBlockSizeBytes()
+    {
+        return blockSizeBytes;
+    }
+
+    /**
+     * @return Returns the average size of the an element inserted.
+     */
+    protected long getAveragePutSizeBytes()
+    {
+        if ( this.putCount == 0 )
+        {
+            return 0;
+        }
+        return this.putBytes / this.putCount;
+    }
+
+    /**
+     * @return Returns the number of empty blocks.
+     */
+    protected int getEmptyBlocks()
+    {
+        return this.emptyBlocks.size();
+    }
+
+    /**
+     * For debugging only.
+     * <p>
+     * @return String with details.
+     */
+    public String toString()
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "\nBlock Disk " );
+        buf.append( "\n  Filepath [" + filepath + "]" );
+        buf.append( "\n  NumberOfBlocks [" + getNumberOfBlocks() + "]" );
+        buf.append( "\n  BlockSizeBytes [" + getBlockSizeBytes() + "]" );
+        buf.append( "\n  Put Bytes [" + this.putBytes + "]" );
+        buf.append( "\n  Put Count [" + this.putCount + "]" );
+        buf.append( "\n  Average Size [" + getAveragePutSizeBytes() + "]" );
+        buf.append( "\n  Empty Blocks [" + this.getEmptyBlocks() + "]" );
+        try
+        {
+            buf.append( "\n  Length [" + length() + "]" );
+        }
+        catch ( IOException e )
+        {
+            // swallow
+        }
+        return buf.toString();
+    }
+}



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


Mime
View raw message