pax_global_header 0000666 0000000 0000000 00000000064 12521130655 0014512 g ustar 00root root 0000000 0000000 52 comment=f3e06224f8e9f2f0ac968a56ea8ce84acbebf9af
libcommons-jcs-java-2.0~beta1/ 0000775 0000000 0000000 00000000000 12521130655 0016324 5 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/BUILDING.txt 0000664 0000000 0000000 00000000362 12521130655 0020263 0 ustar 00root root 0000000 0000000 Default build is using:
mvn clean install
Release build is ising (to get distributions - ie src/bin assemblies - and force TCKs to pass):
mvn clean install -Prelease
Note: this only passes on Java 7 since TCKs have to run on it.
libcommons-jcs-java-2.0~beta1/LICENSE.txt 0000664 0000000 0000000 00000026136 12521130655 0020157 0 ustar 00root root 0000000 0000000
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.
libcommons-jcs-java-2.0~beta1/NOTICE.txt 0000664 0000000 0000000 00000000263 12521130655 0020047 0 ustar 00root root 0000000 0000000 Apache Commons JCS
Copyright 2001-2015 The Apache Software Foundation.
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
libcommons-jcs-java-2.0~beta1/checkstyle.xml 0000664 0000000 0000000 00000015170 12521130655 0021210 0 ustar 00root root 0000000 0000000
libcommons-jcs-java-2.0~beta1/commons-jcs-core/ 0000775 0000000 0000000 00000000000 12521130655 0021502 5 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/LICENSE.txt 0000664 0000000 0000000 00000026137 12521130655 0023336 0 ustar 00root root 0000000 0000000
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.
libcommons-jcs-java-2.0~beta1/commons-jcs-core/NOTICE 0000664 0000000 0000000 00000000265 12521130655 0022411 0 ustar 00root root 0000000 0000000 Apache Commons JCS
Copyright 2001-2015 The Apache Software Foundation.
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
libcommons-jcs-java-2.0~beta1/commons-jcs-core/pom.xml 0000664 0000000 0000000 00000013675 12521130655 0023033 0 ustar 00root root 0000000 0000000
4.0.0
org.apache.commons
commons-jcs
2.0-beta-1
../pom.xml
commons-jcs-core
jar
Apache Commons JCS :: Core
1.6
1.6
commons-logging
commons-logging
commons-dbcp
commons-dbcp
true
commons-pool
commons-pool
true
hsqldb
hsqldb
true
org.apache.commons
commons-collections4
test
junit
junit
test
org.hamcrest
hamcrest-library
test
log4j
log4j
test
org.apache.velocity
velocity-tools
true
commons-httpclient
commons-httpclient
true
javax.servlet
servlet-api
true
src/test/test-conf
**/*.properties
**/*.ccf
org.apache.maven.plugins
maven-surefire-plugin
${commons.surefire.version}
-Xmx256m -Djava.security.manager -Djava.security.policy=${basedir}/src/test/conf/cache.policy
pertest
**/*UnitTest.java
**/BlockDiskElementDescriptorUnitTest.java
**/HSQLDiskCacheConcurrentUnitTest.java
**/HSQLDiskCacheUnitTest.java
**/IndexedDiskCacheOptimizationUnitTest.java
**/TestTCPLateralUnitTest.java
**/UDPDiscoveryUnitTest.java
**/UDPDiscoverySenderUnitTest.java
org.apache.rat
apache-rat-plugin
**/zipcodes.txt
org.apache.maven.plugins
maven-jar-plugin
test-jar
libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/ 0000775 0000000 0000000 00000000000 12521130655 0022271 5 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/ 0000775 0000000 0000000 00000000000 12521130655 0023215 5 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/ 0000775 0000000 0000000 00000000000 12521130655 0024136 5 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/ 0000775 0000000 0000000 00000000000 12521130655 0024725 5 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/ 0000775 0000000 0000000 00000000000 12521130655 0026146 5 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/ 0000775 0000000 0000000 00000000000 12521130655 0027621 5 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/ 0000775 0000000 0000000 00000000000 12521130655 0030400 5 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/JCS.java 0000664 0000000 0000000 00000020013 12521130655 0031656 0 ustar 00root root 0000000 0000000 package org.apache.commons.jcs;
/*
* 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.jcs.access.CacheAccess;
import org.apache.commons.jcs.access.GroupCacheAccess;
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import org.apache.commons.jcs.engine.control.CompositeCache;
import org.apache.commons.jcs.engine.control.CompositeCacheManager;
import org.apache.commons.jcs.engine.control.group.GroupAttrName;
import java.util.Properties;
/**
* Simple class for using JCS. To use JCS in your application, you can use the static methods of
* this class to get access objects (instances of this class) for your cache regions. One CacheAccess
* object should be created for each region you want to access. If you have several regions, then
* get instances for each. For best performance the getInstance call should be made in an
* initialization method.
*/
public abstract class JCS
{
/** cache.ccf alternative. */
private static String configFilename = null;
/** alternative configuration properties */
private static Properties configProps = null;
/** Cache manager use by the various forms of defineRegion and getAccess */
private static CompositeCacheManager cacheMgr;
/**
* Define a new cache region with the given name. In the oracle specification, these attributes
* are global and not region specific, regional overrides is a value add each region should be
* able to house both cache and element attribute sets. It is more efficient to define a cache
* in the props file and then strictly use the get access method. Use of the define region
* outside of an initialization block should be avoided.
*
* @param name Name that will identify the region
* @return CacheAccess instance for the new region
* @throws CacheException
*/
public static CacheAccess defineRegion( String name )
throws CacheException
{
CompositeCache cache = getCacheManager().getCache( name );
return new CacheAccess( cache );
}
/**
* Define a new cache region with the specified name and attributes.
*
* @param name Name that will identify the region
* @param cattr CompositeCacheAttributes for the region
* @return CacheAccess instance for the new region
* @throws CacheException
*/
public static CacheAccess defineRegion( String name, ICompositeCacheAttributes cattr )
throws CacheException
{
CompositeCache cache = getCacheManager().getCache( name, cattr );
return new CacheAccess( cache );
}
/**
* Define a new cache region with the specified name and attributes and return a CacheAccess to
* it.
*
* @param name Name that will identify the region
* @param cattr CompositeCacheAttributes for the region
* @param attr Attributes for the region
* @return CacheAccess instance for the new region
* @throws CacheException
*/
public static CacheAccess defineRegion( String name, ICompositeCacheAttributes cattr, IElementAttributes attr )
throws CacheException
{
CompositeCache cache = getCacheManager().getCache( name, cattr, attr );
return new CacheAccess( cache );
}
/**
* Set the filename that the cache manager will be initialized with. Only matters before the
* instance is initialized.
*
* @param configFilename
*/
public static void setConfigFilename( String configFilename )
{
JCS.configFilename = configFilename;
}
/**
* Set the properties that the cache manager will be initialized with. Only
* matters before the instance is initialized.
*
* @param configProps
*/
public static void setConfigProperties( Properties configProps )
{
JCS.configProps = configProps;
}
/**
* Helper method which checks to make sure the cacheMgr class field is set, and if not requests
* an instance from CacheManagerFactory.
*
* @throws CacheException if the configuration cannot be loaded
*/
private static CompositeCacheManager getCacheManager() throws CacheException
{
synchronized ( JCS.class )
{
if ( cacheMgr == null || !cacheMgr.isInitialized())
{
if ( configProps != null )
{
cacheMgr = CompositeCacheManager.getUnconfiguredInstance();
cacheMgr.configure( configProps );
}
else if ( configFilename != null )
{
cacheMgr = CompositeCacheManager.getUnconfiguredInstance();
cacheMgr.configure( configFilename );
}
else
{
cacheMgr = CompositeCacheManager.getInstance();
}
}
return cacheMgr;
}
}
/**
* Get a CacheAccess which accesses the provided region.
*
* @param region Region that return CacheAccess will provide access to
* @return A CacheAccess which provides access to a given region.
* @throws CacheException
*/
public static CacheAccess getInstance( String region )
throws CacheException
{
CompositeCache cache = getCacheManager().getCache( region );
return new CacheAccess( cache );
}
/**
* Get a CacheAccess which accesses the provided region.
*
* @param region Region that return CacheAccess will provide access to
* @param icca CacheAttributes for region
* @return A CacheAccess which provides access to a given region.
* @throws CacheException
*/
public static CacheAccess getInstance( String region, ICompositeCacheAttributes icca )
throws CacheException
{
CompositeCache cache = getCacheManager().getCache( region, icca );
return new CacheAccess( cache );
}
/**
* Get a GroupCacheAccess which accesses the provided region.
*
* @param region Region that return GroupCacheAccess will provide access to
* @return A GroupCacheAccess which provides access to a given region.
* @throws CacheException
*/
public static GroupCacheAccess getGroupCacheInstance( String region )
throws CacheException
{
CompositeCache, V> cache = getCacheManager().getCache( region );
return new GroupCacheAccess( cache );
}
/**
* Get a GroupCacheAccess which accesses the provided region.
*
* @param region Region that return GroupCacheAccess will provide access to
* @param icca CacheAttributes for region
* @return A GroupCacheAccess which provides access to a given region.
* @throws CacheException
*/
public static GroupCacheAccess getGroupCacheInstance( String region, ICompositeCacheAttributes icca )
throws CacheException
{
CompositeCache, V> cache = getCacheManager().getCache( region, icca );
return new GroupCacheAccess( cache );
}
}
libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/ 0000775 0000000 0000000 00000000000 12521130655 0031641 5 ustar 00root root 0000000 0000000 AbstractCacheAccess.java 0000664 0000000 0000000 00000014532 12521130655 0036243 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access package org.apache.commons.jcs.access;
/*
* 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.jcs.access.behavior.ICacheAccessManagement;
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import org.apache.commons.jcs.engine.control.CompositeCache;
import org.apache.commons.jcs.engine.stats.behavior.ICacheStats;
import java.io.IOException;
/**
* This class provides the common methods for all types of access to the cache.
*
* An instance of this class is tied to a specific cache region. Static methods are provided to get
* such instances.
*
* Using this class you can retrieve an item, the item's wrapper, and the element's configuration. You can also put an
* item in the cache, remove an item, and clear a region.
*
* The JCS class is the preferred way to access these methods.
*/
public abstract class AbstractCacheAccess
implements ICacheAccessManagement
{
/**
* The cache that a given instance of this class provides access to.
*
* TODO Should this be the interface?
*/
private final CompositeCache cacheControl;
/**
* Constructor for the CacheAccess object.
*
* @param cacheControl The cache which the created instance accesses
*/
public AbstractCacheAccess( CompositeCache cacheControl )
{
this.cacheControl = cacheControl;
}
/**
* Removes all of the elements from a region.
*
* @throws CacheException
*/
@Override
public void clear()
throws CacheException
{
try
{
this.getCacheControl().removeAll();
}
catch ( IOException e )
{
throw new CacheException( e );
}
}
/**
* This method is does not reset the attributes for items already in the cache. It could
* potentially do this for items in memory, and maybe on disk (which would be slow) but not
* remote items. Rather than have unpredictable behavior, this method just sets the default
* attributes. Items subsequently put into the cache will use these defaults if they do not
* specify specific attributes.
*
* @param attr the default attributes.
* @throws CacheException if something goes wrong.
*/
@Override
public void setDefaultElementAttributes( IElementAttributes attr )
throws CacheException
{
this.getCacheControl().setElementAttributes( attr );
}
/**
* Retrieves A COPY OF the default element attributes used by this region. This does not provide
* a reference to the element attributes.
*
* Each time an element is added to the cache without element attributes, the default element
* attributes are cloned.
*
* @return the default element attributes used by this region.
* @throws CacheException
*/
@Override
public IElementAttributes getDefaultElementAttributes()
throws CacheException
{
return this.getCacheControl().getElementAttributes();
}
/**
* This returns the ICacheStats object with information on this region and its auxiliaries.
*
* This data can be formatted as needed.
*
* @return ICacheStats
*/
@Override
public ICacheStats getStatistics()
{
return this.getCacheControl().getStatistics();
}
/**
* @return A String version of the stats.
*/
@Override
public String getStats()
{
return this.getCacheControl().getStats();
}
/**
* Dispose this region. Flushes objects to and closes auxiliary caches. This is a shutdown
* command!
*
* To simply remove all elements from the region use clear().
*/
@Override
public void dispose()
{
this.getCacheControl().dispose();
}
/**
* Gets the ICompositeCacheAttributes of the cache region.
*
* @return ICompositeCacheAttributes, the controllers config info, defined in the top section of
* a region definition.
*/
@Override
public ICompositeCacheAttributes getCacheAttributes()
{
return this.getCacheControl().getCacheAttributes();
}
/**
* Sets the ICompositeCacheAttributes of the cache region.
*
* @param cattr The new ICompositeCacheAttribute value
*/
@Override
public void setCacheAttributes( ICompositeCacheAttributes cattr )
{
this.getCacheControl().setCacheAttributes( cattr );
}
/**
* This instructs the memory cache to remove the numberToFree according to its eviction
* policy. For example, the LRUMemoryCache will remove the numberToFree least recently
* used items. These will be spooled to disk if a disk auxiliary is available.
*
* @param numberToFree
* @return the number that were removed. if you ask to free 5, but there are only 3, you will
* get 3.
* @throws CacheException
*/
@Override
public int freeMemoryElements( int numberToFree )
throws CacheException
{
int numFreed = -1;
try
{
numFreed = this.getCacheControl().getMemoryCache().freeElements( numberToFree );
}
catch ( IOException ioe )
{
String message = "Failure freeing memory elements.";
throw new CacheException( message, ioe );
}
return numFreed;
}
public CompositeCache getCacheControl() {
return cacheControl;
}
}
CacheAccess.java 0000664 0000000 0000000 00000025517 12521130655 0034564 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access package org.apache.commons.jcs.access;
/*
* 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.jcs.access.behavior.ICacheAccess;
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.commons.jcs.access.exception.InvalidArgumentException;
import org.apache.commons.jcs.access.exception.InvalidHandleException;
import org.apache.commons.jcs.access.exception.ObjectExistsException;
import org.apache.commons.jcs.engine.CacheElement;
import org.apache.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import org.apache.commons.jcs.engine.control.CompositeCache;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* This class provides an interface for all types of access to the cache.
*
* An instance of this class is tied to a specific cache region. Static methods are provided to get
* such instances.
*
* Using this class you can retrieve an item, the item's wrapper, and the element's configuration. You can also put an
* item in the cache, remove an item, and clear a region.
*
* The JCS class is the preferred way to access these methods.
*/
public class CacheAccess
extends AbstractCacheAccess
implements ICacheAccess
{
/** The logger. */
private static final Log log = LogFactory.getLog( CacheAccess.class );
/**
* Constructor for the CacheAccess object.
*
* @param cacheControl The cache which the created instance accesses
*/
public CacheAccess( CompositeCache cacheControl )
{
super(cacheControl);
}
/**
* Retrieve an object from the cache region this instance provides access to.
*
* @param name Key the object is stored as
* @return The object if found or null
*/
@Override
public V get( K name )
{
ICacheElement element = this.getCacheControl().get( name );
return ( element != null ) ? element.getVal() : null;
}
/**
* Retrieve matching objects from the cache region this instance provides access to.
*
* @param pattern - a key pattern for the objects stored
* @return A map of key to values. These are stripped from the wrapper.
*/
@Override
public Map getMatching( String pattern )
{
HashMap unwrappedResults = new HashMap();
Map> wrappedResults = this.getCacheControl().getMatching( pattern );
if ( wrappedResults != null )
{
for (Map.Entry> entry : wrappedResults.entrySet())
{
ICacheElement element = entry.getValue();
if ( element != null )
{
unwrappedResults.put( entry.getKey(), element.getVal() );
}
}
}
return unwrappedResults;
}
/**
* This method returns the ICacheElement wrapper which provides access to element info and other
* attributes.
*
* This returns a reference to the wrapper. Any modifications will be reflected in the cache. No
* defensive copy is made.
*
* This method is most useful if you want to determine things such as the how long the element
* has been in the cache.
*
* The last access time in the ElementAttributes should be current.
*
* @param name Key the Serializable is stored as
* @return The ICacheElement if the object is found or null
*/
@Override
public ICacheElement getCacheElement( K name )
{
return this.getCacheControl().get( name );
}
/**
* Get multiple elements from the cache based on a set of cache keys.
*
* This method returns the ICacheElement wrapper which provides access to element info and other
* attributes.
*
* This returns a reference to the wrapper. Any modifications will be reflected in the cache. No
* defensive copy is made.
*
* This method is most useful if you want to determine things such as the how long the element
* has been in the cache.
*
* The last access time in the ElementAttributes should be current.
*
* @param names set of Serializable cache keys
* @return a map of K key to ICacheElement element, or empty map if none of the keys are present
*/
@Override
public Map> getCacheElements( Set names )
{
return this.getCacheControl().getMultiple( names );
}
/**
* Get multiple elements from the cache based on a set of cache keys.
*
* This method returns the ICacheElement wrapper which provides access to element info and other
* attributes.
*
* This returns a reference to the wrapper. Any modifications will be reflected in the cache. No
* defensive copy is made.
*
* This method is most useful if you want to determine things such as the how long the element
* has been in the cache.
*
* The last access time in the ElementAttributes should be current.
*
* @param pattern key search pattern
* @return a map of K key to ICacheElement element, or empty map if no keys match the pattern
*/
@Override
public Map> getMatchingCacheElements( String pattern )
{
return this.getCacheControl().getMatching( pattern );
}
/**
* Place a new object in the cache, associated with key name. If there is currently an object
* associated with name in the region an ObjectExistsException is thrown. Names are scoped to a
* region so they must be unique within the region they are placed.
*
* @param key Key object will be stored with
* @param value Object to store
* @throws CacheException and ObjectExistsException is thrown if the item is already in the
* cache.
*/
@Override
public void putSafe( K key, V value )
{
if ( this.getCacheControl().get( key ) != null )
{
throw new ObjectExistsException( "putSafe failed. Object exists in the cache for key [" + key
+ "]. Remove first or use a non-safe put to override the value." );
}
put( key, value );
}
/**
* Place a new object in the cache, associated with key name. If there is currently an object
* associated with name in the region it is replaced. Names are scoped to a region so they must
* be unique within the region they are placed.
* @param name Key object will be stored with
* @param obj Object to store
*/
@Override
public void put( K name, V obj )
{
// Call put with a copy of the contained caches default attributes.
// the attributes are copied by the cacheControl
put( name, obj, this.getCacheControl().getElementAttributes() );
}
/**
* Constructs a cache element with these attributes, and puts it into the cache.
*
* If the key or the value is null, and InvalidArgumentException is thrown.
*
* @see org.apache.commons.jcs.access.behavior.ICacheAccess#put(java.io.Serializable, java.io.Serializable,
* org.apache.commons.jcs.engine.behavior.IElementAttributes)
*/
@Override
public void put( K key, V val, IElementAttributes attr )
{
if ( key == null )
{
throw new InvalidArgumentException( "Key must not be null" );
}
if ( val == null )
{
throw new InvalidArgumentException( "Value must not be null" );
}
// Create the element and update. This may throw an IOException which
// should be wrapped by cache access.
try
{
CacheElement ce = new CacheElement( this.getCacheControl().getCacheName(), key,
val );
ce.setElementAttributes( attr );
this.getCacheControl().update( ce );
}
catch ( IOException e )
{
throw new CacheException( e );
}
}
/**
* Removes a single item by name.
*
* @param name the name of the item to remove.
*/
@Override
public void remove( K name )
{
this.getCacheControl().remove( name );
}
/**
* Reset attributes for a particular element in the cache. NOTE: this method is currently not
* implemented.
*
* @param name Key of object to reset attributes for
* @param attr New attributes for the object
* @throws InvalidHandleException if the item does not exist.
*/
@Override
public void resetElementAttributes( K name, IElementAttributes attr )
{
ICacheElement element = this.getCacheControl().get( name );
if ( element == null )
{
throw new InvalidHandleException( "Object for name [" + name + "] is not in the cache" );
}
// Although it will work currently, don't assume pass by reference here,
// i.e. don't do this:
// element.setElementAttributes( attr );
// Another reason to call put is to force the changes to be distributed.
put( element.getKey(), element.getVal(), attr );
}
/**
* GetElementAttributes will return an attribute object describing the current attributes
* associated with the object name. The name object must override the Object.equals and
* Object.hashCode methods.
*
* @param name Key of object to get attributes for
* @return Attributes for the object, null if object not in cache
*/
@Override
public IElementAttributes getElementAttributes( K name )
{
IElementAttributes attr = null;
try
{
attr = this.getCacheControl().getElementAttributes( name );
}
catch ( IOException ioe )
{
log.error( "Failure getting element attributes", ioe );
}
return attr;
}
}
GroupCacheAccess.java 0000664 0000000 0000000 00000014371 12521130655 0035575 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access package org.apache.commons.jcs.access;
/*
* 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.jcs.access.behavior.IGroupCacheAccess;
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.commons.jcs.access.exception.InvalidArgumentException;
import org.apache.commons.jcs.engine.CacheElement;
import org.apache.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import org.apache.commons.jcs.engine.control.CompositeCache;
import org.apache.commons.jcs.engine.control.group.GroupAttrName;
import org.apache.commons.jcs.engine.control.group.GroupId;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
/**
* Access for groups.
*/
public class GroupCacheAccess
extends AbstractCacheAccess, V>
implements IGroupCacheAccess
{
/**
* Constructor for the GroupCacheAccess object
*
* @param cacheControl
*/
public GroupCacheAccess( CompositeCache, V> cacheControl )
{
super(cacheControl);
}
/**
* Gets an item out of the cache that is in a specified group.
*
* @param name
* The key name.
* @param group
* The group name.
* @return The cached value, null if not found.
*/
@Override
public V getFromGroup( K name, String group )
{
ICacheElement, V> element = this.getCacheControl().get( getGroupAttrName( group, name ) );
return ( element != null ) ? element.getVal() : null;
}
/**
* Internal method used for group functionality.
*
* @param group
* @param name
* @return GroupAttrName
*/
private GroupAttrName getGroupAttrName( String group, K name )
{
GroupId gid = new GroupId( this.getCacheControl().getCacheName(), group );
return new GroupAttrName( gid, name );
}
/**
* Allows the user to put an object into a group within a particular cache
* region. This method sets the object's attributes to the default for the
* region.
*
* @param name
* The key name.
* @param groupName
* The group name.
* @param value
* The object to cache
* @throws CacheException
*/
@Override
public void putInGroup( K name, String groupName, V value )
throws CacheException
{
putInGroup( name, groupName, value, null );
}
/**
* Allows the user to put an object into a group within a particular cache
* region. This method allows the object's attributes to be individually
* specified.
*
* @param name
* The key name.
* @param groupName
* The group name.
* @param value
* The object to cache
* @param attr
* The objects attributes.
* @throws CacheException
*/
@Override
public void putInGroup( K name, String groupName, V value, IElementAttributes attr )
throws CacheException
{
if ( name == null )
{
throw new InvalidArgumentException( "Key must not be null" );
}
if ( value == null )
{
throw new InvalidArgumentException( "Value must not be null" );
}
// Create the element and update. This may throw an IOException which
// should be wrapped by cache access.
try
{
GroupAttrName key = getGroupAttrName( groupName, name );
CacheElement, V> ce =
new CacheElement, V>( this.getCacheControl().getCacheName(), key, value );
IElementAttributes attributes = (attr == null) ? this.getCacheControl().getElementAttributes() : attr;
ce.setElementAttributes( attributes );
this.getCacheControl().update( ce );
}
catch ( IOException e )
{
throw new CacheException( e );
}
}
/**
* @param name
* @param group
*/
@Override
public void removeFromGroup( K name, String group )
{
GroupAttrName key = getGroupAttrName( group, name );
this.getCacheControl().remove( key );
}
/**
* Gets the set of keys of objects currently in the group.
*
* @param group
* @return A Set of keys.
*/
@Override
public Set getGroupKeys( String group )
{
Set groupKeys = new HashSet();
GroupId groupId = new GroupId( this.getCacheControl().getCacheName(), group );
for (GroupAttrName gan : this.getCacheControl().getKeySet())
{
if (gan.groupId.equals( groupId ))
{
groupKeys.add( gan.attrName );
}
}
return groupKeys;
}
/**
* Gets the set of group names in the cache
*
* @return A Set of group names.
*/
public Set getGroupNames()
{
HashSet names = new HashSet();
for (GroupAttrName gan : this.getCacheControl().getKeySet())
{
names.add(gan.groupId.groupName);
}
return names;
}
/**
* Invalidates a group: remove all the group members
*
* @param group
* The name of the group to invalidate
*/
@Override
public void invalidateGroup( String group )
{
this.getCacheControl().remove(getGroupAttrName(group, null));
}
}
PartitionedCacheAccess.java 0000664 0000000 0000000 00000054672 12521130655 0036773 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access package org.apache.commons.jcs.access;
/*
* 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.jcs.JCS;
import org.apache.commons.jcs.access.behavior.ICacheAccess;
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.commons.jcs.access.exception.ConfigurationException;
import org.apache.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import org.apache.commons.jcs.engine.stats.behavior.ICacheStats;
import org.apache.commons.jcs.utils.props.AbstractPropertyContainer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* TODO: Add new methods that will allow you to provide a partition indicator for all major calls. Add an interface as well.
*
* This handles dividing puts and gets.
*
* There are two required properties.
*
*
* - .numberOfPartitions
* - .partitionRegionNamePrefix
*
* System properties will override values in the properties file.
*
* We use a JCS region name for each partition that looks like this: partitionRegionNamePrefix + "_"
* + partitionNumber. The number is 0 indexed based.
*
* @author Aaron Smuts
*/
public class PartitionedCacheAccess
extends AbstractPropertyContainer
implements ICacheAccess
{
/** the logger. */
private static final Log log = LogFactory.getLog( PartitionedCacheAccess.class );
/** The number of partitions. */
private int numberOfPartitions = 1;
/**
* We use a JCS region name for each partition that looks like this: partitionRegionNamePrefix +
* "_" + partitionNumber
*/
private String partitionRegionNamePrefix;
/** An array of partitions built during initialization. */
private ICacheAccess[] partitions;
/** Is the class initialized. */
private boolean initialized = false;
/** Sets default properties heading and group. */
public PartitionedCacheAccess()
{
setPropertiesHeading( "PartitionedCacheAccess" );
setPropertiesGroup( "cache" );
}
/**
* Puts the value into the appropriate cache partition.
*
* @param key key
* @param object object
* @throws CacheException on configuration problem
*/
@Override
public void put( K key, V object )
throws CacheException
{
if ( key == null || object == null )
{
log.warn( "Bad input key [" + key + "]. Cannot put null into the cache." );
return;
}
if (!ensureInit())
{
return;
}
int partition = getPartitionNumberForKey( key );
try
{
partitions[partition].put( key, object );
}
catch ( CacheException e )
{
log.error( "Problem putting value for key [" + key + "] in cache [" + partitions[partition] + "]" );
throw e;
}
}
/**
* Puts in cache if an item does not exist with the name in that region.
*
* @param key
* @param object
* @throws CacheException
*/
@Override
public void putSafe( K key, V object )
throws CacheException
{
if ( key == null || object == null )
{
log.warn( "Bad input key [" + key + "]. Cannot putSafe null into the cache." );
}
if (!ensureInit())
{
return;
}
int partition = getPartitionNumberForKey( key );
partitions[partition].putSafe( key, object );
}
/**
* Puts the value into the appropriate cache partition.
*
* @param key key
* @param object object
* @param attr
* @throws CacheException on configuration problem
*/
@Override
public void put( K key, V object, IElementAttributes attr )
throws CacheException
{
if ( key == null || object == null )
{
log.warn( "Bad input key [" + key + "]. Cannot put null into the cache." );
return;
}
if (!ensureInit())
{
return;
}
int partition = getPartitionNumberForKey( key );
try
{
partitions[partition].put( key, object, attr );
}
catch ( CacheException e )
{
log.error( "Problem putting value for key [" + key + "] in cache [" + partitions[partition] + "]" );
throw e;
}
}
/**
* Gets the object for the key from the desired partition.
*
* @param key key
* @return result, null if not found.
*/
@Override
public V get( K key )
{
if ( key == null )
{
log.warn( "Input key is null." );
return null;
}
if (!ensureInit())
{
return null;
}
int partition = getPartitionNumberForKey( key );
return partitions[partition].get( key );
}
/**
* Gets the ICacheElement (the wrapped object) for the key from the desired partition.
*
* @param key key
* @return result, null if not found.
*/
@Override
public ICacheElement getCacheElement( K key )
{
if ( key == null )
{
log.warn( "Input key is null." );
return null;
}
if (!ensureInit())
{
return null;
}
int partition = getPartitionNumberForKey( key );
return partitions[partition].getCacheElement( key );
}
/**
* This is a getMultiple. We try to group the keys so that we make as few calls as needed.
*
* @param names
* @return Map of keys to ICacheElement
*/
@Override
public Map> getCacheElements( Set names )
{
if ( names == null )
{
log.warn( "Bad input names cannot be null." );
return Collections.emptyMap();
}
if (!ensureInit())
{
return Collections.emptyMap();
}
@SuppressWarnings("unchecked") // No generic arrays in java
Set[] dividedNames = new Set[this.getNumberOfPartitions()];
for (K key : names)
{
int partition = getPartitionNumberForKey( key );
if ( dividedNames[partition] == null )
{
dividedNames[partition] = new HashSet();
}
dividedNames[partition].add( key );
}
Map> result = new HashMap>();
for ( int i = 0; i < partitions.length; i++ )
{
if ( dividedNames[i] != null && !dividedNames[i].isEmpty() )
{
result.putAll( partitions[i].getCacheElements( dividedNames[i] ) );
}
}
return result;
}
/**
* This is tricky. Do we need to get from all the partitions?
*
* If this interface took an object, we could use the hashcode to determine the partition. Then
* we could use the toString for the pattern.
*
* @param pattern
* @return HashMap key to value
*/
@Override
public Map getMatching( String pattern )
{
if ( pattern == null )
{
log.warn( "Input pattern is null." );
return null;
}
if (!ensureInit())
{
return null;
}
Map result = new HashMap();
for (ICacheAccess partition : partitions)
{
result.putAll( partition.getMatching( pattern ) );
}
return result;
}
/**
* This is tricky. Do we need to get from all the partitions?
*
* @param pattern
* @return HashMap key to ICacheElement
*/
@Override
public Map> getMatchingCacheElements( String pattern )
{
if ( pattern == null )
{
log.warn( "Input pattern is null." );
return null;
}
if (!ensureInit())
{
return null;
}
Map> result = new HashMap>();
for (ICacheAccess partition : partitions)
{
result.putAll( partition.getMatchingCacheElements( pattern ) );
}
return result;
}
/**
* Removes the item from the appropriate partition.
*
* @param key
* @throws CacheException
*/
@Override
public void remove( K key )
throws CacheException
{
if ( key == null )
{
log.warn( "Input key is null. Cannot remove null from the cache." );
return;
}
if (!ensureInit())
{
return;
}
int partition = getPartitionNumberForKey( key );
try
{
partitions[partition].remove( key );
}
catch ( CacheException e )
{
log.error( "Problem removing value for key [" + key + "] in cache [" + partitions[partition] + "]" );
throw e;
}
}
/**
* Calls free on each partition.
*
* @param numberToFree
* @return number removed
* @throws CacheException
*/
@Override
public int freeMemoryElements( int numberToFree )
throws CacheException
{
if (!ensureInit())
{
return 0;
}
int count = 0;
for (ICacheAccess partition : partitions)
{
count += partition.freeMemoryElements( numberToFree );
}
return count;
}
/**
* @return ICompositeCacheAttributes from the first partition.
*/
@Override
public ICompositeCacheAttributes getCacheAttributes()
{
if (!ensureInit())
{
return null;
}
if ( partitions.length == 0 )
{
return null;
}
return partitions[0].getCacheAttributes();
}
/**
* @return IElementAttributes from the first partition.
* @throws CacheException
*/
@Override
public IElementAttributes getDefaultElementAttributes()
throws CacheException
{
if (!ensureInit())
{
return null;
}
if ( partitions.length == 0 )
{
return null;
}
return partitions[0].getDefaultElementAttributes();
}
/**
* This is no more efficient than simply getting the cache element.
*
* @param key
* @return IElementAttributes
* @throws CacheException
*/
@Override
public IElementAttributes getElementAttributes( K key )
throws CacheException
{
if ( key == null )
{
log.warn( "Input key is null. Cannot getElementAttributes for null from the cache." );
return null;
}
if (!ensureInit())
{
return null;
}
int partition = getPartitionNumberForKey( key );
return partitions[partition].getElementAttributes( key );
}
/**
* Resets the attributes for this item. This has the same effect as an update, in most cases.
* None of the auxiliaries are optimized to do this more efficiently than a simply update.
*
* @param key
* @param attributes
* @throws CacheException
*/
@Override
public void resetElementAttributes( K key, IElementAttributes attributes )
throws CacheException
{
if ( key == null )
{
log.warn( "Input key is null. Cannot resetElementAttributes for null." );
return;
}
if (!ensureInit())
{
return;
}
int partition = getPartitionNumberForKey( key );
partitions[partition].resetElementAttributes( key, attributes );
}
/**
* Sets the attributes on all the partitions.
*
* @param cattr
*/
@Override
public void setCacheAttributes( ICompositeCacheAttributes cattr )
{
if (!ensureInit())
{
return;
}
for (ICacheAccess partition : partitions)
{
partition.setCacheAttributes( cattr );
}
}
/**
* Removes all of the elements from a region.
*
* @throws CacheException
*/
@Override
public void clear()
throws CacheException
{
if (!ensureInit())
{
return;
}
for (ICacheAccess partition : partitions)
{
partition.clear();
}
}
/**
* This method is does not reset the attributes for items already in the cache. It could
* potentially do this for items in memory, and maybe on disk (which would be slow) but not
* remote items. Rather than have unpredictable behavior, this method just sets the default
* attributes. Items subsequently put into the cache will use these defaults if they do not
* specify specific attributes.
*
* @param attr the default attributes.
* @throws CacheException if something goes wrong.
*/
@Override
public void setDefaultElementAttributes( IElementAttributes attr )
throws CacheException
{
if (!ensureInit())
{
return;
}
for (ICacheAccess partition : partitions)
{
partition.setDefaultElementAttributes(attr);
}
}
/**
* This returns the ICacheStats object with information on this region and its auxiliaries.
*
* This data can be formatted as needed.
*
* @return ICacheStats
*/
@Override
public ICacheStats getStatistics()
{
if (!ensureInit())
{
return null;
}
if ( partitions.length == 0 )
{
return null;
}
return partitions[0].getStatistics();
}
/**
* @return A String version of the stats.
*/
@Override
public String getStats()
{
if (!ensureInit())
{
return "";
}
StringBuilder stats = new StringBuilder();
for (ICacheAccess partition : partitions)
{
stats.append(partition.getStats());
stats.append("\n");
}
return stats.toString();
}
/**
* Dispose this region. Flushes objects to and closes auxiliary caches. This is a shutdown
* command!
*
* To simply remove all elements from the region use clear().
*/
@Override
public synchronized void dispose()
{
if (!ensureInit())
{
return;
}
for (ICacheAccess partition : partitions)
{
partition.dispose();
}
initialized = false;
}
/**
* This expects a numeric key. If the key cannot be converted into a number, we will return 0.
* TODO we could md5 it or get the hashcode.
*
* We determine the partition by taking the mod of the number of partitions.
*
* @param key key
* @return the partition number.
*/
protected int getPartitionNumberForKey( K key )
{
if ( key == null )
{
return 0;
}
long keyNum = getNumericValueForKey( key );
int partition = (int) ( keyNum % getNumberOfPartitions() );
if ( log.isDebugEnabled() )
{
log.debug( "Using partition [" + partition + "] for key [" + key + "]" );
}
return partition;
}
/**
* This can be overridden for special purposes.
*
* @param key key
* @return long
*/
public long getNumericValueForKey( K key )
{
String keyString = key.toString();
long keyNum = -1;
try
{
keyNum = Long.parseLong( keyString );
}
catch ( NumberFormatException e )
{
// THIS IS UGLY, but I can't think of a better failsafe right now.
keyNum = key.hashCode();
log.warn( "Couldn't convert [" + key + "] into a number. Will use hashcode [" + keyNum + "]" );
}
return keyNum;
}
/**
* Initialize if we haven't already.
*
* @throws ConfigurationException on configuration problem
*/
protected synchronized boolean ensureInit()
{
if ( !initialized )
{
try
{
initialize();
}
catch ( ConfigurationException e )
{
log.error( "Couldn't configure partioned access.", e );
return false;
}
}
return true;
}
/**
* Use the partition prefix and the number of partitions to get JCS regions.
*
* @throws ConfigurationException on configuration problem
*/
protected synchronized void initialize()
throws ConfigurationException
{
ensureProperties();
@SuppressWarnings("unchecked") // No generic arrays in java
ICacheAccess[] tempPartitions = new ICacheAccess[this.getNumberOfPartitions()];
for ( int i = 0; i < this.getNumberOfPartitions(); i++ )
{
String regionName = this.getPartitionRegionNamePrefix() + "_" + i;
try
{
tempPartitions[i] = JCS.getInstance( regionName );
}
catch ( CacheException e )
{
log.error( "Problem getting cache for region [" + regionName + "]" );
}
}
partitions = tempPartitions;
initialized = true;
}
/**
* Loads in the needed configuration settings. System properties are checked first. A system
* property will override local property value.
*
* Loads the following JCS Cache specific properties:
*
* - heading.numberOfPartitions
* - heading.partitionRegionNamePrefix
*
* @throws ConfigurationException on configuration problem
*/
@Override
protected void handleProperties()
throws ConfigurationException
{
// Number of Partitions.
String numberOfPartitionsPropertyName = this.getPropertiesHeading() + ".numberOfPartitions";
String numberOfPartitionsPropertyValue = getPropertyForName( numberOfPartitionsPropertyName, true );
try
{
this.setNumberOfPartitions( Integer.parseInt( numberOfPartitionsPropertyValue ) );
}
catch ( NumberFormatException e )
{
String message = "Could not convert [" + numberOfPartitionsPropertyValue + "] into a number for ["
+ numberOfPartitionsPropertyName + "]";
log.error( message );
throw new ConfigurationException( message );
}
// Partition Name Prefix.
String prefixPropertyName = this.getPropertiesHeading() + ".partitionRegionNamePrefix";
String prefix = getPropertyForName( prefixPropertyName, true );
this.setPartitionRegionNamePrefix( prefix );
}
/**
* Checks the system properties before the properties.
*
* @param propertyName name
* @param required is it required?
* @return the property value if one is found
* @throws ConfigurationException thrown if it is required and not found.
*/
protected String getPropertyForName( String propertyName, boolean required )
throws ConfigurationException
{
String propertyValue = null;
propertyValue = System.getProperty( propertyName );
if ( propertyValue != null )
{
if ( log.isInfoEnabled() )
{
log.info( "Found system property override: Name [" + propertyName + "] Value [" + propertyValue + "]" );
}
}
else
{
propertyValue = this.getProperties().getProperty( propertyName );
if ( required && propertyValue == null )
{
String message = "Could not find required property [" + propertyName + "] in propertiesGroup ["
+ this.getPropertiesGroup() + "]";
log.error( message );
throw new ConfigurationException( message );
}
else
{
if ( log.isInfoEnabled() )
{
log.info( "Name [" + propertyName + "] Value [" + propertyValue + "]" );
}
}
}
return propertyValue;
}
/**
* @param numberOfPartitions The numberOfPartitions to set.
*/
protected void setNumberOfPartitions( int numberOfPartitions )
{
this.numberOfPartitions = numberOfPartitions;
}
/**
* @return Returns the numberOfPartitions.
*/
protected int getNumberOfPartitions()
{
return numberOfPartitions;
}
/**
* @param partitionRegionNamePrefix The partitionRegionNamePrefix to set.
*/
protected void setPartitionRegionNamePrefix( String partitionRegionNamePrefix )
{
this.partitionRegionNamePrefix = partitionRegionNamePrefix;
}
/**
* @return Returns the partitionRegionNamePrefix.
*/
protected String getPartitionRegionNamePrefix()
{
return partitionRegionNamePrefix;
}
/**
* @param partitions The partitions to set.
*/
protected void setPartitions( ICacheAccess[] partitions )
{
this.partitions = partitions;
}
/**
* @return Returns the partitions.
*/
protected ICacheAccess[] getPartitions()
{
return partitions;
}
}
libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/behavior/0000775 0000000 0000000 00000000000 12521130655 0033440 5 ustar 00root root 0000000 0000000 ICacheAccess.java 0000664 0000000 0000000 00000012564 12521130655 0036472 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/behavior package org.apache.commons.jcs.access.behavior;
/*
* 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.jcs.access.exception.CacheException;
import org.apache.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import java.util.Map;
import java.util.Set;
/**
* ICacheAccess defines the behavior for client access.
*/
public interface ICacheAccess
extends ICacheAccessManagement
{
/**
* Basic get method.
*
* @param name
* @return Object or null if not found.
*/
V get( K name );
/**
* Retrieve matching objects from the cache region this instance provides access to.
*
* @param pattern - a key pattern for the objects stored
* @return A map of key to values. These are stripped from the wrapper.
*/
Map getMatching( String pattern );
/**
* Puts in cache if an item does not exist with the name in that region.
*
* @param name
* @param obj
* @throws CacheException
*/
void putSafe( K name, V obj )
throws CacheException;
/**
* Puts and/or overrides an element with the name in that region.
*
* @param name
* @param obj
* @throws CacheException
*/
void put( K name, V obj )
throws CacheException;
/**
* Description of the Method
*
* @param name
* @param obj
* @param attr
* @throws CacheException
*/
void put( K name, V obj, IElementAttributes attr )
throws CacheException;
/**
* This method returns the ICacheElement wrapper which provides access to element info and other
* attributes.
*
* This returns a reference to the wrapper. Any modifications will be reflected in the cache. No
* defensive copy is made.
*
* This method is most useful if you want to determine things such as the how long the element
* has been in the cache.
*
* The last access time in the ElementAttributes should be current.
*
* @param name Key the object is stored as
* @return The ICacheElement if the object is found or null
*/
ICacheElement getCacheElement( K name );
/**
* Get multiple elements from the cache based on a set of cache keys.
*
* This method returns the ICacheElement wrapper which provides access to element info and other
* attributes.
*
* This returns a reference to the wrapper. Any modifications will be reflected in the cache. No
* defensive copy is made.
*
* This method is most useful if you want to determine things such as the how long the element
* has been in the cache.
*
* The last access time in the ElementAttributes should be current.
*
* @param names set of Object cache keys
* @return a map of Object key to ICacheElement element, or empty map if none of the keys are
* present
*/
Map> getCacheElements( Set names );
/**
* Get multiple elements from the cache based on a set of cache keys.
*
* This method returns the ICacheElement wrapper which provides access to element info and other
* attributes.
*
* This returns a reference to the wrapper. Any modifications will be reflected in the cache. No
* defensive copy is made.
*
* This method is most useful if you want to determine things such as the how long the element
* has been in the cache.
*
* The last access time in the ElementAttributes should be current.
*
* @param pattern key search pattern
* @return a map of Object key to ICacheElement element, or empty map if no keys match the
* pattern
*/
Map> getMatchingCacheElements( String pattern );
/**
* Remove an object for this key if one exists, else do nothing.
*
* @param name
* @throws CacheException
*/
void remove( K name )
throws CacheException;
/**
* Reset the attributes on the object matching this key name.
*
* @param name
* @param attributes
* @throws CacheException
*/
void resetElementAttributes( K name, IElementAttributes attributes )
throws CacheException;
/**
* Gets the elementAttributes attribute of the ICacheAccess object
*
* @param name
* @return The elementAttributes value
* @throws CacheException
*/
IElementAttributes getElementAttributes( K name )
throws CacheException;
}
ICacheAccessManagement.java 0000664 0000000 0000000 00000007720 12521130655 0040465 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/behavior package org.apache.commons.jcs.access.behavior;
/*
* 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.jcs.access.exception.CacheException;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import org.apache.commons.jcs.engine.stats.behavior.ICacheStats;
/**
* ICacheAccessManagement defines the methods for cache management, cleanup and shutdown.
*/
public interface ICacheAccessManagement
{
/**
* Dispose this region. Flushes objects to and closes auxiliary caches. This is a shutdown
* command!
*
* To simply remove all elements from the region use clear().
*/
void dispose();
/**
* Removes all of the elements from a region.
*
* @throws CacheException
*/
void clear() throws CacheException;
/**
* GetElementAttributes will return an attribute object describing the current attributes
* associated with the object name. If no name parameter is available, the attributes for the
* region will be returned. The name object must override the Object.equals and Object.hashCode
* methods.
*
* @return The elementAttributes value
* @throws CacheException
*/
IElementAttributes getDefaultElementAttributes()
throws CacheException;
/**
* This method is does not reset the attributes for items already in the cache. It could
* potentially do this for items in memory, and maybe on disk (which would be slow) but not
* remote items. Rather than have unpredictable behavior, this method just sets the default
* attributes. Items subsequently put into the cache will use these defaults if they do not
* specify specific attributes.
*
* @param attr the default attributes.
* @throws CacheException if something goes wrong.
*/
void setDefaultElementAttributes( IElementAttributes attr ) throws CacheException;
/**
* Gets the ICompositeCacheAttributes of the cache region
*
* @return ICompositeCacheAttributes
*/
ICompositeCacheAttributes getCacheAttributes();
/**
* Sets the ICompositeCacheAttributes of the cache region
*
* @param cattr The new ICompositeCacheAttribute value
*/
void setCacheAttributes( ICompositeCacheAttributes cattr );
/**
* This instructs the memory cache to remove the numberToFree according to its eviction
* policy. For example, the LRUMemoryCache will remove the numberToFree least recently
* used items. These will be spooled to disk if a disk auxiliary is available.
*
* @param numberToFree
* @return the number that were removed. if you ask to free 5, but there are only 3, you will
* get 3.
* @throws CacheException
*/
int freeMemoryElements( int numberToFree )
throws CacheException;
/**
* This returns the ICacheStats object with information on this region and its auxiliaries.
*
* This data can be formatted as needed.
*
* @return ICacheStats
*/
ICacheStats getStatistics();
/**
* @return A String version of the stats.
*/
String getStats();
}
IGroupCacheAccess.java 0000664 0000000 0000000 00000004762 12521130655 0037510 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/behavior package org.apache.commons.jcs.access.behavior;
/*
* 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.jcs.access.exception.CacheException;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import java.util.Set;
/**
* IGroupCacheAccess defines group specific behavior for the client access
* classes.
*/
public interface IGroupCacheAccess
extends ICacheAccessManagement
{
/**
* Gets the g attribute of the IGroupCacheAccess object
*
* @param name
* @param group
* the name of the group to associate this with.
* @return The object that is keyed by the name in the group
*/
V getFromGroup( K name, String group );
/**
* Puts an item in the cache associated with this group.
*
* @param key
* @param group
* @param obj
* @throws CacheException
*/
void putInGroup( K key, String group, V obj )
throws CacheException;
/**
* Put in the cache associated with this group using these attributes.
*
* @param key
* @param group
* @param obj
* @param attr
* @throws CacheException
*/
void putInGroup( K key, String group, V obj, IElementAttributes attr )
throws CacheException;
/**
* Remove the item from this group in this region by this name.
*
* @param name
* @param group
*/
void removeFromGroup( K name, String group );
/**
* Gets the set of keys of objects currently in the group
*
* @param group
* @return the set of group keys.
*/
Set getGroupKeys( String group );
/**
* Invalidates a group
*
* @param group
*/
void invalidateGroup( String group );
}
exception/ 0000775 0000000 0000000 00000000000 12521130655 0033560 5 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access CacheException.java 0000664 0000000 0000000 00000003410 12521130655 0037303 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/exception package org.apache.commons.jcs.access.exception;
/*
* 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.
*/
/**
* This is the most general exception the cache throws.
*/
public class CacheException
extends RuntimeException
{
/** Don't change. */
private static final long serialVersionUID = 8725795372935590265L;
/**
* Default
*/
public CacheException()
{
super();
}
/**
* Constructor for the CacheException object
* @param nested a nested exception
*/
public CacheException( Throwable nested )
{
super(nested);
}
/**
* Constructor for the CacheException object
* @param message the exception message
*/
public CacheException( String message )
{
super(message);
}
/**
* Constructor for the CacheException object
* @param message the exception message
* @param nested a nested exception
*/
public CacheException(String message, Throwable nested)
{
super(message, nested);
}
}
ConfigurationException.java 0000664 0000000 0000000 00000002643 12521130655 0041116 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/exception package org.apache.commons.jcs.access.exception;
/*
* 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.
*/
/** Thrown if there is some severe configuration problem that makes the cache nonfunctional. */
public class ConfigurationException
extends CacheException
{
/** Don't change. */
private static final long serialVersionUID = 6881044536186097055L;
/** Constructor for the ConfigurationException object */
public ConfigurationException()
{
super();
}
/**
* Constructor for the ConfigurationException object.
*
* @param message
*/
public ConfigurationException( String message )
{
super( message );
}
}
InvalidArgumentException.java 0000664 0000000 0000000 00000002770 12521130655 0041401 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/exception package org.apache.commons.jcs.access.exception;
/*
* 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.
*/
/**
* InvalidArgumentException is thrown if an argument is passed to the cache that is invalid. For
* instance, null values passed to put result in this exception.
*/
public class InvalidArgumentException
extends CacheException
{
/** Don't change. */
private static final long serialVersionUID = -6058373692208755562L;
/** Constructor for the InvalidArgumentException object */
public InvalidArgumentException()
{
super();
}
/**
* Constructor for the InvalidArgumentException object.
*
* @param message
*/
public InvalidArgumentException( String message )
{
super( message );
}
}
InvalidGroupException.java 0000664 0000000 0000000 00000002540 12521130655 0040706 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/exception package org.apache.commons.jcs.access.exception;
/*
* 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.
*/
/**
* InvalidGroupException
*/
public class InvalidGroupException
extends CacheException
{
/** Don't change. */
private static final long serialVersionUID = -5219807114008843480L;
/** Constructor for the InvalidGroupException object */
public InvalidGroupException()
{
super();
}
/**
* Constructor for the InvalidGroupException object
*
* @param message
*/
public InvalidGroupException( String message )
{
super( message );
}
}
InvalidHandleException.java 0000664 0000000 0000000 00000002607 12521130655 0041011 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/exception package org.apache.commons.jcs.access.exception;
/*
* 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.
*/
/**
* InvalidHandleException is not used.
*/
public class InvalidHandleException
extends CacheException
{
/** Don't change. */
private static final long serialVersionUID = -5947822454839845924L;
/** Constructor for the InvalidHandleException object */
public InvalidHandleException()
{
// nothing
super();
}
/**
* Constructor for the InvalidHandleException object.
*
* @param message
*/
public InvalidHandleException( String message )
{
super( message );
}
}
ObjectExistsException.java 0000664 0000000 0000000 00000003434 12521130655 0040714 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/exception package org.apache.commons.jcs.access.exception;
/*
* 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.
*/
/**
* The putSafe method on the JCS convenience class throws this exception if the object is already
* present in the cache.
*
* I'm removing this exception from normal use.
*
* The overhead of throwing exceptions and the cumbersomeness of coding around exceptions warrants
* removal. Exceptions like this don't make sense to throw in the course of normal operations to
* signify a normal and expected condition. Returning null if an object isn't found is sufficient.
*/
public class ObjectExistsException
extends CacheException
{
/** Don't change. */
private static final long serialVersionUID = -3779745827993383872L;
/** Constructor for the ObjectExistsException object */
public ObjectExistsException()
{
super();
}
/**
* Constructor for the ObjectExistsException object
* @param message
*/
public ObjectExistsException( String message )
{
super( message );
}
}
ObjectNotFoundException.java 0000664 0000000 0000000 00000003004 12521130655 0041162 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access/exception package org.apache.commons.jcs.access.exception;
/*
* 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.
*/
/**
* ObjectNotFoundException
*
* TODO see if we can remove this.
*
* This is thrown from the composite cache if you as for the element attributes and the element does
* not exist.
*/
public class ObjectNotFoundException
extends CacheException
{
/** Don't change. */
private static final long serialVersionUID = 5684353421076546842L;
/** Constructor for the ObjectNotFoundException object */
public ObjectNotFoundException()
{
super();
}
/**
* Constructor for the ObjectNotFoundException object
* @param message
*/
public ObjectNotFoundException( String message )
{
super( message );
}
}
package.html 0000664 0000000 0000000 00000001773 12521130655 0034053 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/access
Contains classes for accessing the cache. The CacheAccess interface, which
all classes in this package implement, provides all the methods a client
should need to use a Cache.
libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/ 0000775 0000000 0000000 00000000000 12521130655 0031470 5 ustar 00root root 0000000 0000000 CacheElementInfo.java 0000664 0000000 0000000 00000006437 12521130655 0035417 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin package org.apache.commons.jcs.admin;
/*
* 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.beans.ConstructorProperties;
/**
* Stores info on a cache element for the template
*/
public class CacheElementInfo
{
/** element key */
private final String key;
/** is it eternal */
private final boolean eternal;
/** when it was created */
private final String createTime;
/** max life */
private final long maxLifeSeconds;
/** when it will expire */
private final long expiresInSeconds;
/**
* Parameterized constructor
*
* @param key element key
* @param eternal is it eternal
* @param createTime when it was created
* @param maxLifeSeconds max life
* @param expiresInSeconds when it will expire
*/
@ConstructorProperties({"key", "eternal", "createTime", "maxLifeSeconds", "expiresInSeconds"})
public CacheElementInfo(String key, boolean eternal, String createTime,
long maxLifeSeconds, long expiresInSeconds)
{
super();
this.key = key;
this.eternal = eternal;
this.createTime = createTime;
this.maxLifeSeconds = maxLifeSeconds;
this.expiresInSeconds = expiresInSeconds;
}
/**
* @return a string representation of the key
*/
public String getKey()
{
return this.key;
}
/**
* @return true if the item does not expire
*/
public boolean isEternal()
{
return this.eternal;
}
/**
* @return the time the object was created
*/
public String getCreateTime()
{
return this.createTime;
}
/**
* Ignored if isEternal
* @return the longest this object can live.
*/
public long getMaxLifeSeconds()
{
return this.maxLifeSeconds;
}
/**
* Ignored if isEternal
* @return how many seconds until this object expires.
*/
public long getExpiresInSeconds()
{
return this.expiresInSeconds;
}
/**
* @return string info on the item
*/
@Override
public String toString()
{
StringBuilder buf = new StringBuilder();
buf.append( "\nCacheElementInfo " );
buf.append( "\n Key [" ).append( getKey() ).append( "]" );
buf.append( "\n Eternal [" ).append( isEternal() ).append( "]" );
buf.append( "\n CreateTime [" ).append( getCreateTime() ).append( "]" );
buf.append( "\n MaxLifeSeconds [" ).append( getMaxLifeSeconds() ).append( "]" );
buf.append( "\n ExpiresInSeconds [" ).append( getExpiresInSeconds() ).append( "]" );
return buf.toString();
}
}
CacheRegionInfo.java 0000664 0000000 0000000 00000011271 12521130655 0035241 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin package org.apache.commons.jcs.admin;
/*
* 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.beans.ConstructorProperties;
/**
* Stores info on a cache region for the template
*/
public class CacheRegionInfo
{
/** The name of the cache region */
private final String cacheName;
/** The size of the cache region */
private final int cacheSize;
/** The status of the cache region */
private final String cacheStatus;
/** The statistics of the cache region */
private final String cacheStatistics;
/** The number of memory hits in the cache region */
private final int hitCountRam;
/** The number of auxiliary hits in the cache region */
private final int hitCountAux;
/** The number of misses in the cache region because the items were not found */
private final int missCountNotFound;
/** The number of misses in the cache region because the items were expired */
private final int missCountExpired;
/** The number of bytes counted so far, will be a total of all items */
private final long byteCount;
/**
* Parameterized constructor
*
* @param cacheName The name of the cache region
* @param cacheSize The size of the cache region
* @param cacheStatus The status of the cache region
* @param cacheStatistics The statistics of the cache region
* @param hitCountRam The number of memory hits in the cache region
* @param hitCountAux The number of auxiliary hits in the cache region
* @param missCountNotFound The number of misses in the cache region because the items were not found
* @param missCountExpired The number of misses in the cache region because the items were expired
* @param byteCount The number of bytes counted so far, will be a total of all items
*/
@ConstructorProperties({"cacheName", "cacheSize", "cacheStatus", "cacheStatistics",
"hitCountRam", "hitCountAux", "missCountNotFound", "missCountExpired", "byteCount"})
public CacheRegionInfo(String cacheName, int cacheSize, String cacheStatus,
String cacheStatistics, int hitCountRam, int hitCountAux,
int missCountNotFound, int missCountExpired, long byteCount)
{
super();
this.cacheName = cacheName;
this.cacheSize = cacheSize;
this.cacheStatus = cacheStatus;
this.cacheStatistics = cacheStatistics;
this.hitCountRam = hitCountRam;
this.hitCountAux = hitCountAux;
this.missCountNotFound = missCountNotFound;
this.missCountExpired = missCountExpired;
this.byteCount = byteCount;
}
/**
* @return the cacheName
*/
public String getCacheName()
{
return this.cacheName;
}
/**
* @return the cacheSize
*/
public int getCacheSize()
{
return this.cacheSize;
}
/**
* @return a status string
*/
public String getCacheStatus()
{
return this.cacheStatus;
}
/**
* Return the statistics for the region.
*
* @return String
*/
public String getCacheStatistics()
{
return this.cacheStatistics;
}
/**
* @return the hitCountRam
*/
public int getHitCountRam()
{
return hitCountRam;
}
/**
* @return the hitCountAux
*/
public int getHitCountAux()
{
return hitCountAux;
}
/**
* @return the missCountNotFound
*/
public int getMissCountNotFound()
{
return missCountNotFound;
}
/**
* @return the missCountExpired
*/
public int getMissCountExpired()
{
return missCountExpired;
}
/**
* @return total byte count
*/
public long getByteCount()
{
return this.byteCount;
}
/**
* @return string info on the region
*/
@Override
public String toString()
{
StringBuilder buf = new StringBuilder();
buf.append( "\nCacheRegionInfo " );
if ( cacheName != null )
{
buf.append( "\n CacheName [" + cacheName + "]" );
buf.append( "\n Status [" + cacheStatus + "]" );
}
buf.append( "\n ByteCount [" + getByteCount() + "]" );
return buf.toString();
}
}
CountingOnlyOutputStream.java 0000664 0000000 0000000 00000003746 12521130655 0037313 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin package org.apache.commons.jcs.admin;
/*
* 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;
import java.io.OutputStream;
/**
* Keeps track of the number of bytes written to it, but doesn't write them anywhere.
*/
public class CountingOnlyOutputStream
extends OutputStream
{
/** number of bytes passed through */
private int count; // TODO should this be long?
/**
* count as we write.
*
* @param b
* @throws IOException
*/
@Override
public void write( byte[] b )
throws IOException
{
this.count += b.length;
}
/**
* count as we write.
*
* @param b
* @param off
* @param len
* @throws IOException
*/
@Override
public void write( byte[] b, int off, int len )
throws IOException
{
this.count += len;
}
/**
* count as we write.
*
* @param b
* @throws IOException
*/
@Override
public void write( int b )
throws IOException
{
this.count++;
}
/**
* The number of bytes that have passed through this stream.
*
* @return int
*/
public int getCount()
{
return this.count;
}
}
JCSAdmin.jsp 0000664 0000000 0000000 00000020631 12521130655 0033521 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin <%--
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.
--%>
<%@page import="org.apache.commons.jcs.JCS"%>
<%@page import="org.apache.commons.jcs.access.CacheAccess" %>
<%@page import="org.apache.commons.jcs.admin.CacheElementInfo" %>
<%@page import="org.apache.commons.jcs.admin.CacheRegionInfo" %>
<%@page import="java.io.Serializable" %>
<%@page import="java.util.HashMap" %>
JCS Admin Servlet
<%
String CACHE_NAME_PARAM = "cacheName";
String ACTION_PARAM = "action";
String CLEAR_ALL_REGIONS_ACTION = "clearAllRegions";
String CLEAR_REGION_ACTION = "clearRegion";
String REMOVE_ACTION = "remove";
String DETAIL_ACTION = "detail";
String REGION_SUMMARY_ACTION = "regionSummary";
String ITEM_ACTION = "item";
String KEY_PARAM = "key";
String SILENT_PARAM = "silent";
String DEFAULT_TEMPLATE_NAME = "DEFAULT";
String REGION_DETAIL_TEMPLATE_NAME = "DETAIL";
String ITEM_TEMPLATE_NAME = "ITEM";
String REGION_SUMMARY_TEMPLATE_NAME = "SUMMARY";
String templateName = DEFAULT_TEMPLATE_NAME;
HashMap context = new HashMap();
// Get cacheName for actions from request (might be null)
String cacheName = request.getParameter( CACHE_NAME_PARAM );
if ( cacheName != null )
{
cacheName = cacheName.trim();
}
// If an action was provided, handle it
String action = request.getParameter( ACTION_PARAM );
if ( action != null )
{
if ( action.equals( CLEAR_ALL_REGIONS_ACTION ) )
{
jcsBean.clearAllRegions();
}
else if ( action.equals( CLEAR_REGION_ACTION ) )
{
if ( cacheName == null )
{
// Not Allowed
}
else
{
jcsBean.clearRegion( cacheName );
}
}
else if ( action.equals( REMOVE_ACTION ) )
{
String[] keys = request.getParameterValues( KEY_PARAM );
for ( int i = 0; i < keys.length; i++ )
{
jcsBean.removeItem( cacheName, keys[ i ] );
}
templateName = REGION_DETAIL_TEMPLATE_NAME;
}
else if ( action.equals( DETAIL_ACTION ) )
{
templateName = REGION_DETAIL_TEMPLATE_NAME;
}
else if ( action.equals( ITEM_ACTION ) )
{
templateName = ITEM_TEMPLATE_NAME;
}
else if ( action.equals( REGION_SUMMARY_ACTION ) )
{
templateName = REGION_SUMMARY_TEMPLATE_NAME;
}
}
if ( request.getParameter( SILENT_PARAM ) != null )
{
// If silent parameter was passed, no output should be produced.
//return null;
}
else
{
// Populate the context based on the template
if ( templateName == REGION_DETAIL_TEMPLATE_NAME )
{
//context.put( "cacheName", cacheName );
context.put( "elementInfoRecords", jcsBean.buildElementInfo( cacheName ) );
}
else if ( templateName == DEFAULT_TEMPLATE_NAME )
{
context.put( "cacheInfoRecords", jcsBean.buildCacheInfo() );
}
}
///////////////////////////////////////////////////////////////////////////////////
//handle display
if ( templateName == ITEM_TEMPLATE_NAME )
{
String key = request.getParameter( KEY_PARAM );
if ( key != null )
{
key = key.trim();
}
CacheAccess cache = JCS.getInstance( cacheName );
org.apache.commons.jcs.engine.behavior.ICacheElement, ?> element = cache.getCacheElement( key );
%>
Item for key [<%=key%>] in region [<%=cacheName%>]
Region Detail
| All Regions
<%=element%>
<%
}
else if ( templateName == REGION_SUMMARY_TEMPLATE_NAME )
{
%>
Summary for region [<%=cacheName%>]
All Regions
<%
CacheAccess, ?> cache = JCS.getInstance( cacheName );
String stats = cache.getStats();
%>
Stats for region [<%=cacheName%>]
<%=stats%>
<%
}
else if ( templateName == REGION_DETAIL_TEMPLATE_NAME )
{
%>
Detail for region [<%=cacheName%>]
All Regions
Key |
Eternal? |
Create time |
Max Life (s) |
Till Expiration (s) |
<%
CacheElementInfo[] list = (CacheElementInfo[]) context.get( "elementInfoRecords" );
for (CacheElementInfo element : list)
{
%>
<%=element.getKey()%> |
<%=element.isEternal()%> |
<%=element.getCreateTime()%> |
<%=element.getMaxLifeSeconds()%> |
<%=element.getExpiresInSeconds()%> |
View
| Remove
|
<%
}
CacheAccess, ?> cache = JCS.getInstance( cacheName );
String stats = cache.getStats();
%>
Stats for region [<%=cacheName%>]
<%=stats%>
<%
}
else
{
%>
Cache Regions
These are the regions which are currently defined in the cache. 'Items' and
'Bytes' refer to the elements currently in memory (not spooled). You can clear
all items for a region by selecting 'Remove all' next to the desired region
below. You can also Clear all regions
which empties the entire cache.
Cache Name |
Items |
Bytes |
Status |
Memory Hits |
Aux Hits |
Not Found Misses |
Expired Misses |
<%
CacheRegionInfo[] list = (CacheRegionInfo[]) context.get( "cacheInfoRecords" );
for (CacheRegionInfo record : listSelect)
{
%>
<%=record.getCacheName()%> |
<%=record.getCacheSize()%> |
<%=record.getByteCount()%> |
<%=record.getCacheStatus()%> |
<%=record.getHitCountRam()%> |
<%=record.getHitCountAux()%> |
<%=record.getMissCountNotFound()%> |
<%=record.getMissCountExpired()%> |
Summary
| Detail
| Clear
|
<%
}
%>
<%
}
%>
JCSAdminBean.java 0000664 0000000 0000000 00000036173 12521130655 0034444 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin package org.apache.commons.jcs.admin;
/*
* 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.jcs.access.exception.CacheException;
import org.apache.commons.jcs.auxiliary.remote.server.RemoteCacheServer;
import org.apache.commons.jcs.auxiliary.remote.server.RemoteCacheServerFactory;
import org.apache.commons.jcs.engine.CacheElementSerialized;
import org.apache.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.behavior.IElementAttributes;
import org.apache.commons.jcs.engine.control.CompositeCache;
import org.apache.commons.jcs.engine.control.CompositeCacheManager;
import org.apache.commons.jcs.engine.memory.behavior.IMemoryCache;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.text.DateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.Set;
/**
* A servlet which provides HTTP access to JCS. Allows a summary of regions to be viewed, and
* removeAll to be run on individual regions or all regions. Also provides the ability to remove
* items (any number of key arguments can be provided with action 'remove'). Should be initialized
* with a properties file that provides at least a classpath resource loader.
*/
public class JCSAdminBean implements JCSJMXBean
{
/** The cache manager. */
private final CompositeCacheManager cacheHub;
/**
* Default constructor
*/
public JCSAdminBean()
{
super();
try
{
this.cacheHub = CompositeCacheManager.getInstance();
}
catch (CacheException e)
{
throw new RuntimeException("Could not retrieve cache manager instance", e);
}
}
/**
* Parameterized constructor
*
* @param cacheHub the cache manager instance
*/
public JCSAdminBean(CompositeCacheManager cacheHub)
{
super();
this.cacheHub = cacheHub;
}
/**
* Builds up info about each element in a region.
*
* @param cacheName
* @return Array of CacheElementInfo objects
* @throws Exception
*/
@Override
public CacheElementInfo[] buildElementInfo( String cacheName )
throws Exception
{
CompositeCache cache = cacheHub.getCache( cacheName );
Serializable[] keys = cache.getMemoryCache().getKeySet().toArray(new Serializable[0]);
// Attempt to sort keys according to their natural ordering. If that
// fails, get the key array again and continue unsorted.
try
{
Arrays.sort( keys );
}
catch ( Exception e )
{
keys = cache.getMemoryCache().getKeySet().toArray(new Serializable[0]);
}
LinkedList records = new LinkedList();
ICacheElement element;
IElementAttributes attributes;
CacheElementInfo elementInfo;
DateFormat format = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT );
long now = System.currentTimeMillis();
for (Serializable key : keys)
{
element = cache.getMemoryCache().getQuiet( key );
attributes = element.getElementAttributes();
elementInfo = new CacheElementInfo(
String.valueOf( key ),
attributes.getIsEternal(),
format.format(new Date(attributes.getCreateTime())),
attributes.getMaxLife(),
(now - attributes.getCreateTime() - attributes.getMaxLife() * 1000 ) / -1000);
records.add( elementInfo );
}
return records.toArray(new CacheElementInfo[0]);
}
/**
* Builds up data on every region.
*
* TODO we need a most light weight method that does not count bytes. The byte counting can
* really swamp a server.
* @return list of CacheRegionInfo objects
* @throws Exception
*/
@Override
public CacheRegionInfo[] buildCacheInfo()
throws Exception
{
String[] cacheNames = cacheHub.getCacheNames();
Arrays.sort( cacheNames );
LinkedList cacheInfo = new LinkedList();
CacheRegionInfo regionInfo;
CompositeCache, ?> cache;
for ( int i = 0; i < cacheNames.length; i++ )
{
cache = cacheHub.getCache( cacheNames[i] );
regionInfo = new CacheRegionInfo(
cache.getCacheName(),
cache.getSize(),
cache.getStatus().toString(),
cache.getStats(),
cache.getHitCountRam(),
cache.getHitCountAux(),
cache.getMissCountNotFound(),
cache.getMissCountExpired(),
getByteCount( cache ));
cacheInfo.add( regionInfo );
}
return cacheInfo.toArray(new CacheRegionInfo[0]);
}
/**
* Tries to estimate how much data is in a region. This is expensive. If there are any non serializable objects in
* the region or an error occurs, suppresses exceptions and returns 0.
*
*
* @return int The size of the region in bytes.
*/
@Override
public int getByteCount(String cacheName)
{
return getByteCount(cacheHub.getCache(cacheName));
}
/**
* Tries to estimate how much data is in a region. This is expensive. If there are any non serializable objects in
* the region or an error occurs, suppresses exceptions and returns 0.
*
*
* @return int The size of the region in bytes.
*/
public int getByteCount(CompositeCache cache)
{
if (cache == null)
{
throw new IllegalArgumentException("The cache object specified was null.");
}
long size = 0;
IMemoryCache memCache = cache.getMemoryCache();
for (K key : memCache.getKeySet())
{
ICacheElement ice = null;
try
{
ice = memCache.get(key);
}
catch (IOException e)
{
throw new RuntimeException("IOException while trying to get a cached element", e);
}
if (ice == null)
{
continue;
}
if (ice instanceof CacheElementSerialized)
{
size = size + ((CacheElementSerialized) ice).getSerializedValue().length;
}
else
{
Object element = ice.getVal();
//CountingOnlyOutputStream: Keeps track of the number of bytes written to it, but doesn't write them anywhere.
CountingOnlyOutputStream counter = new CountingOnlyOutputStream();
ObjectOutputStream out = null;
try
{
out = new ObjectOutputStream(counter);
out.writeObject(element);
}
catch (IOException e)
{
throw new RuntimeException("IOException while trying to measure the size of the cached element", e);
}
finally
{
try
{
if (out != null)
{
out.close();
}
}
catch (IOException e)
{
// ignore
}
try
{
counter.close();
}
catch (IOException e)
{
// ignore
}
}
// 4 bytes lost for the serialization header
size = size + counter.getCount() - 4;
}
}
if (size > Integer.MAX_VALUE)
{
throw new IllegalStateException("The size of cache " + cache.getCacheName() + " (" + size + " bytes) is too large to be represented as an integer.");
}
return (int) size;
}
/**
* Clears all regions in the cache.
*
* If this class is running within a remote cache server, clears all regions via the RemoteCacheServer
* API, so that removes will be broadcast to client machines. Otherwise clears all regions in the cache directly via
* the usual cache API.
*/
@Override
public void clearAllRegions() throws IOException
{
if (RemoteCacheServerFactory.getRemoteCacheServer() == null)
{
// Not running in a remote cache server.
// Remove objects from the cache directly, as no need to broadcast removes to client machines...
String[] names = cacheHub.getCacheNames();
for (int i = 0; i < names.length; i++)
{
cacheHub.getCache(names[i]).removeAll();
}
}
else
{
// Running in a remote cache server.
// Remove objects via the RemoteCacheServer API, so that removes will be broadcast to client machines...
try
{
String[] cacheNames = cacheHub.getCacheNames();
// Call remoteCacheServer.removeAll(String) for each cacheName...
RemoteCacheServer, ?> remoteCacheServer = RemoteCacheServerFactory.getRemoteCacheServer();
for (int i = 0; i < cacheNames.length; i++)
{
String cacheName = cacheNames[i];
remoteCacheServer.removeAll(cacheName);
}
}
catch (IOException e)
{
throw new IllegalStateException("Failed to remove all elements from all cache regions: " + e, e);
}
}
}
/**
* Clears a particular cache region.
*
* If this class is running within a remote cache server, clears the region via the RemoteCacheServer
* API, so that removes will be broadcast to client machines. Otherwise clears the region directly via the usual
* cache API.
*/
@Override
public void clearRegion(String cacheName) throws IOException
{
if (cacheName == null)
{
throw new IllegalArgumentException("The cache name specified was null.");
}
if (RemoteCacheServerFactory.getRemoteCacheServer() == null)
{
// Not running in a remote cache server.
// Remove objects from the cache directly, as no need to broadcast removes to client machines...
cacheHub.getCache(cacheName).removeAll();
}
else
{
// Running in a remote cache server.
// Remove objects via the RemoteCacheServer API, so that removes will be broadcast to client machines...
try
{
// Call remoteCacheServer.removeAll(String)...
RemoteCacheServer, ?> remoteCacheServer = RemoteCacheServerFactory.getRemoteCacheServer();
remoteCacheServer.removeAll(cacheName);
}
catch (IOException e)
{
throw new IllegalStateException("Failed to remove all elements from cache region [" + cacheName + "]: " + e, e);
}
}
}
/**
* Removes a particular item from a particular region.
*
* If this class is running within a remote cache server, removes the item via the RemoteCacheServer
* API, so that removes will be broadcast to client machines. Otherwise clears the region directly via the usual
* cache API.
*
* @param cacheName
* @param key
*
* @throws IOException
*/
@Override
public void removeItem(String cacheName, String key) throws IOException
{
if (cacheName == null)
{
throw new IllegalArgumentException("The cache name specified was null.");
}
if (key == null)
{
throw new IllegalArgumentException("The key specified was null.");
}
if (RemoteCacheServerFactory.getRemoteCacheServer() == null)
{
// Not running in a remote cache server.
// Remove objects from the cache directly, as no need to broadcast removes to client machines...
cacheHub.getCache(cacheName).remove(key);
}
else
{
// Running in a remote cache server.
// Remove objects via the RemoteCacheServer API, so that removes will be broadcast to client machines...
try
{
Object keyToRemove = null;
CompositeCache, ?> cache = CompositeCacheManager.getInstance().getCache(cacheName);
// A String key was supplied, but to remove elements via the RemoteCacheServer API, we need the
// actual key object as stored in the cache (i.e. a Serializable object). To find the key in this form,
// we iterate through all keys stored in the memory cache until we find one whose toString matches
// the string supplied...
Set> allKeysInCache = cache.getMemoryCache().getKeySet();
for (Object keyInCache : allKeysInCache)
{
if (keyInCache.toString().equals(key))
{
if (keyToRemove == null)
{
keyToRemove = keyInCache;
}
else
{
// A key matching the one specified was already found...
throw new IllegalStateException("Unexpectedly found duplicate keys in the cache region matching the key specified.");
}
}
}
if (keyToRemove == null)
{
throw new IllegalStateException("No match for this key could be found in the set of keys retrieved from the memory cache.");
}
// At this point, we have retrieved the matching K key.
// Call remoteCacheServer.remove(String, Serializable)...
RemoteCacheServer remoteCacheServer = RemoteCacheServerFactory.getRemoteCacheServer();
remoteCacheServer.remove(cacheName, key);
}
catch (Exception e)
{
throw new IllegalStateException("Failed to remove element with key [" + key + ", " + key.getClass() + "] from cache region [" + cacheName + "]: " + e, e);
}
}
}
}
JCSJMXBean.java 0000664 0000000 0000000 00000006147 12521130655 0034050 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin package org.apache.commons.jcs.admin;
/*
* 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 javax.management.MXBean;
import java.io.IOException;
/**
* A MXBean to expose the JCS statistics to JMX
*/
@MXBean
public interface JCSJMXBean
{
/**
* Builds up info about each element in a region.
*
* @param cacheName
* @return Array of CacheElementInfo objects
* @throws Exception
*/
CacheElementInfo[] buildElementInfo( String cacheName ) throws Exception;
/**
* Builds up data on every region.
*
* TODO we need a most light weight method that does not count bytes. The byte counting can
* really swamp a server.
* @return Array of CacheRegionInfo objects
* @throws Exception
*/
CacheRegionInfo[] buildCacheInfo() throws Exception;
/**
* Tries to estimate how much data is in a region. This is expensive. If there are any non serializable objects in
* the region or an error occurs, suppresses exceptions and returns 0.
*
*
* @return int The size of the region in bytes.
*/
int getByteCount(String cacheName);
/**
* Clears all regions in the cache.
*
* If this class is running within a remote cache server, clears all regions via the RemoteCacheServer
* API, so that removes will be broadcast to client machines. Otherwise clears all regions in the cache directly via
* the usual cache API.
*/
void clearAllRegions() throws IOException;
/**
* Clears a particular cache region.
*
* If this class is running within a remote cache server, clears the region via the RemoteCacheServer
* API, so that removes will be broadcast to client machines. Otherwise clears the region directly via the usual
* cache API.
*/
void clearRegion(String cacheName) throws IOException;
/**
* Removes a particular item from a particular region.
*
* If this class is running within a remote cache server, removes the item via the RemoteCacheServer
* API, so that removes will be broadcast to client machines. Otherwise clears the region directly via the usual
* cache API.
*
* @param cacheName
* @param key
*
* @throws IOException
*/
void removeItem(String cacheName, String key) throws IOException;
}
libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/servlet/ 0000775 0000000 0000000 00000000000 12521130655 0033154 5 ustar 00root root 0000000 0000000 JCSAdminServlet.java 0000664 0000000 0000000 00000013121 12521130655 0036673 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/servlet package org.apache.commons.jcs.admin.servlet;
/*
* 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.jcs.admin.JCSAdminBean;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import org.apache.velocity.tools.view.VelocityViewServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* A servlet which provides HTTP access to JCS. Allows a summary of regions to
* be viewed, and removeAll to be run on individual regions or all regions. Also
* provides the ability to remove items (any number of key arguments can be
* provided with action 'remove'). Should be initialized with a properties file
* that provides at least a classpath resource loader. Since this extends
* VelocityServlet, which uses the singleton model for velocity, it will share
* configuration with any other Velocity in the same JVM.
*
* Initialization in a webapp will look something like this:
*
*
*
*
* [servlet]
* [servlet-name]JCSAdminServlet[/servlet-name]
* [servlet-class]org.apache.commons.jcs.admin.servlet.JCSAdminServlet[/servlet-class]
* [init-param]
* [param-name]properties[/param-name]
* [param-value]WEB-INF/conf/JCSAdminServlet.velocity.properties[/param-value]
* [/init-param]
* [/servlet]
*
*
*
*
* FIXME: It would be nice to use the VelocityEngine model so this can be truly
* standalone. Right now if you run it in the same container as, say, turbine,
* turbine must be run first to ensure it's config takes precedence.
*
*/
public class JCSAdminServlet
extends VelocityViewServlet
{
private static final long serialVersionUID = -5519844149238645275L;
private static final String DEFAULT_TEMPLATE_NAME = "/org/apache/jcs/admin/servlet/JCSAdminServletDefault.vm";
private static final String REGION_DETAIL_TEMPLATE_NAME = "/org/apache/jcs/admin/servlet/JCSAdminServletRegionDetail.vm";
// Keys for parameters
private static final String CACHE_NAME_PARAM = "cacheName";
private static final String ACTION_PARAM = "action";
private static final String KEY_PARAM = "key";
private static final String SILENT_PARAM = "silent";
// Possible values for 'action' parameter
private static final String CLEAR_ALL_REGIONS_ACTION = "clearAllRegions";
private static final String CLEAR_REGION_ACTION = "clearRegion";
private static final String REMOVE_ACTION = "remove";
private static final String DETAIL_ACTION = "detail";
/**
* Velocity based admin servlet.
*
* @param request
* @param response
* @param context
* @return Template
* @throws Exception
*
*/
@Override
protected Template handleRequest( HttpServletRequest request, HttpServletResponse response, Context context )
{
JCSAdminBean admin = new JCSAdminBean();
String templateName = DEFAULT_TEMPLATE_NAME;
// Get cacheName for actions from request (might be null)
String cacheName = request.getParameter( CACHE_NAME_PARAM );
// If an action was provided, handle it
String action = request.getParameter( ACTION_PARAM );
try
{
if ( action != null )
{
if ( action.equals( CLEAR_ALL_REGIONS_ACTION ) )
{
admin.clearAllRegions();
}
else if ( action.equals( CLEAR_REGION_ACTION ) )
{
if ( cacheName != null )
{
admin.clearRegion( cacheName );
}
}
else if ( action.equals( REMOVE_ACTION ) )
{
String[] keys = request.getParameterValues( KEY_PARAM );
for ( int i = 0; i < keys.length; i++ )
{
admin.removeItem( cacheName, keys[i] );
}
templateName = REGION_DETAIL_TEMPLATE_NAME;
}
else if ( action.equals( DETAIL_ACTION ) )
{
templateName = REGION_DETAIL_TEMPLATE_NAME;
}
}
}
catch (IOException e)
{
getLog().error("Could not execute action.", e);
return null;
}
if ( request.getParameter( SILENT_PARAM ) != null )
{
// If silent parameter was passed, no output should be produced.
return null;
}
// Populate the context based on the template
try
{
if ( templateName == REGION_DETAIL_TEMPLATE_NAME )
{
context.put( "cacheName", cacheName );
context.put( "elementInfoRecords", admin.buildElementInfo( cacheName ) );
}
else if ( templateName == DEFAULT_TEMPLATE_NAME )
{
context.put( "cacheInfoRecords", admin.buildCacheInfo() );
}
}
catch (Exception e)
{
getLog().error("Could not populate context.", e);
}
return getTemplate( templateName );
}
}
JCSAdminServletDefault.vm 0000664 0000000 0000000 00000004301 12521130655 0037701 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/servlet ## 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.
JCS Admin Servlet
Cache Regions
These are the regions which are currently defined in the cache. 'Items' and
'Bytes' refer to the elements currently in memory (not spooled). You can clear
all items for a region by selecting 'Remove all' next to the desired region
below. You can also Clear all regions
which empties the entire cache.
Cache Name |
Items |
Bytes |
Status |
Memory Hits |
Aux Hits |
Not Found Misses |
Expired Misses |
#foreach ( $record in $cacheInfoRecords )
$record.cache.cacheName |
$record.cache.size |
$record.byteCount |
$record.status |
$record.cache.hitCountRam |
$record.cache.hitCountAux |
$record.cache.missCountNotFound |
$record.cache.missCountExpired |
Detail
| Remove all
|
#end
JCSAdminServletRegionDetail.vm 0000664 0000000 0000000 00000003031 12521130655 0040662 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/admin/servlet ## 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.
JCS Admin Servlet Region Detail
Keys for region: $cacheName
Key |
Eternal? |
Create time |
Max Life (s) |
Till Expiration (s) |
#foreach ( $element in $elementInfoRecords )
$element.key |
$element.eternal |
$element.createTime |
$element.maxLifeSeconds |
$element.expiresInSeconds |
Remove |
#end
libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/ 0000775 0000000 0000000 00000000000 12521130655 0032407 5 ustar 00root root 0000000 0000000 AbstractAuxiliaryCache.java 0000664 0000000 0000000 00000014004 12521130655 0037551 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary package org.apache.commons.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.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.behavior.IElementSerializer;
import org.apache.commons.jcs.engine.logging.CacheEvent;
import org.apache.commons.jcs.engine.logging.behavior.ICacheEvent;
import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
import org.apache.commons.jcs.engine.match.KeyMatcherPatternImpl;
import org.apache.commons.jcs.engine.match.behavior.IKeyMatcher;
import org.apache.commons.jcs.utils.serialization.StandardSerializer;
/** This holds convenience methods used by most auxiliary caches. */
public abstract class AbstractAuxiliaryCache
implements AuxiliaryCache
{
/** An optional event logger */
private ICacheEventLogger cacheEventLogger;
/** The serializer. Uses a standard serializer by default. */
private IElementSerializer elementSerializer = new StandardSerializer();
/** Key matcher used by the getMatching API */
private IKeyMatcher keyMatcher = new KeyMatcherPatternImpl();
/**
* Logs an event if an event logger is configured.
*
* @param item
* @param eventName
* @return ICacheEvent
*/
protected ICacheEvent createICacheEvent( ICacheElement item, String eventName )
{
if ( cacheEventLogger == null )
{
return new CacheEvent();
}
String diskLocation = getEventLoggingExtraInfo();
String regionName = null;
K key = null;
if ( item != null )
{
regionName = item.getCacheName();
key = item.getKey();
}
return cacheEventLogger.createICacheEvent( getAuxiliaryCacheAttributes().getName(), regionName, eventName,
diskLocation, key );
}
/**
* Logs an event if an event logger is configured.
*
* @param regionName
* @param key
* @param eventName
* @return ICacheEvent
*/
protected ICacheEvent createICacheEvent( String regionName, T key, String eventName )
{
if ( cacheEventLogger == null )
{
return new CacheEvent();
}
String diskLocation = getEventLoggingExtraInfo();
return cacheEventLogger.createICacheEvent( getAuxiliaryCacheAttributes().getName(), regionName, eventName,
diskLocation, key );
}
/**
* Logs an event if an event logger is configured.
*
* @param cacheEvent
*/
protected void logICacheEvent( ICacheEvent cacheEvent )
{
if ( cacheEventLogger != null )
{
cacheEventLogger.logICacheEvent( cacheEvent );
}
}
/**
* Logs an event if an event logger is configured.
*
* @param source
* @param eventName
* @param optionalDetails
*/
protected void logApplicationEvent( String source, String eventName, String optionalDetails )
{
if ( cacheEventLogger != null )
{
cacheEventLogger.logApplicationEvent( source, eventName, optionalDetails );
}
}
/**
* Logs an event if an event logger is configured.
*
* @param source
* @param eventName
* @param errorMessage
*/
protected void logError( String source, String eventName, String errorMessage )
{
if ( cacheEventLogger != null )
{
cacheEventLogger.logError( source, eventName, errorMessage );
}
}
/**
* Gets the extra info for the event log.
*
* @return IP, or disk location, etc.
*/
public abstract String getEventLoggingExtraInfo();
/**
* Allows it to be injected.
*
* @param cacheEventLogger
*/
@Override
public void setCacheEventLogger( ICacheEventLogger cacheEventLogger )
{
this.cacheEventLogger = cacheEventLogger;
}
/**
* Allows it to be injected.
*
* @return cacheEventLogger
*/
public ICacheEventLogger getCacheEventLogger()
{
return this.cacheEventLogger;
}
/**
* Allows you to inject a custom serializer. A good example would be a compressing standard
* serializer.
*
* Does not allow you to set it to null.
*
* @param elementSerializer
*/
@Override
public void setElementSerializer( IElementSerializer elementSerializer )
{
if ( elementSerializer != null )
{
this.elementSerializer = elementSerializer;
}
}
/**
* Allows it to be injected.
*
* @return elementSerializer
*/
public IElementSerializer getElementSerializer()
{
return this.elementSerializer;
}
/**
* Sets the key matcher used by get matching.
*
* @param keyMatcher
*/
@Override
public void setKeyMatcher( IKeyMatcher keyMatcher )
{
if ( keyMatcher != null )
{
this.keyMatcher = keyMatcher;
}
}
/**
* Returns the key matcher used by get matching.
*
* @return keyMatcher
*/
public IKeyMatcher getKeyMatcher()
{
return this.keyMatcher;
}
}
AbstractAuxiliaryCacheAttributes.java 0000664 0000000 0000000 00000006523 12521130655 0041627 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary package org.apache.commons.jcs.auxiliary;
import org.apache.commons.jcs.engine.behavior.ICacheEventQueue;
/*
* 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.
*/
/**
* This has common attributes used by all auxiliaries.
*/
public abstract class AbstractAuxiliaryCacheAttributes
implements AuxiliaryCacheAttributes
{
/** Don't change */
private static final long serialVersionUID = -6594609334959187673L;
/** cacheName */
private String cacheName;
/** name */
private String name;
/** eventQueueType -- pooled, or single threaded */
private ICacheEventQueue.QueueType eventQueueType;
/** Named when pooled */
private String eventQueuePoolName;
/**
* @param name
*/
@Override
public void setCacheName( String name )
{
this.cacheName = name;
}
/**
* Gets the cacheName attribute of the AuxiliaryCacheAttributes object
*
* @return The cacheName value
*/
@Override
public String getCacheName()
{
return this.cacheName;
}
/**
* This is the name of the auxiliary in configuration file.
*
* @see org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes#setName(java.lang.String)
*/
@Override
public void setName( String s )
{
this.name = s;
}
/**
* Gets the name attribute of the AuxiliaryCacheAttributes object
*
* @return The name value
*/
@Override
public String getName()
{
return this.name;
}
/**
* SINGLE is the default. If you choose POOLED, the value of EventQueuePoolName will be used
*
* @param queueType SINGLE or POOLED
*/
@Override
public void setEventQueueType( ICacheEventQueue.QueueType queueType )
{
this.eventQueueType = queueType;
}
/**
* @return SINGLE or POOLED
*/
@Override
public ICacheEventQueue.QueueType getEventQueueType()
{
return eventQueueType;
}
/**
* 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
*/
@Override
public void setEventQueuePoolName( String s )
{
eventQueuePoolName = s;
}
/**
* 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
*/
@Override
public String getEventQueuePoolName()
{
return eventQueuePoolName;
}
}
AbstractAuxiliaryCacheEventLogging.java 0000664 0000000 0000000 00000023664 12521130655 0042076 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary package org.apache.commons.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.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.logging.behavior.ICacheEvent;
import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
/**
* All ICacheEvents are defined as final. Children must implement process events. These are wrapped
* in event log parent calls.
*
* You can override the public method, but if you don't, the default will call getWithTiming.
*/
public abstract class AbstractAuxiliaryCacheEventLogging
extends AbstractAuxiliaryCache
{
/**
* Puts an item into the cache.
*
* @param cacheElement
* @throws IOException
*/
@Override
public void update( ICacheElement cacheElement )
throws IOException
{
updateWithEventLogging( cacheElement );
}
/**
* Puts an item into the cache. Wrapped in logging.
*
* @param cacheElement
* @throws IOException
*/
protected final void updateWithEventLogging( ICacheElement cacheElement )
throws IOException
{
ICacheEvent cacheEvent = createICacheEvent( cacheElement, ICacheEventLogger.UPDATE_EVENT );
try
{
processUpdate( cacheElement );
}
finally
{
logICacheEvent( cacheEvent );
}
}
/**
* Implementation of put.
*
* @param cacheElement
* @throws IOException
*/
protected abstract void processUpdate( ICacheElement cacheElement )
throws IOException;
/**
* Gets the item from the cache.
*
* @param key
* @return ICacheElement, a wrapper around the key, value, and attributes
* @throws IOException
*/
@Override
public ICacheElement get( K key )
throws IOException
{
return getWithEventLogging( key );
}
/**
* Gets the item from the cache. Wrapped in logging.
*
* @param key
* @return ICacheElement, a wrapper around the key, value, and attributes
* @throws IOException
*/
protected final ICacheElement getWithEventLogging( K key )
throws IOException
{
ICacheEvent cacheEvent = createICacheEvent( getCacheName(), key, ICacheEventLogger.GET_EVENT );
try
{
return processGet( key );
}
finally
{
logICacheEvent( cacheEvent );
}
}
/**
* Implementation of get.
*
* @param key
* @return ICacheElement, a wrapper around the key, value, and attributes
* @throws IOException
*/
protected abstract ICacheElement processGet( K key )
throws IOException;
/**
* Gets multiple items from the cache based on the given set of keys.
*
* @param keys
* @return a map of K key to ICacheElement element, or an empty map if there is no
* data in cache for any of these keys
* @throws IOException
*/
@Override
public Map> getMultiple(Set keys)
throws IOException
{
return getMultipleWithEventLogging( keys );
}
/**
* Gets multiple items from the cache based on the given set of keys.
*
* @param keys
* @return a map of K key to ICacheElement element, or an empty map if there is no
* data in cache for any of these keys
* @throws IOException
*/
protected final Map> getMultipleWithEventLogging(Set keys )
throws IOException
{
ICacheEvent cacheEvent = createICacheEvent( getCacheName(), (Serializable) keys,
ICacheEventLogger.GETMULTIPLE_EVENT );
try
{
return processGetMultiple( keys );
}
finally
{
logICacheEvent( cacheEvent );
}
}
/**
* Implementation of getMultiple.
*
* @param keys
* @return a map of K key to ICacheElement element, or an empty map if there is no
* data in cache for any of these keys
* @throws IOException
*/
protected abstract Map> processGetMultiple(Set keys)
throws IOException;
/**
* Gets items from the cache matching the given pattern. Items from memory will replace those
* from remote sources.
*
* This only works with string keys. It's too expensive to do a toString on every key.
*
* Auxiliaries will do their best to handle simple expressions. For instance, the JDBC disk
* cache will convert * to % and . to _
*
* @param pattern
* @return a map of K key to ICacheElement element, or an empty map if there is no
* data matching the pattern.
* @throws IOException
*/
@Override
public Map> getMatching( String pattern )
throws IOException
{
return getMatchingWithEventLogging( pattern );
}
/**
* Gets mmatching items from the cache based on the given pattern.
*
* @param pattern
* @return a map of K key to ICacheElement element, or an empty map if there is no
* data matching the pattern.
* @throws IOException
*/
protected final Map> getMatchingWithEventLogging( String pattern )
throws IOException
{
ICacheEvent cacheEvent = createICacheEvent( getCacheName(), pattern, ICacheEventLogger.GETMATCHING_EVENT );
try
{
return processGetMatching( pattern );
}
finally
{
logICacheEvent( cacheEvent );
}
}
/**
* Implementation of getMatching.
*
* @param pattern
* @return a map of K key to ICacheElement element, or an empty map if there is no
* data matching the pattern.
* @throws IOException
*/
protected abstract Map> processGetMatching( String pattern )
throws IOException;
/**
* Removes the item from the cache. Wraps the remove in event logs.
*
* @param key
* @return boolean, whether or not the item was removed
* @throws IOException
*/
@Override
public boolean remove( K key )
throws IOException
{
return removeWithEventLogging( key );
}
/**
* Removes the item from the cache. Wraps the remove in event logs.
*
* @param key
* @return boolean, whether or not the item was removed
* @throws IOException
*/
protected final boolean removeWithEventLogging( K key )
throws IOException
{
ICacheEvent cacheEvent = createICacheEvent( getCacheName(), key, ICacheEventLogger.REMOVE_EVENT );
try
{
return processRemove( key );
}
finally
{
logICacheEvent( cacheEvent );
}
}
/**
* Specific implementation of remove.
*
* @param key
* @return boolean, whether or not the item was removed
* @throws IOException
*/
protected abstract boolean processRemove( K key )
throws IOException;
/**
* Removes all from the region. Wraps the removeAll in event logs.
*
* @throws IOException
*/
@Override
public void removeAll()
throws IOException
{
removeAllWithEventLogging();
}
/**
* Removes all from the region. Wraps the removeAll in event logs.
*
* @throws IOException
*/
protected final void removeAllWithEventLogging()
throws IOException
{
ICacheEvent cacheEvent = createICacheEvent( getCacheName(), "all", ICacheEventLogger.REMOVEALL_EVENT );
try
{
processRemoveAll();
}
finally
{
logICacheEvent( cacheEvent );
}
}
/**
* Specific implementation of removeAll.
*
* @throws IOException
*/
protected abstract void processRemoveAll()
throws IOException;
/**
* Synchronously dispose the remote cache; if failed, replace the remote handle with a zombie.
*
* @throws IOException
*/
@Override
public void dispose()
throws IOException
{
disposeWithEventLogging();
}
/**
* Synchronously dispose the remote cache; if failed, replace the remote handle with a zombie.
* Wraps the removeAll in event logs.
*
* @throws IOException
*/
protected final void disposeWithEventLogging()
throws IOException
{
ICacheEvent cacheEvent = createICacheEvent( getCacheName(), "none", ICacheEventLogger.DISPOSE_EVENT );
try
{
processDispose();
}
finally
{
logICacheEvent( cacheEvent );
}
}
/**
* Specific implementation of dispose.
*
* @throws IOException
*/
protected abstract void processDispose()
throws IOException;
}
AuxiliaryCache.java 0000664 0000000 0000000 00000005403 12521130655 0036070 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary package org.apache.commons.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.commons.jcs.engine.behavior.ICache;
import org.apache.commons.jcs.engine.behavior.IElementSerializer;
import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
import org.apache.commons.jcs.engine.stats.behavior.IStats;
import java.io.IOException;
import java.util.Set;
/**
* Tag interface for auxiliary caches. Currently this provides no additional methods over what is in
* ICache, but I anticipate that will change. For example, there will be a mechanism for determining
* the type (disk/lateral/remote) of the auxiliary here -- and the existing getCacheType will be
* removed from ICache.
*/
public interface AuxiliaryCache
extends ICache
{
/**
* Get a set of the keys for all elements in the auxiliary cache.
*
* @return a set of the key type
* TODO This should probably be done in chunks with a range passed in. This
* will be a problem if someone puts a 1,000,000 or so items in a
* region.
* @throws IOException if access to the auxiliary cache fails
*/
Set getKeySet() throws IOException;
/**
* @return the historical and statistical data for a region's auxiliary cache.
*/
IStats getStatistics();
/**
* This returns the generic attributes for an auxiliary cache. Most implementations will cast
* this to a more specific type.
*
* @return the attributes for the auxiliary cache
*/
AuxiliaryCacheAttributes getAuxiliaryCacheAttributes();
/**
* Allows you to inject a custom serializer. A good example would be a compressing standard
* serializer.
*
* @param elementSerializer
*/
void setElementSerializer( IElementSerializer elementSerializer );
/**
* Every Auxiliary must allow for the use of an event logger.
*
* @param cacheEventLogger
*/
void setCacheEventLogger( ICacheEventLogger cacheEventLogger );
}
AuxiliaryCacheAttributes.java 0000664 0000000 0000000 00000005247 12521130655 0040145 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary package org.apache.commons.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.commons.jcs.engine.behavior.ICacheEventQueue;
import java.io.Serializable;
/**
* 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 Serializable
{
/**
* Sets the name of the cache, referenced by the appropriate manager.
*
* @param s The new cacheName value
*/
void setCacheName( String s );
/**
* Gets the cacheName attribute of the AuxiliaryCacheAttributes object
*
* @return The cacheName value
*/
String getCacheName();
/**
* Name known by by configurator
*
* @param s The new name value
*/
void setName( String s );
/**
* Gets the name attribute of the AuxiliaryCacheAttributes object
*
* @return The name value
*/
String getName();
/**
* SINGLE is the default. If you choose POOLED, the value of EventQueuePoolName will be used
*
* @param s SINGLE or POOLED
*/
void setEventQueueType( ICacheEventQueue.QueueType s );
/**
* @return SINGLE or POOLED
*/
ICacheEventQueue.QueueType getEventQueueType();
/**
* 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
*/
void setEventQueuePoolName( String s );
/**
* 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
*/
String getEventQueuePoolName();
/**
* Clones
*
* @return a copy
*/
AuxiliaryCacheAttributes copy();
}
AuxiliaryCacheConfigurator.java 0000664 0000000 0000000 00000011457 12521130655 0040461 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary package org.apache.commons.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.commons.jcs.engine.behavior.IElementSerializer;
import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
import org.apache.commons.jcs.utils.config.OptionConverter;
import org.apache.commons.jcs.utils.config.PropertySetter;
import org.apache.commons.jcs.utils.serialization.StandardSerializer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Properties;
/**
* Configuration util for auxiliary caches. I plan to move the auxiliary configuration from the
* composite cache configurator here.
*/
public class AuxiliaryCacheConfigurator
{
/** The logger. */
private static final Log log = LogFactory.getLog( AuxiliaryCacheConfigurator.class );
/** .attributes */
public static final String ATTRIBUTE_PREFIX = ".attributes";
/**
* jcs.auxiliary.NAME.cacheeventlogger=CLASSNAME
*
* jcs.auxiliary.NAME.cacheeventlogger.attributes.CUSTOMPROPERTY=VALUE
*/
public static final String CACHE_EVENT_LOGGER_PREFIX = ".cacheeventlogger";
/**
* jcs.auxiliary.NAME.serializer=CLASSNAME
*
* jcs.auxiliary.NAME.serializer.attributes.CUSTOMPROPERTY=VALUE
*/
public static final String SERIALIZER_PREFIX = ".serializer";
/**
* Parses the event logger config, if there is any for the auxiliary.
*
* @param props
* @param auxPrefix - ex. AUXILIARY_PREFIX + auxName
* @return cacheEventLogger
*/
public static ICacheEventLogger parseCacheEventLogger( Properties props, String auxPrefix )
{
ICacheEventLogger cacheEventLogger = null;
// auxFactory was not previously initialized.
String eventLoggerClassName = auxPrefix + CACHE_EVENT_LOGGER_PREFIX;
cacheEventLogger = OptionConverter.instantiateByKey( props, eventLoggerClassName, null );
if ( cacheEventLogger != null )
{
String cacheEventLoggerAttributePrefix = auxPrefix + CACHE_EVENT_LOGGER_PREFIX + ATTRIBUTE_PREFIX;
PropertySetter.setProperties( cacheEventLogger, props, cacheEventLoggerAttributePrefix + "." );
if ( log.isInfoEnabled() )
{
log.info( "Using custom cache event logger [" + cacheEventLogger + "] for auxiliary [" + auxPrefix
+ "]" );
}
}
else
{
if ( log.isInfoEnabled() )
{
log.info( "No cache event logger defined for auxiliary [" + auxPrefix + "]" );
}
}
return cacheEventLogger;
}
/**
* Parses the element config, if there is any for the auxiliary.
*
* @param props
* @param auxPrefix - ex. AUXILIARY_PREFIX + auxName
* @return cacheEventLogger
*/
public static IElementSerializer parseElementSerializer( Properties props, String auxPrefix )
{
// TODO take in the entire prop key
IElementSerializer elementSerializer = null;
// auxFactory was not previously initialized.
String elementSerializerClassName = auxPrefix + SERIALIZER_PREFIX;
elementSerializer = OptionConverter.instantiateByKey( props, elementSerializerClassName, null );
if ( elementSerializer != null )
{
String attributePrefix = auxPrefix + SERIALIZER_PREFIX + ATTRIBUTE_PREFIX;
PropertySetter.setProperties( elementSerializer, props, attributePrefix + "." );
if ( log.isInfoEnabled() )
{
log.info( "Using custom element serializer [" + elementSerializer + "] for auxiliary [" + auxPrefix
+ "]" );
}
}
else
{
// use the default standard serializer
elementSerializer = new StandardSerializer();
if ( log.isInfoEnabled() )
{
log.info( "Using standard serializer [" + elementSerializer + "] for auxiliary [" + auxPrefix + "]" );
}
}
return elementSerializer;
}
}
AuxiliaryCacheFactory.java 0000664 0000000 0000000 00000004221 12521130655 0037415 0 ustar 00root root 0000000 0000000 libcommons-jcs-java-2.0~beta1/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary package org.apache.commons.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.commons.jcs.engine.behavior.ICompositeCacheManager;
import org.apache.commons.jcs.engine.behavior.IElementSerializer;
import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
/**
* All auxiliary caches must have a factory that the cache configurator can use to create instances.
*/
public interface AuxiliaryCacheFactory
{
/**
* Creates an auxiliary using the supplied attributes. Adds it to the composite cache manager.
*
* @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.
* @param cacheEventLogger
* @param elementSerializer
* @return AuxiliaryCache
*/
AuxiliaryCache