[jbosscache-commits] JBoss Cache SVN: r6884 - in core/branches/flat/src/main/java/org/jboss: cache/config/parsing/element and 11 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Wed Oct 8 12:24:08 EDT 2008
Author: manik.surtani at jboss.com
Date: 2008-10-08 12:24:08 -0400 (Wed, 08 Oct 2008)
New Revision: 6884
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/config/BuddyReplicationConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/CacheLoaderConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/CloneableConfigurationComponent.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationException.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/CustomInterceptorConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/Dynamic.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionRegionConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/MissingPolicyException.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/OldFileFormatException.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/Option.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/PluggableConfigurationComponent.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/RuntimeConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/UnsupportedEvictionImplException.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/XmlParsingConfigurationRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseEvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseSortedEvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionActionPolicy.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionActionPolicy.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithmConfigBase.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionEvent.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionException.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionListEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueueList.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionTimerTask.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NodeEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithm.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithmConfig.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RegionNameConflictException.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RemoveOnEvictActionPolicy.java
core/branches/flat/src/main/java/org/jboss/starobrno/eviction/SortedEvictionQueue.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/BootstrapFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/BuddyManagerFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/EmptyConstructorFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/InterceptorChainFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/ReplicationQueueFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/RuntimeConfigAwareFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/StateTransferFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/StateTransferManagerFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/TransactionManagerFactory.java
Removed:
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/CacheConfig.java
Modified:
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/ConfigFilesConvertor.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/ParsedAttributes.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/RootElementBuilder.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/CustomInterceptorsElementParser.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/BaseTransactionalContextInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InvocationContextInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java
core/branches/flat/src/main/java/org/jboss/starobrno/lock/StripedLockManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntryWrapper.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/RepeatableReadEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionTable.java
Log:
Moved stuff
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/CacheConfigsXmlParser.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,31 +1,31 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.config.parsing;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config.parsing;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.util.FileLookup;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -118,18 +118,11 @@
throw new ConfigurationException("Element " + element + " has no name attribute");
XmlConfigurationParser parser = new XmlConfigurationParser();
- Configuration c;
+ Configuration c = null;
if (parser.isValidElementRoot(element))
{
- // FIXME - This should be using a valid schema!!!
c = parser.parseElementIgnoringRoot(element);
}
- else
- {
- log.warn("Detected legacy configuration file format when parsing configuration file. Migrating to the new (3.x) file format is recommended. See FAQs for details.");
- XmlConfigurationParser2x oldParser = new XmlConfigurationParser2x();
- c = oldParser.parseConfiguration(element);
- }
// Prove that we can successfully clone it
c = c.clone();
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/ConfigFilesConvertor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/ConfigFilesConvertor.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/ConfigFilesConvertor.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-package org.jboss.cache.config.parsing;
+package org.jboss.starobrno.config.parsing;
import org.jboss.cache.util.FileLookup;
import org.w3c.dom.Document;
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/JGroupsStackParser.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,25 +1,25 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.config.parsing;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config.parsing;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/ParsedAttributes.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/ParsedAttributes.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/ParsedAttributes.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-package org.jboss.cache.config.parsing;
+package org.jboss.starobrno.config.parsing;
import org.w3c.dom.Element;
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/RootElementBuilder.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/RootElementBuilder.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/RootElementBuilder.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,29 +1,29 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.config.parsing;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config.parsing;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.ConfigurationException;
+import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.util.xml.JBossEntityResolver;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigHelper.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -19,12 +19,12 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-package org.jboss.cache.config.parsing;
+package org.jboss.starobrno.config.parsing;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.util.BeanUtils;
+import org.jboss.starobrno.config.ConfigurationException;
import org.jboss.util.StringPropertyReplacer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -19,21 +19,21 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-package org.jboss.cache.config.parsing;
+package org.jboss.starobrno.config.parsing;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.BuddyReplicationConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.CustomInterceptorConfig;
-import org.jboss.cache.config.parsing.element.BuddyElementParser;
-import org.jboss.cache.config.parsing.element.CustomInterceptorsElementParser;
-import org.jboss.cache.config.parsing.element.EvictionElementParser;
-import org.jboss.cache.config.parsing.element.LoadersElementParser;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.util.FileLookup;
+import org.jboss.starobrno.config.BuddyReplicationConfig;
+import org.jboss.starobrno.config.CacheLoaderConfig;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.CustomInterceptorConfig;
+import org.jboss.starobrno.config.parsing.element.BuddyElementParser;
+import org.jboss.starobrno.config.parsing.element.CustomInterceptorsElementParser;
+import org.jboss.starobrno.config.parsing.element.EvictionElementParser;
+import org.jboss.starobrno.config.parsing.element.LoadersElementParser;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.ErrorHandler;
Deleted: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser2x.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,597 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.config.parsing;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.RegionManagerImpl;
-import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
-import org.jboss.cache.config.BuddyReplicationConfig;
-import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionAlgorithmConfig;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.eviction.EvictionAlgorithm;
-import org.jboss.cache.eviction.EvictionPolicy;
-import org.jboss.cache.eviction.ModernizablePolicy;
-import org.jboss.cache.util.FileLookup;
-import org.jboss.cache.util.Util;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-
-/**
- * Reads in XMLconfiguration files and spits out a {@link org.jboss.cache.config.Configuration} object. When deployed as a
- * JBoss MBean, this role is performed by the JBoss Microcontainer. This class is only used internally in unit tests
- * or within {@link org.jboss.cache.CacheFactory} implementations for standalone JBoss Cache usage.
- *
- * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
- * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
- * @since 2.00.
- * @deprecated
- */
-public class XmlConfigurationParser2x
-{
- private static final Log log = LogFactory.getLog(XmlConfigurationParser2x.class);
-
- public static final String ATTR = "attribute";
- public static final String NAME = "name";
-
- /**
- * Parses an XML file and returns a new configuration. This method attempts to look for the file name passed in on
- * the classpath. If not found, it will search for the file on the file system instead, treating the name as an
- * absolute path.
- *
- * @param filename the name of the XML file to parse.
- * @return a configured Configuration object representing the configuration in the file
- */
- public Configuration parseFile(String filename)
- {
- InputStream is = new FileLookup().lookupFile(filename);
- if (is == null)
- {
- throw new ConfigurationException("Unable to find config file " + filename + " either in classpath or on the filesystem!");
- }
-
- return parseStream(is);
- }
-
- /**
- * Parses an input stream containing XML text and returns a new configuration.
- *
- * @param stream input stream to parse. SHould not be null.
- * @return a configured Configuration object representing the configuration in the stream
- * @since 2.1.0
- */
- public Configuration parseStream(InputStream stream)
- {
- // loop through all elements in XML.
- Element root = XmlConfigHelper.getDocumentRoot(stream);
- Element mbeanElement = getMBeanElement(root);
-
- return parseConfiguration(mbeanElement);
- }
-
- public Configuration parseConfiguration(Element configurationRoot)
- {
- ParsedAttributes attributes = XmlConfigHelper.extractAttributes(configurationRoot);
-
- // Deal with legacy attributes we no longer support
- handleRemovedAttributes(attributes);
-
- // Deal with legacy attributes that we renamed or otherwise altered
- handleRenamedAttributes(attributes);
-
- Configuration c = new Configuration();
- XmlConfigHelper.setValues(c, attributes.stringAttribs, false, false);
- // Special handling for XML elements -- we hard code the parsing
- setXmlValues(c, attributes.xmlAttribs);
-
- return c;
- }
-
- /**
- * Check for and remove any attributes that were supported in the
- * 1.x releases and no longer are. Log a WARN or throw a
- * {@link ConfigurationException} if any are found. Which is done depends
- * on the attribute:
- * <p/>
- * <ul>
- * <li><i>MultiplexerService</i> -- throws an Exception</li>
- * <li><i>ServiceName</i> -- logs a WARN</li>
- * </ul>
- *
- * @param attributes
- */
- protected void handleRemovedAttributes(ParsedAttributes attributes)
- {
- String evictionPolicy = attributes.stringAttribs.remove("EvictionPolicyClass");
- if (evictionPolicy != null)
- {
- throw new ConfigurationException("XmlConfigurationParser does not " +
- "support the JBC 1.x attribute EvictionPolicyClass. Set the default " +
- "eviction policy via the policyClass element in the EvictionConfig section");
- }
- String multiplexerService = attributes.stringAttribs.remove("MultiplexerService");
- if (multiplexerService != null)
- {
- throw new ConfigurationException("XmlConfigurationParser does not " +
- "support the JBC 1.x attribute MultiplexerService. Inject the " +
- "multiplexer directly using Configuration.getRuntimeConfig().setMuxChannelFactory()");
- }
- String serviceName = attributes.stringAttribs.remove("ServiceName");
- if (serviceName != null)
- {
- log.warn("XmlConfigurationParser does not support the deprecated " +
- "attribute ServiceName. If JMX registration is needed, " +
- "register a CacheJmxWrapper or PojoCacheJmxWrapper in " +
- "JMX with the desired name");
- }
- }
-
- /**
- * Check for any attributes that were supported in the
- * 1.x releases but whose name has changed. Log a WARN if any are found, but
- * convert the attribute to the new name.
- * <p/>
- * <ul>
- * <li><i>UseMbean</i> becomes <i>ExposeManagementStatistics</i></li>
- * </ul>
- *
- * @param attributes
- */
- private void handleRenamedAttributes(ParsedAttributes attributes)
- {
- String keepStats = attributes.stringAttribs.remove("UseInterceptorMbeans");
- if (keepStats != null && attributes.stringAttribs.get("ExposeManagementStatistics") == null)
- {
- log.warn("Found non-existent JBC 1.x attribute 'UseInterceptorMbeans' and replaced " +
- "with 'ExposeManagementStatistics'. Please update your config " +
- "to use the new attribute name");
- attributes.stringAttribs.put("ExposeManagementStatistics", keepStats);
- }
- Element clc = attributes.xmlAttribs.remove("CacheLoaderConfiguration");
- if (clc != null && attributes.xmlAttribs.get("CacheLoaderConfig") == null)
- {
- log.warn("Found non-existent JBC 1.x attribute 'CacheLoaderConfiguration' and replaced " +
- "with 'CacheLoaderConfig'. Please update your config " +
- "to use the new attribute name");
- attributes.xmlAttribs.put("CacheLoaderConfig", clc);
- }
- }
-
- protected Element getMBeanElement(Element root)
- {
- // This is following JBoss convention.
- NodeList list = root.getElementsByTagName(XmlConfigHelper.ROOT);
- if (list == null) throw new ConfigurationException("Can't find " + XmlConfigHelper.ROOT + " tag");
-
- if (list.getLength() > 1) throw new ConfigurationException("Has multiple " + XmlConfigHelper.ROOT + " tag");
-
- Node node = list.item(0);
- Element element;
- if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE)
- {
- element = (Element) node;
- }
- else
- {
- throw new ConfigurationException("Can't find " + XmlConfigHelper.ROOT + " element");
- }
- return element;
- }
-
- protected void setXmlValues(Configuration conf, Map<String, Element> attribs)
- {
- for (Entry<String, Element> entry : attribs.entrySet())
- {
- String propname = entry.getKey();
- if ("BuddyReplicationConfiguration".equals(propname)
- || "BuddyReplicationConfig".equals(propname))
- {
- BuddyReplicationConfig brc = parseBuddyReplicationConfig(entry.getValue());
- conf.setBuddyReplicationConfig(brc);
- }
- else if ("CacheLoaderConfiguration".equals(propname)
- || "CacheLoaderConfig".equals(propname))
- {
- CacheLoaderConfig clc = parseCacheLoaderConfig(entry.getValue());
- conf.setCacheLoaderConfig(clc);
- }
- else if ("EvictionPolicyConfiguration".equals(propname)
- || "EvictionPolicyConfig".equals(propname))
- {
- EvictionConfig ec = parseEvictionConfig(entry.getValue());
- conf.setEvictionConfig(ec);
- }
- else if ("ClusterConfig".equals(propname))
- {
- String jgc = parseClusterConfigXml(entry.getValue());
- conf.setClusterConfig(jgc);
- }
- else
- {
- throw new ConfigurationException("Unknown configuration element " + propname);
- }
- }
- }
-
- private static BuddyReplicationConfig parseBuddyReplicationConfig(Element element)
- {
- BuddyReplicationConfig brc = new BuddyReplicationConfig();
- brc.setEnabled(XmlConfigHelper.readBooleanContents(element, "buddyReplicationEnabled"));
- brc.setDataGravitationRemoveOnFind(XmlConfigHelper.readBooleanContents(element, "dataGravitationRemoveOnFind", true));
- brc.setDataGravitationSearchBackupTrees(XmlConfigHelper.readBooleanContents(element, "dataGravitationSearchBackupTrees", true));
- brc.setAutoDataGravitation(brc.isEnabled() && XmlConfigHelper.readBooleanContents(element, "autoDataGravitation", false));
-
- String strBuddyCommunicationTimeout = XmlConfigHelper.readStringContents(element, "buddyCommunicationTimeout");
- try
- {
- brc.setBuddyCommunicationTimeout(Integer.parseInt(strBuddyCommunicationTimeout));
- }
- catch (Exception e)
- {
- if (log.isTraceEnabled()) log.trace(e.getMessage());
- }
- finally
- {
- if (log.isDebugEnabled())
- {
- log.debug("Using buddy communication timeout of " + brc.getBuddyCommunicationTimeout() + " millis");
- }
- }
- String buddyPoolName = XmlConfigHelper.readStringContents(element, "buddyPoolName");
- if ("".equals(buddyPoolName))
- {
- buddyPoolName = null;
- }
-
- brc.setBuddyPoolName(buddyPoolName);
-
- // now read the buddy locator details
-
- String buddyLocatorClass = XmlConfigHelper.readStringContents(element, "buddyLocatorClass");
- if (buddyLocatorClass == null || buddyLocatorClass.length() == 0)
- {
- buddyLocatorClass = NextMemberBuddyLocator.class.getName();
- }
- Properties props = null;
- props = XmlConfigHelper.readPropertiesContents(element, "buddyLocatorProperties");
- BuddyLocatorConfig blc = new BuddyLocatorConfig();
- blc.setBuddyLocatorClass(buddyLocatorClass);
- blc.setBuddyLocatorProperties(props);
- brc.setBuddyLocatorConfig(blc);
-
- return brc;
- }
-
- private static CacheLoaderConfig parseCacheLoaderConfig(Element element)
- {
- CacheLoaderConfig clc = new CacheLoaderConfig();
- clc.setPassivation(XmlConfigHelper.readBooleanContents(element, "passivation"));
- String s = XmlConfigHelper.readStringContents(element, "preload");
- if (s != null && s.length() > 0) clc.setPreload(s);
- clc.setShared(XmlConfigHelper.readBooleanContents(element, "shared"));
-
- NodeList cacheLoaderNodes = element.getElementsByTagName("cacheloader");
- for (int i = 0; i < cacheLoaderNodes.getLength(); i++)
- {
- Node node = cacheLoaderNodes.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE)
- {
- Element indivElement = (Element) node;
- CacheLoaderConfig.IndividualCacheLoaderConfig iclc = new CacheLoaderConfig.IndividualCacheLoaderConfig();
- iclc.setAsync(XmlConfigHelper.readBooleanContents(indivElement, "async", false));
- iclc.setIgnoreModifications(XmlConfigHelper.readBooleanContents(indivElement, "ignoreModifications", false));
- iclc.setFetchPersistentState(XmlConfigHelper.readBooleanContents(indivElement, "fetchPersistentState", false));
- iclc.setPurgeOnStartup(XmlConfigHelper.readBooleanContents(indivElement, "purgeOnStartup", false));
- iclc.setClassName(XmlConfigHelper.readStringContents(indivElement, "class"));
- iclc.setProperties(XmlConfigHelper.readPropertiesContents(indivElement, "properties"));
-
- SingletonStoreConfig ssc = parseSingletonStoreConfig(indivElement);
- if (ssc != null)
- {
- iclc.setSingletonStoreConfig(ssc);
- }
-
- clc.addIndividualCacheLoaderConfig(iclc);
- }
- }
- return clc;
- }
-
- private static CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig parseSingletonStoreConfig(Element cacheLoaderelement)
- {
- /* singletonStore element can only appear once in a cacheloader, so we just take the first one ignoring any
- subsequent definitions in cacheloader element*/
- Node singletonStoreNode = cacheLoaderelement.getElementsByTagName("singletonStore").item(0);
- if (singletonStoreNode != null && singletonStoreNode.getNodeType() == Node.ELEMENT_NODE)
- {
- Element singletonStoreElement = (Element) singletonStoreNode;
- boolean singletonStoreEnabled = XmlConfigHelper.readBooleanContents(singletonStoreElement, "enabled");
- String singletonStoreClass = XmlConfigHelper.readStringContents(singletonStoreElement, "class");
- Properties singletonStoreproperties;
- singletonStoreproperties = XmlConfigHelper.readPropertiesContents(singletonStoreElement, "properties");
- CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig ssc = new CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig();
- ssc.setSingletonStoreEnabled(singletonStoreEnabled);
- ssc.setSingletonStoreClass(singletonStoreClass);
- ssc.setSingletonStoreproperties(singletonStoreproperties);
-
- return ssc;
- }
-
- return null;
- }
-
- @SuppressWarnings("unchecked")
- public static EvictionConfig parseEvictionConfig(Element element)
- {
- EvictionConfig evictionConfig = new EvictionConfig();
-
- if (element != null)
- {
- // If they set the default eviction policy in the element, use that
- // in preference to the external attribute
- String temp = XmlConfigHelper.getTagContents(element, "policyClass", ATTR, NAME);
- String defaultEvPolicyClassName = null;
- if (temp != null && temp.length() > 0)
- {
- defaultEvPolicyClassName = temp;
- EvictionAlgorithmConfig eac = getEvictionAlgorithmConfig(temp);
- evictionConfig.getDefaultEvictionRegionConfig().setEvictionAlgorithmConfig(eac);
- }
-
- temp = XmlConfigHelper.getTagContents(element, "wakeUpIntervalSeconds", ATTR, NAME);
-
- int wakeupIntervalSeconds = 0;
- if (temp != null)
- {
- wakeupIntervalSeconds = Integer.parseInt(temp);
- }
-
- if (wakeupIntervalSeconds <= 0)
- {
- wakeupIntervalSeconds = EvictionConfig.WAKEUP_DEFAULT;
- }
-
- evictionConfig.setWakeupInterval(wakeupIntervalSeconds * 1000);
-
- int eventQueueSize = 0;
- temp = XmlConfigHelper.getTagContents(element, "eventQueueSize", ATTR, NAME);
-
- if (temp != null)
- {
- eventQueueSize = Integer.parseInt(temp);
- }
-
- if (eventQueueSize <= 0)
- {
- eventQueueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
- }
-
- evictionConfig.getDefaultEvictionRegionConfig().setEventQueueSize(eventQueueSize);
-
- NodeList list = element.getElementsByTagName(EvictionRegionConfig.REGION);
- if (list != null && list.getLength() > 0)
- {
- List regionConfigs = new ArrayList(list.getLength());
- for (int i = 0; i < list.getLength(); i++)
- {
- org.w3c.dom.Node node = list.item(i);
- if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
- {
- continue;
- }
- try
- {
- EvictionRegionConfig evictionRegionConfig = parseEvictionRegionConfig((Element) node, defaultEvPolicyClassName, eventQueueSize);
- if (!evictionRegionConfig.getRegionFqn().equals(RegionManagerImpl.DEFAULT_REGION))
- {
- regionConfigs.add(evictionRegionConfig);
- }
- else
- {
- evictionConfig.getDefaultEvictionRegionConfig().setEventQueueSize(evictionRegionConfig.getEventQueueSize());
- evictionConfig.getDefaultEvictionRegionConfig().setEvictionAlgorithmConfig(evictionRegionConfig.getEvictionAlgorithmConfig());
- }
- }
- catch (MissingPolicyException missingPolicy)
- {
- LogFactory.getLog(EvictionConfig.class).warn(missingPolicy.getLocalizedMessage());
- throw missingPolicy;
- }
- }
-
- evictionConfig.setEvictionRegionConfigs(regionConfigs);
- }
- }
-
- return evictionConfig;
-
- }
-
- private static EvictionRegionConfig parseEvictionRegionConfig(Element element, String defaultEvPolicyClassName, int defaultQueueCapacity)
- {
- EvictionRegionConfig erc = new EvictionRegionConfig();
-
- erc.setRegionName(element.getAttribute(EvictionRegionConfig.NAME));
-
- String temp = element.getAttribute("eventQueueSize");
- if (temp != null && temp.length() > 0)
- {
- erc.setEventQueueSize(Integer.parseInt(temp));
- }
- else
- {
- erc.setEventQueueSize(defaultQueueCapacity);
- }
- String evictionClass = element.getAttribute("policyClass");
-
- if (evictionClass == null || evictionClass.length() == 0)
- {
- evictionClass = defaultEvPolicyClassName;
- // if it's still null... what do we setCache?
- if (evictionClass == null || evictionClass.length() == 0)
- {
- throw new MissingPolicyException(
- "There is no Eviction Policy Class specified on the region or for the entire cache!");
- }
- }
-
- EvictionAlgorithmConfig algorithmConfig = getEvictionAlgorithmConfig(evictionClass);
-
- parseEvictionPolicyConfig(element, algorithmConfig);
-
- erc.setEvictionAlgorithmConfig(algorithmConfig);
- return erc;
- }
-
- private static EvictionAlgorithmConfig getEvictionAlgorithmConfig(String evictionClass)
- {
- EvictionConfig.assertIsTransformable(evictionClass);
-
- EvictionAlgorithm algorithm;
-
- try
- {
- EvictionPolicy ep = (EvictionPolicy) Util.getInstance(evictionClass);
- Class<? extends EvictionAlgorithm> algoClass = ((ModernizablePolicy) ep).modernizePolicy();
- if (log.isTraceEnabled()) log.trace("Using algo class " + algoClass);
- algorithm = Util.getInstance(algoClass);
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw new RuntimeException("Eviction class is not properly loaded in classloader", e);
- }
-
- EvictionAlgorithmConfig algorithmConfig;
- try
- {
- algorithmConfig = algorithm.getConfigurationClass().newInstance();
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw new RuntimeException("Failed to instantiate eviction configuration of class " +
- algorithm.getConfigurationClass(), e);
- }
- return algorithmConfig;
- }
-
- @SuppressWarnings("unchecked")
- private static void parseEvictionPolicyConfig(Element element, EvictionAlgorithmConfig target)
- {
- target.reset();
- ParsedAttributes attributes = XmlConfigHelper.extractAttributes(element);
- Map updatedElements = new HashMap();
- for (Map.Entry entry : attributes.stringAttribs.entrySet())
- {
- String key = (String) entry.getKey();
- String value = (String) entry.getValue();
- if (key.indexOf("Seconds") > 0)
- {
- key = key.substring(0, key.length() - "Seconds".length());
- value = value.trim() + "000";
- }
- updatedElements.put(key, value);
- }
- attributes.stringAttribs.clear();
- attributes.stringAttribs.putAll(updatedElements);
- XmlConfigHelper.setValues(target, attributes.stringAttribs, false, true);
- XmlConfigHelper.setValues(target, attributes.xmlAttribs, true, true);
- }
-
-
- /**
- * Parses the cluster config which is used to start a JGroups channel
- *
- * @param config an old-style JGroups protocol config String
- */
- public static String parseClusterConfigXml(Element config)
- {
- StringBuilder buffer = new StringBuilder();
- NodeList stack = config.getChildNodes();
- int length = stack.getLength();
-
- for (int s = 0; s < length; s++)
- {
- org.w3c.dom.Node node = stack.item(s);
- if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
- {
- continue;
- }
-
- Element tag = (Element) node;
- String protocol = tag.getTagName();
- buffer.append(protocol);
- NamedNodeMap attrs = tag.getAttributes();
- int attrLength = attrs.getLength();
- if (attrLength > 0)
- {
- buffer.append('(');
- }
- for (int a = 0; a < attrLength; a++)
- {
- Attr attr = (Attr) attrs.item(a);
- String name = attr.getName();
- String value = attr.getValue();
- buffer.append(name);
- buffer.append('=');
- buffer.append(value);
- if (a < attrLength - 1)
- {
- buffer.append(';');
- }
- }
- if (attrLength > 0)
- {
- buffer.append(')');
- }
- buffer.append(':');
- }
- // Remove the trailing ':'
- buffer.setLength(buffer.length() - 1);
- return buffer.toString();
- }
-}
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/XmlParserBase.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,25 +1,25 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.config.parsing;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config.parsing;
import org.jboss.util.StringPropertyReplacer;
import org.w3c.dom.Element;
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/BuddyElementParser.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,30 +1,30 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.config.parsing.element;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config.parsing.element;
import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
-import org.jboss.cache.config.BuddyReplicationConfig;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.jboss.cache.config.parsing.XmlParserBase;
+import org.jboss.starobrno.config.BuddyReplicationConfig;
+import org.jboss.starobrno.config.parsing.XmlConfigHelper;
+import org.jboss.starobrno.config.parsing.XmlParserBase;
import org.w3c.dom.Element;
import java.util.Properties;
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/CustomInterceptorsElementParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/CustomInterceptorsElementParser.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/CustomInterceptorsElementParser.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,33 +1,34 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.config.parsing.element;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config.parsing.element;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.CustomInterceptorConfig;
-import org.jboss.cache.config.parsing.ParsedAttributes;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.jboss.cache.config.parsing.XmlParserBase;
-import org.jboss.cache.interceptors.base.CommandInterceptor;
+
import org.jboss.cache.util.Util;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.CustomInterceptorConfig;
+import org.jboss.starobrno.config.parsing.ParsedAttributes;
+import org.jboss.starobrno.config.parsing.XmlConfigHelper;
+import org.jboss.starobrno.config.parsing.XmlParserBase;
+import org.jboss.starobrno.interceptors.base.CommandInterceptor;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/EvictionElementParser.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,36 +1,36 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.config.parsing.element;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config.parsing.element;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionAlgorithmConfig;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.MissingPolicyException;
-import org.jboss.cache.config.parsing.ParsedAttributes;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.jboss.cache.config.parsing.XmlParserBase;
-import org.jboss.cache.eviction.EvictionAlgorithm;
import org.jboss.cache.util.Util;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.config.EvictionConfig;
+import org.jboss.starobrno.config.EvictionRegionConfig;
+import org.jboss.starobrno.config.MissingPolicyException;
+import org.jboss.starobrno.config.parsing.ParsedAttributes;
+import org.jboss.starobrno.config.parsing.XmlConfigHelper;
+import org.jboss.starobrno.config.parsing.XmlParserBase;
+import org.jboss.starobrno.eviction.EvictionAlgorithm;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Modified: core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/cache/config/parsing/element/LoadersElementParser.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,30 +1,30 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.config.parsing.element;
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config.parsing.element;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.jboss.cache.config.parsing.XmlParserBase;
+import org.jboss.starobrno.config.CacheLoaderConfig;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.parsing.XmlConfigHelper;
+import org.jboss.starobrno.config.parsing.XmlParserBase;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -21,16 +21,20 @@
*/
package org.jboss.starobrno;
-import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.starobrno.invocation.InvocationContextContainer;
import org.jboss.starobrno.commands.CommandsFactory;
+import org.jboss.starobrno.commands.read.GetKeyValueCommand;
import org.jboss.starobrno.commands.read.SizeCommand;
-import org.jboss.starobrno.commands.read.GetKeyValueCommand;
-import org.jboss.starobrno.commands.write.*;
+import org.jboss.starobrno.commands.write.ClearCommand;
+import org.jboss.starobrno.commands.write.EvictCommand;
+import org.jboss.starobrno.commands.write.PutKeyValueCommand;
+import org.jboss.starobrno.commands.write.PutMapCommand;
+import org.jboss.starobrno.commands.write.RemoveCommand;
+import org.jboss.starobrno.commands.write.ReplaceCommand;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.interceptors.InterceptorChain;
-import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.invocation.InvocationContextContainer;
import org.jboss.starobrno.notifier.Notifier;
-import org.jboss.util.NotImplementedException;
import java.util.Collection;
import java.util.Map;
@@ -57,13 +61,13 @@
public boolean remove(Object key, Object value)
{
RemoveCommand command = commandsFactory.buildRemoveCommand(key, value);
- return (Boolean)invoker.invoke(buildCtx(), command);
+ return (Boolean) invoker.invoke(buildCtx(), command);
}
public boolean replace(Object key, Object oldValue, Object newValue)
{
ReplaceCommand command = commandsFactory.buildReplaceCommand(key, oldValue, newValue);
- return (Boolean)invoker.invoke(buildCtx(), command);
+ return (Boolean) invoker.invoke(buildCtx(), command);
}
public Object replace(Object key, Object value)
@@ -178,6 +182,16 @@
else invocationContextContainer.set(ctx);
}
+ public AtomicGroup putAtomicGroup(Object key, AtomicGroup group)
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ public AtomicGroup getAtomicGroup(Object key)
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
public void start()
{
//TODO: Autogenerated. Implement me properly
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -21,7 +21,6 @@
*/
package org.jboss.starobrno;
-import org.jboss.starobrno.config.CacheConfig;
import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.context.InvocationContext;
import org.jboss.util.NotImplementedException;
@@ -38,14 +37,13 @@
{
private ConcurrentHashMap data = new ConcurrentHashMap();
private Map<String, AtomicGroup> atomicGroups = new ConcurrentHashMap<String, AtomicGroup>();
- private CacheConfig cacheConfig;
+// private CacheConfig cacheConfig;
+// public CacheImpl(CacheConfig cacheConfig)
+// {
+// this.cacheConfig = cacheConfig;
+// }
- public CacheImpl(CacheConfig cacheConfig)
- {
- this.cacheConfig = cacheConfig;
- }
-
public Object putIfAbsent(Object key, Object value)
{
return data.putIfAbsent(key, value);
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheManager.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheManager.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -22,10 +22,9 @@
package org.jboss.starobrno;
import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.config.CacheConfig;
+import java.util.HashMap;
import java.util.Map;
-import java.util.HashMap;
/**
* @author Mircea.Markus at jboss.com
@@ -42,11 +41,15 @@
public CacheImpl getCache(String confName)
{
+ return null; // TODO
+
+ /*
if (caches.containsKey(confName)) return caches.get(confName);
+
CacheConfig config = this.config.getCacheConfig(confName);
if (config == null) throw new IllegalArgumentException("No such cache config: " + confName);
CacheImpl result = new CacheImpl(config);
caches.put(confName, result);
- return result;
+ return result;*/
}
}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/BuddyReplicationConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/BuddyReplicationConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/BuddyReplicationConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,208 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.jboss.cache.buddyreplication.NextMemberBuddyLocator;
+import org.jboss.cache.util.Util;
+
+import java.util.Properties;
+
+
+public class BuddyReplicationConfig extends ConfigurationComponent
+{
+ private static final long serialVersionUID = -4826380823985089339L;
+
+ /**
+ * Test whether buddy replication is enabled.
+ */
+ private boolean enabled;
+
+ /**
+ * Name of the buddy pool for current instance. May be null if buddy pooling is not used.
+ */
+ private String buddyPoolName;
+
+ private boolean autoDataGravitation = true;
+ private boolean dataGravitationRemoveOnFind = true;
+ private boolean dataGravitationSearchBackupTrees = true;
+ @Dynamic
+ private int buddyCommunicationTimeout = 10000;
+ private BuddyLocatorConfig buddyLocatorConfig;
+
+ public boolean isAutoDataGravitation()
+ {
+ return autoDataGravitation;
+ }
+
+ public void setAutoDataGravitation(boolean autoDataGravitation)
+ {
+ testImmutability("autoDataGravitation");
+ this.autoDataGravitation = autoDataGravitation;
+ }
+
+ public int getBuddyCommunicationTimeout()
+ {
+ return buddyCommunicationTimeout;
+ }
+
+ public void setBuddyCommunicationTimeout(int buddyCommunicationTimeout)
+ {
+ testImmutability("buddyCommunicationTimeout");
+ this.buddyCommunicationTimeout = buddyCommunicationTimeout;
+ }
+
+ public String getBuddyPoolName()
+ {
+ return buddyPoolName;
+ }
+
+ public void setBuddyPoolName(String buddyPoolName)
+ {
+ testImmutability("buddyPoolName");
+ this.buddyPoolName = buddyPoolName;
+ }
+
+ public boolean isDataGravitationRemoveOnFind()
+ {
+ return dataGravitationRemoveOnFind;
+ }
+
+ public void setDataGravitationRemoveOnFind(boolean dataGravitationRemoveOnFind)
+ {
+ testImmutability("dataGravitationRemoveOnFind");
+ this.dataGravitationRemoveOnFind = dataGravitationRemoveOnFind;
+ }
+
+ public boolean isDataGravitationSearchBackupTrees()
+ {
+ return dataGravitationSearchBackupTrees;
+ }
+
+ public void setDataGravitationSearchBackupTrees(boolean dataGravitationSearchBackupTrees)
+ {
+ testImmutability("dataGravitationSearchBackupTrees");
+ this.dataGravitationSearchBackupTrees = dataGravitationSearchBackupTrees;
+ }
+
+ public boolean isEnabled()
+ {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled)
+ {
+ testImmutability("enabled");
+ this.enabled = enabled;
+ }
+
+ public BuddyLocatorConfig getBuddyLocatorConfig()
+ {
+ return buddyLocatorConfig;
+ }
+
+ public void setBuddyLocatorConfig(BuddyLocatorConfig buddyLocatorConfig)
+ {
+ testImmutability("buddyLocatorConfig");
+ replaceChildConfig(this.buddyLocatorConfig, buddyLocatorConfig);
+ this.buddyLocatorConfig = buddyLocatorConfig;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+
+ if (obj instanceof BuddyReplicationConfig)
+ {
+ BuddyReplicationConfig other = (BuddyReplicationConfig) obj;
+ return (this.autoDataGravitation == other.autoDataGravitation)
+ && (this.dataGravitationRemoveOnFind == other.dataGravitationRemoveOnFind)
+ && (this.dataGravitationSearchBackupTrees == other.dataGravitationSearchBackupTrees)
+ && (this.enabled == other.enabled)
+ && (this.buddyCommunicationTimeout == other.buddyCommunicationTimeout)
+ && Util.safeEquals(this.buddyPoolName, other.buddyPoolName)
+ && Util.safeEquals(this.buddyLocatorConfig, other.buddyLocatorConfig);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = 11;
+ result = 29 * result + (autoDataGravitation ? 0 : 1);
+ result = 29 * result + (dataGravitationRemoveOnFind ? 0 : 1);
+ result = 29 * result + (dataGravitationSearchBackupTrees ? 0 : 1);
+ result = 29 * result + (enabled ? 0 : 1);
+ result = 29 * result + buddyCommunicationTimeout;
+ result = 29 * result + (buddyPoolName == null ? 0 : buddyPoolName.hashCode());
+ result = 29 * result + (buddyLocatorConfig == null ? 0 : buddyLocatorConfig.hashCode());
+ return result;
+ }
+
+ @Override
+ public BuddyReplicationConfig clone() throws CloneNotSupportedException
+ {
+ BuddyReplicationConfig clone = (BuddyReplicationConfig) super.clone();
+ if (buddyLocatorConfig != null)
+ clone.setBuddyLocatorConfig(buddyLocatorConfig.clone());
+ return clone;
+ }
+
+ public static class BuddyLocatorConfig extends PluggableConfigurationComponent
+ {
+ private static final long serialVersionUID = -8003634097931826091L;
+
+ public BuddyLocatorConfig()
+ {
+ // default
+ className = NextMemberBuddyLocator.class.getName();
+ }
+
+ public String getBuddyLocatorClass()
+ {
+ return className;
+ }
+
+ public void setBuddyLocatorClass(String buddyLocatorClass)
+ {
+ setClassName(buddyLocatorClass);
+ }
+
+ public Properties getBuddyLocatorProperties()
+ {
+ return properties;
+ }
+
+ public void setBuddyLocatorProperties(Properties buddyLocatorProperties)
+ {
+ setProperties(buddyLocatorProperties);
+ }
+
+ public BuddyLocatorConfig clone() throws CloneNotSupportedException
+ {
+ return (BuddyLocatorConfig) super.clone();
+ }
+ }
+}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/config/CacheConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/CacheConfig.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/CacheConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,1074 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.config;
-
-import org.jboss.cache.Version;
-import org.jboss.cache.buddyreplication.BuddyManager;
-import org.jboss.cache.config.parsing.JGroupsStackParser;
-import org.jboss.cache.config.*;
-import org.jboss.cache.factories.annotations.NonVolatile;
-import org.jboss.cache.factories.annotations.Start;
-import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.marshall.Marshaller;
-import org.w3c.dom.Element;
-
-import java.net.URL;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-
-/**
- * Encapsulates the configuration of a Cache.
- *
- * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
- */
- at NonVolatile
-public class CacheConfig extends ConfigurationComponent
-{
- private static final long serialVersionUID = 5553791890144997466L;
-
- private Marshaller marshaller;
-
- private transient JGroupsStackParser jGroupsStackParser = new JGroupsStackParser();
- private boolean invocationBatchingEnabled;
-
- /**
- * Behavior of the JVM shutdown hook registered by the cache
- */
- public static enum ShutdownHookBehavior
- {
- /**
- * By default a shutdown hook is registered if no MBean server (apart from the JDK default) is detected.
- */
- DEFAULT,
- /**
- * Forces the cache to register a shutdown hook even if an MBean server is detected.
- */
- REGISTER,
- /**
- * Forces the cache NOT to register a shutdown hook, even if no MBean server is detected.
- */
- DONT_REGISTER
- }
-
- /**
- * Cache replication mode.
- */
- public static enum CacheMode
- {
- /**
- * Data is not replicated.
- */
- LOCAL,
-
- /**
- * Data replicated synchronously.
- */
- REPL_SYNC,
-
- /**
- * Data replicated asynchronously.
- */
- REPL_ASYNC,
-
- /**
- * Data invalidated synchronously.
- */
- INVALIDATION_SYNC,
-
- /**
- * Data invalidated asynchronously.
- */
- INVALIDATION_ASYNC;
-
- /**
- * Returns true if the mode is invalidation, either sync or async.
- */
- public boolean isInvalidation()
- {
- return this == INVALIDATION_SYNC || this == INVALIDATION_ASYNC;
- }
-
- public boolean isSynchronous()
- {
- return this == REPL_SYNC || this == INVALIDATION_SYNC || this == LOCAL;
- }
-
- }
-
- public static CacheMode legacyModeToCacheMode(int legacyMode)
- {
- switch (legacyMode)
- {
- case 1:
- return CacheMode.LOCAL;
- case 2:
- return CacheMode.REPL_ASYNC;
- case 3:
- return CacheMode.REPL_SYNC;
- case 4:
- return CacheMode.INVALIDATION_ASYNC;
- case 5:
- return CacheMode.INVALIDATION_SYNC;
- default:
- throw new IllegalArgumentException("Unknown legacy cache mode " +
- legacyMode);
- }
- }
-
- /**
- * Cache node locking scheme.
- */
- public static enum NodeLockingScheme
- {
- /**
- * Data is locked using the MVCC locking scheme. This is the default locking scheme in JBoss Cache 3.0.0.
- *
- * @see <a href="http://wiki.jboss.org/wiki/JBossCacheMVCC">http://wiki.jboss.org/wiki/JBossCacheMVCC</a>
- */
- MVCC,
- /**
- * Data is exclusively locked during modification.
- *
- * @see <a href="http://en.wikipedia.org/wiki/Concurrency_control">http://en.wikipedia.org/wiki/Concurrency_control (pessimistic)</a>
- */
- PESSIMISTIC,
- /**
- * Data is unlocked during modification, modifications merged at commit.
- *
- * @see <a href="http://en.wikipedia.org/wiki/Optimistic_concurrency_control">http://en.wikipedia.org/wiki/Optimistic_concurrency_control</a>
- */
- OPTIMISTIC;
-
- /**
- * @return true if the node locking scheme uses versioning.
- */
- public boolean isVersionedScheme()
- {
- return this == OPTIMISTIC;
- }
- }
-
- /**
- * Default replication version, from {@link org.jboss.cache.Version#getVersionShort}.
- */
- public static final short DEFAULT_REPLICATION_VERSION = Version.getVersionShort();
-
- // ------------------------------------------------------------------------------------------------------------
- // CONFIGURATION OPTIONS
- // ------------------------------------------------------------------------------------------------------------
-
- private String clusterName = "JBossCache-Cluster";
- private String clusterConfig = null;
- private boolean useReplQueue = false;
- @Dynamic
- private int replQueueMaxElements = 1000;
- @Dynamic
- private long replQueueInterval = 5000;
- private boolean exposeManagementStatistics = true;
- @Dynamic
- private boolean fetchInMemoryState = true;
- private short replicationVersion = DEFAULT_REPLICATION_VERSION;
- @Dynamic
- private long lockAcquisitionTimeout = 10000;
- @Dynamic
- private long syncReplTimeout = 15000;
- private CacheMode cacheMode = CacheMode.LOCAL;
- private boolean inactiveOnStartup = false;
- @Dynamic
- private long stateRetrievalTimeout = 10000;
- private IsolationLevel isolationLevel = IsolationLevel.REPEATABLE_READ;
- @Dynamic
- private boolean lockParentForChildInsertRemove = false;
- @Dynamic
- private EvictionConfig evictionConfig = null;
- private boolean useRegionBasedMarshalling = false;
- private String transactionManagerLookupClass = null;
- private CacheLoaderConfig cacheLoaderConfig = null;
- @Dynamic
- private boolean syncCommitPhase = false;
- @Dynamic
- private boolean syncRollbackPhase = false;
- private BuddyReplicationConfig buddyReplicationConfig;
-
- private NodeLockingScheme nodeLockingScheme = NodeLockingScheme.MVCC;
- private String muxStackName = null;
- private boolean usingMultiplexer = false;
- private transient RuntimeConfig runtimeConfig;
- private String marshallerClass;
- private ShutdownHookBehavior shutdownHookBehavior = ShutdownHookBehavior.DEFAULT;
- private boolean useLazyDeserialization = false;
- private int objectInputStreamPoolSize = 50;
- private int objectOutputStreamPoolSize = 50;
- private List<CustomInterceptorConfig> customInterceptors = Collections.emptyList();
- private boolean writeSkewCheck = false;
- private int concurrencyLevel = 500;
- private int listenerAsyncPoolSize = 1;
- private int serializationExecutorPoolSize = 25;
-
- @Start(priority = 1)
- private void correctIsolationLevels()
- {
- // ensure the correct isolation level upgrades and/or downgrades are performed.
- if (nodeLockingScheme == NodeLockingScheme.MVCC)
- {
- switch (isolationLevel)
- {
- case NONE:
- case READ_UNCOMMITTED:
- isolationLevel = IsolationLevel.READ_COMMITTED;
- break;
- case SERIALIZABLE:
- isolationLevel = IsolationLevel.REPEATABLE_READ;
- break;
- }
- }
- }
-
- // ------------------------------------------------------------------------------------------------------------
- // SETTERS - MAKE SURE ALL SETTERS PERFORM testImmutability()!!!
- // ------------------------------------------------------------------------------------------------------------
-
- public void setCacheMarshaller(Marshaller instance)
- {
- marshaller = instance;
- }
-
- public Marshaller getMarshaller()
- {
- return marshaller;
- }
-
- public boolean isWriteSkewCheck()
- {
- return writeSkewCheck;
- }
-
- public void setWriteSkewCheck(boolean writeSkewCheck)
- {
- testImmutability("writeSkewCheck");
- this.writeSkewCheck = writeSkewCheck;
- }
-
- public int getConcurrencyLevel()
- {
- return concurrencyLevel;
- }
-
- public void setConcurrencyLevel(int concurrencyLevel)
- {
- testImmutability("concurrencyLevel");
- this.concurrencyLevel = concurrencyLevel;
- }
-
- /**
- * Converts a list of elements to a Java Groups property string.
- */
- public void setClusterConfig(Element config)
- {
- setClusterConfig(jGroupsStackParser.parseClusterConfigXml(config));
- }
-
- public void setClusterName(String clusterName)
- {
- testImmutability("clusterName");
- this.clusterName = clusterName;
- }
-
- public void setClusterConfig(String clusterConfig)
- {
- testImmutability("clusterConfig");
- this.clusterConfig = clusterConfig;
- }
-
- public void setReplQueueMaxElements(int replQueueMaxElements)
- {
- testImmutability("replQueueMaxElements");
- this.replQueueMaxElements = replQueueMaxElements;
- }
-
- public void setReplQueueInterval(long replQueueInterval)
- {
- testImmutability("replQueueInterval");
- this.replQueueInterval = replQueueInterval;
- }
-
- public void setExposeManagementStatistics(boolean useMbean)
- {
- testImmutability("exposeManagementStatistics");
- this.exposeManagementStatistics = useMbean;
- }
-
- /**
- * Enables invocation batching if set to <tt>true</tt>. You still need to use {@link org.jboss.cache.Cache#startBatch()}
- * and {@link org.jboss.cache.Cache#endBatch(boolean)} to demarcate the start and end of batches.
- *
- * @param enabled if true, batching is enabled.
- * @since 3.0
- */
- public void setInvocationBatchingEnabled(boolean enabled)
- {
- testImmutability("invocationBatchingEnabled");
- this.invocationBatchingEnabled = enabled;
- }
-
- public void setFetchInMemoryState(boolean fetchInMemoryState)
- {
- testImmutability("fetchInMemoryState");
- this.fetchInMemoryState = fetchInMemoryState;
- }
-
- public void setReplicationVersion(short replicationVersion)
- {
- testImmutability("replicationVersion");
- this.replicationVersion = replicationVersion;
- }
-
- public void setReplVersionString(String replVersionString)
- {
- setReplicationVersion(replVersionString == null ? 0 : Version.getVersionShort(replVersionString));
- }
-
- public void setLockAcquisitionTimeout(long lockAcquisitionTimeout)
- {
- testImmutability("lockAcquisitionTimeout");
- this.lockAcquisitionTimeout = lockAcquisitionTimeout;
- }
-
- public void setSyncReplTimeout(long syncReplTimeout)
- {
- testImmutability("syncReplTimeout");
- this.syncReplTimeout = syncReplTimeout;
- }
-
- public void setCacheMode(CacheMode cacheModeInt)
- {
- testImmutability("cacheMode");
- this.cacheMode = cacheModeInt;
- }
-
- public void setCacheMode(String cacheMode)
- {
- testImmutability("cacheMode");
- if (cacheMode == null) throw new ConfigurationException("Cache mode cannot be null", "CacheMode");
- this.cacheMode = CacheMode.valueOf(uc(cacheMode));
- if (this.cacheMode == null)
- {
- log.warn("Unknown cache mode '" + cacheMode + "', using defaults.");
- this.cacheMode = CacheMode.LOCAL;
- }
- }
-
- public String getCacheModeString()
- {
- return cacheMode == null ? null : cacheMode.toString();
- }
-
- public void setCacheModeString(String cacheMode)
- {
- setCacheMode(cacheMode);
- }
-
- public void setInactiveOnStartup(boolean inactiveOnStartup)
- {
- testImmutability("inactiveOnStartup");
- this.inactiveOnStartup = inactiveOnStartup;
- }
-
- public EvictionConfig getEvictionConfig()
- {
- return evictionConfig;
- }
-
- public void setEvictionConfig(EvictionConfig config)
- {
- testImmutability("evictionConfig");
- this.evictionConfig = config;
- }
-
- /**
- * This is a deprecated configuration option. While it will be supported for the 2.x series for backward compatibility,
- * expect to see it disappear in 3.x.
- * <p/>
- * With {@link #isUseLazyDeserialization()}, which is enabled by default, custom class loaders are handled implicitly.
- * See the user guide for details on how this is handled.
- * <p/>
- */
- public void setUseRegionBasedMarshalling(boolean useRegionBasedMarshalling)
- {
- testImmutability("useRegionBasedMarshalling");
- this.useRegionBasedMarshalling = useRegionBasedMarshalling;
- }
-
- public void setTransactionManagerLookupClass(String transactionManagerLookupClass)
- {
- testImmutability("transactionManagerLookupClass");
- this.transactionManagerLookupClass = transactionManagerLookupClass;
- }
-
- public void setCacheLoaderConfig(CacheLoaderConfig config)
- {
- testImmutability("cacheLoaderConfig");
- replaceChildConfig(this.cacheLoaderConfig, config);
- this.cacheLoaderConfig = config;
- }
-
- public void setSyncCommitPhase(boolean syncCommitPhase)
- {
- testImmutability("syncCommitPhase");
- this.syncCommitPhase = syncCommitPhase;
- }
-
- public void setSyncRollbackPhase(boolean syncRollbackPhase)
- {
- testImmutability("syncRollbackPhase");
- this.syncRollbackPhase = syncRollbackPhase;
- }
-
- /**
- * Sets the size of the asynchronous listener notification thread pool size. Defaults to 1, and if set to below 1,
- * all async listeners (specified with {@link org.jboss.cache.notifications.annotation.CacheListener#sync()} are notified
- * synchronously.
- *
- * @param listenerAsyncPoolSize number of threads in pool
- * @since 3.0
- */
- public void setListenerAsyncPoolSize(int listenerAsyncPoolSize)
- {
- testImmutability("asyncListenerPoolSize");
- this.listenerAsyncPoolSize = listenerAsyncPoolSize;
- }
-
- public void setBuddyReplicationConfig(BuddyReplicationConfig config)
- {
- testImmutability("buddyReplicationConfig");
- replaceChildConfig(this.buddyReplicationConfig, config);
- this.buddyReplicationConfig = config;
- }
-
- public void setNodeLockingScheme(NodeLockingScheme nodeLockingScheme)
- {
- testImmutability("nodeLockingScheme");
- testImmutability("nodeLockingOptimistic");
- this.nodeLockingScheme = nodeLockingScheme;
- }
-
- public void setUseReplQueue(boolean useReplQueue)
- {
- testImmutability("useReplQueue");
- this.useReplQueue = useReplQueue;
- }
-
- public void setIsolationLevel(IsolationLevel isolationLevel)
- {
- testImmutability("isolationLevel");
- this.isolationLevel = isolationLevel;
- }
-
- /**
- * Starting with 3.x there are 3 locking schemes, so if true is passed in then state is not defined.
- * It is here for backward compatibility reasons only and should not be used by new code.
- */
- @Deprecated
- public void setNodeLockingOptimistic(boolean nodeLockingOptimistic)
- {
- testImmutability("nodeLockingOptimistic");
- if (nodeLockingOptimistic) setNodeLockingScheme(NodeLockingScheme.OPTIMISTIC);
- else setNodeLockingScheme(NodeLockingScheme.PESSIMISTIC);
- }
-
- public void setStateRetrievalTimeout(long stateRetrievalTimeout)
- {
- testImmutability("stateRetrievalTimeout");
- this.stateRetrievalTimeout = stateRetrievalTimeout;
- }
-
- public void setNodeLockingScheme(String nodeLockingScheme)
- {
- testImmutability("nodeLockingScheme");
- if (nodeLockingScheme == null)
- {
- throw new ConfigurationException("Node locking scheme cannot be null", "NodeLockingScheme");
- }
- this.nodeLockingScheme = NodeLockingScheme.valueOf(uc(nodeLockingScheme));
- if (this.nodeLockingScheme == null)
- {
- log.warn("Unknown node locking scheme '" + nodeLockingScheme + "', using defaults.");
- this.nodeLockingScheme = NodeLockingScheme.PESSIMISTIC;
- }
- }
-
- public String getNodeLockingSchemeString()
- {
- return nodeLockingScheme == null ? null : nodeLockingScheme.toString();
- }
-
- public void setNodeLockingSchemeString(String nodeLockingScheme)
- {
- setNodeLockingScheme(nodeLockingScheme);
- }
-
- private static String uc(String s)
- {
- return s.toUpperCase(Locale.ENGLISH);
- }
-
- public void setIsolationLevel(String isolationLevel)
- {
- testImmutability("isolationLevel");
- if (isolationLevel == null) throw new ConfigurationException("Isolation level cannot be null", "IsolationLevel");
- this.isolationLevel = IsolationLevel.valueOf(uc(isolationLevel));
- if (this.isolationLevel == null)
- {
- log.warn("Unknown isolation level '" + isolationLevel + "', using defaults.");
- this.isolationLevel = IsolationLevel.REPEATABLE_READ;
- }
- }
-
- public String getIsolationLevelString()
- {
- return isolationLevel == null ? null : isolationLevel.toString();
- }
-
- public void setIsolationLevelString(String isolationLevel)
- {
- setIsolationLevel(isolationLevel);
- }
-
- /**
- * Sets whether inserting or removing a node requires a write lock
- * on the node's parent (when pessimistic locking is used.)
- * <p/>
- * The default value is <code>false</code>
- */
- public void setLockParentForChildInsertRemove(boolean lockParentForChildInsertRemove)
- {
- testImmutability("lockParentForChildInsertRemove");
- this.lockParentForChildInsertRemove = lockParentForChildInsertRemove;
- }
-
- public void setMultiplexerStack(String stackName)
- {
- testImmutability("muxStackName");
- this.muxStackName = stackName;
- }
-
- public boolean isUsingMultiplexer()
- {
- return usingMultiplexer;
- }
-
- public void setUsingMultiplexer(boolean usingMultiplexer)
- {
- testImmutability("usingMultiplexer");
- this.usingMultiplexer = usingMultiplexer;
- }
-
- public void setShutdownHookBehavior(ShutdownHookBehavior shutdownHookBehavior)
- {
- testImmutability("shutdownHookBehavior");
- this.shutdownHookBehavior = shutdownHookBehavior;
- }
-
- public void setShutdownHookBehavior(String shutdownHookBehavior)
- {
- testImmutability("shutdownHookBehavior");
- if (shutdownHookBehavior == null)
- throw new ConfigurationException("Shutdown hook behavior cannot be null", "ShutdownHookBehavior");
- this.shutdownHookBehavior = ShutdownHookBehavior.valueOf(uc(shutdownHookBehavior));
- if (this.shutdownHookBehavior == null)
- {
- log.warn("Unknown shutdown hook behavior '" + shutdownHookBehavior + "', using defaults.");
- this.shutdownHookBehavior = ShutdownHookBehavior.DEFAULT;
- }
- }
-
- public void setUseLazyDeserialization(boolean useLazyDeserialization)
- {
- testImmutability("useLazyDeserialization");
- this.useLazyDeserialization = useLazyDeserialization;
- }
-
- /**
- * Initialises the size of the object input stream pool size, which defaults to 50.
- *
- * @param objectInputStreamPoolSize
- * @since 2.1.0
- */
- public void setObjectInputStreamPoolSize(int objectInputStreamPoolSize)
- {
- testImmutability("objectInputStreamPoolSize");
- this.objectInputStreamPoolSize = objectInputStreamPoolSize;
- }
-
- /**
- * Initialises the size of the object output stream pool size, which defaults to 50.
- *
- * @param objectOutputStreamPoolSize
- * @since 2.1.0
- */
- public void setObjectOutputStreamPoolSize(int objectOutputStreamPoolSize)
- {
- testImmutability("objectOutputStreamPoolSize");
- this.objectOutputStreamPoolSize = objectOutputStreamPoolSize;
- }
-
- /**
- * Sets the async replication serialization executor pool size for async replication. Has no effect if the
- * replication queue is used.
- *
- * @param serializationExecutorPoolSize number of threads to use
- */
- public void setSerializationExecutorPoolSize(int serializationExecutorPoolSize)
- {
- testImmutability("serializationExecutorPoolSize");
- this.serializationExecutorPoolSize = serializationExecutorPoolSize;
- }
-
- // ------------------------------------------------------------------------------------------------------------
- // GETTERS
- // ------------------------------------------------------------------------------------------------------------
-
-
- public ShutdownHookBehavior getShutdownHookBehavior()
- {
- return this.shutdownHookBehavior;
- }
-
- /**
- * This helper method is deprecated and will be removed when optimistic and pessimistic locking support is dropped.
- *
- * @return true if node locking scheme is optimistic.
- * @deprecated use {@link #getNodeLockingScheme()} to determine node locking scheme used.
- */
- @Deprecated
- public boolean isNodeLockingOptimistic()
- {
- return nodeLockingScheme == NodeLockingScheme.OPTIMISTIC;
- }
-
- public boolean isUseReplQueue()
- {
- return useReplQueue;
- }
-
- public String getClusterName()
- {
- return clusterName;
- }
-
- public String getClusterConfig()
- {
- return clusterConfig;
- }
-
- public int getReplQueueMaxElements()
- {
- return replQueueMaxElements;
- }
-
- public long getReplQueueInterval()
- {
- return replQueueInterval;
- }
-
- /**
- * @deprecated use isExposeManagementStatistics()
- */
- @Deprecated
- public boolean getExposeManagementStatistics()
- {
- return exposeManagementStatistics;
- }
-
- public boolean isExposeManagementStatistics()
- {
- return exposeManagementStatistics;
- }
-
- /**
- * @return true if invocation batching is enabled.
- * @since 3.0
- */
- public boolean isInvocationBatchingEnabled()
- {
- return invocationBatchingEnabled;
- }
-
- public boolean isFetchInMemoryState()
- {
- return fetchInMemoryState;
- }
-
- public short getReplicationVersion()
- {
- return replicationVersion;
- }
-
- public String getReplVersionString()
- {
- return Version.getVersionString(replicationVersion);
- }
-
- public long getLockAcquisitionTimeout()
- {
- return lockAcquisitionTimeout;
- }
-
- public long getSyncReplTimeout()
- {
- return syncReplTimeout;
- }
-
- public CacheMode getCacheMode()
- {
- return cacheMode;
- }
-
- public boolean isInactiveOnStartup()
- {
- return inactiveOnStartup;
- }
-
- public IsolationLevel getIsolationLevel()
- {
- return isolationLevel;
- }
-
- /**
- * Gets whether inserting or removing a node requires a write lock
- * on the node's parent (when pessimistic locking is used.)
- * <p/>
- * The default value is <code>false</code>
- */
- public boolean isLockParentForChildInsertRemove()
- {
- return lockParentForChildInsertRemove;
- }
-
- public boolean isUseRegionBasedMarshalling()
- {
- return useRegionBasedMarshalling;
- }
-
- public String getTransactionManagerLookupClass()
- {
- return transactionManagerLookupClass;
- }
-
- public CacheLoaderConfig getCacheLoaderConfig()
- {
- return cacheLoaderConfig;
- }
-
- public boolean isSyncCommitPhase()
- {
- return syncCommitPhase;
- }
-
- public boolean isSyncRollbackPhase()
- {
- return syncRollbackPhase;
- }
-
- /**
- * Gets the size of the asynchronous listener notification thread pool size. Defaults to 1, and if set to below 1,
- * all async listeners (specified with {@link org.jboss.cache.notifications.annotation.CacheListener#sync()} are notified
- * synchronously.
- *
- * @return thread pool size
- * @since 3.0
- */
- public int getListenerAsyncPoolSize()
- {
- return listenerAsyncPoolSize;
- }
-
- public BuddyReplicationConfig getBuddyReplicationConfig()
- {
- return buddyReplicationConfig;
- }
-
- public NodeLockingScheme getNodeLockingScheme()
- {
- return nodeLockingScheme;
- }
-
- public long getStateRetrievalTimeout()
- {
- return stateRetrievalTimeout;
- }
-
- public String getMultiplexerStack()
- {
- return muxStackName;
- }
-
- public boolean isUseLazyDeserialization()
- {
- return useLazyDeserialization;
- }
-
- public synchronized RuntimeConfig getRuntimeConfig()
- {
- if (runtimeConfig == null)
- {
- setRuntimeConfig(new RuntimeConfig(), false);
- }
- return runtimeConfig;
- }
-
- public void setRuntimeConfig(RuntimeConfig runtimeConfig)
- {
- setRuntimeConfig(runtimeConfig, true);
- }
-
- private void setRuntimeConfig(RuntimeConfig runtimeConfig, boolean testImmutability)
- {
- if (testImmutability)
- {
- testImmutability("runtimeConfig");
- }
- this.runtimeConfig = runtimeConfig;
- }
-
- public String getMarshallerClass()
- {
- return marshallerClass;
- }
-
- public void setMarshallerClass(String marshallerClass)
- {
- this.marshallerClass = marshallerClass;
- }
-
- /**
- * @return the size of he object input stream pool
- * @since 2.1.0
- */
- public int getObjectInputStreamPoolSize()
- {
- return objectInputStreamPoolSize;
- }
-
- /**
- * @return the size of he object output stream pool
- * @since 2.1.0
- */
- public int getObjectOutputStreamPoolSize()
- {
- return objectOutputStreamPoolSize;
- }
-
-
- /**
- * Returns a {@link java.net.URL} to a default JGroups configuration file.
- *
- * @return a default JGroups config file
- */
- public URL getDefaultClusterConfig()
- {
- URL url = getClass().getClassLoader().getResource("flush-udp.xml");
- if (log.isTraceEnabled()) log.trace("Using default JGroups configuration file " + url);
- return url;
- }
-
- /**
- * @return the serialization executor pool size.
- */
- public int getSerializationExecutorPoolSize()
- {
- return serializationExecutorPoolSize;
- }
-
- // ------------------------------------------------------------------------------------------------------------
- // HELPERS
- // ------------------------------------------------------------------------------------------------------------
-
- // ------------------------------------------------------------------------------------------------------------
- // OVERRIDDEN METHODS
- // ------------------------------------------------------------------------------------------------------------
-
- @Override
- public boolean equals(Object o)
- {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- CacheConfig that = (CacheConfig) o;
-
- if (exposeManagementStatistics != that.exposeManagementStatistics) return false;
- if (fetchInMemoryState != that.fetchInMemoryState) return false;
- if (inactiveOnStartup != that.inactiveOnStartup) return false;
- if (lockAcquisitionTimeout != that.lockAcquisitionTimeout) return false;
- if (lockParentForChildInsertRemove != that.lockParentForChildInsertRemove) return false;
- if (objectInputStreamPoolSize != that.objectInputStreamPoolSize) return false;
- if (objectOutputStreamPoolSize != that.objectOutputStreamPoolSize) return false;
- if (replQueueInterval != that.replQueueInterval) return false;
- if (replQueueMaxElements != that.replQueueMaxElements) return false;
- if (replicationVersion != that.replicationVersion) return false;
- if (stateRetrievalTimeout != that.stateRetrievalTimeout) return false;
- if (syncCommitPhase != that.syncCommitPhase) return false;
- if (syncReplTimeout != that.syncReplTimeout) return false;
- if (syncRollbackPhase != that.syncRollbackPhase) return false;
- if (useLazyDeserialization != that.useLazyDeserialization) return false;
- if (useRegionBasedMarshalling != that.useRegionBasedMarshalling) return false;
- if (useReplQueue != that.useReplQueue) return false;
- if (usingMultiplexer != that.usingMultiplexer) return false;
- if (buddyReplicationConfig != null ? !buddyReplicationConfig.equals(that.buddyReplicationConfig) : that.buddyReplicationConfig != null)
- return false;
- if (cacheLoaderConfig != null ? !cacheLoaderConfig.equals(that.cacheLoaderConfig) : that.cacheLoaderConfig != null)
- return false;
- if (cacheMode != that.cacheMode) return false;
- if (clusterConfig != null ? !clusterConfig.equals(that.clusterConfig) : that.clusterConfig != null) return false;
- if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
- if (evictionConfig != null ? !evictionConfig.equals(that.evictionConfig) : that.evictionConfig != null)
- return false;
- if (isolationLevel != that.isolationLevel) return false;
- if (marshaller != null ? !marshaller.equals(that.marshaller) : that.marshaller != null) return false;
- if (marshallerClass != null ? !marshallerClass.equals(that.marshallerClass) : that.marshallerClass != null)
- return false;
- if (muxStackName != null ? !muxStackName.equals(that.muxStackName) : that.muxStackName != null) return false;
- if (nodeLockingScheme != that.nodeLockingScheme) return false;
- if (runtimeConfig != null ? !runtimeConfig.equals(that.runtimeConfig) : that.runtimeConfig != null) return false;
- if (shutdownHookBehavior != that.shutdownHookBehavior) return false;
- if (transactionManagerLookupClass != null ? !transactionManagerLookupClass.equals(that.transactionManagerLookupClass) : that.transactionManagerLookupClass != null)
- return false;
- if (listenerAsyncPoolSize != that.listenerAsyncPoolSize) return false;
- if (serializationExecutorPoolSize != that.serializationExecutorPoolSize) return false;
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- int result;
- result = (marshaller != null ? marshaller.hashCode() : 0);
- result = 31 * result + (clusterName != null ? clusterName.hashCode() : 0);
- result = 31 * result + (clusterConfig != null ? clusterConfig.hashCode() : 0);
- result = 31 * result + (useReplQueue ? 1 : 0);
- result = 31 * result + replQueueMaxElements;
- result = 31 * result + (int) (replQueueInterval ^ (replQueueInterval >>> 32));
- result = 31 * result + (exposeManagementStatistics ? 1 : 0);
- result = 31 * result + (fetchInMemoryState ? 1 : 0);
- result = 31 * result + (int) replicationVersion;
- result = 31 * result + (int) (lockAcquisitionTimeout ^ (lockAcquisitionTimeout >>> 32));
- result = 31 * result + (int) (syncReplTimeout ^ (syncReplTimeout >>> 32));
- result = 31 * result + (cacheMode != null ? cacheMode.hashCode() : 0);
- result = 31 * result + (inactiveOnStartup ? 1 : 0);
- result = 31 * result + (int) (stateRetrievalTimeout ^ (stateRetrievalTimeout >>> 32));
- result = 31 * result + (isolationLevel != null ? isolationLevel.hashCode() : 0);
- result = 31 * result + (lockParentForChildInsertRemove ? 1 : 0);
- result = 31 * result + (evictionConfig != null ? evictionConfig.hashCode() : 0);
- result = 31 * result + (useRegionBasedMarshalling ? 1 : 0);
- result = 31 * result + (transactionManagerLookupClass != null ? transactionManagerLookupClass.hashCode() : 0);
- result = 31 * result + (cacheLoaderConfig != null ? cacheLoaderConfig.hashCode() : 0);
- result = 31 * result + (syncCommitPhase ? 1 : 0);
- result = 31 * result + (syncRollbackPhase ? 1 : 0);
- result = 31 * result + (buddyReplicationConfig != null ? buddyReplicationConfig.hashCode() : 0);
- result = 31 * result + (nodeLockingScheme != null ? nodeLockingScheme.hashCode() : 0);
- result = 31 * result + (muxStackName != null ? muxStackName.hashCode() : 0);
- result = 31 * result + (usingMultiplexer ? 1 : 0);
- result = 31 * result + (runtimeConfig != null ? runtimeConfig.hashCode() : 0);
- result = 31 * result + (marshallerClass != null ? marshallerClass.hashCode() : 0);
- result = 31 * result + (shutdownHookBehavior != null ? shutdownHookBehavior.hashCode() : 0);
- result = 31 * result + (useLazyDeserialization ? 1 : 0);
- result = 31 * result + objectInputStreamPoolSize;
- result = 31 * result + objectOutputStreamPoolSize;
- result = 31 * result + serializationExecutorPoolSize;
- return result;
- }
-
- @Override
- public org.jboss.cache.config.Configuration clone() throws CloneNotSupportedException
- {
- org.jboss.cache.config.Configuration c = (org.jboss.cache.config.Configuration) super.clone();
- if (buddyReplicationConfig != null)
- {
- c.setBuddyReplicationConfig(buddyReplicationConfig.clone());
- }
- if (evictionConfig != null)
- {
- c.setEvictionConfig(evictionConfig.clone());
- }
- if (cacheLoaderConfig != null)
- {
- c.setCacheLoaderConfig(cacheLoaderConfig.clone());
- }
- if (runtimeConfig != null)
- {
- c.setRuntimeConfig(runtimeConfig.clone());
- // always make sure we reset the runtime when cloning.
- c.getRuntimeConfig().reset();
- }
- return c;
- }
-
- public boolean isUsingCacheLoaders()
- {
- return getCacheLoaderConfig() != null && !getCacheLoaderConfig().getIndividualCacheLoaderConfigs().isEmpty();
- }
-
- public boolean isUsingBuddyReplication()
- {
- return getBuddyReplicationConfig() != null && getBuddyReplicationConfig().isEnabled() &&
- getCacheMode() != CacheConfig.CacheMode.LOCAL;
- }
-
- public String getMuxStackName()
- {
- return muxStackName;
- }
-
- public void setMuxStackName(String muxStackName)
- {
- this.muxStackName = muxStackName;
- }
-
- /**
- * Returns the {@link org.jboss.cache.config.CustomInterceptorConfig}, if any, associated with this configuration
- * object. The custom interceptors will be added to the cache at startup in the sequence defined by this list.
- *
- * @return List of cutom interceptors, never null
- */
- @SuppressWarnings("unchecked")
- public List<CustomInterceptorConfig> getCustomInterceptors()
- {
- return customInterceptors == null ? Collections.EMPTY_LIST : customInterceptors;
- }
-
- /**
- * @see #getCustomInterceptors()
- */
- public void setCustomInterceptors(List<CustomInterceptorConfig> customInterceptors)
- {
- testImmutability("customInterceptors");
- this.customInterceptors = customInterceptors;
- }
-
- public BuddyManager getConsistentHashing()
- {
- return null;
- }
-
-}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/CacheLoaderConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/CacheLoaderConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/CacheLoaderConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,444 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.jboss.cache.loader.CacheLoader;
+import org.jboss.cache.loader.SingletonStoreCacheLoader;
+import org.jboss.cache.util.Util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Holds the configuration of the cache loader chain. ALL cache loaders should be defined using this class, adding
+ * individual cache loaders to the chain by calling {@link CacheLoaderConfig#addIndividualCacheLoaderConfig}
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ * @author Brian Stansberry
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+public class CacheLoaderConfig extends ConfigurationComponent
+{
+ private static final long serialVersionUID = 2210349340378984424L;
+
+ private boolean passivation;
+ private String preload;
+ private List<IndividualCacheLoaderConfig> cacheLoaderConfigs = new ArrayList<IndividualCacheLoaderConfig>();
+
+ private boolean shared;
+
+ public String getPreload()
+ {
+ return preload;
+ }
+
+ public void setPreload(String preload)
+ {
+ testImmutability("preload");
+ this.preload = preload;
+ }
+
+ public void setPassivation(boolean passivation)
+ {
+ testImmutability("passivation");
+ this.passivation = passivation;
+ }
+
+ public boolean isPassivation()
+ {
+ return passivation;
+ }
+
+ public void addIndividualCacheLoaderConfig(IndividualCacheLoaderConfig clc)
+ {
+ testImmutability("cacheLoaderConfigs");
+ cacheLoaderConfigs.add(clc);
+ // Ensure this config gets our back ref to the cache
+ addChildConfig(clc);
+ }
+
+ public List<IndividualCacheLoaderConfig> getIndividualCacheLoaderConfigs()
+ {
+ return cacheLoaderConfigs;
+ }
+
+ public void setIndividualCacheLoaderConfigs(List<IndividualCacheLoaderConfig> configs)
+ {
+ testImmutability("cacheLoaderConfigs");
+ // Ensure these configs get our back ref to the cache
+ replaceChildConfigs(this.cacheLoaderConfigs, configs);
+ this.cacheLoaderConfigs = configs == null ? new ArrayList<IndividualCacheLoaderConfig>() : configs;
+ }
+
+ public IndividualCacheLoaderConfig getFirstCacheLoaderConfig()
+ {
+ if (cacheLoaderConfigs.size() == 0) return null;
+ return cacheLoaderConfigs.get(0);
+ }
+
+ public boolean useChainingCacheLoader()
+ {
+ return !isPassivation() && cacheLoaderConfigs.size() > 1;
+ }
+
+ @Override
+ public String toString()
+ {
+ return new StringBuilder().append("CacheLoaderConfig{").append("shared=").append(shared).append(", passivation=").append(passivation).append(", preload='").append(preload).append('\'').append(", cacheLoaderConfigs.size()=").append(cacheLoaderConfigs.size()).append('}').toString();
+ }
+
+ public void setShared(boolean shared)
+ {
+ testImmutability("shared");
+ this.shared = shared;
+ }
+
+ public boolean isShared()
+ {
+ return shared;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+
+ if (obj instanceof CacheLoaderConfig)
+ {
+ CacheLoaderConfig other = (CacheLoaderConfig) obj;
+ return (this.passivation == other.passivation)
+ && (this.shared == other.shared)
+ && Util.safeEquals(this.preload, other.preload)
+ && Util.safeEquals(this.cacheLoaderConfigs, other.cacheLoaderConfigs);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = 19;
+ result = 51 * result + (passivation ? 0 : 1);
+ result = 51 * result + (shared ? 0 : 1);
+ result = 51 * result + (preload == null ? 0 : preload.hashCode());
+ result = 51 * result + (cacheLoaderConfigs == null ? 0 : cacheLoaderConfigs.hashCode());
+ return result;
+ }
+
+
+ @Override
+ public CacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ CacheLoaderConfig clone = (CacheLoaderConfig) super.clone();
+ if (cacheLoaderConfigs != null)
+ {
+ List<IndividualCacheLoaderConfig> clcs = new ArrayList<IndividualCacheLoaderConfig>(cacheLoaderConfigs.size());
+ for (IndividualCacheLoaderConfig clc : cacheLoaderConfigs)
+ {
+ clcs.add(clc.clone());
+ }
+ clone.setIndividualCacheLoaderConfigs(clcs);
+ }
+ return clone;
+ }
+
+ /**
+ * Loops through all individual cache loader configs and checks if fetchPersistentState is set on any of them
+ */
+ public boolean isFetchPersistentState()
+ {
+ for (IndividualCacheLoaderConfig iclc : cacheLoaderConfigs)
+ {
+ if (iclc.isFetchPersistentState()) return true;
+ }
+ return false;
+ }
+
+
+ /**
+ * Configuration object that holds the confguration of an individual cache loader.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ */
+ public static class IndividualCacheLoaderConfig extends PluggableConfigurationComponent
+ {
+ private static final long serialVersionUID = -2282396799100828593L;
+
+ private boolean async;
+ private boolean ignoreModifications;
+ private boolean fetchPersistentState;
+
+ private boolean purgeOnStartup;
+
+ private SingletonStoreConfig singletonStoreConfig;
+ private transient CacheLoader cacheLoader;
+
+ protected void populateFromBaseConfig(IndividualCacheLoaderConfig base)
+ {
+ if (base != null)
+ {
+ setAsync(base.isAsync());
+ setIgnoreModifications(base.isIgnoreModifications());
+ setFetchPersistentState(base.isFetchPersistentState());
+ setSingletonStoreConfig(base.getSingletonStoreConfig());
+ setPurgeOnStartup(base.isPurgeOnStartup());
+ setProperties(base.getProperties());
+ }
+ }
+
+ public boolean isPurgeOnStartup()
+ {
+ return purgeOnStartup;
+ }
+
+ public boolean isFetchPersistentState()
+ {
+ return fetchPersistentState;
+ }
+
+ public void setFetchPersistentState(boolean fetchPersistentState)
+ {
+ testImmutability("fetchPersistentState");
+ this.fetchPersistentState = fetchPersistentState;
+ }
+
+ public void setAsync(boolean async)
+ {
+ testImmutability("async");
+ this.async = async;
+ }
+
+ public boolean isAsync()
+ {
+ return async;
+ }
+
+ public void setIgnoreModifications(boolean ignoreModifications)
+ {
+ testImmutability("ignoreModifications");
+ this.ignoreModifications = ignoreModifications;
+ }
+
+ public boolean isIgnoreModifications()
+ {
+ return ignoreModifications;
+ }
+
+ public void setPurgeOnStartup(boolean purgeOnStartup)
+ {
+ testImmutability("purgeOnStartup");
+ this.purgeOnStartup = purgeOnStartup;
+ }
+
+ public SingletonStoreConfig getSingletonStoreConfig()
+ {
+ return singletonStoreConfig;
+ }
+
+ public void setSingletonStoreConfig(SingletonStoreConfig singletonStoreConfig)
+ {
+ testImmutability("singletonStoreConfig");
+ replaceChildConfig(this.singletonStoreConfig, singletonStoreConfig);
+ this.singletonStoreConfig = singletonStoreConfig;
+ }
+
+ /**
+ * Provides the ability to get and set a running cache loader, which, if exists, will be used rather than
+ * constructing a new one. Primarily to facilitate testing with mock objects.
+ *
+ * @return cache loader, if one exists
+ * @since 2.1.0
+ */
+ public CacheLoader getCacheLoader()
+ {
+ return cacheLoader;
+ }
+
+ /**
+ * Provides the ability to get and set a running cache loader, which, if exists, will be used rather than
+ * constructing a new one. Primarily to facilitate testing with mock objects.
+ *
+ * @param cacheLoader cacheLoader to set
+ * @since 2.1.0
+ */
+ public void setCacheLoader(CacheLoader cacheLoader)
+ {
+ this.cacheLoader = cacheLoader;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (super.equals(obj))
+ {
+ IndividualCacheLoaderConfig i = (IndividualCacheLoaderConfig) obj;
+ return equalsExcludingProperties(i);
+ }
+ return false;
+ }
+
+ protected boolean equalsExcludingProperties(Object obj)
+ {
+ if (!(obj instanceof IndividualCacheLoaderConfig))
+ return false;
+ IndividualCacheLoaderConfig other = (IndividualCacheLoaderConfig) obj;
+
+ return Util.safeEquals(this.className, other.className)
+ && (this.async == other.async)
+ && (this.ignoreModifications == other.ignoreModifications)
+ && (this.fetchPersistentState == other.fetchPersistentState)
+ && Util.safeEquals(this.singletonStoreConfig, other.singletonStoreConfig);
+
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return 31 * hashCodeExcludingProperties() + (properties == null ? 0 : properties.hashCode());
+ }
+
+ protected int hashCodeExcludingProperties()
+ {
+ int result = 17;
+ result = 31 * result + (className == null ? 0 : className.hashCode());
+ result = 31 * result + (async ? 0 : 1);
+ result = 31 * result + (ignoreModifications ? 0 : 1);
+ result = 31 * result + (fetchPersistentState ? 0 : 1);
+ result = 31 * result + (singletonStoreConfig == null ? 0 : singletonStoreConfig.hashCode());
+ result = 31 * result + (purgeOnStartup ? 0 : 1);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return new StringBuilder().append("IndividualCacheLoaderConfig{").append("className='").append(className).append('\'')
+ .append(", async=").append(async)
+ .append(", ignoreModifications=").append(ignoreModifications)
+ .append(", fetchPersistentState=").append(fetchPersistentState)
+ .append(", properties=").append(properties)
+ .append(", purgeOnStartup=").append(purgeOnStartup).append("},")
+ .append("SingletonStoreConfig{").append(singletonStoreConfig).append('}')
+ .toString();
+ }
+
+ @Override
+ public IndividualCacheLoaderConfig clone() throws CloneNotSupportedException
+ {
+ IndividualCacheLoaderConfig clone = (IndividualCacheLoaderConfig) super.clone();
+ if (singletonStoreConfig != null)
+ clone.setSingletonStoreConfig(singletonStoreConfig.clone());
+ clone.cacheLoader = cacheLoader;
+ return clone;
+ }
+
+ /**
+ * Configuration for a SingletonStoreCacheLoader
+ */
+ public static class SingletonStoreConfig extends PluggableConfigurationComponent
+ {
+ private static final long serialVersionUID = 824251894176131850L;
+
+ /**
+ * Indicates whether the singleton store functionality is enabled or not.
+ */
+ private boolean singletonStoreEnabled;
+
+ public SingletonStoreConfig()
+ {
+ // default value
+ className = SingletonStoreCacheLoader.class.getName();
+ }
+
+ public boolean isSingletonStoreEnabled()
+ {
+ return singletonStoreEnabled;
+ }
+
+ public void setSingletonStoreEnabled(boolean singletonStoreEnabled)
+ {
+ testImmutability("singletonStoreEnabled");
+ this.singletonStoreEnabled = singletonStoreEnabled;
+ }
+
+ public String getSingletonStoreClass()
+ {
+ return className;
+ }
+
+ public void setSingletonStoreClass(String className)
+ {
+ setClassName(className);
+ }
+
+ public Properties getSingletonStoreproperties()
+ {
+ return properties;
+ }
+
+ public void setSingletonStoreproperties(Properties properties)
+ {
+ setProperties(properties);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+
+ if (super.equals(obj))
+ {
+ SingletonStoreConfig other = (SingletonStoreConfig) obj;
+ return this.singletonStoreEnabled == other.singletonStoreEnabled;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = 19;
+ result = 41 * result + super.hashCode();
+ result = 41 * result + (singletonStoreEnabled ? 0 : 1);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return super.toString() + " enabled=" + singletonStoreEnabled +
+ " class=" + className +
+ " properties=" + properties;
+ }
+
+ @Override
+ public SingletonStoreConfig clone() throws CloneNotSupportedException
+ {
+ return (SingletonStoreConfig) super.clone();
+ }
+ }
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/CloneableConfigurationComponent.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/CloneableConfigurationComponent.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/CloneableConfigurationComponent.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import java.io.Serializable;
+
+/**
+ * Interface for all configurable components
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public interface CloneableConfigurationComponent extends Serializable, Cloneable
+{
+ CloneableConfigurationComponent clone() throws CloneNotSupportedException;
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -1,55 +1,1024 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.starobrno.config;
-
-import org.jboss.util.NotImplementedException;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author Mircea.Markus at jboss.com
- */
-public class Configuration
-{
- public Map<String, CacheConfig> cacheConfigs = new HashMap<String, CacheConfig>();
-
- //todo - to be implemented, do the parsing here
- public Configuration(String configFile)
- {
- throw new NotImplementedException("not impl!");
- }
-
- public Configuration()
- {
- }
-
- public CacheConfig getCacheConfig(String name)
- {
- return cacheConfigs.get(name);
- }
-
- public void addCacheConfig(String name, CacheConfig config)
- {
- cacheConfigs.put(name, config);
- }
-}
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.jboss.cache.Version;
+import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.marshall.Marshaller;
+import org.jboss.starobrno.config.parsing.JGroupsStackParser;
+import org.jboss.starobrno.factories.annotations.NonVolatile;
+import org.jboss.starobrno.factories.annotations.Start;
+import org.w3c.dom.Element;
+
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Encapsulates the configuration of a Cache.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ */
+ at NonVolatile
+public class Configuration extends ConfigurationComponent
+{
+ private static final long serialVersionUID = 5553791890144997466L;
+
+ private Marshaller marshaller;
+
+ private transient JGroupsStackParser jGroupsStackParser = new JGroupsStackParser();
+ private boolean invocationBatchingEnabled;
+
+ /**
+ * Behavior of the JVM shutdown hook registered by the cache
+ */
+ public static enum ShutdownHookBehavior
+ {
+ /**
+ * By default a shutdown hook is registered if no MBean server (apart from the JDK default) is detected.
+ */
+ DEFAULT,
+ /**
+ * Forces the cache to register a shutdown hook even if an MBean server is detected.
+ */
+ REGISTER,
+ /**
+ * Forces the cache NOT to register a shutdown hook, even if no MBean server is detected.
+ */
+ DONT_REGISTER
+ }
+
+ /**
+ * Cache replication mode.
+ */
+ public static enum CacheMode
+ {
+ /**
+ * Data is not replicated.
+ */
+ LOCAL,
+
+ /**
+ * Data replicated synchronously.
+ */
+ REPL_SYNC,
+
+ /**
+ * Data replicated asynchronously.
+ */
+ REPL_ASYNC,
+
+ /**
+ * Data invalidated synchronously.
+ */
+ INVALIDATION_SYNC,
+
+ /**
+ * Data invalidated asynchronously.
+ */
+ INVALIDATION_ASYNC;
+
+ /**
+ * Returns true if the mode is invalidation, either sync or async.
+ */
+ public boolean isInvalidation()
+ {
+ return this == INVALIDATION_SYNC || this == INVALIDATION_ASYNC;
+ }
+
+ public boolean isSynchronous()
+ {
+ return this == REPL_SYNC || this == INVALIDATION_SYNC || this == LOCAL;
+ }
+
+ }
+
+ public static CacheMode legacyModeToCacheMode(int legacyMode)
+ {
+ switch (legacyMode)
+ {
+ case 1:
+ return CacheMode.LOCAL;
+ case 2:
+ return CacheMode.REPL_ASYNC;
+ case 3:
+ return CacheMode.REPL_SYNC;
+ case 4:
+ return CacheMode.INVALIDATION_ASYNC;
+ case 5:
+ return CacheMode.INVALIDATION_SYNC;
+ default:
+ throw new IllegalArgumentException("Unknown legacy cache mode " +
+ legacyMode);
+ }
+ }
+
+ /**
+ * Cache node locking scheme.
+ */
+ public static enum NodeLockingScheme
+ {
+ /**
+ * Data is locked using the MVCC locking scheme. This is the default locking scheme in JBoss Cache 3.0.0.
+ *
+ * @see <a href="http://wiki.jboss.org/wiki/JBossCacheMVCC">http://wiki.jboss.org/wiki/JBossCacheMVCC</a>
+ */
+ MVCC
+ }
+
+ /**
+ * Default replication version, from {@link Version#getVersionShort}.
+ */
+ public static final short DEFAULT_REPLICATION_VERSION = Version.getVersionShort();
+
+ // ------------------------------------------------------------------------------------------------------------
+ // CONFIGURATION OPTIONS
+ // ------------------------------------------------------------------------------------------------------------
+
+ private String clusterName = "JBossCache-Cluster";
+ private String clusterConfig = null;
+ private boolean useReplQueue = false;
+ @Dynamic
+ private int replQueueMaxElements = 1000;
+ @Dynamic
+ private long replQueueInterval = 5000;
+ private boolean exposeManagementStatistics = true;
+ @Dynamic
+ private boolean fetchInMemoryState = true;
+ private short replicationVersion = DEFAULT_REPLICATION_VERSION;
+ @Dynamic
+ private long lockAcquisitionTimeout = 10000;
+ @Dynamic
+ private long syncReplTimeout = 15000;
+ private CacheMode cacheMode = CacheMode.LOCAL;
+ private boolean inactiveOnStartup = false;
+ @Dynamic
+ private long stateRetrievalTimeout = 10000;
+ private IsolationLevel isolationLevel = IsolationLevel.REPEATABLE_READ;
+ @Dynamic
+ private boolean lockParentForChildInsertRemove = false;
+ @Dynamic
+ private EvictionConfig evictionConfig = null;
+ private boolean useRegionBasedMarshalling = false;
+ private String transactionManagerLookupClass = null;
+ private CacheLoaderConfig cacheLoaderConfig = null;
+ @Dynamic
+ private boolean syncCommitPhase = false;
+ @Dynamic
+ private boolean syncRollbackPhase = false;
+ private BuddyReplicationConfig buddyReplicationConfig;
+
+ private NodeLockingScheme nodeLockingScheme = NodeLockingScheme.MVCC;
+ private String muxStackName = null;
+ private boolean usingMultiplexer = false;
+ private transient RuntimeConfig runtimeConfig;
+ private String marshallerClass;
+ private ShutdownHookBehavior shutdownHookBehavior = ShutdownHookBehavior.DEFAULT;
+ private boolean useLazyDeserialization = false;
+ private int objectInputStreamPoolSize = 50;
+ private int objectOutputStreamPoolSize = 50;
+ private List<CustomInterceptorConfig> customInterceptors = Collections.emptyList();
+ private boolean writeSkewCheck = false;
+ private int concurrencyLevel = 500;
+ private int listenerAsyncPoolSize = 1;
+ private int serializationExecutorPoolSize = 25;
+
+ @Start(priority = 1)
+ private void correctIsolationLevels()
+ {
+ // ensure the correct isolation level upgrades and/or downgrades are performed.
+ if (nodeLockingScheme == NodeLockingScheme.MVCC)
+ {
+ switch (isolationLevel)
+ {
+ case NONE:
+ case READ_UNCOMMITTED:
+ isolationLevel = IsolationLevel.READ_COMMITTED;
+ break;
+ case SERIALIZABLE:
+ isolationLevel = IsolationLevel.REPEATABLE_READ;
+ break;
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------------------------------------------
+ // SETTERS - MAKE SURE ALL SETTERS PERFORM testImmutability()!!!
+ // ------------------------------------------------------------------------------------------------------------
+
+ public void setCacheMarshaller(Marshaller instance)
+ {
+ marshaller = instance;
+ }
+
+ public Marshaller getMarshaller()
+ {
+ return marshaller;
+ }
+
+ public boolean isWriteSkewCheck()
+ {
+ return writeSkewCheck;
+ }
+
+ public void setWriteSkewCheck(boolean writeSkewCheck)
+ {
+ testImmutability("writeSkewCheck");
+ this.writeSkewCheck = writeSkewCheck;
+ }
+
+ public int getConcurrencyLevel()
+ {
+ return concurrencyLevel;
+ }
+
+ public void setConcurrencyLevel(int concurrencyLevel)
+ {
+ testImmutability("concurrencyLevel");
+ this.concurrencyLevel = concurrencyLevel;
+ }
+
+ /**
+ * Converts a list of elements to a Java Groups property string.
+ */
+ public void setClusterConfig(Element config)
+ {
+ setClusterConfig(jGroupsStackParser.parseClusterConfigXml(config));
+ }
+
+ public void setClusterName(String clusterName)
+ {
+ testImmutability("clusterName");
+ this.clusterName = clusterName;
+ }
+
+ public void setClusterConfig(String clusterConfig)
+ {
+ testImmutability("clusterConfig");
+ this.clusterConfig = clusterConfig;
+ }
+
+ public void setReplQueueMaxElements(int replQueueMaxElements)
+ {
+ testImmutability("replQueueMaxElements");
+ this.replQueueMaxElements = replQueueMaxElements;
+ }
+
+ public void setReplQueueInterval(long replQueueInterval)
+ {
+ testImmutability("replQueueInterval");
+ this.replQueueInterval = replQueueInterval;
+ }
+
+ public void setExposeManagementStatistics(boolean useMbean)
+ {
+ testImmutability("exposeManagementStatistics");
+ this.exposeManagementStatistics = useMbean;
+ }
+
+ /**
+ * Enables invocation batching if set to <tt>true</tt>. You still need to use {@link org.jboss.cache.Cache#startBatch()}
+ * and {@link org.jboss.cache.Cache#endBatch(boolean)} to demarcate the start and end of batches.
+ *
+ * @param enabled if true, batching is enabled.
+ * @since 3.0
+ */
+ public void setInvocationBatchingEnabled(boolean enabled)
+ {
+ testImmutability("invocationBatchingEnabled");
+ this.invocationBatchingEnabled = enabled;
+ }
+
+ public void setFetchInMemoryState(boolean fetchInMemoryState)
+ {
+ testImmutability("fetchInMemoryState");
+ this.fetchInMemoryState = fetchInMemoryState;
+ }
+
+ public void setReplicationVersion(short replicationVersion)
+ {
+ testImmutability("replicationVersion");
+ this.replicationVersion = replicationVersion;
+ }
+
+ public void setReplVersionString(String replVersionString)
+ {
+ setReplicationVersion(replVersionString == null ? 0 : Version.getVersionShort(replVersionString));
+ }
+
+ public void setLockAcquisitionTimeout(long lockAcquisitionTimeout)
+ {
+ testImmutability("lockAcquisitionTimeout");
+ this.lockAcquisitionTimeout = lockAcquisitionTimeout;
+ }
+
+ public void setSyncReplTimeout(long syncReplTimeout)
+ {
+ testImmutability("syncReplTimeout");
+ this.syncReplTimeout = syncReplTimeout;
+ }
+
+ public void setCacheMode(CacheMode cacheModeInt)
+ {
+ testImmutability("cacheMode");
+ this.cacheMode = cacheModeInt;
+ }
+
+ public void setCacheMode(String cacheMode)
+ {
+ testImmutability("cacheMode");
+ if (cacheMode == null) throw new ConfigurationException("Cache mode cannot be null", "CacheMode");
+ this.cacheMode = CacheMode.valueOf(uc(cacheMode));
+ if (this.cacheMode == null)
+ {
+ log.warn("Unknown cache mode '" + cacheMode + "', using defaults.");
+ this.cacheMode = CacheMode.LOCAL;
+ }
+ }
+
+ public String getCacheModeString()
+ {
+ return cacheMode == null ? null : cacheMode.toString();
+ }
+
+ public void setCacheModeString(String cacheMode)
+ {
+ setCacheMode(cacheMode);
+ }
+
+ public void setInactiveOnStartup(boolean inactiveOnStartup)
+ {
+ testImmutability("inactiveOnStartup");
+ this.inactiveOnStartup = inactiveOnStartup;
+ }
+
+ public EvictionConfig getEvictionConfig()
+ {
+ return evictionConfig;
+ }
+
+ public void setEvictionConfig(EvictionConfig config)
+ {
+ testImmutability("evictionConfig");
+ this.evictionConfig = config;
+ }
+
+ /**
+ * This is a deprecated configuration option. While it will be supported for the 2.x series for backward compatibility,
+ * expect to see it disappear in 3.x.
+ * <p/>
+ * With {@link #isUseLazyDeserialization()}, which is enabled by default, custom class loaders are handled implicitly.
+ * See the user guide for details on how this is handled.
+ * <p/>
+ */
+ public void setUseRegionBasedMarshalling(boolean useRegionBasedMarshalling)
+ {
+ testImmutability("useRegionBasedMarshalling");
+ this.useRegionBasedMarshalling = useRegionBasedMarshalling;
+ }
+
+ public void setTransactionManagerLookupClass(String transactionManagerLookupClass)
+ {
+ testImmutability("transactionManagerLookupClass");
+ this.transactionManagerLookupClass = transactionManagerLookupClass;
+ }
+
+ public void setCacheLoaderConfig(CacheLoaderConfig config)
+ {
+ testImmutability("cacheLoaderConfig");
+ replaceChildConfig(this.cacheLoaderConfig, config);
+ this.cacheLoaderConfig = config;
+ }
+
+ public void setSyncCommitPhase(boolean syncCommitPhase)
+ {
+ testImmutability("syncCommitPhase");
+ this.syncCommitPhase = syncCommitPhase;
+ }
+
+ public void setSyncRollbackPhase(boolean syncRollbackPhase)
+ {
+ testImmutability("syncRollbackPhase");
+ this.syncRollbackPhase = syncRollbackPhase;
+ }
+
+ /**
+ * Sets the size of the asynchronous listener notification thread pool size. Defaults to 1, and if set to below 1,
+ * all async listeners (specified with {@link org.jboss.cache.notifications.annotation.CacheListener#sync()} are notified
+ * synchronously.
+ *
+ * @param listenerAsyncPoolSize number of threads in pool
+ * @since 3.0
+ */
+ public void setListenerAsyncPoolSize(int listenerAsyncPoolSize)
+ {
+ testImmutability("asyncListenerPoolSize");
+ this.listenerAsyncPoolSize = listenerAsyncPoolSize;
+ }
+
+ public void setBuddyReplicationConfig(BuddyReplicationConfig config)
+ {
+ testImmutability("buddyReplicationConfig");
+ replaceChildConfig(this.buddyReplicationConfig, config);
+ this.buddyReplicationConfig = config;
+ }
+
+ public void setNodeLockingScheme(NodeLockingScheme nodeLockingScheme)
+ {
+ testImmutability("nodeLockingScheme");
+ testImmutability("nodeLockingOptimistic");
+ this.nodeLockingScheme = nodeLockingScheme;
+ }
+
+ public void setUseReplQueue(boolean useReplQueue)
+ {
+ testImmutability("useReplQueue");
+ this.useReplQueue = useReplQueue;
+ }
+
+ public void setIsolationLevel(IsolationLevel isolationLevel)
+ {
+ testImmutability("isolationLevel");
+ this.isolationLevel = isolationLevel;
+ }
+
+ public void setStateRetrievalTimeout(long stateRetrievalTimeout)
+ {
+ testImmutability("stateRetrievalTimeout");
+ this.stateRetrievalTimeout = stateRetrievalTimeout;
+ }
+
+ public void setNodeLockingScheme(String nodeLockingScheme)
+ {
+ testImmutability("nodeLockingScheme");
+ if (nodeLockingScheme == null)
+ {
+ throw new ConfigurationException("Node locking scheme cannot be null", "NodeLockingScheme");
+ }
+ this.nodeLockingScheme = NodeLockingScheme.valueOf(uc(nodeLockingScheme));
+ }
+
+ public String getNodeLockingSchemeString()
+ {
+ return nodeLockingScheme == null ? null : nodeLockingScheme.toString();
+ }
+
+ public void setNodeLockingSchemeString(String nodeLockingScheme)
+ {
+ setNodeLockingScheme(nodeLockingScheme);
+ }
+
+ private static String uc(String s)
+ {
+ return s.toUpperCase(Locale.ENGLISH);
+ }
+
+ public void setIsolationLevel(String isolationLevel)
+ {
+ testImmutability("isolationLevel");
+ if (isolationLevel == null) throw new ConfigurationException("Isolation level cannot be null", "IsolationLevel");
+ this.isolationLevel = IsolationLevel.valueOf(uc(isolationLevel));
+ if (this.isolationLevel == null)
+ {
+ log.warn("Unknown isolation level '" + isolationLevel + "', using defaults.");
+ this.isolationLevel = IsolationLevel.REPEATABLE_READ;
+ }
+ }
+
+ public String getIsolationLevelString()
+ {
+ return isolationLevel == null ? null : isolationLevel.toString();
+ }
+
+ public void setIsolationLevelString(String isolationLevel)
+ {
+ setIsolationLevel(isolationLevel);
+ }
+
+ /**
+ * Sets whether inserting or removing a node requires a write lock
+ * on the node's parent (when pessimistic locking is used.)
+ * <p/>
+ * The default value is <code>false</code>
+ */
+ public void setLockParentForChildInsertRemove(boolean lockParentForChildInsertRemove)
+ {
+ testImmutability("lockParentForChildInsertRemove");
+ this.lockParentForChildInsertRemove = lockParentForChildInsertRemove;
+ }
+
+ public void setMultiplexerStack(String stackName)
+ {
+ testImmutability("muxStackName");
+ this.muxStackName = stackName;
+ }
+
+ public boolean isUsingMultiplexer()
+ {
+ return usingMultiplexer;
+ }
+
+ public void setUsingMultiplexer(boolean usingMultiplexer)
+ {
+ testImmutability("usingMultiplexer");
+ this.usingMultiplexer = usingMultiplexer;
+ }
+
+ public void setShutdownHookBehavior(ShutdownHookBehavior shutdownHookBehavior)
+ {
+ testImmutability("shutdownHookBehavior");
+ this.shutdownHookBehavior = shutdownHookBehavior;
+ }
+
+ public void setShutdownHookBehavior(String shutdownHookBehavior)
+ {
+ testImmutability("shutdownHookBehavior");
+ if (shutdownHookBehavior == null)
+ throw new ConfigurationException("Shutdown hook behavior cannot be null", "ShutdownHookBehavior");
+ this.shutdownHookBehavior = ShutdownHookBehavior.valueOf(uc(shutdownHookBehavior));
+ if (this.shutdownHookBehavior == null)
+ {
+ log.warn("Unknown shutdown hook behavior '" + shutdownHookBehavior + "', using defaults.");
+ this.shutdownHookBehavior = ShutdownHookBehavior.DEFAULT;
+ }
+ }
+
+ public void setUseLazyDeserialization(boolean useLazyDeserialization)
+ {
+ testImmutability("useLazyDeserialization");
+ this.useLazyDeserialization = useLazyDeserialization;
+ }
+
+ /**
+ * Initialises the size of the object input stream pool size, which defaults to 50.
+ *
+ * @param objectInputStreamPoolSize
+ * @since 2.1.0
+ */
+ public void setObjectInputStreamPoolSize(int objectInputStreamPoolSize)
+ {
+ testImmutability("objectInputStreamPoolSize");
+ this.objectInputStreamPoolSize = objectInputStreamPoolSize;
+ }
+
+ /**
+ * Initialises the size of the object output stream pool size, which defaults to 50.
+ *
+ * @param objectOutputStreamPoolSize
+ * @since 2.1.0
+ */
+ public void setObjectOutputStreamPoolSize(int objectOutputStreamPoolSize)
+ {
+ testImmutability("objectOutputStreamPoolSize");
+ this.objectOutputStreamPoolSize = objectOutputStreamPoolSize;
+ }
+
+ /**
+ * Sets the async replication serialization executor pool size for async replication. Has no effect if the
+ * replication queue is used.
+ *
+ * @param serializationExecutorPoolSize number of threads to use
+ */
+ public void setSerializationExecutorPoolSize(int serializationExecutorPoolSize)
+ {
+ testImmutability("serializationExecutorPoolSize");
+ this.serializationExecutorPoolSize = serializationExecutorPoolSize;
+ }
+
+ // ------------------------------------------------------------------------------------------------------------
+ // GETTERS
+ // ------------------------------------------------------------------------------------------------------------
+
+
+ public ShutdownHookBehavior getShutdownHookBehavior()
+ {
+ return this.shutdownHookBehavior;
+ }
+
+ public boolean isUseReplQueue()
+ {
+ return useReplQueue;
+ }
+
+ public String getClusterName()
+ {
+ return clusterName;
+ }
+
+ public String getClusterConfig()
+ {
+ return clusterConfig;
+ }
+
+ public int getReplQueueMaxElements()
+ {
+ return replQueueMaxElements;
+ }
+
+ public long getReplQueueInterval()
+ {
+ return replQueueInterval;
+ }
+
+ /**
+ * @deprecated use isExposeManagementStatistics()
+ */
+ @Deprecated
+ public boolean getExposeManagementStatistics()
+ {
+ return exposeManagementStatistics;
+ }
+
+ public boolean isExposeManagementStatistics()
+ {
+ return exposeManagementStatistics;
+ }
+
+ /**
+ * @return true if invocation batching is enabled.
+ * @since 3.0
+ */
+ public boolean isInvocationBatchingEnabled()
+ {
+ return invocationBatchingEnabled;
+ }
+
+ public boolean isFetchInMemoryState()
+ {
+ return fetchInMemoryState;
+ }
+
+ public short getReplicationVersion()
+ {
+ return replicationVersion;
+ }
+
+ public String getReplVersionString()
+ {
+ return Version.getVersionString(replicationVersion);
+ }
+
+ public long getLockAcquisitionTimeout()
+ {
+ return lockAcquisitionTimeout;
+ }
+
+ public long getSyncReplTimeout()
+ {
+ return syncReplTimeout;
+ }
+
+ public CacheMode getCacheMode()
+ {
+ return cacheMode;
+ }
+
+ public boolean isInactiveOnStartup()
+ {
+ return inactiveOnStartup;
+ }
+
+ public IsolationLevel getIsolationLevel()
+ {
+ return isolationLevel;
+ }
+
+ /**
+ * Gets whether inserting or removing a node requires a write lock
+ * on the node's parent (when pessimistic locking is used.)
+ * <p/>
+ * The default value is <code>false</code>
+ */
+ public boolean isLockParentForChildInsertRemove()
+ {
+ return lockParentForChildInsertRemove;
+ }
+
+ public boolean isUseRegionBasedMarshalling()
+ {
+ return useRegionBasedMarshalling;
+ }
+
+ public String getTransactionManagerLookupClass()
+ {
+ return transactionManagerLookupClass;
+ }
+
+ public CacheLoaderConfig getCacheLoaderConfig()
+ {
+ return cacheLoaderConfig;
+ }
+
+ public boolean isSyncCommitPhase()
+ {
+ return syncCommitPhase;
+ }
+
+ public boolean isSyncRollbackPhase()
+ {
+ return syncRollbackPhase;
+ }
+
+ /**
+ * Gets the size of the asynchronous listener notification thread pool size. Defaults to 1, and if set to below 1,
+ * all async listeners (specified with {@link org.jboss.cache.notifications.annotation.CacheListener#sync()} are notified
+ * synchronously.
+ *
+ * @return thread pool size
+ * @since 3.0
+ */
+ public int getListenerAsyncPoolSize()
+ {
+ return listenerAsyncPoolSize;
+ }
+
+ public BuddyReplicationConfig getBuddyReplicationConfig()
+ {
+ return buddyReplicationConfig;
+ }
+
+ public NodeLockingScheme getNodeLockingScheme()
+ {
+ return nodeLockingScheme;
+ }
+
+ public long getStateRetrievalTimeout()
+ {
+ return stateRetrievalTimeout;
+ }
+
+ public String getMultiplexerStack()
+ {
+ return muxStackName;
+ }
+
+ public boolean isUseLazyDeserialization()
+ {
+ return useLazyDeserialization;
+ }
+
+ public synchronized RuntimeConfig getRuntimeConfig()
+ {
+ if (runtimeConfig == null)
+ {
+ setRuntimeConfig(new RuntimeConfig(), false);
+ }
+ return runtimeConfig;
+ }
+
+ public void setRuntimeConfig(RuntimeConfig runtimeConfig)
+ {
+ setRuntimeConfig(runtimeConfig, true);
+ }
+
+ private void setRuntimeConfig(RuntimeConfig runtimeConfig, boolean testImmutability)
+ {
+ if (testImmutability)
+ {
+ testImmutability("runtimeConfig");
+ }
+ this.runtimeConfig = runtimeConfig;
+ }
+
+ public String getMarshallerClass()
+ {
+ return marshallerClass;
+ }
+
+ public void setMarshallerClass(String marshallerClass)
+ {
+ this.marshallerClass = marshallerClass;
+ }
+
+ /**
+ * @return the size of he object input stream pool
+ * @since 2.1.0
+ */
+ public int getObjectInputStreamPoolSize()
+ {
+ return objectInputStreamPoolSize;
+ }
+
+ /**
+ * @return the size of he object output stream pool
+ * @since 2.1.0
+ */
+ public int getObjectOutputStreamPoolSize()
+ {
+ return objectOutputStreamPoolSize;
+ }
+
+
+ /**
+ * Returns a {@link java.net.URL} to a default JGroups configuration file.
+ *
+ * @return a default JGroups config file
+ */
+ public URL getDefaultClusterConfig()
+ {
+ URL url = getClass().getClassLoader().getResource("flush-udp.xml");
+ if (log.isTraceEnabled()) log.trace("Using default JGroups configuration file " + url);
+ return url;
+ }
+
+ /**
+ * @return the serialization executor pool size.
+ */
+ public int getSerializationExecutorPoolSize()
+ {
+ return serializationExecutorPoolSize;
+ }
+
+ // ------------------------------------------------------------------------------------------------------------
+ // HELPERS
+ // ------------------------------------------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------------------------------------------
+ // OVERRIDDEN METHODS
+ // ------------------------------------------------------------------------------------------------------------
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Configuration that = (Configuration) o;
+
+ if (exposeManagementStatistics != that.exposeManagementStatistics) return false;
+ if (fetchInMemoryState != that.fetchInMemoryState) return false;
+ if (inactiveOnStartup != that.inactiveOnStartup) return false;
+ if (lockAcquisitionTimeout != that.lockAcquisitionTimeout) return false;
+ if (lockParentForChildInsertRemove != that.lockParentForChildInsertRemove) return false;
+ if (objectInputStreamPoolSize != that.objectInputStreamPoolSize) return false;
+ if (objectOutputStreamPoolSize != that.objectOutputStreamPoolSize) return false;
+ if (replQueueInterval != that.replQueueInterval) return false;
+ if (replQueueMaxElements != that.replQueueMaxElements) return false;
+ if (replicationVersion != that.replicationVersion) return false;
+ if (stateRetrievalTimeout != that.stateRetrievalTimeout) return false;
+ if (syncCommitPhase != that.syncCommitPhase) return false;
+ if (syncReplTimeout != that.syncReplTimeout) return false;
+ if (syncRollbackPhase != that.syncRollbackPhase) return false;
+ if (useLazyDeserialization != that.useLazyDeserialization) return false;
+ if (useRegionBasedMarshalling != that.useRegionBasedMarshalling) return false;
+ if (useReplQueue != that.useReplQueue) return false;
+ if (usingMultiplexer != that.usingMultiplexer) return false;
+ if (buddyReplicationConfig != null ? !buddyReplicationConfig.equals(that.buddyReplicationConfig) : that.buddyReplicationConfig != null)
+ return false;
+ if (cacheLoaderConfig != null ? !cacheLoaderConfig.equals(that.cacheLoaderConfig) : that.cacheLoaderConfig != null)
+ return false;
+ if (cacheMode != that.cacheMode) return false;
+ if (clusterConfig != null ? !clusterConfig.equals(that.clusterConfig) : that.clusterConfig != null) return false;
+ if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+ if (evictionConfig != null ? !evictionConfig.equals(that.evictionConfig) : that.evictionConfig != null)
+ return false;
+ if (isolationLevel != that.isolationLevel) return false;
+ if (marshaller != null ? !marshaller.equals(that.marshaller) : that.marshaller != null) return false;
+ if (marshallerClass != null ? !marshallerClass.equals(that.marshallerClass) : that.marshallerClass != null)
+ return false;
+ if (muxStackName != null ? !muxStackName.equals(that.muxStackName) : that.muxStackName != null) return false;
+ if (nodeLockingScheme != that.nodeLockingScheme) return false;
+ if (runtimeConfig != null ? !runtimeConfig.equals(that.runtimeConfig) : that.runtimeConfig != null) return false;
+ if (shutdownHookBehavior != that.shutdownHookBehavior) return false;
+ if (transactionManagerLookupClass != null ? !transactionManagerLookupClass.equals(that.transactionManagerLookupClass) : that.transactionManagerLookupClass != null)
+ return false;
+ if (listenerAsyncPoolSize != that.listenerAsyncPoolSize) return false;
+ if (serializationExecutorPoolSize != that.serializationExecutorPoolSize) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result;
+ result = (marshaller != null ? marshaller.hashCode() : 0);
+ result = 31 * result + (clusterName != null ? clusterName.hashCode() : 0);
+ result = 31 * result + (clusterConfig != null ? clusterConfig.hashCode() : 0);
+ result = 31 * result + (useReplQueue ? 1 : 0);
+ result = 31 * result + replQueueMaxElements;
+ result = 31 * result + (int) (replQueueInterval ^ (replQueueInterval >>> 32));
+ result = 31 * result + (exposeManagementStatistics ? 1 : 0);
+ result = 31 * result + (fetchInMemoryState ? 1 : 0);
+ result = 31 * result + (int) replicationVersion;
+ result = 31 * result + (int) (lockAcquisitionTimeout ^ (lockAcquisitionTimeout >>> 32));
+ result = 31 * result + (int) (syncReplTimeout ^ (syncReplTimeout >>> 32));
+ result = 31 * result + (cacheMode != null ? cacheMode.hashCode() : 0);
+ result = 31 * result + (inactiveOnStartup ? 1 : 0);
+ result = 31 * result + (int) (stateRetrievalTimeout ^ (stateRetrievalTimeout >>> 32));
+ result = 31 * result + (isolationLevel != null ? isolationLevel.hashCode() : 0);
+ result = 31 * result + (lockParentForChildInsertRemove ? 1 : 0);
+ result = 31 * result + (evictionConfig != null ? evictionConfig.hashCode() : 0);
+ result = 31 * result + (useRegionBasedMarshalling ? 1 : 0);
+ result = 31 * result + (transactionManagerLookupClass != null ? transactionManagerLookupClass.hashCode() : 0);
+ result = 31 * result + (cacheLoaderConfig != null ? cacheLoaderConfig.hashCode() : 0);
+ result = 31 * result + (syncCommitPhase ? 1 : 0);
+ result = 31 * result + (syncRollbackPhase ? 1 : 0);
+ result = 31 * result + (buddyReplicationConfig != null ? buddyReplicationConfig.hashCode() : 0);
+ result = 31 * result + (nodeLockingScheme != null ? nodeLockingScheme.hashCode() : 0);
+ result = 31 * result + (muxStackName != null ? muxStackName.hashCode() : 0);
+ result = 31 * result + (usingMultiplexer ? 1 : 0);
+ result = 31 * result + (runtimeConfig != null ? runtimeConfig.hashCode() : 0);
+ result = 31 * result + (marshallerClass != null ? marshallerClass.hashCode() : 0);
+ result = 31 * result + (shutdownHookBehavior != null ? shutdownHookBehavior.hashCode() : 0);
+ result = 31 * result + (useLazyDeserialization ? 1 : 0);
+ result = 31 * result + objectInputStreamPoolSize;
+ result = 31 * result + objectOutputStreamPoolSize;
+ result = 31 * result + serializationExecutorPoolSize;
+ return result;
+ }
+
+ @Override
+ public Configuration clone() throws CloneNotSupportedException
+ {
+ Configuration c = (Configuration) super.clone();
+ if (buddyReplicationConfig != null)
+ {
+ c.setBuddyReplicationConfig(buddyReplicationConfig.clone());
+ }
+ if (evictionConfig != null)
+ {
+ c.setEvictionConfig(evictionConfig.clone());
+ }
+ if (cacheLoaderConfig != null)
+ {
+ c.setCacheLoaderConfig(cacheLoaderConfig.clone());
+ }
+ if (runtimeConfig != null)
+ {
+ c.setRuntimeConfig(runtimeConfig.clone());
+ // always make sure we reset the runtime when cloning.
+ c.getRuntimeConfig().reset();
+ }
+ return c;
+ }
+
+ public boolean isUsingCacheLoaders()
+ {
+ return getCacheLoaderConfig() != null && !getCacheLoaderConfig().getIndividualCacheLoaderConfigs().isEmpty();
+ }
+
+ public boolean isUsingBuddyReplication()
+ {
+ return getBuddyReplicationConfig() != null && getBuddyReplicationConfig().isEnabled() &&
+ getCacheMode() != Configuration.CacheMode.LOCAL;
+ }
+
+ public String getMuxStackName()
+ {
+ return muxStackName;
+ }
+
+ public void setMuxStackName(String muxStackName)
+ {
+ this.muxStackName = muxStackName;
+ }
+
+ /**
+ * Returns the {@link org.jboss.cache.config.CustomInterceptorConfig}, if any, associated with this configuration
+ * object. The custom interceptors will be added to the cache at startup in the sequence defined by this list.
+ *
+ * @return List of cutom interceptors, never null
+ */
+ @SuppressWarnings("unchecked")
+ public List<CustomInterceptorConfig> getCustomInterceptors()
+ {
+ return customInterceptors == null ? Collections.EMPTY_LIST : customInterceptors;
+ }
+
+ /**
+ * @see #getCustomInterceptors()
+ */
+ public void setCustomInterceptors(List<CustomInterceptorConfig> customInterceptors)
+ {
+ testImmutability("customInterceptors");
+ this.customInterceptors = customInterceptors;
+ }
+
+ public BuddyManager getConsistentHashing()
+ {
+ return null;
+ }
+
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationComponent.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,168 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.CacheStatus;
+import org.jboss.starobrno.factories.ComponentRegistry;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.Start;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Base superclass of Cache configuration classes that expose some properties
+ * that can be changed after the cache is started.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 6776 $
+ * @see #testImmutability(String)
+ */
+public abstract class ConfigurationComponent implements CloneableConfigurationComponent
+{
+ private static final long serialVersionUID = 4879873994727821938L;
+
+ protected transient Log log = LogFactory.getLog(getClass());
+ private transient CacheSPI cache; // back-reference to test whether the cache is running.
+ private final Set<ConfigurationComponent> children = Collections.synchronizedSet(new HashSet<ConfigurationComponent>());
+ private transient ComponentRegistry cr;
+ // a workaround to get over immutability checks
+ private boolean accessible;
+
+ protected ConfigurationComponent()
+ {
+ }
+
+ public void passCacheToChildConfig(ConfigurationComponent child)
+ {
+ if (child != null)
+ {
+ child.setCache(cache);
+ }
+ }
+
+ protected void addChildConfig(ConfigurationComponent child)
+ {
+ if (child != null && children.add(child))
+ child.setCache(cache);
+ }
+
+ protected void addChildConfigs(Collection<? extends ConfigurationComponent> toAdd)
+ {
+ if (toAdd != null)
+ {
+ for (ConfigurationComponent child : toAdd)
+ addChildConfig(child);
+ }
+ }
+
+ protected void removeChildConfig(ConfigurationComponent child)
+ {
+ children.remove(child);
+ }
+
+ protected void removeChildConfigs(Collection<? extends ConfigurationComponent> toRemove)
+ {
+ if (toRemove != null)
+ {
+ for (ConfigurationComponent child : toRemove)
+ removeChildConfig(child);
+ }
+ }
+
+ protected void replaceChildConfig(ConfigurationComponent oldConfig, ConfigurationComponent newConfig)
+ {
+ removeChildConfig(oldConfig);
+ addChildConfig(newConfig);
+ }
+
+ protected void replaceChildConfigs(Collection<? extends ConfigurationComponent> oldConfigs,
+ Collection<? extends ConfigurationComponent> newConfigs)
+ {
+ synchronized (children)
+ {
+ removeChildConfigs(oldConfigs);
+ addChildConfigs(newConfigs);
+ }
+ }
+
+ /**
+ * Checks field modifications via setters
+ *
+ * @param fieldName
+ */
+ protected void testImmutability(String fieldName)
+ {
+ try
+ {
+ if (!accessible && cache != null && cache.getCacheStatus() != null && cache.getCacheStatus() == CacheStatus.STARTED && !getClass().getDeclaredField(fieldName).isAnnotationPresent(Dynamic.class))
+ {
+ throw new ConfigurationException("Attempted to modify a non-Dynamic configuration element [" + fieldName + "] after the cache has started!");
+ }
+ }
+ catch (NoSuchFieldException e)
+ {
+ log.warn("Field " + fieldName + " not found!!");
+ }
+ finally
+ {
+ accessible = false;
+ }
+ }
+
+ public void setCache(CacheSPI cache)
+ {
+ this.cache = cache;
+ synchronized (children)
+ {
+ for (ConfigurationComponent child : children)
+ {
+ child.setCache(cache);
+ }
+ }
+ }
+
+ @Inject
+ private void injectDependencies(ComponentRegistry cr)
+ {
+ this.cr = cr;
+ }
+
+ @Start
+ private void start()
+ {
+ setCache(cr.getComponent(CacheSPI.class));
+ }
+
+ @Override
+ public CloneableConfigurationComponent clone() throws CloneNotSupportedException
+ {
+ ConfigurationComponent c = (ConfigurationComponent) super.clone();
+ c.setCache(null);
+ return c;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationException.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationException.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationException.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.jboss.starobrno.CacheException;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An exception that represents an error in the configuration. This could be a parsing error or a logical error involving clashing
+ * configuration options or missing mandatory configuration elements.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ * @see org.jboss.cache.config.Configuration
+ * @see org.jboss.cache.CacheFactory
+ */
+public class ConfigurationException extends CacheException
+{
+
+ private static final long serialVersionUID = -5576382839360927955L;
+
+ private List<String> erroneousAttributes = new ArrayList<String>();
+
+ public ConfigurationException(Exception e)
+ {
+ super(e);
+ }
+
+ public ConfigurationException(String string)
+ {
+ super(string);
+ }
+
+ public ConfigurationException(String string, String erroneousAttribute)
+ {
+ super(string);
+ erroneousAttributes.add(erroneousAttribute);
+ }
+
+ public ConfigurationException(String string, Throwable throwable)
+ {
+ super(string, throwable);
+ }
+
+ public List<String> getErroneousAttributes()
+ {
+ return erroneousAttributes;
+ }
+
+ public void addErroneousAttribute(String s)
+ {
+ erroneousAttributes.add(s);
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationRegistry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationRegistry.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import java.util.Set;
+
+
+/**
+ * A registry for {@link Configuration}s.
+ *
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public interface ConfigurationRegistry
+{
+ /**
+ * Gets a {@link Configuration#clone() clone} of the {@link Configuration}
+ * registered under the given name.
+ * <p/>
+ * The returned object is a clone of the internally held configuration,
+ * so any changes made to it by the caller will not affect the internal
+ * state of this registry.
+ *
+ * @param configName the name of the configuration
+ * @return a <code>Configuration</code>. Will not be <code>null</code>.
+ * @throws IllegalArgumentException if no configuration is registered
+ * under <code>configName</code>
+ */
+ Configuration getConfiguration(String configName) throws Exception;
+
+ /**
+ * Register the given configuration under the given name.
+ * <p/>
+ * The configuration will be cloned before being stored internally,
+ * so the copy under the control of the registry will not be affected
+ * by any external changes.
+ *
+ * @param configName the name of the configuration
+ * @param config the configuration
+ * @throws CloneNotSupportedException
+ * @throws IllegalStateException if a configuration is already registered
+ * under <code>configName</code>
+ */
+ void registerConfiguration(String configName, Configuration config) throws CloneNotSupportedException;
+
+ /**
+ * Unregisters the named configuration.
+ *
+ * @param configName the name of the configuration
+ * @throws IllegalStateException if no configuration is registered
+ * under <code>configName</code>
+ */
+ void unregisterConfiguration(String configName);
+
+ /**
+ * Gets the names of all registered configurations.
+ *
+ * @return a set of configuration names
+ */
+ Set<String> getConfigurationNames();
+}
\ No newline at end of file
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/config/ConfigurationRegistry.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/CustomInterceptorConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/CustomInterceptorConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/CustomInterceptorConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,223 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import net.jcip.annotations.Immutable;
+import org.jboss.starobrno.interceptors.base.CommandInterceptor;
+
+/**
+ * Holds information about the custom interceptors defined in the configuration file.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 3.0
+ */
+ at Immutable
+public class CustomInterceptorConfig extends ConfigurationComponent
+{
+ private CommandInterceptor interceptor;
+ private boolean isFirst;
+ private boolean isLast;
+ private int index = -1;
+ private String afterClass;
+ private String beforeClass;
+
+ /**
+ * Builds a custom interceptor.
+ *
+ * @param interceptor interceptor instance, already initialized with all attributes specified in the configuration
+ * @param first true if you wan this to be the first interceptor in the chain
+ * @param last true if you wan this to be the last interceptor in the chain
+ * @param index an absolute position within the interceptor chain
+ * @param afterClass if you want this interceptor immediately after the specified class in the chain
+ * @param beforeClass immediately before the specified class in the chain
+ */
+ public CustomInterceptorConfig(CommandInterceptor interceptor, boolean first, boolean last, int index,
+ String afterClass, String beforeClass)
+ {
+ this.interceptor = interceptor;
+ isFirst = first;
+ isLast = last;
+ this.index = index;
+ this.afterClass = afterClass;
+ this.beforeClass = beforeClass;
+ }
+
+ /**
+ * Constructs an interceptor config based on the supplied interceptor instance.
+ *
+ * @param interceptor
+ */
+ public CustomInterceptorConfig(CommandInterceptor interceptor)
+ {
+ this.interceptor = interceptor;
+ }
+
+ /**
+ * Shall this interceptor be the first one in the chain?
+ */
+ public void setFirst(boolean first)
+ {
+ testImmutability("first");
+ isFirst = first;
+ }
+
+ /**
+ * Shall this intercepto be the last one in the chain?
+ */
+ public void setLast(boolean last)
+ {
+ testImmutability("last");
+ isLast = last;
+ }
+
+ /**
+ * Put this interceptor at the specified index, after the default chain is built.
+ * If the index is not valid (negative or grater than the size of the chain)
+ * an {@link org.jboss.cache.config.ConfigurationException} is thrown at construction time.
+ */
+ public void setIndex(int index)
+ {
+ testImmutability("index");
+ this.index = index;
+ }
+
+ /**
+ * Adds the interceptor immediately after the first occurance of an interceptor having the given class.
+ * If the chain does not contain such an interceptor then this interceptor definition is ignored.
+ */
+ public void setAfterClass(String afterClass)
+ {
+ testImmutability("afterClass");
+ this.afterClass = afterClass;
+ }
+
+ /**
+ * Adds the interceptor immediately before the first occurance of an interceptor having the given class.
+ * If the chain does not contain such an interceptor then this interceptor definition is ignored.
+ */
+ public void setBeforeClass(String beforeClass)
+ {
+ testImmutability("beforeClass");
+ this.beforeClass = beforeClass;
+ }
+
+ /**
+ * Returns a the interceptor that we want to add to the chain.
+ */
+ public CommandInterceptor getInterceptor()
+ {
+ return interceptor;
+ }
+
+ /**
+ * @see #setFirst(boolean)
+ */
+ public boolean isFirst()
+ {
+ return isFirst;
+ }
+
+ /**
+ * @see #setLast(boolean)
+ */
+ public boolean isLast()
+ {
+ return isLast;
+ }
+
+ /**
+ * @see #getIndex()
+ */
+ public int getIndex()
+ {
+ return index;
+ }
+
+ /**
+ * @see #getAfterClass()
+ */
+ public String getAfterClass()
+ {
+ return afterClass;
+ }
+
+ /**
+ * @see #getBeforeClass()
+ */
+ public String getBeforeClass()
+ {
+ return beforeClass;
+ }
+
+ public String toString()
+ {
+ return "CustomInterceptorConfig{" +
+ "interceptor='" + interceptor + '\'' +
+ ", isFirst=" + isFirst +
+ ", isLast=" + isLast +
+ ", index=" + index +
+ ", afterClass='" + afterClass + '\'' +
+ ", beforeClass='" + beforeClass + '\'' +
+ '}';
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (!(o instanceof CustomInterceptorConfig)) return false;
+
+ CustomInterceptorConfig that = (CustomInterceptorConfig) o;
+
+ if (index != that.index) return false;
+ if (isFirst != that.isFirst) return false;
+ if (isLast != that.isLast) return false;
+ if (afterClass != null ? !afterClass.equals(that.afterClass) : that.afterClass != null) return false;
+ if (beforeClass != null ? !beforeClass.equals(that.beforeClass) : that.beforeClass != null) return false;
+ if (interceptor != null ? !interceptor.equals(that.interceptor) : that.interceptor != null)
+ return false;
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (interceptor != null ? interceptor.hashCode() : 0);
+ result = 31 * result + (isFirst ? 1 : 0);
+ result = 31 * result + (isLast ? 1 : 0);
+ result = 31 * result + index;
+ result = 31 * result + (afterClass != null ? afterClass.hashCode() : 0);
+ result = 31 * result + (beforeClass != null ? beforeClass.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public CustomInterceptorConfig clone() throws CloneNotSupportedException
+ {
+ CustomInterceptorConfig dolly = (CustomInterceptorConfig) super.clone();
+ dolly.interceptor = interceptor;
+ dolly.isFirst = isFirst;
+ dolly.isLast = isLast;
+ dolly.afterClass = afterClass;
+ dolly.beforeClass = beforeClass;
+ return dolly;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/Dynamic.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/Dynamic.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/Dynamic.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation that marks fields in {@link Configuration} as being modifiable even after the cache has started.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ * @since 2.0.0
+ */
+
+// ensure this annotation is available at runtime.
+ at Retention(RetentionPolicy.RUNTIME)
+
+// ensure that this annotation is documented on fields in Configuration
+ at Documented
+
+// only applies to fields.
+ at Target(ElementType.FIELD)
+
+public @interface Dynamic
+{
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionAlgorithmConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+/**
+ * An interface used to configure an eviction algorithm. Replaces the deprecated {@link org.jboss.cache.config.EvictionPolicyConfig}.
+ * <p/>
+ * In its most basic form, it is implemented by {@link org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase}, but
+ * more specific eviction policies may subclass {@link org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase} or re-implement
+ * this interface to provide access to more config variables.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public interface EvictionAlgorithmConfig extends CloneableConfigurationComponent
+{
+ /**
+ * Gets the class name of the {@link org.jboss.starobrno.eviction.EvictionAlgorithm} implementation
+ * this object will configure.
+ *
+ * @return fully qualified class name
+ */
+ String getEvictionAlgorithmClassName();
+
+ /**
+ * Validate the configuration. Will be called after any configuration
+ * properties are set.
+ *
+ * @throws ConfigurationException if any values for the configuration
+ * properties are invalid
+ */
+ void validate() throws ConfigurationException;
+
+ /**
+ * Resets the values to their defaults.
+ */
+ void reset();
+
+ /**
+ * @return a clone of the EvictionAlgorithmConfig.
+ */
+ EvictionAlgorithmConfig clone() throws CloneNotSupportedException;
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,307 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.RegionManagerImpl;
+import org.jboss.starobrno.eviction.DefaultEvictionActionPolicy;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+public class EvictionConfig extends ConfigurationComponent
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -7979639000026975201L;
+
+ public static final int WAKEUP_DEFAULT = 5000;
+ public static final int EVENT_QUEUE_SIZE_DEFAULT = 200000;
+ public static final String EVICTION_ACTION_POLICY_CLASS_DEFAULT = DefaultEvictionActionPolicy.class.getName();
+
+ /**
+ * value expressed in millis
+ */
+ @Dynamic
+ private long wakeupInterval = WAKEUP_DEFAULT;
+
+ private int defaultEventQueueSize = EVENT_QUEUE_SIZE_DEFAULT;
+
+ // Dynamic to support runtime adds/removes of regions
+ @Dynamic
+ private List<EvictionRegionConfig> evictionRegionConfigs;
+ private EvictionRegionConfig defaultEvictionRegionConfig;
+ @Deprecated
+ private String defaultEvictionPolicyClass;
+
+ public EvictionConfig()
+ {
+ evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
+ defaultEvictionRegionConfig = new EvictionRegionConfig(Fqn.ROOT);
+ defaultEvictionRegionConfig.setEventQueueSize(EVENT_QUEUE_SIZE_DEFAULT);
+ defaultEvictionRegionConfig.setEvictionActionPolicyClassName(DefaultEvictionActionPolicy.class.getName());
+ }
+
+ public EvictionConfig(EvictionRegionConfig defaultEvictionRegionConfig)
+ {
+ evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
+ try
+ {
+ this.defaultEvictionRegionConfig = defaultEvictionRegionConfig.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ throw new ConfigurationException(e);
+ }
+ this.defaultEvictionRegionConfig.setEventQueueSize(EVENT_QUEUE_SIZE_DEFAULT);
+ if (this.defaultEvictionRegionConfig.getEvictionActionPolicyClassName() == null)
+ this.defaultEvictionRegionConfig.setEvictionActionPolicyClassName(DefaultEvictionActionPolicy.class.getName());
+ }
+
+ public EvictionConfig(EvictionRegionConfig defaultEvictionRegionConfig, int wakeupInterval)
+ {
+ this(defaultEvictionRegionConfig);
+ this.wakeupInterval = wakeupInterval;
+ }
+
+ public boolean isValidConfig()
+ {
+ return (defaultEvictionRegionConfig != null && defaultEvictionRegionConfig.getEvictionActionPolicyClassName() != null && defaultEvictionRegionConfig.getEvictionAlgorithmConfig() != null)
+ || (evictionRegionConfigs != null && evictionRegionConfigs.size() > 0);
+ }
+
+ public EvictionRegionConfig getDefaultEvictionRegionConfig()
+ {
+ return defaultEvictionRegionConfig;
+ }
+
+ public void setDefaultEvictionRegionConfig(EvictionRegionConfig defaultEvictionRegionConfig)
+ {
+ this.defaultEvictionRegionConfig = defaultEvictionRegionConfig;
+ this.defaultEvictionRegionConfig.setEventQueueSizeIfUnset(EVENT_QUEUE_SIZE_DEFAULT);
+ }
+
+ /**
+ * @deprecated use {@link #getDefaultEvictionRegionConfig()} instead.
+ */
+ @Deprecated
+ public String getDefaultEvictionPolicyClass()
+ {
+ return defaultEvictionPolicyClass;
+ }
+
+ /**
+ * Creates an EvictionRegionConfig for the
+ * {@link org.jboss.cache.RegionManagerImpl#DEFAULT_REGION "_default_"} region using the
+ * {@link #getDefaultEvictionPolicyClass()} default eviction policy class}. Throws a
+ * {@link ConfigurationException} if
+ * {@link #setDefaultEvictionPolicyClass(String) a default eviction policy class}
+ * has not been set.
+ *
+ * @return an EvictionRegionConfig whose FQN is {@link org.jboss.cache.RegionManagerImpl#DEFAULT_REGION}
+ * and whose EvictionPolicyConfig is the default config for the
+ * default eviction policy class.
+ * @throws ConfigurationException if a
+ * {@link #setDefaultEvictionPolicyClass(String) a default eviction policy class}
+ * has not been set or there is a problem instantiating the configuration.
+ * @deprecated the default region is now created when this instance is constructed. Use {@link #getDefaultEvictionRegionConfig()} instead.
+ */
+ @Deprecated
+ public EvictionRegionConfig createDefaultEvictionRegionConfig()
+ {
+ return getDefaultEvictionRegionConfig();
+ }
+
+ public List<EvictionRegionConfig> getEvictionRegionConfigs()
+ {
+ return evictionRegionConfigs;
+ }
+
+ public void setEvictionRegionConfigs(List<EvictionRegionConfig> evictionRegionConfigs)
+ {
+ testImmutability("evictionRegionConfigs");
+ EvictionRegionConfig toRemove = null;
+ for (EvictionRegionConfig erc : evictionRegionConfigs)
+ {
+ if (erc.getRegionFqn().isRoot() || erc.getRegionFqn().equals(RegionManagerImpl.DEFAULT_REGION))
+ {
+ mergeWithDefault(erc);
+ toRemove = erc;
+ break;
+ }
+ }
+
+ if (toRemove != null) evictionRegionConfigs.remove(toRemove);
+
+ this.evictionRegionConfigs = evictionRegionConfigs;
+ }
+
+ private void mergeWithDefault(EvictionRegionConfig erc)
+ {
+ erc.setEventQueueSizeIfUnset(defaultEvictionRegionConfig.getEventQueueSize());
+ if (erc.getEvictionAlgorithmConfig() == null)
+ erc.setEvictionAlgorithmConfig(defaultEvictionRegionConfig.getEvictionAlgorithmConfig());
+ defaultEvictionRegionConfig = erc;
+ }
+
+ public void addEvictionRegionConfig(EvictionRegionConfig evictionRegionConfig)
+ {
+ testImmutability("evictionRegionConfigs");
+ if (evictionRegionConfig.getRegionFqn().isRoot() || evictionRegionConfig.getRegionFqn().equals(RegionManagerImpl.DEFAULT_REGION))
+ {
+ mergeWithDefault(evictionRegionConfig);
+ }
+ else
+ {
+ evictionRegionConfigs.add(evictionRegionConfig);
+ }
+ }
+
+ /**
+ * @return the wake up interval of the eviction thread, in milliseconds.
+ */
+ public long getWakeupInterval()
+ {
+ return wakeupInterval;
+ }
+
+ /**
+ * Set the wake up interval for the eviction thread. 0 or a negative number disables the eviction thread.
+ *
+ * @param wakeupInterval interval, in milliseconds.
+ */
+ public void setWakeupInterval(long wakeupInterval)
+ {
+ testImmutability("wakeupInterval");
+ this.wakeupInterval = wakeupInterval;
+ }
+
+ /**
+ * Set the wake up interval for the eviction thread. 0 or a negative number disables the eviction thread.
+ *
+ * @param wakeupInterval interval
+ * @param timeUnit for the interval provided
+ */
+ public void setWakeupInterval(long wakeupInterval, TimeUnit timeUnit)
+ {
+ testImmutability("wakeupInterval");
+ this.wakeupInterval = timeUnit.toMillis(wakeupInterval);
+ }
+
+ /**
+ * @deprecated Use {@link #getWakeupIntervalSeconds()}.
+ */
+ @Deprecated
+ public int getWakeupIntervalSeconds()
+ {
+ return (int) TimeUnit.MILLISECONDS.toSeconds(wakeupInterval);
+ }
+
+ /**
+ * @deprecated Use {@link #setWakeupInterval(long)}.
+ */
+ @Deprecated
+ public void setWakeupIntervalSeconds(int wakeupIntervalSeconds)
+ {
+ setWakeupInterval(wakeupIntervalSeconds, TimeUnit.SECONDS);
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (!(o instanceof EvictionConfig)) return false;
+
+ EvictionConfig that = (EvictionConfig) o;
+
+ if (defaultEventQueueSize != that.defaultEventQueueSize) return false;
+ if (wakeupInterval != that.wakeupInterval) return false;
+ if (defaultEvictionRegionConfig != null ? !defaultEvictionRegionConfig.equals(that.defaultEvictionRegionConfig) : that.defaultEvictionRegionConfig != null)
+ return false;
+ if (evictionRegionConfigs != null ? !evictionRegionConfigs.equals(that.evictionRegionConfigs) : that.evictionRegionConfigs != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = 31 + (int) (wakeupInterval ^ (wakeupInterval >>> 32));
+ result = 31 * result + defaultEventQueueSize;
+ result = 31 * result + (evictionRegionConfigs != null ? evictionRegionConfigs.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public EvictionConfig clone() throws CloneNotSupportedException
+ {
+ EvictionConfig clone = (EvictionConfig) super.clone();
+ if (evictionRegionConfigs != null)
+ {
+ // needs to be a deep copy
+ clone.evictionRegionConfigs = new LinkedList<EvictionRegionConfig>();
+ for (EvictionRegionConfig erc : evictionRegionConfigs)
+ clone.addEvictionRegionConfig(erc.clone());
+ }
+ return clone;
+ }
+
+
+ /**
+ * Returns the <code>EvictionRegionConfig</code> coresponding to given region fqn, or <code>null</code> if no
+ * match is found.
+ */
+ public EvictionRegionConfig getEvictionRegionConfig(String region)
+ {
+ Fqn fqn = Fqn.fromString(region);
+ for (EvictionRegionConfig evConfig : getEvictionRegionConfigs())
+ {
+ if (evConfig.getRegionFqn().equals(fqn))
+ {
+ return evConfig;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Applies defaults to a config passed in
+ *
+ * @param config config to apply defaults to
+ */
+ public void applyDefaults(EvictionRegionConfig config)
+ {
+ if (config == null) return; // no op
+ config.setDefaults(defaultEvictionRegionConfig);
+ }
+
+ /**
+ * @deprecated set these attributes on the default eviction region config.
+ */
+ @Deprecated
+ public void setDefaultEventQueueSize(int queueSize)
+ {
+ defaultEvictionRegionConfig.setEventQueueSize(queueSize);
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionRegionConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionRegionConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/EvictionRegionConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,218 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.util.Util;
+
+import java.lang.reflect.Method;
+
+public class EvictionRegionConfig extends ConfigurationComponent
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -5482474634995601400L;
+
+ public static final String NAME = "name";
+ public static final String REGION = "region";
+
+ private Fqn regionFqn;
+ @Dynamic
+ private Integer eventQueueSize;
+ private EvictionAlgorithmConfig evictionAlgorithmConfig;
+ private String evictionActionPolicyClassName;
+
+ public EvictionRegionConfig()
+ {
+ }
+
+ public EvictionRegionConfig(Fqn regionFqn, EvictionAlgorithmConfig evictionAlgorithmConfig)
+ {
+ this.regionFqn = regionFqn;
+ this.evictionAlgorithmConfig = evictionAlgorithmConfig;
+ }
+
+ public EvictionRegionConfig(Fqn regionFqn, EvictionAlgorithmConfig evictionAlgorithmConfig, int queueSize)
+ {
+ this.regionFqn = regionFqn;
+ this.evictionAlgorithmConfig = evictionAlgorithmConfig;
+ this.eventQueueSize = queueSize;
+ }
+
+ public EvictionRegionConfig(Fqn fqn)
+ {
+ this.regionFqn = fqn;
+ }
+
+ public EvictionAlgorithmConfig getEvictionAlgorithmConfig()
+ {
+ return evictionAlgorithmConfig;
+ }
+
+ public void setEvictionAlgorithmConfig(EvictionAlgorithmConfig config)
+ {
+ testImmutability("evictionAlgorithmConfig");
+ this.evictionAlgorithmConfig = config;
+ }
+
+ public Fqn getRegionFqn()
+ {
+ return regionFqn;
+ }
+
+ public void setRegionFqn(Fqn regionFqn)
+ {
+ testImmutability("regionFqn");
+ this.regionFqn = regionFqn;
+ }
+
+ public String getRegionName()
+ {
+ return regionFqn == null ? null : regionFqn.toString();
+ }
+
+ public void setRegionName(String name)
+ {
+ setRegionFqn(name == null ? null : Fqn.fromString(name));
+ }
+
+ public int getEventQueueSize()
+ {
+ return eventQueueSize == null ? EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT : eventQueueSize;
+ }
+
+ public void setEventQueueSize(int queueSize)
+ {
+ testImmutability("eventQueueSize");
+ if (queueSize <= 0)
+ {
+ LogFactory.getLog(EvictionRegionConfig.class).warn("Ignoring invalid queue capacity " +
+ queueSize + " -- using " +
+ EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT);
+ queueSize = EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT;
+ }
+ this.eventQueueSize = queueSize;
+ }
+
+ public void setDefaults(EvictionRegionConfig defaults)
+ {
+ // go thru each element that is unset here and copy from "defaults"
+ if (eventQueueSize == null) eventQueueSize = defaults.getEventQueueSize();
+ if (evictionAlgorithmConfig == null) evictionAlgorithmConfig = defaults.getEvictionAlgorithmConfig();
+ if (evictionActionPolicyClassName == null)
+ evictionActionPolicyClassName = defaults.getEvictionActionPolicyClassName();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+
+ if (obj instanceof EvictionRegionConfig)
+ {
+ EvictionRegionConfig other = (EvictionRegionConfig) obj;
+ boolean equalRegions = Util.safeEquals(this.regionFqn, other.regionFqn);
+ boolean equalConfigurations = Util.safeEquals(this.evictionAlgorithmConfig, other.evictionAlgorithmConfig);
+ boolean equalEventQueuSizes = this.getEventQueueSize() == other.getEventQueueSize();
+ return equalRegions && equalConfigurations && equalConfigurations && equalEventQueuSizes;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = 17;
+ result = 31 * result + (regionFqn == null ? 0 : regionFqn.hashCode());
+
+ return result;
+ }
+
+ @Override
+ public EvictionRegionConfig clone() throws CloneNotSupportedException
+ {
+ EvictionRegionConfig clone = (EvictionRegionConfig) super.clone();
+ if (evictionAlgorithmConfig != null)
+ {
+ if (evictionAlgorithmConfig instanceof ConfigurationComponent)
+ {
+ clone.setEvictionAlgorithmConfig((EvictionAlgorithmConfig) ((ConfigurationComponent) evictionAlgorithmConfig).clone());
+ }
+ else
+ {
+ try
+ {
+ Method cloneMethod = this.evictionAlgorithmConfig.getClass().getDeclaredMethod("clone");
+ EvictionAlgorithmConfig evictionAlgorithmConfig = (EvictionAlgorithmConfig) cloneMethod.invoke(this.evictionAlgorithmConfig);
+ clone.setEvictionAlgorithmConfig(evictionAlgorithmConfig);
+ }
+ catch (Exception e)
+ {
+ CloneNotSupportedException cnse = new CloneNotSupportedException("Cannot invoke clone() on " + evictionAlgorithmConfig);
+ cnse.initCause(e);
+ throw cnse;
+ }
+ }
+ }
+
+ clone.evictionActionPolicyClassName = evictionActionPolicyClassName;
+
+ return clone;
+ }
+
+ public boolean isDefaultRegion()
+ {
+ return regionFqn.isRoot();
+ }
+
+ public String getEvictionActionPolicyClassName()
+ {
+ return evictionActionPolicyClassName == null ? EvictionConfig.EVICTION_ACTION_POLICY_CLASS_DEFAULT : evictionActionPolicyClassName;
+ }
+
+ public void setEvictionActionPolicyClassName(String evictionActionPolicyClassName)
+ {
+ this.evictionActionPolicyClassName = evictionActionPolicyClassName;
+ }
+
+ public void setEventQueueSizeIfUnset(int eventQueueSize)
+ {
+ if (this.eventQueueSize == null) this.eventQueueSize = eventQueueSize;
+ }
+
+ /**
+ * Ensure this is a valid eviction region configuration.
+ */
+ public void validate()
+ {
+ if (eventQueueSize < 1)
+ throw new ConfigurationException("Eviction event queue size cannot be less than 1!");
+
+ if (evictionAlgorithmConfig == null)
+ throw new MissingPolicyException("Eviction algorithm configuration cannot be null!");
+
+ evictionAlgorithmConfig.validate();
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/MissingPolicyException.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/MissingPolicyException.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/MissingPolicyException.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+public class MissingPolicyException extends ConfigurationException
+{
+
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = 6107098975617303157L;
+
+ public MissingPolicyException(String message)
+ {
+ super(message);
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/OldFileFormatException.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/OldFileFormatException.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/OldFileFormatException.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+/**
+ * This exception indicates that an old configuration file is passed to a parser that only knows how to handle newer
+ * configuration file.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 3.0
+ */
+public class OldFileFormatException extends ConfigurationException
+{
+ public OldFileFormatException(String string)
+ {
+ super(string);
+ }
+
+ public OldFileFormatException()
+ {
+ this("The configuration file has an old format.");
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/Option.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/Option.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/Option.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,440 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+
+/**
+ * Used to override characteristics of specific calls to the cache. The javadocs of each of the setters below detail functionality and behaviour.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ * @since 1.3.0
+ */
+public class Option implements Cloneable
+{
+ private boolean failSilently;
+ private boolean cacheModeLocal;
+ private boolean suppressLocking;
+ private boolean forceDataGravitation;
+ private boolean skipDataGravitation;
+
+ private boolean forceWriteLock;
+ private boolean skipCacheStatusCheck;
+
+ private boolean forceAsynchronous;
+ private boolean forceSynchronous;
+
+ private long syncReplTimeout = -1;
+ private int groupRequestMode = -1;
+
+ private int lockAcquisitionTimeout = -1;
+ private boolean suppressPersistence;
+
+ /**
+ * @since 1.4.0
+ */
+ public boolean isSuppressLocking()
+ {
+ return suppressLocking;
+ }
+
+ /**
+ * Suppresses acquiring locks for the given invocation. Used with pessimistic locking only. Use with extreme care, may lead to a breach in data integrity!
+ *
+ * @since 1.4.0
+ */
+ public void setSuppressLocking(boolean suppressLocking)
+ {
+ this.suppressLocking = suppressLocking;
+ }
+
+
+ /**
+ * @since 1.3.0
+ */
+ public boolean isFailSilently()
+ {
+ return failSilently;
+ }
+
+ /**
+ * suppress any failures in your cache operation, including version mismatches with optimistic locking, timeouts obtaining locks, transaction rollbacks. If this is option is set, the method invocation will __never fail or throw an exception__, although it may not succeed. With this option enabled the call will <b>not</b> participate in any ongoing transactions even if a transaction is running.
+ *
+ * @since 1.3.0
+ */
+ public void setFailSilently(boolean failSilently)
+ {
+ this.failSilently = failSilently;
+ }
+
+ /**
+ * only applies to put() and remove() methods on the cache.
+ *
+ * @since 1.3.0
+ */
+ public boolean isCacheModeLocal()
+ {
+ return cacheModeLocal;
+ }
+
+ /**
+ * overriding CacheMode from REPL_SYNC, REPL_ASYNC, INVALIDATION_SYNC, INVALIDATION_ASYNC to LOCAL. Only applies to put() and remove() methods on the cache.
+ *
+ * @param cacheModeLocal
+ * @since 1.3.0
+ */
+ public void setCacheModeLocal(boolean cacheModeLocal)
+ {
+ this.cacheModeLocal = cacheModeLocal;
+ }
+
+ /**
+ * @since 1.4.0
+ */
+ public boolean getForceDataGravitation()
+ {
+ return forceDataGravitation;
+ }
+
+ /**
+ * Enables data gravitation calls if a cache miss is detected when using <a href="http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossCacheBuddyReplicationDesign">Buddy Replication</a>.
+ * Enabled only for a given invocation, and only useful if <code>autoDataGravitation</code> is set to <code>false</code>.
+ * See <a href="http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossCacheBuddyReplicationDesign">Buddy Replication</a> documentation for more details.
+ *
+ * @since 1.4.0
+ */
+ public void setForceDataGravitation(boolean enableDataGravitation)
+ {
+ this.forceDataGravitation = enableDataGravitation;
+ }
+
+ /**
+ * @return true if skipDataGravitation is set to true.
+ * @since 1.4.1.SP6
+ */
+ public boolean isSkipDataGravitation()
+ {
+ return skipDataGravitation;
+ }
+
+ /**
+ * Suppresses data gravitation when buddy replication is used. If true, overrides {@link #setForceDataGravitation(boolean)}
+ * being set to true. Typically used to suppress gravitation calls when {@link org.jboss.cache.config.BuddyReplicationConfig#setAutoDataGravitation(boolean)}
+ * is set to true.
+ *
+ * @param skipDataGravitation
+ * @since 1.4.1.SP6
+ */
+ public void setSkipDataGravitation(boolean skipDataGravitation)
+ {
+ this.skipDataGravitation = skipDataGravitation;
+ }
+
+ /**
+ * Gets whether replication or invalidation should be done asynchronously,
+ * even if the cache is configured in a synchronous mode. Has no
+ * effect if the call is occuring within a transactional context.
+ *
+ * @return <code>true</code> if replication/invalidation should be done
+ * asynchronously; <code>false</code> if the default mode
+ * configured for the cache should be used.
+ */
+ public boolean isForceAsynchronous()
+ {
+ return forceAsynchronous;
+ }
+
+ /**
+ * Sets whether replication or invalidation should be done asynchronously,
+ * even if the cache is configured in a synchronous mode. Has no
+ * effect if the call is occuring within a transactional context.
+ *
+ * @param forceAsynchronous <code>true</code> if replication/invalidation
+ * should be done asynchronously; <code>false</code>
+ * if the default mode configured for the cache
+ * should be used.
+ */
+ public void setForceAsynchronous(boolean forceAsynchronous)
+ {
+ this.forceAsynchronous = forceAsynchronous;
+ }
+
+ /**
+ * Gets whether replication or invalidation should be done synchronously,
+ * even if the cache is configured in an asynchronous mode. Has no
+ * effect if the call is occuring within a transactional context.
+ *
+ * @return <code>true</code> if replication/invalidation should be done
+ * synchronously; <code>false</code> if the default mode
+ * configured for the cache should be used.
+ */
+ public boolean isForceSynchronous()
+ {
+ return forceSynchronous;
+ }
+
+ /**
+ * Sets whether replication or invalidation should be done synchronously,
+ * even if the cache is configured in an asynchronous mode. Has no
+ * effect if the call is occuring within a transactional context.
+ *
+ * @param forceSynchronous <code>true</code> if replication/invalidation
+ * should be done synchronously; <code>false</code>
+ * if the default mode configured for the cache
+ * should be used.
+ */
+ public void setForceSynchronous(boolean forceSynchronous)
+ {
+ this.forceSynchronous = forceSynchronous;
+ }
+
+ /**
+ * Gets any lock acquisition timeout configured for the call.
+ *
+ * @return the time in ms that lock acquisition attempts should block
+ * before failing with a TimeoutException. A value < 0 indicates
+ * that the cache's default timeout should be used.
+ */
+ public int getLockAcquisitionTimeout()
+ {
+ return lockAcquisitionTimeout;
+ }
+
+ /**
+ * Sets any lock acquisition timeout configured for the call.
+ *
+ * @param lockAcquisitionTimeout the time in ms that lock acquisition
+ * attempts should block before failing with a
+ * TimeoutException. A value < 0 indicates
+ * that the cache's default timeout should be used.
+ */
+ public void setLockAcquisitionTimeout(int lockAcquisitionTimeout)
+ {
+ this.lockAcquisitionTimeout = lockAcquisitionTimeout;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Option{" +
+ "failSilently=" + failSilently +
+ ", cacheModeLocal=" + cacheModeLocal +
+ ", suppressLocking=" + suppressLocking +
+ ", lockAcquisitionTimeout=" + lockAcquisitionTimeout +
+ ", forceDataGravitation=" + forceDataGravitation +
+ ", skipDataGravitation=" + skipDataGravitation +
+ ", forceAsynchronous=" + forceAsynchronous +
+ ", forceSynchronous=" + forceSynchronous +
+ '}';
+ }
+
+ /**
+ * @see #copy()
+ * @deprecated this method may disappear in future, please use copy() instead.
+ */
+ @Override
+ @Deprecated
+ public Option clone() throws CloneNotSupportedException
+ {
+ return (Option) super.clone();
+ }
+
+ /**
+ * @return a new Option instance with all fields shallow-copied.
+ */
+ public Option copy()
+ {
+ try
+ {
+ return (Option) super.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ // should never happen
+ return null;
+ }
+ }
+
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ final Option option = (Option) o;
+
+ if (skipDataGravitation != option.skipDataGravitation) return false;
+ if (cacheModeLocal != option.cacheModeLocal) return false;
+ if (failSilently != option.failSilently) return false;
+ if (forceDataGravitation != option.forceDataGravitation) return false;
+ if (suppressLocking != option.suppressLocking) return false;
+ if (forceWriteLock != option.forceWriteLock) return false;
+ if (forceAsynchronous != option.forceAsynchronous) return false;
+ if (forceSynchronous != option.forceSynchronous) return false;
+ if (lockAcquisitionTimeout != option.lockAcquisitionTimeout) return false;
+ if (suppressPersistence != option.suppressPersistence) return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result;
+ result = (failSilently ? 1 : 0);
+ result = 29 * result + (cacheModeLocal ? 1 : 0);
+ result = 29 * result + (suppressLocking ? 1 : 0);
+ result = 29 * result + (forceDataGravitation ? 1 : 0);
+ result = 29 * result + (skipDataGravitation ? 1 : 0);
+ result = 29 * result + (forceWriteLock ? 0 : 1);
+ result = 29 * result + (forceAsynchronous ? 0 : 1);
+ result = 29 * result + (forceSynchronous ? 0 : 1);
+ result = 29 * result + (lockAcquisitionTimeout);
+ result = 29 * result + (suppressPersistence ? 0 : 1);
+ return result;
+ }
+
+ /**
+ * Resets this option to defaults.
+ */
+ public void reset()
+ {
+ this.skipDataGravitation = false;
+ this.cacheModeLocal = false;
+ this.failSilently = false;
+ this.forceDataGravitation = false;
+ this.suppressLocking = false;
+ this.forceWriteLock = false;
+ this.forceAsynchronous = false;
+ this.forceSynchronous = false;
+ this.lockAcquisitionTimeout = -1;
+ this.suppressPersistence = false;
+ }
+
+ /**
+ * Forces a write lock to be acquired on the call, regardless of whether it is a read or write. Only applies to the {@link org.jboss.cache.interceptors.PessimisticLockInterceptor}
+ *
+ * @param forceWriteLock
+ * @since 2.0.0
+ */
+ public void setForceWriteLock(boolean forceWriteLock)
+ {
+ this.forceWriteLock = forceWriteLock;
+ }
+
+
+ /**
+ * Tests whether a write lock has been forced on the call, regardless of whether it is a read or write. Only applies to the {@link org.jboss.cache.interceptors.PessimisticLockInterceptor}
+ *
+ * @since 2.0.0
+ */
+ public boolean isForceWriteLock()
+ {
+ return forceWriteLock;
+ }
+
+ /**
+ * If set to true, cache lifecycle checks will be skipped. DO NOT USE unless you really know what you're doing.
+ *
+ * @since 2.0.0
+ */
+ public void setSkipCacheStatusCheck(boolean skipCacheStatusCheck)
+ {
+ this.skipCacheStatusCheck = skipCacheStatusCheck;
+ }
+
+ /**
+ * @return true if skipCacheStatusCheck is true
+ * @since 2.0.0
+ */
+ public boolean isSkipCacheStatusCheck()
+ {
+ return skipCacheStatusCheck;
+ }
+
+ /**
+ * @return the value of the sync replication timeout (used when cache mode is either {@link org.jboss.cache.config.Configuration.CacheMode#REPL_SYNC}
+ * or {@link org.jboss.cache.config.Configuration.CacheMode#INVALIDATION_SYNC}) to be used for this specific call, or -1 (default) if the
+ * default value in {@link Configuration#getSyncReplTimeout()} is to be used instead.
+ * @since 2.1.0
+ */
+ public long getSyncReplTimeout()
+ {
+ return syncReplTimeout;
+ }
+
+ /**
+ * Used to override the value in {@link Configuration#getSyncReplTimeout()} (used when cache mode is either {@link org.jboss.cache.config.Configuration.CacheMode#REPL_SYNC}
+ * or {@link org.jboss.cache.config.Configuration.CacheMode#INVALIDATION_SYNC}) for this specific invocation. Defaults to -1,
+ * which means use the default in the configuration.
+ *
+ * @param syncReplTimeout new timeout value for this invocation.
+ * @since 2.1.0
+ */
+ public void setSyncReplTimeout(long syncReplTimeout)
+ {
+ this.syncReplTimeout = syncReplTimeout;
+ }
+
+ /**
+ * @return overridden JGroups {@link org.jgroups.blocks.GroupRequest} mode to use, or -1 if the {@link org.jboss.cache.RPCManager}'s
+ * own logic is to be used to select a group request mode (this is the default).
+ * @since 2.1.0
+ */
+ public int getGroupRequestMode()
+ {
+ return groupRequestMode;
+ }
+
+ /**
+ * By default, the {@link org.jboss.cache.RPCManager} has inbuilt logic when it comes to selecting a group request mode.
+ * This can be overridden by setting the group request mode here, using this method, for a specific invocation.
+ *
+ * @param groupRequestMode a group request mode, found in the {@link org.jgroups.blocks.GroupRequest} class.
+ * @since 2.1.0
+ */
+ public void setGroupRequestMode(int groupRequestMode)
+ {
+ this.groupRequestMode = groupRequestMode;
+ }
+
+ /**
+ * If set to true, any persistence to a cache loader will be suppressed for the current invocation only. Does not apply to transactional calls.
+ *
+ * @return true if persistence is suppressed.
+ * @since 3.0
+ */
+ public boolean isSuppressPersistence()
+ {
+ return suppressPersistence;
+ }
+
+ /**
+ * If set to true, any persistence to a cache loader will be suppressed for the current invocation only. Does not apply to transactional calls.
+ *
+ * @param suppressPersistence if true, will suppress persistence.
+ * @since 3.0
+ */
+ public void setSuppressPersistence(boolean suppressPersistence)
+ {
+ this.suppressPersistence = suppressPersistence;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/PluggableConfigurationComponent.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/PluggableConfigurationComponent.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/PluggableConfigurationComponent.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.jboss.starobrno.config.parsing.XmlConfigHelper;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * A configuration component where the implementation class can be specified, and comes with its own set of properties.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.2.0
+ */
+public abstract class PluggableConfigurationComponent extends ConfigurationComponent
+{
+ protected String className;
+ protected Properties properties;
+
+ public String getClassName()
+ {
+ return className;
+ }
+
+ public void setClassName(String className)
+ {
+ if (className == null || className.length() == 0) return;
+ testImmutability("className");
+ this.className = className;
+ }
+
+ public Properties getProperties()
+ {
+ return properties;
+ }
+
+ public void setProperties(Properties properties)
+ {
+ testImmutability("properties");
+ this.properties = properties;
+ }
+
+ public void setProperties(String properties) throws IOException
+ {
+ if (properties == null) return;
+
+ testImmutability("properties");
+ // JBCACHE-531: escape all backslash characters
+ // replace any "\" that is not preceded by a backslash with "\\"
+ properties = XmlConfigHelper.escapeBackslashes(properties);
+ ByteArrayInputStream is = new ByteArrayInputStream(properties.trim().getBytes("ISO8859_1"));
+ this.properties = new Properties();
+ this.properties.load(is);
+ is.close();
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ PluggableConfigurationComponent that = (PluggableConfigurationComponent) o;
+
+ if (className != null ? !className.equals(that.className) : that.className != null) return false;
+ if (properties != null ? !properties.equals(that.properties) : that.properties != null) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (className != null ? className.hashCode() : 0);
+ result = 31 * result + (properties != null ? properties.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getClass().getSimpleName() + " {className = " + className +
+ ", properties=" + properties + "}";
+ }
+
+ @Override
+ public PluggableConfigurationComponent clone() throws CloneNotSupportedException
+ {
+ PluggableConfigurationComponent clone = (PluggableConfigurationComponent) super.clone();
+ if (properties != null) clone.properties = (Properties) properties.clone();
+ return clone;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/RuntimeConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/RuntimeConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/RuntimeConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,288 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.jboss.cache.RPCManager;
+import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jboss.cache.util.Util;
+import org.jgroups.Channel;
+import org.jgroups.ChannelFactory;
+import org.jgroups.util.ThreadFactory;
+
+import javax.transaction.TransactionManager;
+import java.util.concurrent.ExecutorService;
+
+public class RuntimeConfig extends ConfigurationComponent
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = 5626847485703341794L;
+
+ private transient TransactionManager transactionManager;
+ private transient Channel channel;
+ private transient ChannelFactory muxChannelFactory;
+ private transient BuddyGroup buddyGroup;
+ private RPCManager rpcManager;
+ private transient ThreadFactory evictionTimerThreadFactory;
+ private transient ExecutorService asyncSerializationExecutor;
+ private transient ExecutorService asyncCacheListenerExecutor;
+
+ /**
+ * Resets the runtime to default values.
+ */
+ public void reset()
+ {
+ channel = null;
+ rpcManager = null;
+ }
+
+
+ /**
+ * Gets the factory the cache will use to create a multiplexed channel.
+ *
+ * @return the channel, or <code>null</code> if not set
+ */
+ public ChannelFactory getMuxChannelFactory()
+ {
+ return muxChannelFactory;
+ }
+
+ /**
+ * Sets the factory the cache should use to create a multiplexed channel.
+ * Ignored if a Channel is directly configured via
+ * {@link #setChannel(Channel)}. If the channel factory is set,
+ * {@link Configuration#setMultiplexerStack(String)} must also be set, or
+ * a <code>CacheException</code> will be thrown during cache startup.
+ *
+ * @param multiplexerChannelFactory channel factory
+ */
+ public void setMuxChannelFactory(ChannelFactory multiplexerChannelFactory)
+ {
+ testImmutability("muxChannelFactory");
+ this.muxChannelFactory = multiplexerChannelFactory;
+ }
+
+ /**
+ * Gets the channel the cache is using.
+ * <p/>
+ * External callers should use extreme care if they access the channel.
+ * The cache expects it has exclusive access to the channel; external code
+ * trying to send or receive messages via the channel will almost certainly
+ * disrupt the operation of the cache.
+ * </p>
+ *
+ * @return the channel. May return <code>null</code> if the channel was
+ * not externally set via {@link #setChannel(Channel)} and the
+ * cache has not yet been started.
+ * @see #setChannel(Channel)
+ */
+ public Channel getChannel()
+ {
+ return channel;
+ }
+
+ /**
+ * Sets the channel the cache will use. The channel should not be
+ * connected or closed.
+ * <p/>
+ * External callers should use extreme care if they access the channel.
+ * The cache expects it has exclusive access to the channel; external code
+ * trying to send or receive messages via the channel will almost certainly
+ * disrupt the operation of the cache.
+ * </p>
+ * <p/>
+ * If an application wishes to send and receive messages using the same
+ * underlying channel as the <ocde>Cache</code>, a multiplexed channel should
+ * be used. Two separate mux channels should be created from the same
+ * <code>ChannelFactory</code> using the same <i>stack name</i> but different
+ * <code>id</code>s.
+ * See {@link ChannelFactory#createMultiplexerChannel(String,String,boolean,String)}.
+ * These two mux channels will share the same underlying channel. One of the
+ * two mux channels can be injected into the cache; the other can be used by
+ * the application. The cache will not see the application messages and vice versa.
+ * </p>
+ * <p/>
+ * Configuring the cache to use a mux channel can also be done by configuring
+ * {@link #setMuxChannelFactory(ChannelFactory) the channel factory} and the
+ * {@link Configuration#setMultiplexerStack(String) stack name}, in which case
+ * the cache will create and use a mux channel.
+ * </p>
+ *
+ * @param channel channel to set
+ */
+ public void setChannel(Channel channel)
+ {
+ this.channel = channel;
+ }
+
+ public TransactionManager getTransactionManager()
+ {
+ return transactionManager;
+ }
+
+ public void setTransactionManager(TransactionManager transactionManager)
+ {
+ testImmutability("transactionManager");
+ this.transactionManager = transactionManager;
+ }
+
+ /**
+ * This is only relevant if an eviction timer thread factory has been set using {@link #setEvictionTimerThreadFactory(org.jgroups.util.ThreadFactory)}.
+ * Will return a null if the eviction timer thread factory needs to be created internally.
+ * <p/>
+ *
+ * @return the thread factory used by the eviction timer's scheduled executor.
+ * @since 3.0
+ */
+ public ThreadFactory getEvictionTimerThreadFactory()
+ {
+ return evictionTimerThreadFactory;
+ }
+
+ /**
+ * Sets the eviction timer thread factory to use when creating a scheduled executor. If this is not set, the eviction
+ * timer task will use a default thread factory.
+ *
+ * @param evictionTimerThreadFactory factory to use
+ * @since 3.0
+ */
+ public void setEvictionTimerThreadFactory(ThreadFactory evictionTimerThreadFactory)
+ {
+ this.evictionTimerThreadFactory = evictionTimerThreadFactory;
+ }
+
+ /**
+ * This is only relevant if the async cache replication executor has been set using {@link #setAsyncSerializationExecutor(java.util.concurrent.ExecutorService)}.
+ * If the executor is created internally, this method will return null.
+ * <p/>
+ *
+ * @return the executor used for async replication.
+ * @since 3.0
+ */
+ public ExecutorService getAsyncSerializationExecutor()
+ {
+ return asyncSerializationExecutor;
+ }
+
+ /**
+ * This is used to set the executor to use for async cache replucation, and effectively overrides {@link org.jboss.cache.config.Configuration#setSerializationExecutorPoolSize(int)}
+ * <p/>
+ *
+ * @param asyncSerializationExecutor executor to set
+ * @since 3.0
+ */
+ public void setAsyncSerializationExecutor(ExecutorService asyncSerializationExecutor)
+ {
+ this.asyncSerializationExecutor = asyncSerializationExecutor;
+ }
+
+ /**
+ * This is only relevant if the async cache listener executor has been set using {@link #setAsyncCacheListenerExecutor(java.util.concurrent.ExecutorService)}.
+ * If the executor is created internally, this method will return null.
+ * <p/>
+ *
+ * @return the executor to use for async cache listeners
+ * @since 3.0
+ */
+ public ExecutorService getAsyncCacheListenerExecutor()
+ {
+ return asyncCacheListenerExecutor;
+ }
+
+ /**
+ * This is used to set the executor to use for async cache listeners, and effectively overrides {@link org.jboss.cache.config.Configuration#setListenerAsyncPoolSize(int)}
+ * <p/>
+ *
+ * @param asyncCacheListenerExecutor the executor to use for async cache listeners
+ * @since 3.0
+ */
+ public void setAsyncCacheListenerExecutor(ExecutorService asyncCacheListenerExecutor)
+ {
+ this.asyncCacheListenerExecutor = asyncCacheListenerExecutor;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if (obj instanceof RuntimeConfig)
+ {
+ RuntimeConfig other = (RuntimeConfig) obj;
+ return Util.safeEquals(transactionManager, other.transactionManager)
+ && Util.safeEquals(muxChannelFactory, other.muxChannelFactory)
+ && Util.safeEquals(rpcManager, other.rpcManager)
+ && Util.safeEquals(channel, other.channel)
+ && Util.safeEquals(evictionTimerThreadFactory, other.evictionTimerThreadFactory)
+ && Util.safeEquals(asyncCacheListenerExecutor, other.asyncCacheListenerExecutor)
+ && Util.safeEquals(asyncSerializationExecutor, other.asyncSerializationExecutor);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = 17;
+ result = result * 29 + (transactionManager == null ? 0 : transactionManager.hashCode());
+ result = result * 29 + (muxChannelFactory == null ? 0 : muxChannelFactory.hashCode());
+ result = result * 29 + (rpcManager == null ? 0 : rpcManager.hashCode());
+ result = result * 29 + (channel == null ? 0 : channel.hashCode());
+ result = result * 29 + (evictionTimerThreadFactory == null ? 0 : evictionTimerThreadFactory.hashCode());
+ result = result * 29 + (asyncCacheListenerExecutor == null ? 0 : asyncCacheListenerExecutor.hashCode());
+ result = result * 29 + (asyncSerializationExecutor == null ? 0 : asyncSerializationExecutor.hashCode());
+ return result;
+ }
+
+ public void setBuddyGroup(BuddyGroup buddyGroup)
+ {
+ this.buddyGroup = buddyGroup;
+ }
+
+ public BuddyGroup getBuddyGroup()
+ {
+ return buddyGroup;
+ }
+
+ public void setRPCManager(RPCManager rpcManager)
+ {
+ this.rpcManager = rpcManager;
+ }
+
+ public RPCManager getRPCManager()
+ {
+ return rpcManager;
+ }
+
+ @Override
+ public RuntimeConfig clone() throws CloneNotSupportedException
+ {
+ return (RuntimeConfig) super.clone();
+ }
+
+
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/UnsupportedEvictionImplException.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/UnsupportedEvictionImplException.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/UnsupportedEvictionImplException.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+/**
+ * Thrown if an eviction configuration that cannot be translated to the new 3.x eviction interfaces is used.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public class UnsupportedEvictionImplException extends ConfigurationException
+{
+ public UnsupportedEvictionImplException(Exception e)
+ {
+ super(e);
+ }
+
+ public UnsupportedEvictionImplException(String string)
+ {
+ super(string);
+ }
+
+ public UnsupportedEvictionImplException(String string, String erroneousAttribute)
+ {
+ super(string, erroneousAttribute);
+ }
+
+ public UnsupportedEvictionImplException(String string, Throwable throwable)
+ {
+ super(string, throwable);
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/config/XmlParsingConfigurationRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/XmlParsingConfigurationRegistry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/XmlParsingConfigurationRegistry.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,125 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.config;
+
+import org.jboss.starobrno.config.parsing.CacheConfigsXmlParser;
+
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * {@link ConfigurationRegistry} that obtains its initial set of configurations
+ * by parsing an XML document.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision: 1 $
+ */
+public class XmlParsingConfigurationRegistry implements ConfigurationRegistry
+{
+ private final CacheConfigsXmlParser parser;
+ private final String configResource;
+ private final Map<String, Configuration> configs = new Hashtable<String, Configuration>();
+ private boolean started;
+
+ public XmlParsingConfigurationRegistry(String configResource)
+ {
+ parser = new CacheConfigsXmlParser();
+ this.configResource = configResource;
+ }
+
+ public void start() throws Exception
+ {
+ if (!started)
+ {
+ if (configResource != null)
+ configs.putAll(parser.parseConfigs(configResource));
+ started = true;
+ }
+ }
+
+ public void stop()
+ {
+ if (started)
+ {
+ synchronized (configs)
+ {
+ configs.clear();
+ }
+ started = false;
+ }
+ }
+
+ public String getConfigResource()
+ {
+ return configResource;
+ }
+
+ public Set<String> getConfigurationNames()
+ {
+ return new HashSet<String>(configs.keySet());
+ }
+
+ public void registerConfiguration(String configName, Configuration config)
+ throws CloneNotSupportedException
+ {
+ synchronized (configs)
+ {
+ if (configs.containsKey(configName))
+ throw new IllegalStateException(configName + " already registered");
+ configs.put(configName, config.clone());
+ }
+ }
+
+ public void unregisterConfiguration(String configName)
+ {
+ synchronized (configs)
+ {
+ if (configs.remove(configName) == null)
+ throw new IllegalStateException(configName + " not registered");
+ }
+ }
+
+ public Configuration getConfiguration(String configName)
+ {
+ Configuration config;
+ synchronized (configs)
+ {
+ config = configs.get(configName);
+ }
+
+ if (config == null)
+ throw new IllegalArgumentException("unknown config " + configName);
+
+ // Don't hand out a ref to our master copy
+ try
+ {
+ return config.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ // This should not happen, as we already cloned the config
+ throw new RuntimeException("Could not clone configuration " + configName, e);
+ }
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/config/XmlParsingConfigurationRegistry.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -21,8 +21,8 @@
*/
package org.jboss.starobrno.context;
-import org.jboss.cache.config.Option;
import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.config.Option;
import org.jboss.starobrno.transaction.GlobalTransaction;
import javax.transaction.Transaction;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -23,9 +23,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.Option;
import org.jboss.cache.util.Immutables;
import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.config.Option;
import org.jboss.starobrno.mvcc.MVCCEntry;
import org.jboss.starobrno.transaction.GlobalTransaction;
import org.jboss.starobrno.transaction.TransactionTable;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -21,9 +21,9 @@
*/
package org.jboss.starobrno.context;
-import org.jboss.cache.config.Option;
import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.config.Option;
import javax.transaction.Transaction;
import java.util.List;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -21,16 +21,23 @@
*/
package org.jboss.starobrno.context;
-import org.jboss.cache.config.Option;
import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
import org.jboss.cache.util.Immutables;
import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.config.Option;
import org.jboss.starobrno.mvcc.MVCCEntry;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* A transaction context specially geared to dealing with MVCC.
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseEvictionAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseEvictionAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseEvictionAlgorithm.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,614 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.lock.TimeoutException;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.EvictionEvent.Type;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Abstract Event Processing Eviction Algorithm.
+ * This class is used to implement basic event processing for Eviction Algorithms.
+ * To extend this abstract class to make an Eviction Algorithm, implement the
+ * abstract methods and a policy.
+ *
+ * @author Daniel Huang - dhuang at jboss.org 10/2005
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
+ * @version $Revision: 6776 $
+ */
+public abstract class BaseEvictionAlgorithm implements EvictionAlgorithm
+{
+ private static final Log log = LogFactory.getLog(BaseEvictionAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+ protected org.jboss.starobrno.eviction.EvictionActionPolicy evictionActionPolicy;
+ protected EvictionAlgorithmConfig evictionAlgorithmConfig;
+ /**
+ * Contains Fqn instances.
+ */
+ protected BlockingQueue<Fqn> recycleQueue;
+ /**
+ * Contains NodeEntry instances.
+ */
+ protected org.jboss.starobrno.eviction.EvictionQueue evictionQueue;
+ protected boolean allowTombstones = false;
+ protected Configuration configuration;
+ protected Fqn regionFqn;
+ protected CacheSPI<?, ?> cache;
+
+ /**
+ * This method will create an EvictionQueue implementation and prepare it for use.
+ *
+ * @return The created EvictionQueue to be used as the eviction queue for this algorithm.
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ * if there are problems
+ * @see org.jboss.starobrno.eviction.EvictionQueue
+ */
+ protected abstract org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException;
+
+ /**
+ * This method will check whether the given node should be evicted or not.
+ *
+ * @param ne NodeEntry to test eviction for.
+ * @return True if the given node should be evicted. False if the given node should not be evicted.
+ */
+ protected abstract boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne);
+
+ protected BaseEvictionAlgorithm()
+ {
+ recycleQueue = new LinkedBlockingQueue<Fqn>(500000);
+ }
+
+ public synchronized void initialize()
+ {
+ if (evictionQueue == null)
+ {
+ evictionQueue = setupEvictionQueue();
+ allowTombstones = false;
+ }
+ }
+
+ public org.jboss.starobrno.eviction.EvictionActionPolicy getEvictionActionPolicy()
+ {
+ return evictionActionPolicy;
+ }
+
+ public void setEvictionActionPolicy(org.jboss.starobrno.eviction.EvictionActionPolicy evictionActionPolicy)
+ {
+ this.evictionActionPolicy = evictionActionPolicy;
+ }
+
+ public EvictionAlgorithmConfig getEvictionAlgorithmConfig()
+ {
+ return evictionAlgorithmConfig;
+ }
+
+ public void assignToRegion(Fqn fqn, CacheSPI<?, ?> cache, EvictionAlgorithmConfig evictionAlgorithmConfig, Configuration configuration)
+ {
+ this.regionFqn = fqn;
+ this.cache = cache;
+ this.evictionAlgorithmConfig = evictionAlgorithmConfig;
+ this.configuration = configuration;
+ }
+
+ public boolean canIgnoreEvent(Type eventType)
+ {
+ return false; // don't ignore anything!
+ }
+
+ /**
+ * Process the given eviction event queue. Eviction Processing encompasses the following:
+ * <p/>
+ * - Add/Remove/Visit Nodes
+ * - Prune according to Eviction Algorithm
+ * - Empty/Retry the recycle queue of previously evicted but locked (during actual cache eviction) nodes.
+ *
+ * @param eventQueue queue containing eviction events
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ *
+ */
+ public void process(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> eventQueue) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ if (trace) log.trace("process(): region: " + regionFqn);
+ initialize();
+ this.processQueues(eventQueue);
+ this.emptyRecycleQueue();
+ this.prune();
+ }
+
+ public void resetEvictionQueue()
+ {
+ // a no-op
+ }
+
+ /**
+ * Get the underlying EvictionQueue implementation.
+ *
+ * @return the EvictionQueue used by this algorithm
+ * @see org.jboss.starobrno.eviction.EvictionQueue
+ */
+ public org.jboss.starobrno.eviction.EvictionQueue getEvictionQueue()
+ {
+ return this.evictionQueue;
+ }
+
+ protected org.jboss.starobrno.eviction.EvictionEvent getNextInQueue(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> queue)
+ {
+ try
+ {
+ return queue.poll(0, TimeUnit.SECONDS);
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ return null;
+ }
+
+ /**
+ * Event processing for Evict/Add/Visiting of nodes.
+ * <p/>
+ * - On AddEvents a new element is added into the eviction queue
+ * - On RemoveEvents, the removed element is removed from the eviction queue.
+ * - On VisitEvents, the visited node has its eviction statistics updated (idleTime, numberOfNodeVisists, etc..)
+ *
+ * @param queue queue to inspect
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ * in the event of problems
+ */
+ protected void processQueues(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> queue) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ org.jboss.starobrno.eviction.EvictionEvent node;
+ int count = 0;
+ while ((node = getNextInQueue(queue)) != null)
+ {
+ count++;
+ switch (node.getEventType())
+ {
+ case ADD_NODE_EVENT:
+ this.processAddedNodes(node);
+ break;
+ case REMOVE_NODE_EVENT:
+ this.processRemovedNodes(node);
+ break;
+ case VISIT_NODE_EVENT:
+ this.processVisitedNodes(node);
+ break;
+ case ADD_ELEMENT_EVENT:
+ this.processAddedElement(node);
+ break;
+ case REMOVE_ELEMENT_EVENT:
+ this.processRemovedElement(node);
+ break;
+ case MARK_IN_USE_EVENT:
+ this.processMarkInUseNodes(node.getFqn(), node.getInUseTimeout());
+ break;
+ case UNMARK_USE_EVENT:
+ this.processUnmarkInUseNodes(node.getFqn());
+ break;
+ default:
+ throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
+ }
+ }
+
+ if (trace) log.trace("processed " + count + " node events");
+ }
+
+ protected void evict(org.jboss.starobrno.eviction.NodeEntry ne)
+ {
+// NodeEntry ne = evictionQueue.getNodeEntry(fqn);
+ if (ne != null)
+ {
+ evictionQueue.removeNodeEntry(ne);
+ if (!this.evictCacheNode(ne.getFqn()))
+ {
+ try
+ {
+ boolean result = recycleQueue.offer(ne.getFqn(), 5, TimeUnit.SECONDS);
+ if (!result)
+ {
+ log.warn("Unable to add Fqn[" + ne.getFqn() + "] to recycle " +
+ "queue because it's full. This is often sign that " +
+ "evictions are not occurring and nodes that should be " +
+ "evicted are piling up waiting to be evicted.");
+ }
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("InterruptedException", e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Evict a node from cache.
+ *
+ * @param fqn node corresponds to this fqn
+ * @return True if successful
+ */
+ protected boolean evictCacheNode(Fqn fqn)
+ {
+ if (trace) log.trace("Attempting to evict cache node with fqn of " + fqn);
+
+ try
+ {
+ evictionActionPolicy.evict(fqn);
+ }
+ catch (TimeoutException e)
+ {
+ log.warn("Eviction of " + fqn + " timed out, retrying later");
+ log.debug(e, e);
+ return false;
+ }
+ catch (Exception e)
+ {
+ log.error("Eviction of " + fqn + " failed", e);
+ return false;
+ }
+
+ if (trace)
+ {
+ log.trace("Eviction of cache node with fqn of " + fqn + " successful");
+ }
+
+ return true;
+ }
+
+ protected void processMarkInUseNodes(Fqn fqn, long inUseTimeout) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ if (trace)
+ {
+ log.trace("Marking node " + fqn + " as in use with a usage timeout of " + inUseTimeout);
+ }
+
+ org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
+ if (ne != null)
+ {
+ ne.setCurrentlyInUse(true, inUseTimeout);
+ }
+ }
+
+ protected void processUnmarkInUseNodes(Fqn fqn) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ if (trace)
+ {
+ log.trace("Unmarking node " + fqn + " as in use");
+ }
+
+ org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
+ if (ne != null)
+ {
+ ne.setCurrentlyInUse(false, 0);
+ }
+ }
+
+ /**
+ * Convenience method, which calls {@link #processAddedNodes(org.jboss.starobrno.eviction.EvictionEvent , int)} using values in the
+ * evictedEventNode for number of added elements and the resetElementCount flag.
+ *
+ * @param evictedEventNode an evictedEventNode to process
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ * on problems
+ */
+ protected void processAddedNodes(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ processAddedNodes(evictedEventNode, evictedEventNode.getElementDifference());
+ }
+
+ protected void processAddedNodes(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode, int numAddedElements) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ Fqn fqn = evictedEventNode.getFqn();
+
+ if (trace)
+ {
+ log.trace("Adding node " + fqn + " with " + numAddedElements + " elements to eviction queue");
+ }
+
+ org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
+ if (ne != null)
+ {
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
+ ne.setNumberOfNodeVisits(ne.getNumberOfNodeVisits() + 1);
+ ne.setNumberOfElements(ne.getNumberOfElements() + numAddedElements);
+ if (trace)
+ {
+ log.trace("Queue already contains " + ne.getFqn() + " processing it as visited");
+ }
+ processVisitedNodes(evictedEventNode);
+ return;
+ }
+
+ ne = new org.jboss.starobrno.eviction.NodeEntry(fqn);
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
+ ne.setNumberOfNodeVisits(1);
+ ne.setNumberOfElements(numAddedElements);
+
+ evictionQueue.addNodeEntry(ne);
+
+ if (trace)
+ {
+ log.trace(ne.getFqn() + " added successfully to eviction queue");
+ }
+ }
+
+ /**
+ * Remove a node from cache.
+ * <p/>
+ * This method will remove the node from the eviction queue as well as
+ * evict the node from cache.
+ * <p/>
+ * If a node cannot be removed from cache, this method will remove it from the eviction queue
+ * and place the element into the recycleQueue. Each node in the recycle queue will get retried until
+ * proper cache eviction has taken place.
+ * <p/>
+ * Because EvictionQueues are collections, when iterating them from an iterator, use iterator.remove()
+ * to avoid ConcurrentModificationExceptions. Use the boolean parameter to indicate the calling context.
+ *
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ *
+ */
+ protected void processRemovedNodes(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ Fqn fqn = evictedEventNode.getFqn();
+
+ if (trace)
+ {
+ log.trace("Removing node " + fqn + " from eviction queue and attempting eviction");
+ }
+
+ org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
+ if (ne != null)
+ {
+ if (allowTombstones)
+ {
+ // don't remove from the queue - deleting a node results in a tombstone which means the nodes
+ // still need to be considered for eviction!
+ return;
+ }
+ else
+ {
+ // a removeNode operation will simply remove the node. Nothing to worry about.
+ evictionQueue.removeNodeEntry(ne);
+ }
+ }
+ else
+ {
+ if (trace)
+ {
+ log.trace("processRemoveNodes(): Can't find node associated with fqn: " + fqn
+ + "Could have been evicted earlier. Will just continue.");
+ }
+ return;
+ }
+
+ if (trace)
+ {
+ log.trace(fqn + " removed from eviction queue");
+ }
+ }
+
+ /**
+ * Visit a node in cache.
+ * <p/>
+ * This method will update the numVisits and modifiedTimestamp properties of the Node.
+ * These properties are used as statistics to determine eviction (LRU, LFU, MRU, etc..)
+ * <p/>
+ * *Note* that this method updates Node Entries by reference and does not put them back
+ * into the queue. For some sorted collections, a remove, and a re-add is required to
+ * maintain the sorted order of the elements.
+ *
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ *
+ */
+ protected void processVisitedNodes(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ Fqn fqn = evictedEventNode.getFqn();
+ org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
+ if (ne == null)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Visiting node that was not added to eviction queues. Assuming that it has 1 element.");
+ }
+ this.processAddedNodes(evictedEventNode, 1);
+ return;
+ }
+ // note this method will visit and modify the node statistics by reference!
+ // if a collection is only guaranteed sort order by adding to the collection,
+ // this implementation will not guarantee sort order.
+ ne.setNumberOfNodeVisits(ne.getNumberOfNodeVisits() + 1);
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
+ }
+
+ protected void processRemovedElement(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ Fqn fqn = evictedEventNode.getFqn();
+ org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
+
+ if (ne == null)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Removing element from " + fqn + " but eviction queue does not contain this node. " +
+ "Ignoring removeElement event.");
+ }
+ return;
+ }
+
+ ne.setNumberOfElements(ne.getNumberOfElements() - 1);
+ // also treat it as a node visit.
+ ne.setNumberOfNodeVisits(ne.getNumberOfNodeVisits() + 1);
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
+ }
+
+ protected void processAddedElement(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ Fqn fqn = evictedEventNode.getFqn();
+ org.jboss.starobrno.eviction.NodeEntry ne = evictionQueue.getNodeEntry(fqn);
+ if (ne == null)
+ {
+ if (trace)
+ {
+ log.trace("Adding element " + fqn + " for a node that doesn't exist yet. Process as an add.");
+ }
+ this.processAddedNodes(evictedEventNode, 1);
+ return;
+ }
+
+ ne.setNumberOfElements(ne.getNumberOfElements() + 1);
+
+ // also treat it as a node visit.
+ ne.setNumberOfNodeVisits(ne.getNumberOfNodeVisits() + 1);
+ ne.setModifiedTimeStamp(evictedEventNode.getCreationTimestamp());
+// log.error ("*** Processing nodeAdded for fqn " + fqn + " NodeEntry's hashcode is " + ne.hashCode());
+ }
+
+
+ /**
+ * Empty the Recycle Queue.
+ * <p/>
+ * This method will go through the recycle queue and retry to evict the nodes from cache.
+ *
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ *
+ */
+ protected void emptyRecycleQueue() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ while (true)
+ {
+ Fqn fqn;
+
+ try
+ {
+ //fqn = (Fqn) recycleQueue.take();
+ fqn = recycleQueue.poll(0, TimeUnit.SECONDS);
+ }
+ catch (InterruptedException e)
+ {
+ log.debug(e, e);
+ break;
+ }
+
+ if (fqn == null)
+ {
+ if (trace)
+ {
+ log.trace("Recycle queue is empty");
+ }
+ break;
+ }
+
+ if (trace)
+ {
+ log.trace("emptying recycle bin. Evict node " + fqn);
+ }
+
+ // Still doesn't work
+ if (!evictCacheNode(fqn))
+ {
+ try
+ {
+ recycleQueue.put(fqn);
+ }
+ catch (InterruptedException e)
+ {
+ log.debug(e, e);
+ }
+ break;
+ }
+ }
+ }
+
+ protected boolean isNodeInUseAndNotTimedOut(org.jboss.starobrno.eviction.NodeEntry ne)
+ {
+ if (ne.isCurrentlyInUse())
+ {
+ if (ne.getInUseTimeoutTimestamp() == 0)
+ {
+ return true;
+ }
+
+ if (System.currentTimeMillis() < ne.getInUseTimeoutTimestamp())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected void prune() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ org.jboss.starobrno.eviction.NodeEntry entry;
+ while ((entry = evictionQueue.getFirstNodeEntry()) != null)
+ {
+ if (this.shouldEvictNode(entry))
+ {
+ this.evict(entry);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ /**
+ * Returns debug information.
+ */
+ @Override
+ public String toString()
+ {
+ return super.toString() +
+ " recycle=" + recycleQueue.size() +
+ " evict=" + evictionQueue.getNumberOfNodes();
+ }
+
+ /**
+ * Tests whether a node entry is younger than the minimum time to live - if one is configured.
+ *
+ * @param entry the node entry being examined
+ * @return true if the node is younger than - or exactly equal to - the minimum time to live, if one is configured for the given region. False otherwise.
+ */
+ protected boolean isYoungerThanMinimumTimeToLive(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ if (evictionAlgorithmConfig instanceof org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase)
+ {
+ org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase cfg = (org.jboss.starobrno.eviction.EvictionAlgorithmConfigBase) evictionAlgorithmConfig;
+ long minTTL = cfg.getMinTimeToLive();
+ return minTTL >= 1 && (entry.getModifiedTimeStamp() + minTTL > System.currentTimeMillis());
+ }
+ else
+ {
+ log.trace("Eviction policy implementation does not support minimum TTL!");
+ return false;
+ }
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseSortedEvictionAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseSortedEvictionAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/BaseSortedEvictionAlgorithm.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.concurrent.BlockingQueue;
+
+
+/**
+ * An abstract SortedEvictionAlgorithm.
+ * <p/>
+ * This class supports early termination of the eviction queue processing. Because the eviction
+ * queue is sorted by first to evict to last to evict, when iterating the eviction queue, the first time
+ * a node is encountered that does not require eviction will terminate the loop early. This way we don't incur
+ * the full breadth of the O(n) = n operation everytime we need to check for eviction (defined by eviction poll time
+ * interval).
+ *
+ * @author Daniel Huang - dhuang at jboss.org - 10/2005
+ */
+public abstract class BaseSortedEvictionAlgorithm extends BaseEvictionAlgorithm
+{
+ private static final Log log = LogFactory.getLog(BaseSortedEvictionAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ @Override
+ protected void processQueues(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> queue) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ boolean evictionNodesModified = false;
+
+ org.jboss.starobrno.eviction.EvictionEvent node;
+ int count = 0;
+ while ((node = getNextInQueue(queue)) != null)
+ {
+ count++;
+ switch (node.getEventType())
+ {
+ case ADD_NODE_EVENT:
+ this.processAddedNodes(node);
+ evictionNodesModified = true;
+ break;
+ case REMOVE_NODE_EVENT:
+ this.processRemovedNodes(node);
+ break;
+ case VISIT_NODE_EVENT:
+ this.processVisitedNodes(node);
+ evictionNodesModified = true;
+ break;
+ case ADD_ELEMENT_EVENT:
+ this.processAddedElement(node);
+ evictionNodesModified = true;
+ break;
+ case REMOVE_ELEMENT_EVENT:
+ this.processRemovedElement(node);
+ evictionNodesModified = true;
+ break;
+ default:
+ throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
+ }
+ }
+
+ if (trace)
+ {
+ log.trace("Eviction nodes visited or added requires resort of queue " + evictionNodesModified);
+ }
+
+ this.resortEvictionQueue(evictionNodesModified);
+
+
+ if (trace)
+ {
+ log.trace("processed " + count + " node events");
+ }
+
+ }
+
+ /**
+ * This method is called to resort the queue after add or visit events have occurred.
+ * <p/>
+ * If the parameter is true, the queue needs to be resorted. If it is false, the queue does not
+ * need resorting.
+ *
+ * @param evictionQueueModified True if the queue was added to or visisted during event processing.
+ */
+ protected void resortEvictionQueue(boolean evictionQueueModified)
+ {
+ if (!evictionQueueModified)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Eviction queue not modified. Resort unnecessary.");
+ }
+ return;
+ }
+ long begin = System.currentTimeMillis();
+ ((org.jboss.starobrno.eviction.SortedEvictionQueue) evictionQueue).resortEvictionQueue();
+ long end = System.currentTimeMillis();
+
+ if (trace)
+ {
+ long diff = end - begin;
+ log.trace("Took " + diff + "ms to sort queue with " + getEvictionQueue().getNumberOfNodes() + " elements");
+ }
+ }
+
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionActionPolicy.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionActionPolicy.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/DefaultEvictionActionPolicy.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+
+/**
+ * Default eviction action policy that calls {@link org.jboss.cache.Cache#evict(org.jboss.cache.Fqn)} to evict a node.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public class DefaultEvictionActionPolicy implements EvictionActionPolicy
+{
+ Cache<?, ?> cache;
+ private static final Log log = LogFactory.getLog(DefaultEvictionActionPolicy.class);
+
+ public void setCache(Cache<?, ?> cache)
+ {
+ this.cache = cache;
+ }
+
+ public boolean evict(Fqn fqn)
+ {
+ try
+ {
+ if (log.isTraceEnabled()) log.trace("Evicting Fqn " + fqn);
+ cache.evict(fqn);
+ return true;
+ }
+ catch (Exception e)
+ {
+ if (log.isDebugEnabled()) log.debug("Unable to evict " + fqn, e);
+ return false;
+ }
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithm.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+
+/**
+ * @author Daniel Huang
+ * @version $Revision: 6776 $
+ */
+public class ElementSizeAlgorithm extends BaseSortedEvictionAlgorithm
+{
+ @Override
+ protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ return new org.jboss.starobrno.eviction.ElementSizeQueue();
+ }
+
+ @Override
+ protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne)
+ {
+ // check the minimum time to live and see if we should not evict the node. This check will
+ // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
+ if (isYoungerThanMinimumTimeToLive(ne)) return false;
+ int size = this.getEvictionQueue().getNumberOfNodes();
+ org.jboss.starobrno.eviction.ElementSizeAlgorithmConfig config = (org.jboss.starobrno.eviction.ElementSizeAlgorithmConfig) evictionAlgorithmConfig;
+ return config.getMaxNodes() > -1 && size > config.getMaxNodes() || ne.getNumberOfElements() > config.getMaxElementsPerNode();
+ }
+
+ @Override
+ protected void prune() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ super.prune();
+
+ // clean up the Queue's eviction removals
+ ((org.jboss.starobrno.eviction.ElementSizeQueue) this.evictionQueue).prune();
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return ElementSizeAlgorithmConfig.class;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeAlgorithmConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.Dynamic;
+
+/**
+ * Configuration for {@link org.jboss.starobrno.eviction.ElementSizeAlgorithm}.
+ * <p/>
+ * Requires a positive "maxElementsPerNode" value otherwise a ConfigurationException is thrown.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class ElementSizeAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = 2510593544656833758L;
+
+ @Dynamic
+ private int maxElementsPerNode;
+
+ public ElementSizeAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.ElementSizeAlgorithm.class.getName();
+ // Force configuration of maxElementsPerNode
+ setMaxElementsPerNode(-1);
+ }
+
+ public ElementSizeAlgorithmConfig(int maxNodes, int maxElementsPerNode)
+ {
+ this();
+ setMaxNodes(maxNodes);
+ setMaxElementsPerNode(maxElementsPerNode);
+ }
+
+ public int getMaxElementsPerNode()
+ {
+ return maxElementsPerNode;
+ }
+
+ public void setMaxElementsPerNode(int maxElementsPerNode)
+ {
+ testImmutability("maxElementsPerNode");
+ this.maxElementsPerNode = maxElementsPerNode;
+ }
+
+ /**
+ * Requires a positive maxElementsPerNode value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ super.validate();
+ if (maxElementsPerNode < 0)
+ {
+ throw new ConfigurationException("maxElementsPerNode must be must be " +
+ "configured to a value greater than or equal to 0");
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder str = new StringBuilder();
+ str.append("ElementSizeConfiguration: maxElementsPerNode =");
+ str.append(getMaxElementsPerNode()).append(" maxNodes =").append(getMaxNodes());
+ return str.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj instanceof ElementSizeAlgorithmConfig && super.equals(obj))
+ {
+ return this.maxElementsPerNode == ((ElementSizeAlgorithmConfig) obj).maxElementsPerNode;
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + maxElementsPerNode;
+ return result;
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ setMaxElementsPerNode(-1);
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.ElementSizeAlgorithm.class.getName();
+ }
+
+ @Override
+ public ElementSizeAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (ElementSizeAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ElementSizeQueue.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,230 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.Fqn;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * @author Daniel Huang
+ * @version $Revision: 6776 $
+ */
+public class ElementSizeQueue implements SortedEvictionQueue
+{
+ private Map<Fqn, org.jboss.starobrno.eviction.NodeEntry> nodeMap;
+ private LinkedList<org.jboss.starobrno.eviction.NodeEntry> evictionList;
+ private Comparator<org.jboss.starobrno.eviction.NodeEntry> comparator;
+
+ private Set<org.jboss.starobrno.eviction.NodeEntry> removalQueue;
+ private int numElements = 0;
+
+ protected ElementSizeQueue()
+ {
+ nodeMap = new HashMap<Fqn, org.jboss.starobrno.eviction.NodeEntry>();
+ evictionList = new LinkedList<org.jboss.starobrno.eviction.NodeEntry>();
+ comparator = new MaxElementComparator();
+ removalQueue = new HashSet<org.jboss.starobrno.eviction.NodeEntry>();
+ }
+
+ public void resortEvictionQueue()
+ {
+ Collections.sort(evictionList, comparator);
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
+ {
+ try
+ {
+ org.jboss.starobrno.eviction.NodeEntry ne;
+ while ((ne = evictionList.getFirst()) != null)
+ {
+ if (removalQueue.contains(ne))
+ {
+ evictionList.removeFirst();
+ removalQueue.remove(ne);
+ }
+ else
+ {
+ break;
+ }
+ }
+ return ne;
+ }
+ catch (NoSuchElementException e)
+ {
+ //
+ }
+
+ return null;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
+ {
+ return nodeMap.get(fqn);
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
+ {
+ return this.getNodeEntry(Fqn.fromString(fqn));
+ }
+
+ public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ Fqn fqn = entry.getFqn();
+ return this.getNodeEntry(fqn) != null;
+ }
+
+ public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ org.jboss.starobrno.eviction.NodeEntry ne = nodeMap.remove(entry.getFqn());
+ if (ne != null)
+ {
+ // don't remove directly from the LinkedList otherwise we will incur a O(n) = n
+ // performance penalty for every removal! In the prune method for LFU, we will iterate the LinkedList through ONCE
+ // doing a single O(n) = n operation and removal. This is much preferred over running O(n) = n every single time
+ // remove is called. There is also special logic in the getFirstNodeEntry that will know to check
+ // the removalQueue before returning.
+ this.removalQueue.add(ne);
+/* if(!evictionList.remove(ne)) {
+ throw new RuntimeException("");
+ } */
+ this.numElements -= ne.getNumberOfElements();
+ }
+ }
+
+ public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ Fqn fqn = entry.getFqn();
+ entry.queue = this;
+ nodeMap.put(fqn, entry);
+ evictionList.add(entry);
+ this.numElements += entry.getNumberOfElements();
+ }
+ }
+
+ public int getNumberOfNodes()
+ {
+ return nodeMap.size();
+ }
+
+ public int getNumberOfElements()
+ {
+ return this.numElements;
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ this.numElements += difference;
+ }
+
+ public void clear()
+ {
+ nodeMap.clear();
+ evictionList.clear();
+ removalQueue.clear();
+ this.numElements = 0;
+ }
+
+ protected final List<org.jboss.starobrno.eviction.NodeEntry> getEvictionList()
+ {
+ return evictionList;
+ }
+
+ protected final Set<org.jboss.starobrno.eviction.NodeEntry> getRemovalQueue()
+ {
+ return removalQueue;
+ }
+
+ protected final void prune()
+ {
+ Iterator<org.jboss.starobrno.eviction.NodeEntry> it = evictionList.iterator();
+ while (it.hasNext() && removalQueue.size() > 0)
+ {
+ if (removalQueue.remove(it.next()))
+ {
+ it.remove();
+ }
+ }
+ }
+
+ public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
+ {
+ return evictionList.iterator();
+ }
+
+ /**
+ * Comparator class for Max Elements.
+ * <p/>
+ * This class will sort the eviction queue in the correct eviction order.
+ * The top of the list should evict before the bottom of the list.
+ * <p/>
+ * The sort is based on descending order of numElements.
+ * <p/>
+ * Note: this class has a natural ordering that is inconsistent with equals as defined by the java.lang.Comparator
+ * contract.
+ */
+ protected static class MaxElementComparator implements Comparator<org.jboss.starobrno.eviction.NodeEntry>
+ {
+
+ public int compare(org.jboss.starobrno.eviction.NodeEntry ne1, org.jboss.starobrno.eviction.NodeEntry ne2)
+ {
+ if (ne1.equals(ne2))
+ {
+ return 0;
+ }
+
+ int neNumElements = ne1.getNumberOfElements();
+ int neNumElements2 = ne2.getNumberOfElements();
+
+ if (neNumElements > neNumElements2)
+ {
+ return -1;
+ }
+ else if (neNumElements < neNumElements2)
+ {
+ return 1;
+ }
+ else if (neNumElements == neNumElements2)
+ {
+ return 0;
+ }
+
+ throw new RuntimeException("Should never reach this condition");
+ }
+
+ }
+
+}
+
+
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionActionPolicy.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionActionPolicy.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionActionPolicy.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+
+/**
+ * Performs an eviction on a given Fqn.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public interface EvictionActionPolicy
+{
+ /**
+ * Sets a reference to the cache.
+ *
+ * @param cache cache
+ */
+ void setCache(Cache<?, ?> cache);
+
+ /**
+ * Performs an eviction on a given node.
+ *
+ * @param fqn fqn to evict
+ * @return true if the eviction was successful, false if not.
+ */
+ boolean evict(Fqn fqn);
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithm.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.EvictionEvent.Type;
+
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * Interface for all eviction algorithms.
+ * <p/>
+ * Note: None of the Eviction classes are thread safe. It is assumed that an individual instance of an EvictionPolicy/
+ * EvictionAlgorithm/EvictionQueue/EvictionConfiguration are only operated on by one thread at any given time.
+ *
+ * @author Ben Wang 2-2004
+ * @author Daniel Huang - dhuang at jboss.org - 10/2005
+ * @version $Revision: 6776 $
+ */
+public interface EvictionAlgorithm
+{
+ /**
+ * Entry point for eviction algorithm. Invoking this will cause the algorithm to process the queue of {@link EvictionEvent}
+ * passed in.
+ *
+ * @param queue to process
+ */
+ void process(BlockingQueue<EvictionEvent> queue) throws org.jboss.starobrno.eviction.EvictionException;
+
+ /**
+ * Reset the whole eviction queue. The queue may need to be reset due to corrupted state, for example.
+ */
+ void resetEvictionQueue();
+
+ /**
+ * Get the EvictionQueue implementation used by this algorithm.
+ *
+ * @return the EvictionQueue implementation.
+ */
+ org.jboss.starobrno.eviction.EvictionQueue getEvictionQueue();
+
+ /**
+ * Sets the eviction action policy, so the algorithm knows what to do when a node is to be evicted.
+ *
+ * @param evictionActionPolicy to set
+ */
+ void setEvictionActionPolicy(org.jboss.starobrno.eviction.EvictionActionPolicy evictionActionPolicy);
+
+ /**
+ * Assigns the algorithm instance to a specific region.
+ *
+ * @param fqn of the region to be assigned to
+ * @param cache cache reference
+ * @param evictionAlgorithmConfig configuration for the current algorithm instance.
+ * @param configuration for the entire cache.
+ */
+ void assignToRegion(Fqn fqn, CacheSPI<?, ?> cache, EvictionAlgorithmConfig evictionAlgorithmConfig, Configuration configuration);
+
+ /**
+ * Tests whether the algorithm would ignore certain event types on certain Fqns.
+ *
+ * @param eventType event type to test for
+ * @return true if the event representing the parameters would be ignored by this algorithm or not.
+ */
+ boolean canIgnoreEvent(Type eventType);
+
+ /**
+ * Invoked by the region manager when the enclosing region is initialized.
+ */
+ void initialize();
+
+ /**
+ * This is a helper so that the XML parser will be able to select and use the correct {@link org.jboss.cache.config.EvictionAlgorithmConfig} implementation
+ * class corresponding to this EvictionAlgorithm. E.g., the {@link FIFOAlgorithm} would return {@link FIFOAlgorithmConfig}.class.
+ *
+ * @return a class that is used to configure this EvictionAlgorithm.
+ */
+ Class<? extends EvictionAlgorithmConfig> getConfigurationClass();
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithm.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithmConfigBase.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithmConfigBase.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionAlgorithmConfigBase.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.annotations.Compat;
+import org.jboss.starobrno.config.ConfigurationComponent;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.Dynamic;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A base class used for configuring eviction algorithms.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public abstract class EvictionAlgorithmConfigBase extends ConfigurationComponent implements EvictionAlgorithmConfig
+{
+ private static final long serialVersionUID = 4591691674370188932L;
+
+ protected String evictionAlgorithmClassName;
+ @Dynamic
+ protected int maxNodes = 0;
+ @Dynamic
+ protected long minTimeToLive;
+
+ /**
+ * Can only be instantiated by a subclass.
+ */
+ protected EvictionAlgorithmConfigBase()
+ {
+ }
+
+ public String getEvictionAlgorithmClassName()
+ {
+ return evictionAlgorithmClassName;
+ }
+
+ public int getMaxNodes()
+ {
+ return maxNodes;
+ }
+
+ public void setMaxNodes(int maxNodes)
+ {
+ testImmutability("maxNodes");
+ this.maxNodes = maxNodes;
+ }
+
+ /**
+ * @return The minimum time to live, in milliseconds.
+ */
+ public long getMinTimeToLive()
+ {
+ return minTimeToLive;
+ }
+
+ /**
+ * @param minTimeToLive time to live, in milliseconds
+ */
+ public void setMinTimeToLive(long minTimeToLive)
+ {
+ testImmutability("minTimeToLive");
+ this.minTimeToLive = minTimeToLive;
+ }
+
+ public void setMinTimeToLive(long time, TimeUnit timeUnit)
+ {
+ testImmutability("minTimeToLive");
+ minTimeToLive = timeUnit.toMillis(time);
+ }
+
+ @Deprecated
+ @Compat
+ public void setMinTimeToLiveSeconds(long time)
+ {
+ setMinTimeToLive(time, TimeUnit.SECONDS);
+ }
+
+ public void validate() throws ConfigurationException
+ {
+ if (evictionAlgorithmClassName == null)
+ throw new ConfigurationException("Eviction algorithm class name cannot be null!");
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (!(o instanceof EvictionAlgorithmConfigBase)) return false;
+
+ EvictionAlgorithmConfigBase that = (EvictionAlgorithmConfigBase) o;
+
+ if (maxNodes != that.maxNodes) return false;
+ if (minTimeToLive != that.minTimeToLive) return false;
+ if (evictionAlgorithmClassName != null ? !evictionAlgorithmClassName.equals(that.evictionAlgorithmClassName) : that.evictionAlgorithmClassName != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (evictionAlgorithmClassName != null ? evictionAlgorithmClassName.hashCode() : 0);
+ result = 31 * result + maxNodes;
+ result = (int) (31 * result + minTimeToLive);
+ result = 31 * result + (int) (minTimeToLive ^ (minTimeToLive >>> 32));
+ return result;
+ }
+
+ public void reset()
+ {
+ maxNodes = 0;
+ minTimeToLive = 0;
+ }
+
+ public EvictionAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (EvictionAlgorithmConfig) super.clone();
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionEvent.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionEvent.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.Fqn;
+
+/**
+ * An eviction event records activity on nodes in the cache. These are recorded on a {@link org.jboss.cache.Region} for processing
+ * later by calls to {@link org.jboss.cache.Region#processEvictionQueues()}.
+ * <p/>
+ *
+ * @see org.jboss.cache.Region
+ */
+public class EvictionEvent
+{
+ private Fqn fqn;
+ private Type type;
+ private int elementDifference;
+
+ private long inUseTimeout;
+ private long creationTimestamp;
+
+ public EvictionEvent()
+ {
+ }
+
+ public static enum Type
+ {
+ ADD_NODE_EVENT,
+ REMOVE_NODE_EVENT,
+ VISIT_NODE_EVENT,
+ ADD_ELEMENT_EVENT,
+ REMOVE_ELEMENT_EVENT,
+ MARK_IN_USE_EVENT,
+ UNMARK_USE_EVENT
+ }
+
+ public EvictionEvent(Fqn fqn, Type type, int elementDifference)
+ {
+ this.fqn = fqn;
+ this.type = type;
+ this.elementDifference = elementDifference;
+ this.creationTimestamp = System.currentTimeMillis();
+ }
+
+ public long getCreationTimestamp()
+ {
+ return creationTimestamp;
+ }
+
+ public long getInUseTimeout()
+ {
+ return inUseTimeout;
+ }
+
+ public void setInUseTimeout(long inUseTimeout)
+ {
+ this.inUseTimeout = inUseTimeout;
+ }
+
+ public int getElementDifference()
+ {
+ return elementDifference;
+ }
+
+ public void setElementDifference(int elementDifference)
+ {
+ this.elementDifference = elementDifference;
+ }
+
+ public Fqn getFqn()
+ {
+ return fqn;
+ }
+
+ public void setFqn(Fqn fqn)
+ {
+ this.fqn = fqn;
+ }
+
+ public void setEventType(Type event)
+ {
+ type = event;
+ }
+
+ public Type getEventType()
+ {
+ return type;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "EvictedEventNode[fqn=" + fqn + " event=" + type + " diff=" + elementDifference + "]";
+ }
+
+ /**
+ * Copies this evicted event node to create a new one with the same values, except with a new Fqn root.
+ *
+ * @param newRoot new Fqn root to use
+ * @return a new EvictedEventNode instance
+ * @see org.jboss.cache.Region#copy(org.jboss.cache.Fqn)
+ */
+ public EvictionEvent copy(Fqn newRoot)
+ {
+ return new EvictionEvent(Fqn.fromRelativeFqn(newRoot, fqn), type, elementDifference);
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionEvent.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionException.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionException.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionException.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.CacheException;
+
+/**
+ * @author Ben Wang, Feb 11, 2004
+ */
+public class EvictionException extends CacheException
+{
+
+ private static final long serialVersionUID = 4006783737166646935L;
+
+ public EvictionException()
+ {
+ super();
+ }
+
+ public EvictionException(String msg)
+ {
+ super(msg);
+ }
+
+ public EvictionException(String msg, Throwable cause)
+ {
+ super(msg, cause);
+ }
+
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionListEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionListEntry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionListEntry.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+class EvictionListEntry
+{
+ EvictionListEntry next;
+ EvictionListEntry previous;
+
+ NodeEntry node;
+
+ EvictionListEntry()
+ {
+ }
+
+ EvictionListEntry(NodeEntry node)
+ {
+ this.node = node;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (!(o instanceof EvictionListEntry))
+ return false;
+ EvictionListEntry entry = (EvictionListEntry) o;
+ return this.node.getFqn().equals(entry.node.getFqn());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return this.node.getFqn().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "EntryLE=" + node;
+ }
+
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueue.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.Fqn;
+
+
+/**
+ * Eviction Queue interface defines a contract for the Eviction Queue implementations used by EvictionPolicies.
+ * <p/>
+ * Note: None of the Eviction classes are thread safe. It is assumed that an individual instance of an EvictionPolicy/
+ * EvictionAlgorithm/EvictionQueue/EvictionConfiguration are only operated on by one thread at any given time.
+ *
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @version $Revision: 6776 $
+ */
+public interface EvictionQueue extends Iterable<org.jboss.starobrno.eviction.NodeEntry>
+{
+ /**
+ * Get the first entry in the queue.
+ * <p/>
+ * If there are no entries in queue, this method will return null.
+ * <p/>
+ * The first node returned is expected to be the first node to evict.
+ *
+ * @return first NodeEntry in queue.
+ */
+ org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry();
+
+ /**
+ * Retrieve a node entry by Fqn.
+ * <p/>
+ * This will return null if the entry is not found.
+ *
+ * @param fqn Fqn of the node entry to retrieve.
+ * @return Node Entry object associated with given Fqn param.
+ */
+ org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn);
+
+ org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn);
+
+ /**
+ * Check if queue contains the given NodeEntry.
+ *
+ * @param entry NodeEntry to check for existence in queue.
+ * @return true/false if NodeEntry exists in queue.
+ */
+ boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry);
+
+ /**
+ * Remove a NodeEntry from queue.
+ * <p/>
+ * If the NodeEntry does not exist in the queue, this method will return normally.
+ *
+ * @param entry The NodeEntry to remove from queue.
+ */
+ void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry);
+
+ /**
+ * Add a NodeEntry to the queue.
+ *
+ * @param entry The NodeEntry to add to queue.
+ */
+ void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry);
+
+ /**
+ * Get the number of nodes in the queue.
+ *
+ * @return The number of nodes in the queue.
+ */
+ int getNumberOfNodes();
+
+ /**
+ * Get the number of elements in the queue.
+ *
+ * @return The number of elements in the queue.
+ */
+ int getNumberOfElements();
+
+ void modifyElementCount(int difference);
+
+ /**
+ * Clear the queue.
+ */
+ void clear();
+
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueueList.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueueList.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionQueueList.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,349 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+
+/**
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class EvictionQueueList
+{
+ EvictionListEntry head;
+ EvictionListEntry tail;
+ int modCount;
+ private int size;
+
+ EvictionQueueList()
+ {
+ head = null;
+ tail = null;
+ size = 0;
+ modCount = 0;
+ }
+
+ void addToTop(EvictionListEntry entry)
+ {
+ EvictionListEntry formerHead = head;
+ head = entry;
+ // if there was no previous head then this list was empty.
+ if (formerHead != null)
+ {
+ formerHead.previous = head;
+ head.next = formerHead;
+ head.previous = null;
+ }
+ else
+ {
+ tail = entry;
+ }
+ size++;
+ modCount++;
+ }
+
+ void addToBottom(EvictionListEntry entry)
+ {
+ EvictionListEntry formerTail = tail;
+ tail = entry;
+ // if there was no previous head then this list was empty.
+ if (formerTail != null)
+ {
+ tail.previous = formerTail;
+ formerTail.next = tail;
+ tail.next = null;
+ }
+ else
+ {
+ head = entry;
+ }
+ size++;
+ modCount++;
+ }
+
+ void remove(EvictionListEntry entry)
+ {
+ if (this.isEmpty())
+ {
+ return;
+ }
+
+ if (isSingleNode(entry))
+ {
+ head = null;
+ tail = null;
+ }
+ else if (isTail(entry))
+ {
+ tail = entry.previous;
+ // unlink the last node.
+ entry.previous.next = null;
+ }
+ else if (isHead(entry))
+ {
+ head = entry.next;
+ head.previous = null;
+ }
+ else
+ {
+ // node is in between two other nodes.
+ entry.next.previous = entry.previous;
+ entry.previous.next = entry.next;
+ }
+ size--;
+ modCount++;
+ }
+
+ int size()
+ {
+ return this.size;
+ }
+
+ void clear()
+ {
+ head = null;
+ tail = null;
+ size = 0;
+ modCount++;
+ }
+
+ EvictionListEntry getFirst()
+ {
+ if (head == null)
+ {
+ throw new NoSuchElementException("List is empty");
+ }
+ return head;
+ }
+
+ EvictionListEntry getLast()
+ {
+ if (tail == null)
+ {
+ throw new NoSuchElementException("List is empty");
+ }
+ return tail;
+ }
+
+ Iterator<NodeEntry> iterator()
+ {
+ return new EvictionListIterator();
+ }
+
+ NodeEntry[] toNodeEntryArray()
+ {
+ if (isEmpty())
+ {
+ return null;
+ }
+ NodeEntry[] ret = new NodeEntry[size];
+ int i = 0;
+ EvictionListEntry temp = head;
+
+ do
+ {
+ ret[i] = temp.node;
+ temp = temp.next;
+ i++;
+ }
+ while (temp != null);
+
+ return ret;
+ }
+
+ EvictionListEntry[] toArray()
+ {
+ if (isEmpty())
+ {
+ return null;
+ }
+ EvictionListEntry[] ret = new EvictionListEntry[size];
+ int i = 0;
+ EvictionListEntry temp = head;
+
+ do
+ {
+ ret[i] = temp;
+ temp = temp.next;
+ i++;
+ }
+ while (temp != null);
+
+ return ret;
+ }
+
+ void fromArray(EvictionListEntry[] evictionListEntries)
+ {
+
+ for (EvictionListEntry evictionListEntry : evictionListEntries)
+ {
+ this.addToBottom(evictionListEntry);
+ }
+ }
+
+ private boolean isEmpty()
+ {
+ return head == null && tail == null;
+ }
+
+ private boolean isSingleNode(EvictionListEntry entry)
+ {
+ return isTail(entry) && isHead(entry);
+ }
+
+ private boolean isTail(EvictionListEntry entry)
+ {
+ return entry.next == null;
+ }
+
+ private boolean isHead(EvictionListEntry entry)
+ {
+ return entry.previous == null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return Arrays.asList(toArray()).toString();
+ }
+
+ static class EvictionListComparator implements Comparator<EvictionListEntry>
+ {
+ Comparator<NodeEntry> nodeEntryComparator;
+
+ EvictionListComparator(Comparator<NodeEntry> nodeEntryComparator)
+ {
+ this.nodeEntryComparator = nodeEntryComparator;
+ }
+
+ public int compare(EvictionListEntry e1, EvictionListEntry e2)
+ {
+ return nodeEntryComparator.compare(e1.node, e2.node);
+ }
+ }
+
+ class EvictionListIterator implements ListIterator<NodeEntry>
+ {
+ EvictionListEntry next = head;
+ EvictionListEntry previous;
+ EvictionListEntry cursor;
+
+ int initialModCount = EvictionQueueList.this.modCount;
+
+ public boolean hasNext()
+ {
+ this.doConcurrentModCheck();
+ return next != null;
+ }
+
+ public NodeEntry next()
+ {
+ this.doConcurrentModCheck();
+ this.forwardCursor();
+ return cursor.node;
+ }
+
+ public boolean hasPrevious()
+ {
+ this.doConcurrentModCheck();
+ return previous != null;
+ }
+
+ public NodeEntry previous()
+ {
+ this.doConcurrentModCheck();
+ this.rewindCursor();
+ return cursor.node;
+ }
+
+ public int nextIndex()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int previousIndex()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void remove()
+ {
+ this.doConcurrentModCheck();
+ if (cursor == null)
+ {
+ throw new IllegalStateException("Cannot remove from iterator when there is nothing at the current iteration point");
+ }
+ EvictionQueueList.this.remove(cursor);
+ cursor = null;
+ initialModCount++;
+ }
+
+ public void set(NodeEntry o)
+ {
+ this.doConcurrentModCheck();
+ cursor.node = (NodeEntry) o;
+ }
+
+ public void add(NodeEntry o)
+ {
+ this.doConcurrentModCheck();
+ initialModCount++;
+ }
+
+ private void doConcurrentModCheck()
+ {
+ if (EvictionQueueList.this.modCount != initialModCount)
+ {
+ throw new ConcurrentModificationException();
+ }
+ }
+
+ private void forwardCursor()
+ {
+ if (next == null)
+ {
+ throw new NoSuchElementException("No more objects to iterate.");
+ }
+ previous = cursor;
+ cursor = next;
+ next = cursor.next;
+ }
+
+ private void rewindCursor()
+ {
+ if (previous == null)
+ {
+ throw new NoSuchElementException();
+ }
+ next = cursor;
+ cursor = previous;
+ previous = cursor.previous;
+ }
+ }
+
+}
+
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionTimerTask.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionTimerTask.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionTimerTask.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,174 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Region;
+import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+
+import java.util.Set;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Timer threads to do periodic node clean up by running the eviction policy.
+ *
+ * @author Ben Wang 2-2004
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @version $Revision: 6840 $
+ */
+public class EvictionTimerTask
+{
+ private Log log = LogFactory.getLog(EvictionTimerTask.class);
+
+ private final Set<Region> processedRegions;
+ private static AtomicInteger tcount = new AtomicInteger();
+ private long wakeupInterval;
+ ScheduledExecutorService scheduledExecutor;
+ private Task task;
+
+ public EvictionTimerTask()
+ {
+ // synchronized set because we need to maintain thread safety
+ // for dynamic configuration purposes.
+ processedRegions = new ConcurrentHashSet<Region>();
+ task = new Task();
+ }
+
+ public void init(long wakeupInterval, ThreadFactory evictionThreadFactory)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Creating a new eviction listener with wakeupInterval millis set at " + wakeupInterval);
+ this.wakeupInterval = wakeupInterval;
+ start(evictionThreadFactory);
+ }
+
+ /**
+ * Add a MarshRegion to process by the Eviction Thread.
+ *
+ * @param region MarshRegion to process.
+ */
+ public void addRegionToProcess(Region region)
+ {
+ processedRegions.add(region);
+ }
+
+ /**
+ * Remove a MarshRegion to process from the Eviction thread.
+ *
+ * @param region
+ */
+ public void removeRegionToProcess(Region region)
+ {
+ processedRegions.remove(region);
+ }
+
+ public boolean isRegionRegisteredForProcessing(Region region)
+ {
+ return processedRegions.contains(region);
+ }
+
+ public Set<Region> getProcessedRegions()
+ {
+ return processedRegions;
+ }
+
+ public void stop()
+ {
+ if (log.isDebugEnabled()) log.debug("Stopping eviction timer");
+
+ if (scheduledExecutor != null)
+ {
+ scheduledExecutor.shutdownNow();
+ }
+ scheduledExecutor = null;
+ }
+
+ private void start(ThreadFactory tf)
+ {
+ if (wakeupInterval < 1)
+ {
+ if (log.isInfoEnabled())
+ log.info("Wakeup Interval set to " + wakeupInterval + ". Not starting an eviction thread!");
+ return;
+ }
+
+ if (tf == null) tf = new ThreadFactory()
+ {
+ public Thread newThread(Runnable r)
+ {
+ Thread t = new Thread(r, "EvictionTimer-" + tcount.getAndIncrement());
+ t.setDaemon(true);
+ return t;
+ }
+ };
+
+ scheduledExecutor = Executors.newSingleThreadScheduledExecutor(tf);
+ scheduledExecutor.scheduleWithFixedDelay(task, wakeupInterval, wakeupInterval, TimeUnit.MILLISECONDS);
+ }
+
+ private void processRegions()
+ {
+ synchronized (processedRegions)
+ {
+ for (Region region : processedRegions)
+ {
+ handleRegion(region);
+ }
+ }
+ }
+
+ private void handleRegion(Region region)
+ {
+ synchronized (region)
+ {
+ try
+ {
+ region.processEvictionQueues();
+ }
+ catch (EvictionException e)
+ {
+ log.error("run(): error processing eviction with exception: " + e.toString()
+ + " will reset the eviction queue list.");
+ region.resetEvictionQueues();
+ log.debug("trace", e);
+ }
+ }
+ }
+
+ public class Task implements Runnable
+ {
+ public void run()
+ {
+ // Run the eviction thread.
+ // This thread will synchronize the set of regions and iterate through every MarshRegion registered w/ the
+ // Eviction thread. It also synchronizes on each individual region as it is being processed.
+ processRegions();
+ }
+ }
+}
+
+
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/EvictionTimerTask.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithm.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,377 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.EvictionEvent.Type;
+
+import java.util.Iterator;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * Eviction algorithm that uses a key in the Node data that indicates the time
+ * the node should be evicted. The key must be a java.lang.Long object, with
+ * the time to expire as milliseconds past midnight January 1st, 1970 UTC (the
+ * same relative time as provided by {@link
+ * java.lang.System#currentTimeMillis()}).
+ * <p/>
+ * This algorithm also obeys the configuration key {@link
+ * org.jboss.starobrno.eviction.ExpirationAlgorithmConfig#getMaxNodes()}, and will evict the soonest to
+ * expire entires first to reduce the region size. If there are not enough
+ * nodes with expiration keys set, a warning is logged.
+ * <p/>
+ * If a node in the eviction region does not have an expiration value, then
+ * {@link org.jboss.starobrno.eviction.ExpirationAlgorithmConfig#getTimeToLive()} (if set) will be used.
+ * The expiration is updated when a node is added or updated.
+ * <p/>
+ * If there is no time-to-live set, and a node in the eviction region does not
+ * have an expiration value, then that node will never be evicted. As
+ * forgetting to indicate an expiration value is likely a mistake, a warning
+ * message is logged by this class. This warning, however, can be disabled
+ * through {@link org.jboss.starobrno.eviction.ExpirationAlgorithmConfig#setWarnNoExpirationKey(boolean)}.
+ * <p/>
+ * A node's expiration time can be changed by setting a new value in the node.
+ * <p/>
+ * Example usage:
+ * <pre>
+ * Cache cache;
+ * Fqn fqn1 = Fqn.fromString("/node/1");
+ * Long future = new Long(System.currentTimeMillis() + 2000);
+ * cache.put(fqn1, ExpirationConfiguration.EXPIRATION_KEY, future);
+ * cache.put(fqn1, "foo");
+ * assertTrue(cache.get(fqn1) != null);
+ * <p/>
+ * Thread.sleep(5000); // 5 seconds
+ * assertTrue(cache.get(fqn1) == null);
+ * <p/>
+ * </pre>
+ */
+public class ExpirationAlgorithm extends BaseEvictionAlgorithm
+{
+
+ private static final Log log = LogFactory.getLog(ExpirationAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ private org.jboss.starobrno.eviction.ExpirationAlgorithmConfig config;
+
+ private SortedSet<ExpirationEntry> set;
+
+ /**
+ * Constructs a new algorithm with a policy.
+ */
+ public ExpirationAlgorithm()
+ {
+ this.set = new TreeSet<ExpirationEntry>();
+ }
+
+ private void addEvictionEntry(org.jboss.starobrno.eviction.EvictionEvent node)
+ {
+ Fqn fqn = node.getFqn();
+ addEvictionEntry(fqn);
+ }
+
+ private void addEvictionEntry(Fqn fqn)
+ {
+ Long l = getExpiration(fqn);
+ if (l == null)
+ {
+ if (config.isWarnNoExpirationKey() && log.isWarnEnabled())
+ log.warn("No expiration key '" + config.getExpirationKeyName() + "' for Node: " + fqn);
+ else if (log.isDebugEnabled())
+ log.debug("No expiration key for Node: " + fqn);
+ }
+ else
+ {
+ setExpiration(fqn, l);
+ }
+ }
+
+ private void setExpiration(Fqn fqn, Long l)
+ {
+ ExpirationEntry ee = new ExpirationEntry(fqn, l);
+ if (trace)
+ log.trace("adding eviction entry: " + ee);
+ set.add(ee);
+ }
+
+ @SuppressWarnings("unchecked")
+ private Long getExpiration(Fqn fqn)
+ {
+ NodeSPI n = cache.peek(fqn, false);
+ if (n == null)
+ return null;
+ return (Long) n.getDirect(config.getExpirationKeyName());
+ }
+
+ @Override
+ protected void processQueues(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> queue) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ org.jboss.starobrno.eviction.EvictionEvent node;
+ int count = 0;
+ while ((node = getNextInQueue(queue)) != null)
+ {
+ count++;
+ switch (node.getEventType())
+ {
+ case ADD_NODE_EVENT:
+ case ADD_ELEMENT_EVENT:
+ addEvictionEntry(node);
+ break;
+ case REMOVE_ELEMENT_EVENT:
+ case REMOVE_NODE_EVENT:
+ case UNMARK_USE_EVENT:
+ // Removals will be noticed when double-checking expiry time
+ // removeEvictionEntry(node);
+ break;
+ case VISIT_NODE_EVENT:
+ // unused
+ break;
+ case MARK_IN_USE_EVENT:
+ markInUse(node);
+ break;
+ default:
+ throw new RuntimeException("Illegal Eviction Event type " + node.getEventType());
+ }
+ }
+
+ if (trace) log.trace("processed " + count + " node events in region: " + regionFqn);
+ }
+
+ private void markInUse(org.jboss.starobrno.eviction.EvictionEvent node)
+ {
+ long expiration = node.getInUseTimeout() + System.currentTimeMillis();
+ setExpiration(node.getFqn(), expiration);
+ }
+
+ @Override
+ protected void prune() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ if (set.isEmpty())
+ return;
+ long now = System.currentTimeMillis();
+ int max = config.getMaxNodes();
+ for (Iterator<ExpirationEntry> i = set.iterator(); i.hasNext();)
+ {
+ ExpirationEntry ee = i.next();
+ Long ce = getExpiration(ee.getFqn());
+ if (ce == null || ce > ee.getExpiration())
+ {
+ // Expiration now older
+ i.remove();
+ continue;
+ }
+ if (ee.getExpiration() < now || (max != 0 && set.size() > max))
+ {
+ i.remove();
+ evictCacheNode(ee.getFqn());
+ }
+ else
+ {
+ break;
+ }
+ }
+ if (max != 0 && max > set.size())
+ log.warn("Unable to remove nodes to reduce region size below " +
+ config.getMaxNodes() + ". " +
+ "Set expiration for nodes in this region");
+ }
+
+ @Override
+ public void resetEvictionQueue()
+ {
+ for (ExpirationEntry ee : set)
+ {
+ addEvictionEntry(ee.getFqn());
+ }
+ }
+
+ @Override
+ protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ this.config = (org.jboss.starobrno.eviction.ExpirationAlgorithmConfig) evictionAlgorithmConfig;
+ return new DummyEvictionQueue();
+ }
+
+ @Override
+ protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean canIgnoreEvent(Type eventType)
+ {
+ return (eventType == org.jboss.starobrno.eviction.EvictionEvent.Type.VISIT_NODE_EVENT);
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return org.jboss.starobrno.eviction.ExpirationAlgorithmConfig.class;
+ }
+
+ /**
+ * Ordered list of FQN, with the expiration taken from the Map at the time
+ * of processing.
+ */
+ static class ExpirationEntry implements Comparable<ExpirationEntry>
+ {
+
+ private long expiration;
+
+ private Fqn fqn;
+
+ public ExpirationEntry(Fqn fqn)
+ {
+ this.fqn = fqn;
+ }
+
+ public ExpirationEntry(Fqn fqn, long expiration)
+ {
+ this.fqn = fqn;
+ this.expiration = expiration;
+ }
+
+ /**
+ * Compares expiration, then FQN order.
+ */
+ public int compareTo(ExpirationEntry ee)
+ {
+ long n = expiration - ee.expiration;
+ if (n < 0)
+ return -1;
+ if (n > 0)
+ return 1;
+ return fqn.compareTo(ee.fqn);
+ }
+
+ /**
+ * @return the expiration
+ */
+ public long getExpiration()
+ {
+ return expiration;
+ }
+
+ /**
+ * @return the fqn
+ */
+ public Fqn getFqn()
+ {
+ return fqn;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (!(o instanceof ExpirationEntry))
+ return false;
+ ExpirationEntry ee = (ExpirationEntry) o;
+ return expiration == ee.expiration && fqn.equals(ee.fqn);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return (int) expiration ^ fqn.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ long now = System.currentTimeMillis();
+ long ttl = expiration - now;
+ String sttl;
+ if (ttl > 1000 * 60)
+ sttl = (ttl / (1000 * 60)) + "min";
+ else if (ttl > 1000)
+ sttl = (ttl / 1000) + "s";
+ else
+ sttl = ttl + "ms";
+ return "EE fqn=" + fqn + " ttl=" + sttl;
+ }
+ }
+
+ class DummyEvictionQueue implements org.jboss.starobrno.eviction.EvictionQueue
+ {
+
+ public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear()
+ {
+ set.clear();
+ }
+
+ public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ return false;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
+ {
+ return null;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
+ {
+ return null;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
+ {
+ return null;
+ }
+
+ public int getNumberOfElements()
+ {
+ return set.size();
+ }
+
+ public int getNumberOfNodes()
+ {
+ return set.size();
+ }
+
+ public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
+ {
+ return null;
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ }
+
+ public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithm.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithmConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,161 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.annotations.Compat;
+import org.jboss.starobrno.config.Dynamic;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Configuration for indicating the Node key for setting a specific eviction time.
+ */
+public class ExpirationAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+
+ private static final long serialVersionUID = 47338798734219507L;
+
+ /**
+ * Default key name for indicating expiration time.
+ */
+ public static final String EXPIRATION_KEY = "expiration";
+
+ /**
+ * Node key name used to indicate the expiration of a node.
+ */
+ @Dynamic
+ private String expirationKeyName = EXPIRATION_KEY;
+
+ @Dynamic
+ private boolean warnNoExpirationKey = true;
+
+ @Dynamic
+ private long timeToLive = 0;
+
+ public ExpirationAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.ExpirationAlgorithm.class.getName();
+ }
+
+ /**
+ * Returns the expirationKeyName.
+ * This key should point to a java.lang.Long value in the Node data.
+ */
+ public String getExpirationKeyName()
+ {
+ return expirationKeyName;
+ }
+
+ /**
+ * Sets the expirationKeyName.
+ */
+ public void setExpirationKeyName(String expirationKeyName)
+ {
+ this.expirationKeyName = expirationKeyName;
+ }
+
+ /**
+ * Returns true if the algorithm should warn if a expiration key is missing for a node.
+ */
+ public boolean isWarnNoExpirationKey()
+ {
+ return warnNoExpirationKey;
+ }
+
+ /**
+ * Sets if the algorithm should warn if a expiration key is missing for a node.
+ */
+ public void setWarnNoExpirationKey(boolean warnNoExpirationKey)
+ {
+ this.warnNoExpirationKey = warnNoExpirationKey;
+ }
+
+ /**
+ * @return time to live, in milliseconds
+ */
+ public long getTimeToLive()
+ {
+ return timeToLive;
+ }
+
+ /**
+ * Sets the time to live
+ *
+ * @param timeToLive value in milliseconds
+ */
+ public void setTimeToLive(long timeToLive)
+ {
+ this.timeToLive = timeToLive;
+ }
+
+ public void setTimeToLive(long timeToLive, TimeUnit timeUnit)
+ {
+ this.timeToLive = timeUnit.toMillis(timeToLive);
+ }
+
+ @Deprecated
+ @Compat
+ public void setTimeToLiveSeconds(long time)
+ {
+ setTimeToLive(time, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public ExpirationAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (ExpirationAlgorithmConfig) super.clone();
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ if (!super.equals(o)) return false;
+
+ ExpirationAlgorithmConfig that = (ExpirationAlgorithmConfig) o;
+
+ if (timeToLive != that.timeToLive) return false;
+ if (warnNoExpirationKey != that.warnNoExpirationKey) return false;
+ if (expirationKeyName != null ? !expirationKeyName.equals(that.expirationKeyName) : that.expirationKeyName != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + (expirationKeyName != null ? expirationKeyName.hashCode() : 0);
+ result = 31 * result + (warnNoExpirationKey ? 1 : 0);
+ result = 31 * result + (int) (timeToLive ^ (timeToLive >>> 32));
+ return result;
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.ExpirationAlgorithm.class.getName();
+ warnNoExpirationKey = true;
+ timeToLive = 0;
+ }
+}
\ No newline at end of file
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/ExpirationAlgorithmConfig.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithm.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+
+/**
+ * First-in-first-out algorithm used to evict nodes.
+ *
+ * @author Daniel Huang - dhuang at jboss.org
+ * @author Morten Kvistgaard
+ * @version $Revision: 6776 $
+ */
+public class FIFOAlgorithm extends BaseEvictionAlgorithm
+{
+ private static final Log log = LogFactory.getLog(FIFOAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+
+ @Override
+ protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ return new org.jboss.starobrno.eviction.FIFOQueue();
+ }
+
+ /**
+ * For FIFO, a node should be evicted if the queue size is >= to the configured maxNodes size.
+ */
+ @Override
+ protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne)
+ {
+ // check the minimum time to live and see if we should not evict the node. This check will
+ // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
+ if (isYoungerThanMinimumTimeToLive(ne)) return false;
+
+ org.jboss.starobrno.eviction.FIFOAlgorithmConfig config = (org.jboss.starobrno.eviction.FIFOAlgorithmConfig) evictionAlgorithmConfig;
+ if (trace)
+ {
+ log.trace("Deciding whether node in queue " + ne.getFqn() + " requires eviction.");
+ }
+
+ int size = this.getEvictionQueue().getNumberOfNodes();
+ return config.getMaxNodes() != 0 && size > config.getMaxNodes();
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return org.jboss.starobrno.eviction.FIFOAlgorithmConfig.class;
+ }
+}
+
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithm.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOAlgorithmConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.config.ConfigurationException;
+
+/**
+ * Configuration for {@link org.jboss.starobrno.eviction.FIFOAlgorithm}.
+ * <p/>
+ * Requires a "maxNodes" attribute otherwise a ConfigurationException is thrown.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class FIFOAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -7229715009546277313L;
+
+ public FIFOAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.FIFOAlgorithm.class.getName();
+ // We require that maxNodes is set
+ setMaxNodes(-1);
+ }
+
+ public FIFOAlgorithmConfig(int maxNodes)
+ {
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.FIFOAlgorithm.class.getName();
+ // We require that maxNodes is set
+ setMaxNodes(maxNodes);
+ }
+
+ /**
+ * Requires a positive maxNodes value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ super.validate();
+ if (getMaxNodes() < 0)
+ {
+ throw new ConfigurationException("maxNodes must be must be " +
+ "configured to a value greater than or equal to 0");
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder ret = new StringBuilder();
+ ret.append("FIFOAlgorithmConfig: maxNodes = ").append(getMaxNodes());
+ return ret.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return (obj instanceof FIFOAlgorithmConfig && super.equals(obj));
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ setMaxNodes(-1);
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.FIFOAlgorithm.class.getName();
+ }
+
+ @Override
+ public FIFOAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (FIFOAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/FIFOQueue.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,123 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.Fqn;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * FIFO Eviction Queue implementation for FIFO Policy.
+ *
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class FIFOQueue implements EvictionQueue
+{
+ private Map<Fqn, org.jboss.starobrno.eviction.NodeEntry> nodeMap;
+ private int numElements = 0;
+
+ protected FIFOQueue()
+ {
+ nodeMap = new LinkedHashMap<Fqn, org.jboss.starobrno.eviction.NodeEntry>();
+ // We use a LinkedHashMap here because we want to maintain FIFO ordering and still get the benefits of
+ // O(n) = 1 for add/remove/search.
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
+ {
+/* Iterator it = nodeMap.keySet().iterator();
+ if(it.hasNext()) {
+ return (NodeEntry) nodeMap.get(it.next());
+ }
+
+ return null; */
+
+ // this code path is *slightly* faster when profiling. 20ms faster iterating over 200000 entries in queue.
+ if (nodeMap.size() > 0)
+ {
+ return nodeMap.values().iterator().next();
+ }
+
+ return null;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
+ {
+ return nodeMap.get(fqn);
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
+ {
+ return this.getNodeEntry(Fqn.fromString(fqn));
+ }
+
+ public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ Fqn fqn = entry.getFqn();
+ return this.getNodeEntry(fqn) != null;
+ }
+
+ public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ org.jboss.starobrno.eviction.NodeEntry e = nodeMap.remove(entry.getFqn());
+ this.numElements -= e.getNumberOfElements();
+ }
+
+ public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ entry.queue = this;
+ nodeMap.put(entry.getFqn(), entry);
+ this.numElements += entry.getNumberOfElements();
+ }
+ }
+
+ public int getNumberOfNodes()
+ {
+ return nodeMap.size();
+ }
+
+ public int getNumberOfElements()
+ {
+ return this.numElements;
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ this.numElements += difference;
+ }
+
+ public void clear()
+ {
+ nodeMap.clear();
+ this.numElements = 0;
+ }
+
+ public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
+ {
+ return nodeMap.values().iterator();
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithm.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+
+/**
+ * Least Frequently Used algorithm for cache eviction.
+ * Note that this algorithm is not thread-safe.
+ * <p/>
+ * This algorithm relies on maxNodes and minNodes to operate correctly.
+ * Eviction takes place using Least Frequently Used algorithm. A node A
+ * that is used less than a node B is evicted sooner.
+ * <p/>
+ * The minNodes property defines a threshold for eviction. If minNodes = 100,
+ * the LFUAlgorithm will not evict the cache to anything less than 100 elements
+ * still left in cache. The maxNodes property defines the maximum number of nodes
+ * the cache will accept before eviction. maxNodes = 0 means that this region is
+ * unbounded. minNodes = 0 means that the eviction queue will attempt to bring
+ * the cache of this region to 0 elements (evict all elements) whenever it is run.
+ * <p/>
+ * This algorithm uses a sorted eviction queue. The eviction queue is sorted in
+ * ascending order based on the number of times a node is visited. The more frequently
+ * a node is visited, the less likely it will be evicted.
+ *
+ * @author Daniel Huang - dhuang at jboss.org 10/2005
+ * @version $Revision: 6776 $
+ */
+public class LFUAlgorithm extends BaseSortedEvictionAlgorithm
+{
+ private static final Log log = LogFactory.getLog(LFUAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ @Override
+ protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne)
+ {
+ if (trace)
+ {
+ log.trace("Deciding whether node in queue " + ne.getFqn() + " requires eviction.");
+ }
+
+ // check the minimum time to live and see if we should not evict the node. This check will
+ // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
+ if (isYoungerThanMinimumTimeToLive(ne)) return false;
+
+ org.jboss.starobrno.eviction.LFUAlgorithmConfig config = (org.jboss.starobrno.eviction.LFUAlgorithmConfig) evictionAlgorithmConfig;
+ int size = this.getEvictionQueue().getNumberOfNodes();
+ if (config.getMaxNodes() > -1 && size > config.getMaxNodes())
+ {
+ return true;
+ }
+ else if (size > config.getMinNodes())
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Will create a LFUQueue to be used as the underlying eviction queue.
+ *
+ * @return The created LFUQueue.
+ * @throws org.jboss.starobrno.eviction.EvictionException
+ *
+ */
+ @Override
+ protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ return new org.jboss.starobrno.eviction.LFUQueue();
+ }
+
+ @Override
+ protected void prune() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ super.prune();
+
+ // clean up the Queue's eviction removals
+ ((org.jboss.starobrno.eviction.LFUQueue) this.evictionQueue).prune();
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return org.jboss.starobrno.eviction.LFUAlgorithmConfig.class;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUAlgorithmConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.config.Dynamic;
+
+/**
+ * Configuration implementation for {@link org.jboss.starobrno.eviction.LFUAlgorithm}.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class LFUAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = 1865801530398969179L;
+
+ @Dynamic
+ private int minNodes;
+
+ public LFUAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.LFUAlgorithm.class.getName();
+ }
+
+ public LFUAlgorithmConfig(int maxNodes, int minNodes)
+ {
+ this();
+ setMaxNodes(maxNodes);
+ setMinNodes(minNodes);
+ }
+
+ public int getMinNodes()
+ {
+ return minNodes;
+ }
+
+ public void setMinNodes(int minNodes)
+ {
+ testImmutability("minNodes");
+ this.minNodes = minNodes;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder ret = new StringBuilder();
+ ret.append("LFUAlgorithmConfig: maxNodes = ").append(getMaxNodes()).append(" minNodes = ").append(getMinNodes());
+ return ret.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof LFUAlgorithmConfig && super.equals(obj))
+ {
+ return (this.minNodes == ((LFUAlgorithmConfig) obj).minNodes);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + minNodes;
+ return result;
+ }
+
+ @Override
+ public LFUAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (LFUAlgorithmConfig) super.clone();
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ minNodes = -1;
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.LFUAlgorithm.class.getName();
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LFUQueue.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,237 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.Fqn;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * LFUQueue EvictionQueue implementation for LFU Policy.
+ * <p/>
+ * The queue is sorted in least frequently used order.
+ *
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class LFUQueue implements SortedEvictionQueue
+{
+ private Map<Fqn, org.jboss.starobrno.eviction.NodeEntry> nodeMap;
+ private LinkedList<org.jboss.starobrno.eviction.NodeEntry> evictionList;
+ private Comparator<org.jboss.starobrno.eviction.NodeEntry> comparator;
+
+ private Set<org.jboss.starobrno.eviction.NodeEntry> removalQueue;
+ private int numElements = 0;
+
+ protected LFUQueue()
+ {
+ nodeMap = new HashMap<Fqn, org.jboss.starobrno.eviction.NodeEntry>();
+ comparator = new LFUComparator();
+ evictionList = new LinkedList<org.jboss.starobrno.eviction.NodeEntry>();
+ removalQueue = new HashSet<org.jboss.starobrno.eviction.NodeEntry>();
+ }
+
+ /**
+ * Return the first node to evict.
+ * <p/>
+ * This method will return the least frequently used entry in the queue.
+ */
+ public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
+ {
+ try
+ {
+ org.jboss.starobrno.eviction.NodeEntry ne;
+ while ((ne = evictionList.getFirst()) != null)
+ {
+ if (removalQueue.contains(ne))
+ {
+ evictionList.removeFirst();
+ removalQueue.remove(ne);
+ }
+ else
+ {
+ break;
+ }
+ }
+ return ne;
+ }
+ catch (NoSuchElementException e)
+ {
+ //
+ }
+
+ return null;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
+ {
+ return nodeMap.get(fqn);
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
+ {
+ return this.getNodeEntry(Fqn.fromString(fqn));
+ }
+
+ public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ Fqn fqn = entry.getFqn();
+ return this.getNodeEntry(fqn) != null;
+ }
+
+ public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ org.jboss.starobrno.eviction.NodeEntry ne = nodeMap.remove(entry.getFqn());
+ if (ne != null)
+ {
+ // don't remove directly from the LinkedList otherwise we will incur a O(n) = n
+ // performance penalty for every removal! In the prune method for LFU, we will iterate the LinkedList through ONCE
+ // doing a single O(n) = n operation and removal. This is much preferred over running O(n) = n every single time
+ // remove is called. There is also special logic in the getFirstNodeEntry that will know to check
+ // the removalQueue before returning.
+ this.removalQueue.add(ne);
+/* if(!evictionList.remove(ne)) {
+ throw new RuntimeException("");
+ } */
+ this.numElements -= ne.getNumberOfElements();
+ }
+ }
+
+ public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ Fqn fqn = entry.getFqn();
+ entry.queue = this;
+ nodeMap.put(fqn, entry);
+ evictionList.add(entry);
+ this.numElements += entry.getNumberOfElements();
+ }
+ }
+
+ public int getNumberOfNodes()
+ {
+ return nodeMap.size();
+ }
+
+ public int getNumberOfElements()
+ {
+ return this.numElements;
+ }
+
+ public void clear()
+ {
+ nodeMap.clear();
+ evictionList.clear();
+ removalQueue.clear();
+ this.numElements = 0;
+ }
+
+ public void resortEvictionQueue()
+ {
+ Collections.sort(evictionList, comparator);
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ this.numElements += difference;
+ }
+
+ protected void prune()
+ {
+ Iterator<org.jboss.starobrno.eviction.NodeEntry> it = this.iterator();
+ while (it.hasNext() && removalQueue.size() > 0)
+ {
+ if (removalQueue.remove(it.next()))
+ {
+ it.remove();
+ }
+ }
+ }
+
+ protected final List<org.jboss.starobrno.eviction.NodeEntry> getEvictionList()
+ {
+ return this.evictionList;
+ }
+
+ protected final Set<org.jboss.starobrno.eviction.NodeEntry> getRemovalQueue()
+ {
+ return this.removalQueue;
+ }
+
+ public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
+ {
+ return evictionList.iterator();
+ }
+
+ /**
+ * Comparator class for LFU.
+ * <p/>
+ * This class will sort the eviction queue in the correct eviction order.
+ * The top of the list should evict before the bottom of the list.
+ * <p/>
+ * The sort is based on ascending order of nodeVisits.
+ * <p/>
+ * Note: this class has a natural ordering that is inconsistent with equals as defined by the java.lang.Comparator
+ * contract.
+ */
+ protected static class LFUComparator implements Comparator<org.jboss.starobrno.eviction.NodeEntry>
+ {
+
+ public int compare(org.jboss.starobrno.eviction.NodeEntry ne1, org.jboss.starobrno.eviction.NodeEntry ne2)
+ {
+ if (ne1.equals(ne2))
+ {
+ return 0;
+ }
+
+ int neNodeHits = ne1.getNumberOfNodeVisits();
+ int ne2NodeHits = ne2.getNumberOfNodeVisits();
+
+ if (neNodeHits > ne2NodeHits)
+ {
+ return 1;
+ }
+ else if (neNodeHits < ne2NodeHits)
+ {
+ return -1;
+ }
+ else if (neNodeHits == ne2NodeHits)
+ {
+ return 0;
+ }
+
+ throw new RuntimeException("Should never reach this condition");
+ }
+ }
+
+}
+
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithm.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,198 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+
+import java.util.Iterator;
+
+/**
+ * Least recently Used algorithm to purge old data.
+ * Note that this algorithm is not thread-safe.
+ *
+ * @author Ben Wang 02-2004
+ * @author Daniel Huang - dhuang at jboss.org
+ */
+public class LRUAlgorithm extends BaseEvictionAlgorithm
+{
+ private static final Log log = LogFactory.getLog(LRUAlgorithm.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ @Override
+ protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ return new org.jboss.starobrno.eviction.LRUQueue();
+ }
+
+ @Override
+ protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ // check the minimum time to live and see if we should not evict the node. This check will
+ // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
+ if (isYoungerThanMinimumTimeToLive(entry)) return false;
+
+ org.jboss.starobrno.eviction.LRUAlgorithmConfig config = (org.jboss.starobrno.eviction.LRUAlgorithmConfig) evictionAlgorithmConfig;
+ // no idle or max time limit
+ if (config.getTimeToLive() < 0 && config.getMaxAge() < 0) return false;
+
+ long currentTime = System.currentTimeMillis();
+ if (config.getTimeToLive() > -1)
+ {
+ long idleTime = currentTime - entry.getModifiedTimeStamp();
+ if (trace)
+ {
+ log.trace("Node " + entry.getFqn() + " has been idle for " + idleTime + "ms");
+ }
+ if ((idleTime >= (config.getTimeToLive())))
+ {
+ if (trace)
+ {
+ log.trace("Node " + entry.getFqn() + " should be evicted because of idle time");
+ log.trace("Time to live in millies is: " + (config.getTimeToLive()));
+ log.trace("Config instance is: " + System.identityHashCode(config));
+ }
+ return true;
+ }
+ }
+
+ if (config.getMaxAge() > -1)
+ {
+ long objectLifeTime = currentTime - entry.getCreationTimeStamp();
+ if (trace)
+ {
+ log.trace("Node " + entry.getFqn() + " has been alive for " + objectLifeTime + "ms");
+ }
+ if ((objectLifeTime >= config.getMaxAge()))
+ {
+ if (trace)
+ {
+ log.trace("Node " + entry.getFqn() + " should be evicted because of max age");
+ }
+ return true;
+ }
+ }
+
+ if (trace)
+ {
+ log.trace("Node " + entry.getFqn() + " should not be evicted");
+ }
+ return false;
+ }
+
+ @Override
+ protected void evict(org.jboss.starobrno.eviction.NodeEntry ne)
+ {
+ if (ne != null)
+ {
+ if (!this.evictCacheNode(ne.getFqn()))
+ {
+ try
+ {
+ recycleQueue.put(ne.getFqn());
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("InterruptedException", e);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void prune() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ org.jboss.starobrno.eviction.LRUQueue lruQueue = (org.jboss.starobrno.eviction.LRUQueue) evictionQueue;
+ org.jboss.starobrno.eviction.NodeEntry ne;
+ Iterator it = lruQueue.iterateLRUQueue();
+ while (it.hasNext())
+ {
+ ne = (org.jboss.starobrno.eviction.NodeEntry) it.next();
+ if (isNodeInUseAndNotTimedOut(ne))
+ {
+ continue;
+ }
+
+ if (this.shouldEvictNode(ne))
+ {
+ it.remove();
+ lruQueue.removeNodeEntryFromMaxAge(ne);
+ this.evict(ne);
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ it = lruQueue.iterateMaxAgeQueue();
+ while (it.hasNext())
+ {
+ ne = (org.jboss.starobrno.eviction.NodeEntry) it.next();
+ if (isNodeInUseAndNotTimedOut(ne))
+ {
+ continue;
+ }
+
+ if (this.shouldEvictNode(ne))
+ {
+ it.remove();
+ lruQueue.removeNodeEntryFromLRU(ne);
+ this.evict(ne);
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ int maxNodes = ((org.jboss.starobrno.eviction.LRUAlgorithmConfig) evictionAlgorithmConfig).getMaxNodes();
+ if (maxNodes <= 0)
+ {
+ return;
+ }
+
+ it = lruQueue.iterateLRUQueue();
+ while (evictionQueue.getNumberOfNodes() > maxNodes)
+ {
+ ne = (org.jboss.starobrno.eviction.NodeEntry) it.next();
+ if (trace)
+ {
+ log.trace("Node " + ne.getFqn() + " will be evicted because of exceeding the maxNode limit." +
+ " maxNode: " + maxNodes + " but current queue size is: " + evictionQueue.getNumberOfNodes());
+ }
+
+ if (!this.isNodeInUseAndNotTimedOut(ne))
+ {
+ it.remove();
+ lruQueue.removeNodeEntryFromMaxAge(ne);
+ this.evict(ne);
+ }
+ }
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return org.jboss.starobrno.eviction.LRUAlgorithmConfig.class;
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithm.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUAlgorithmConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,194 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.annotations.Compat;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.Dynamic;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Configuration implementation for {@link org.jboss.starobrno.eviction.LRUAlgorithm}.
+ * <p/>
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class LRUAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -3426716488271559729L;
+
+ /**
+ * value expressed in millis
+ */
+ @Dynamic
+ private long timeToLive;
+
+ /**
+ * value expressed in millis
+ */
+ @Dynamic
+ private long maxAge;
+
+ public LRUAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.LRUAlgorithm.class.getName();
+ // Force config of ttls
+ setTimeToLive(-1);
+ setMaxAge(-1);
+ }
+
+ public LRUAlgorithmConfig(long timeToLive, long maxAge)
+ {
+ this();
+ this.timeToLive = timeToLive;
+ this.maxAge = maxAge;
+ }
+
+ public LRUAlgorithmConfig(long timeToLive, int maxAge, int maxNodes)
+ {
+ this(timeToLive, maxAge);
+ this.maxNodes = maxNodes;
+ }
+
+ /**
+ * @return the time to live, in milliseconds
+ */
+ public long getTimeToLive()
+ {
+ return timeToLive;
+ }
+
+ /**
+ * Sets the time to live
+ *
+ * @param timeToLive the time to live, in milliseconds
+ */
+ public void setTimeToLive(long timeToLive)
+ {
+ testImmutability("timeToLive");
+ this.timeToLive = timeToLive;
+ }
+
+ public void setTimeToLive(long timeToLive, TimeUnit timeUnit)
+ {
+ testImmutability("timeToLive");
+ this.timeToLive = timeUnit.toMillis(timeToLive);
+ }
+
+ @Deprecated
+ @Compat
+ public void setTimeToLiveSeconds(long time)
+ {
+ setTimeToLive(time, TimeUnit.SECONDS);
+ }
+
+ /**
+ * @return the max age per element, in milliseconds
+ */
+ public long getMaxAge()
+ {
+ return maxAge;
+ }
+
+ /**
+ * Sets the max age per element
+ *
+ * @param maxAge value in milliseconds
+ */
+ public void setMaxAge(long maxAge)
+ {
+ testImmutability("maxAge");
+ this.maxAge = maxAge;
+ }
+
+ public void setMaxAge(long maxAge, TimeUnit timeUnit)
+ {
+ testImmutability("maxAge");
+ this.maxAge = timeUnit.toMillis(maxAge);
+ }
+
+ /**
+ * Requires a positive timeToLive value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ super.validate();
+ if (timeToLive < -1)
+ {
+ throw new ConfigurationException("timeToLive must be " +
+ "configured to a value greater than or equal to 0 (or -1 for unlimited time to live) for " + getEvictionAlgorithmClassName());
+ }
+ }
+
+ public String toString()
+ {
+ return "LRUAlgorithmConfig {" +
+ "algorithmClassName=" + evictionAlgorithmClassName +
+ ", timeToLive=" + timeToLive +
+ ", maxAge=" + maxAge +
+ '}';
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (!(o instanceof LRUAlgorithmConfig)) return false;
+ if (!super.equals(o)) return false;
+
+ LRUAlgorithmConfig that = (LRUAlgorithmConfig) o;
+
+ if (maxAge != that.maxAge) return false;
+ if (timeToLive != that.timeToLive) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + (int) (timeToLive ^ (timeToLive >>> 32));
+ result = 31 * result + (int) (maxAge ^ (maxAge >>> 32));
+ return result;
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ setTimeToLive(-1);
+ setMaxAge(-1);
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.LRUAlgorithm.class.getName();
+ }
+
+ @Override
+ public LRUAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (LRUAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/LRUQueue.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.Fqn;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * LRU Eviction Queue implementation.
+ * <p/>
+ * This eviction queue will iterate properly through two sorted lists.
+ * One sorted by maxAge and the other sorted by idleTime.
+ *
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class LRUQueue implements EvictionQueue
+{
+ private Map<Fqn, org.jboss.starobrno.eviction.NodeEntry> maxAgeQueue;
+ private Map<Fqn, org.jboss.starobrno.eviction.NodeEntry> lruQueue;
+ private long alternatingCount = 0;
+ private int numElements = 0;
+
+ protected LRUQueue()
+ {
+ maxAgeQueue = new LinkedHashMap<Fqn, org.jboss.starobrno.eviction.NodeEntry>();
+ lruQueue = new LinkedHashMap<Fqn, org.jboss.starobrno.eviction.NodeEntry>(16, 0.75f, true);
+ }
+
+ protected void reorderByLRU(Fqn fqn)
+ {
+ // leave the max age queue alone - it is like a fifo.
+
+ // the lru queue is access ordered. meaning the most recently read item is moved to the bottom of the queue.
+ // simply calling get against it visits it and will cause LinkedHashMap to move it to the bottom of the queue.
+ lruQueue.get(fqn);
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
+ {
+ // because the underlying queue is in two differently sorted queues, we alternate between them when calling
+ // a generic getFirstNodeEntry.
+ // we must alternate to keep things balanced when evicting nodes based on the maxNodes attribute. We don't
+ // want to just prune from one queue but rather we want to be able to prune from both.
+ org.jboss.starobrno.eviction.NodeEntry ne;
+ if (alternatingCount % 2 == 0)
+ {
+ ne = this.getFirstLRUNodeEntry();
+ if (ne == null)
+ {
+ ne = this.getFirstMaxAgeNodeEntry();
+ }
+ }
+ else
+ {
+ ne = this.getFirstMaxAgeNodeEntry();
+ if (ne == null)
+ {
+ ne = this.getFirstLRUNodeEntry();
+ }
+ }
+ alternatingCount++;
+ return ne;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getFirstLRUNodeEntry()
+ {
+ if (lruQueue.size() > 0)
+ {
+ return lruQueue.values().iterator().next();
+ }
+
+ return null;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getFirstMaxAgeNodeEntry()
+ {
+ if (maxAgeQueue.size() > 0)
+ {
+ return maxAgeQueue.values().iterator().next();
+ }
+
+ return null;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
+ {
+ return lruQueue.get(fqn);
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
+ {
+ return this.getNodeEntry(Fqn.fromString(fqn));
+ }
+
+ public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ return this.maxAgeQueue.containsKey(entry.getFqn());
+ }
+
+ protected void removeNodeEntryFromLRU(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ Fqn fqn = entry.getFqn();
+ lruQueue.remove(fqn);
+ }
+
+ protected void removeNodeEntryFromMaxAge(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ Fqn fqn = entry.getFqn();
+ maxAgeQueue.remove(fqn);
+ }
+
+ public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ return;
+ }
+ Fqn fqn = entry.getFqn();
+ org.jboss.starobrno.eviction.NodeEntry ne1 = lruQueue.remove(fqn);
+ org.jboss.starobrno.eviction.NodeEntry ne2 = maxAgeQueue.remove(fqn);
+
+ if (ne1 == null || ne2 == null)
+ {
+ throw new RuntimeException("The queues are out of sync.");
+ }
+
+ this.numElements -= ne1.getNumberOfElements();
+
+ }
+
+ public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ Fqn fqn = entry.getFqn();
+ entry.queue = this;
+ maxAgeQueue.put(fqn, entry);
+ lruQueue.put(fqn, entry);
+ this.numElements += entry.getNumberOfElements();
+ }
+ }
+
+ public int getNumberOfNodes()
+ {
+ return maxAgeQueue.size();
+ }
+
+ public int getNumberOfElements()
+ {
+ return this.numElements;
+ }
+
+ public void clear()
+ {
+ maxAgeQueue.clear();
+ lruQueue.clear();
+ this.numElements = 0;
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ this.numElements += difference;
+ }
+
+ public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
+ {
+ return lruQueue.values().iterator();
+ }
+
+ protected final Iterator<org.jboss.starobrno.eviction.NodeEntry> iterateMaxAgeQueue()
+ {
+ return maxAgeQueue.values().iterator();
+ }
+
+ protected final Iterator<org.jboss.starobrno.eviction.NodeEntry> iterateLRUQueue()
+ {
+ return lruQueue.values().iterator();
+ }
+
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithm.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+
+/**
+ * Most Recently Used Algorithm.
+ * <p/>
+ * This algorithm will evict the most recently used cache entries from cache.
+ * <p/>
+ * Note: None of the Eviction classes are thread safe. It is assumed that an individual instance of an EvictionPolicy/
+ * EvictionAlgorithm/EvictionQueue/EvictionConfiguration are only operated on by one thread at any given time.
+ *
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class MRUAlgorithm extends BaseEvictionAlgorithm
+{
+ @Override
+ protected org.jboss.starobrno.eviction.EvictionQueue setupEvictionQueue() throws org.jboss.starobrno.eviction.EvictionException
+ {
+ return new org.jboss.starobrno.eviction.MRUQueue();
+ }
+
+ @Override
+ protected boolean shouldEvictNode(org.jboss.starobrno.eviction.NodeEntry ne)
+ {
+ // check the minimum time to live and see if we should not evict the node. This check will
+ // ensure that, if configured, nodes are kept alive for at least a minimum period of time.
+ if (isYoungerThanMinimumTimeToLive(ne)) return false;
+
+ org.jboss.starobrno.eviction.MRUAlgorithmConfig config = (org.jboss.starobrno.eviction.MRUAlgorithmConfig) evictionAlgorithmConfig;
+ return evictionQueue.getNumberOfNodes() > config.getMaxNodes();
+ }
+
+ @Override
+ protected void processVisitedNodes(org.jboss.starobrno.eviction.EvictionEvent evictedEventNode) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ super.processVisitedNodes(evictedEventNode);
+ ((org.jboss.starobrno.eviction.MRUQueue) evictionQueue).moveToTopOfStack(evictedEventNode.getFqn());
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return org.jboss.starobrno.eviction.MRUAlgorithmConfig.class;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUAlgorithmConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.config.ConfigurationException;
+
+/**
+ * Configuration for {@link org.jboss.starobrno.eviction.MRUAlgorithm}.
+ * <p/>
+ * Requires a "maxNodes" attribute otherwise a ConfigurationException is thrown.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class MRUAlgorithmConfig extends EvictionAlgorithmConfigBase
+{
+ /**
+ * The serialVersionUID
+ */
+ private static final long serialVersionUID = -8734577898966155218L;
+
+ public MRUAlgorithmConfig()
+ {
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.MRUAlgorithm.class.getName();
+ // We require that maxNodes is set
+ setMaxNodes(-1);
+ }
+
+ public MRUAlgorithmConfig(int maxNodes)
+ {
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.MRUAlgorithm.class.getName();
+ setMaxNodes(maxNodes);
+ }
+
+ /**
+ * Requires a positive maxNodes value or ConfigurationException
+ * is thrown.
+ */
+ @Override
+ public void validate() throws ConfigurationException
+ {
+ super.validate();
+ if (getMaxNodes() < 0)
+ throw new ConfigurationException("maxNodes not configured");
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder str = new StringBuilder();
+ str.append("MRUAlgorithmConfig: ").
+ append(" maxNodes =").append(getMaxNodes());
+ return str.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ return (obj instanceof MRUAlgorithmConfig && super.equals(obj));
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ setMaxNodes(-1);
+ evictionAlgorithmClassName = org.jboss.starobrno.eviction.MRUAlgorithm.class.getName();
+ }
+
+ @Override
+ public MRUAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (MRUAlgorithmConfig) super.clone();
+ }
+
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/MRUQueue.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,169 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.Fqn;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+/**
+ * MRU Eviction Queue implementation.
+ * <p/>
+ * This nodeMap is sorted by MRU. The first entry in the nodeMap
+ * will also be the most recently used entry. The sort is implicit
+ * based on a Stack that we can implicitly sort to the top by moving
+ * a node that is used to the top of the eviction stack.
+ *
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @version $Revision: 6776 $
+ */
+public class MRUQueue implements EvictionQueue
+{
+ // we use our own Stack/Linked List implementation here because it guarantees O(n) = 1 for add, remove, get and
+ // we can sort it in order of MRU implicitly while still getting O(n) = 1 access time
+ // throughout.
+ Map<Fqn, EvictionListEntry> nodeMap;
+ org.jboss.starobrno.eviction.EvictionQueueList list;
+ private int numElements = 0;
+
+ protected MRUQueue()
+ {
+ nodeMap = new HashMap<Fqn, EvictionListEntry>();
+ list = new org.jboss.starobrno.eviction.EvictionQueueList();
+ }
+
+ /**
+ * This call moves a NodeEntry to the top of the stack.
+ * <p/>
+ * When a node is visited this method should be called to guarantee MRU ordering.
+ *
+ * @param fqn Fqn of the nodeEntry to move to the top of the stack.
+ */
+ protected void moveToTopOfStack(Fqn fqn)
+ {
+ EvictionListEntry le = nodeMap.remove(fqn);
+ if (le != null)
+ {
+ list.remove(le);
+ list.addToTop(le);
+ nodeMap.put(le.node.getFqn(), le);
+ }
+ }
+
+ /**
+ * Will return the first entry in the nodeMap.
+ * <p/>
+ * The first entry in this nodeMap will also be the most recently used entry.
+ *
+ * @return The first node entry in nodeMap.
+ */
+ public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
+ {
+ try
+ {
+ return list.getFirst().node;
+ }
+ catch (NoSuchElementException e)
+ {
+ //
+ }
+
+ return null;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
+ {
+ EvictionListEntry le = nodeMap.get(fqn);
+ if (le != null)
+ return le.node;
+
+ return null;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
+ {
+ return this.getNodeEntry(Fqn.fromString(fqn));
+ }
+
+ public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ return nodeMap.containsKey(entry.getFqn());
+ }
+
+ public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ EvictionListEntry le = nodeMap.remove(entry.getFqn());
+ if (le != null)
+ {
+ list.remove(le);
+ this.numElements -= le.node.getNumberOfElements();
+ }
+ }
+
+ public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ if (!this.containsNodeEntry(entry))
+ {
+ entry.queue = this;
+ EvictionListEntry le = new EvictionListEntry(entry);
+ list.addToBottom(le);
+ nodeMap.put(entry.getFqn(), le);
+ this.numElements += entry.getNumberOfElements();
+ }
+ }
+
+ public int getNumberOfNodes()
+ {
+ return list.size();
+ }
+
+ public int getNumberOfElements()
+ {
+ return this.numElements;
+ }
+
+ public void modifyElementCount(int difference)
+ {
+ this.numElements += difference;
+ }
+
+ public void clear()
+ {
+ nodeMap.clear();
+ list.clear();
+ this.numElements = 0;
+ }
+
+ public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
+ {
+ return list.iterator();
+ }
+
+ @Override
+ public String toString()
+ {
+ return list.toString();
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NodeEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NodeEntry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NodeEntry.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.Fqn;
+
+/**
+ * Value object used in queue
+ *
+ * @author Ben Wang 2-2004
+ * @author Daniel Huang - dhuang at jboss.org
+ */
+public class NodeEntry
+{
+ private long modifiedTimeStamp;
+ private long creationTimeStamp;
+ private int numberOfNodeVisits;
+ private int numberOfElements;
+ private Fqn fqn;
+
+ private long inUseTimeoutTimestamp;
+ private boolean currentlyInUse = false;
+
+ EvictionQueue queue;
+
+ /**
+ * Private constructor that automatically sets the creation time stamp of the node entry.
+ */
+ private NodeEntry()
+ {
+ this.creationTimeStamp = System.currentTimeMillis();
+ }
+
+ public NodeEntry(Fqn fqn)
+ {
+ this();
+ setFqn(fqn);
+ }
+
+ public NodeEntry(String fqn)
+ {
+ this();
+ setFqn(Fqn.fromString(fqn));
+ }
+
+ /**
+ * Is the node currently in use.
+ *
+ * @return True/false if the node is currently marked as in use.
+ */
+ public boolean isCurrentlyInUse()
+ {
+ return currentlyInUse;
+ }
+
+ public void setCurrentlyInUse(boolean currentlyInUse, long inUseTimeout)
+ {
+ this.currentlyInUse = currentlyInUse;
+ if (inUseTimeout > 0)
+ {
+ this.inUseTimeoutTimestamp = System.currentTimeMillis() + inUseTimeout;
+ }
+ }
+
+ public long getInUseTimeoutTimestamp()
+ {
+ return this.inUseTimeoutTimestamp;
+ }
+
+ /**
+ * Get modified time stamp. This stamp is created during the node is
+ * processed so it has some fuzy tolerance in there.
+ *
+ * @return The last modified time stamp
+ */
+ public long getModifiedTimeStamp()
+ {
+ return modifiedTimeStamp;
+ }
+
+ public void setModifiedTimeStamp(long modifiedTimeStamp)
+ {
+// log.error("Being modified to " + modifiedTimeStamp, new Throwable());
+ this.modifiedTimeStamp = modifiedTimeStamp;
+ }
+
+ /**
+ * Get the time stamp for when the node entry was created.
+ *
+ * @return The node entry creation time stamp
+ */
+ public long getCreationTimeStamp()
+ {
+ return creationTimeStamp;
+ }
+
+ public void setCreationTimeStamp(long creationTimeStamp)
+ {
+ this.creationTimeStamp = creationTimeStamp;
+ }
+
+ public int getNumberOfNodeVisits()
+ {
+ return numberOfNodeVisits;
+ }
+
+ public void setNumberOfNodeVisits(int numberOfNodeVisits)
+ {
+ this.numberOfNodeVisits = numberOfNodeVisits;
+ }
+
+ public int getNumberOfElements()
+ {
+ return numberOfElements;
+ }
+
+ public void setNumberOfElements(int numberOfElements)
+ {
+ if (queue != null)
+ {
+ int difference = numberOfElements - this.numberOfElements;
+ queue.modifyElementCount(difference);
+ }
+ this.numberOfElements = numberOfElements;
+ }
+
+ public Fqn getFqn()
+ {
+ return fqn;
+ }
+
+ void setFqn(Fqn fqn)
+ {
+ this.fqn = fqn;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return fqn.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (!(o instanceof NodeEntry))
+ return false;
+ NodeEntry ne = (NodeEntry) o;
+ return fqn.equals(ne.getFqn());
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder output = new StringBuilder();
+ output.append("Fqn: ");
+ if (fqn != null)
+ {
+ output.append(fqn);
+ }
+ else
+ {
+ output.append(" null");
+ }
+
+ output.append(" CreateTime: ").append(this.getCreationTimeStamp());
+ output.append(" NodeVisits: ").append(this.getNumberOfNodeVisits());
+ output.append(" ModifiedTime: ").append(this.getModifiedTimeStamp());
+ output.append(" NumberOfElements: ").append(this.getNumberOfElements());
+ output.append(" CurrentlyInUse: ").append(this.isCurrentlyInUse());
+ return output.toString();
+ }
+
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NodeEntry.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithm.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithm.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithm.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+import org.jboss.starobrno.eviction.EvictionEvent.Type;
+
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * An eviction algorithm that does nothing - a no-op for everything.
+ *
+ * @author Brian Stansberry
+ */
+public class NullEvictionAlgorithm implements EvictionAlgorithm
+{
+ /**
+ * Singleton instance of this class.
+ */
+ private static final NullEvictionAlgorithm INSTANCE = new NullEvictionAlgorithm();
+
+ /**
+ * Constructs a new NullEvictionAlgorithm.
+ */
+ private NullEvictionAlgorithm()
+ {
+ }
+
+ public static NullEvictionAlgorithm getInstance()
+ {
+ return INSTANCE;
+ }
+
+ /**
+ * Returns {@link org.jboss.starobrno.eviction.NullEvictionQueue#INSTANCE}.
+ */
+ public org.jboss.starobrno.eviction.EvictionQueue getEvictionQueue()
+ {
+ return org.jboss.starobrno.eviction.NullEvictionQueue.INSTANCE;
+ }
+
+ public void setEvictionActionPolicy(org.jboss.starobrno.eviction.EvictionActionPolicy evictionActionPolicy)
+ {
+ // no-op
+ }
+
+ public void assignToRegion(Fqn fqn, CacheSPI<?, ?> cache, EvictionAlgorithmConfig evictionAlgorithmConfig, Configuration configuration)
+ {
+ // no-op
+ }
+
+ public void process(BlockingQueue<org.jboss.starobrno.eviction.EvictionEvent> queue) throws org.jboss.starobrno.eviction.EvictionException
+ {
+ // no-op
+ }
+
+ public void resetEvictionQueue()
+ {
+ // no-op
+ }
+
+ public boolean canIgnoreEvent(Type eventType)
+ {
+ return true; // always ignore everything!
+ }
+
+ public void initialize()
+ {
+ // no-op
+ }
+
+ public Class<? extends EvictionAlgorithmConfig> getConfigurationClass()
+ {
+ return org.jboss.starobrno.eviction.NullEvictionAlgorithmConfig.class;
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithm.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithmConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithmConfig.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithmConfig.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.starobrno.config.ConfigurationComponent;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.EvictionAlgorithmConfig;
+
+/**
+ * Configuration class for {@link NullEvictionAlgorithm}.
+ *
+ * @author Manik Surtani
+ * @since 3.0
+ */
+public class NullEvictionAlgorithmConfig extends ConfigurationComponent implements EvictionAlgorithmConfig
+{
+ private static final long serialVersionUID = -6591180473728241737L;
+
+ /**
+ * No-op
+ */
+ public void reset()
+ {
+ // no-op
+ }
+
+ public String getEvictionAlgorithmClassName()
+ {
+ return NullEvictionAlgorithm.class.getName();
+ }
+
+ /**
+ * No-op
+ */
+ public void validate() throws ConfigurationException
+ {
+ // no-op
+ }
+
+ public NullEvictionAlgorithmConfig clone() throws CloneNotSupportedException
+ {
+ return (NullEvictionAlgorithmConfig) super.clone();
+ }
+}
\ No newline at end of file
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionAlgorithmConfig.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionQueue.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,161 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.jboss.cache.Fqn;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * A queue that does nothing.
+ *
+ * @author Brian Stansberry
+ */
+public class NullEvictionQueue implements EvictionQueue
+{
+ /**
+ * Singleton instance of this class.
+ */
+ public static final NullEvictionQueue INSTANCE = new NullEvictionQueue();
+
+ /**
+ * Constructs a new NullEvictionQueue.
+ */
+ private NullEvictionQueue()
+ {
+ }
+
+ /**
+ * No-op
+ */
+ public void addNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ // no-op
+ }
+
+ /**
+ * No-op
+ */
+ public void clear()
+ {
+ // no-op
+ }
+
+ /**
+ * Returns <code>false</code>
+ */
+ public boolean containsNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ return false;
+ }
+
+ /**
+ * Returns <code>null</code>
+ */
+ public org.jboss.starobrno.eviction.NodeEntry getFirstNodeEntry()
+ {
+ return null;
+ }
+
+ /**
+ * Returns <code>null</code>
+ */
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(Fqn fqn)
+ {
+ return null;
+ }
+
+ /**
+ * Returns <code>null</code>
+ */
+ public org.jboss.starobrno.eviction.NodeEntry getNodeEntry(String fqn)
+ {
+ return null;
+ }
+
+ /**
+ * Returns <code>0</code>
+ */
+ public int getNumberOfElements()
+ {
+ return 0;
+ }
+
+ /**
+ * Returns <code>0</code>
+ */
+ public int getNumberOfNodes()
+ {
+ return 0;
+ }
+
+ /**
+ * Returns an <code>Iterator</code> whose
+ * <code>hasNext()</code> returns <code>false</code>.
+ */
+ public Iterator<org.jboss.starobrno.eviction.NodeEntry> iterator()
+ {
+ return NullQueueIterator.INSTANCE;
+ }
+
+ /**
+ * No-op
+ */
+ public void modifyElementCount(int difference)
+ {
+ // no-op
+ }
+
+ /**
+ * No-op
+ */
+ public void removeNodeEntry(org.jboss.starobrno.eviction.NodeEntry entry)
+ {
+ // no-op
+ }
+
+ static class NullQueueIterator implements Iterator<org.jboss.starobrno.eviction.NodeEntry>
+ {
+ private static final NullQueueIterator INSTANCE = new NullQueueIterator();
+
+ private NullQueueIterator()
+ {
+ }
+
+ public boolean hasNext()
+ {
+ return false;
+ }
+
+ public org.jboss.starobrno.eviction.NodeEntry next()
+ {
+ throw new NoSuchElementException("No more elements");
+ }
+
+ public void remove()
+ {
+ throw new IllegalStateException("Must call next() before remove()");
+ }
+ }
+
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/NullEvictionQueue.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RegionNameConflictException.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RegionNameConflictException.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RegionNameConflictException.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+/**
+ * MarshRegion name conflicts with pre-existing regions.
+ *
+ * @author Ben Wang 2-2004
+ */
+public class RegionNameConflictException extends Exception
+{
+
+ private static final long serialVersionUID = -6796150029431162837L;
+
+ public RegionNameConflictException()
+ {
+ super();
+ }
+
+ public RegionNameConflictException(String msg)
+ {
+ super(msg);
+ }
+
+ public RegionNameConflictException(String msg, Throwable cause)
+ {
+ super(msg, cause);
+ }
+}
Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RegionNameConflictException.java
___________________________________________________________________
Name: svn:executable
+ *
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RemoveOnEvictActionPolicy.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RemoveOnEvictActionPolicy.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/RemoveOnEvictActionPolicy.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+
+/**
+ * An eviction action policy that calls {@link org.jboss.cache.Cache#removeNode(org.jboss.cache.Fqn)} to evict a node.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public class RemoveOnEvictActionPolicy implements EvictionActionPolicy
+{
+ Cache<?, ?> cache;
+ private static final Log log = LogFactory.getLog(org.jboss.starobrno.eviction.DefaultEvictionActionPolicy.class);
+
+ public void setCache(Cache<?, ?> cache)
+ {
+ this.cache = cache;
+ }
+
+ public boolean evict(Fqn fqn)
+ {
+ try
+ {
+ return cache.removeNode(fqn);
+ }
+ catch (Exception e)
+ {
+ if (log.isDebugEnabled()) log.debug("Unable to evict " + fqn, e);
+ return false;
+ }
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/eviction/SortedEvictionQueue.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/eviction/SortedEvictionQueue.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/eviction/SortedEvictionQueue.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.eviction;
+
+/**
+ * Sorted Eviction Queue implementation.
+ *
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @version $Revision: 6776 $
+ */
+public interface SortedEvictionQueue extends EvictionQueue
+{
+ /**
+ * Provide contract to resort a sorted queue.
+ */
+ void resortEvictionQueue();
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/BootstrapFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/BootstrapFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/BootstrapFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.starobrno.CacheException;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+import org.jboss.starobrno.factories.annotations.NonVolatile;
+
+/**
+ * Factory for setting up bootstrap components
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.2.0
+ */
+ at DefaultFactoryFor(classes = {CacheSPI.class, Configuration.class, ComponentRegistry.class})
+ at NonVolatile
+public class BootstrapFactory extends ComponentFactory
+{
+ CacheSPI cacheSPI;
+
+ public BootstrapFactory(CacheSPI cacheSPI, Configuration configuration, ComponentRegistry componentRegistry)
+ {
+ super(componentRegistry, configuration);
+ this.cacheSPI = cacheSPI;
+ }
+
+ @Override
+ protected <T> T construct(Class<T> componentType)
+ {
+ if (componentType.isAssignableFrom(CacheSPI.class) ||
+ componentType.isAssignableFrom(Configuration.class) ||
+ componentType.isAssignableFrom(ComponentRegistry.class))
+ {
+ return componentType.cast(cacheSPI);
+ }
+
+ throw new CacheException("Don't know how to handle type " + componentType);
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/BuddyManagerFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/BuddyManagerFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/BuddyManagerFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+
+/**
+ * Buddy manager factory
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.1.0
+ */
+ at DefaultFactoryFor(classes = {BuddyManager.class})
+public class BuddyManagerFactory extends EmptyConstructorFactory
+{
+ @Override
+ public <T> T construct(Class<T> componentType)
+ {
+ if (configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled() && configuration.getCacheMode() != Configuration.CacheMode.LOCAL)
+ {
+ return super.construct(componentType);
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.factories.annotations.Inject;
+
+/**
+ * Factory that creates components used internally within JBoss Cache, and also wires dependencies into the components.
+ * <p/>
+ * The {@link org.jboss.cache.DefaultCacheFactory} is a special subclass of this, which bootstraps the construction of
+ * other components. When this class is loaded, it maintains a static list of known default factories for known
+ * components, which it then delegates to, when actually performing the construction.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @see Inject
+ * @see ComponentRegistry
+ * @since 2.1.0
+ */
+public abstract class ComponentFactory
+{
+ protected final Log log = LogFactory.getLog(getClass());
+ protected ComponentRegistry componentRegistry;
+ protected Configuration configuration;
+
+ /**
+ * Constructs a new ComponentFactory.
+ */
+ public ComponentFactory(ComponentRegistry componentRegistry, Configuration configuration)
+ {
+ this.componentRegistry = componentRegistry;
+ this.configuration = configuration;
+ }
+
+ /**
+ * Constructs a new ComponentFactory.
+ */
+ public ComponentFactory()
+ {
+ }
+
+ @Inject
+ private void injectDependencies(Configuration configuration, ComponentRegistry componentRegistry)
+ {
+ this.configuration = configuration;
+ this.componentRegistry = componentRegistry;
+ }
+
+ /**
+ * Constructs a component.
+ *
+ * @param componentType type of component
+ * @return a component
+ */
+ protected abstract <T> T construct(Class<T> componentType);
+
+ protected void assertTypeConstructable(Class requestedType, Class... ableToConstruct)
+ {
+ boolean canConstruct = false;
+ for (Class c : ableToConstruct)
+ {
+ canConstruct = canConstruct || requestedType.isAssignableFrom(c);
+ }
+ if (!canConstruct) throw new ConfigurationException("Don't know how to construct " + requestedType);
+ }
+
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/ComponentRegistry.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,988 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.Version;
+import org.jboss.cache.util.BeanUtils;
+import org.jboss.cache.util.reflect.ReflectionUtil;
+import org.jboss.starobrno.CacheException;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.RuntimeConfig;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+import org.jboss.starobrno.factories.annotations.Destroy;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.NonVolatile;
+import org.jboss.starobrno.factories.annotations.Start;
+import org.jboss.starobrno.factories.annotations.Stop;
+
+import javax.management.MBeanServerFactory;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A registry where components which have been created are stored. Components are stored as singletons, registered under
+ * a specific name.
+ * <p/>
+ * Components can be retrieved from the registry using {@link #getComponent(Class)}.
+ * <p/>
+ * Components can be registered using {@link #registerComponent(Object, Class)}, which will cause any dependencies to be
+ * wired in as well. Components that need to be created as a result of wiring will be done using {@link #getOrCreateComponent(Class)},
+ * which will look up the default factory for the component type (factories annotated with the appropriate {@link DefaultFactoryFor} annotation.
+ * <p/>
+ * Default factories are treated as components too and will need to be wired before being used.
+ * <p/>
+ * The registry can exist in one of several states, as defined by the {@link CacheStatus} enumeration. In terms of the cache,
+ * state changes in the following manner:
+ * <ul>
+ * <li>INSTANTIATED - when first constructed</li>
+ * <li>CONSTRUCTED - when created using the DefaultCacheFactory</li>
+ * <li>When {@link org.jboss.cache.Cache#create()} is called, the components are rewired.</li>
+ * <li>STARTED - when {@link org.jboss.cache.Cache#start()} is called</li>
+ * <li>STOPPED - when {@link org.jboss.cache.Cache#stop()} is called</li>
+ * <li>DESTROYED - when {@link org.jboss.cache.Cache#destroy()} is called.</li>
+ * </ul>
+ * <p/>
+ * Cache configuration can only be changed and will only be reinjected if the cache is not in the {@link org.jboss.cache.CacheStatus#STARTED} state.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.1.0
+ */
+ at NonVolatile
+public class ComponentRegistry
+{
+ /**
+ * Contains class definitions of component factories that can be used to construct certain components
+ */
+ Map<Class, Class<? extends ComponentFactory>> defaultFactories = null;
+
+ private static final Log log = LogFactory.getLog(ComponentRegistry.class);
+ private static final boolean trace = log.isTraceEnabled();
+ protected static final Object NULL_COMPONENT = new Object();
+
+ // component and method containers
+ final Map<String, Component> componentLookup = new HashMap<String, Component>();
+
+ CacheStatus state = CacheStatus.INSTANTIATED;
+
+ /**
+ * Hook to shut down the cache when the JVM exits.
+ */
+ private Thread shutdownHook;
+ /**
+ * A flag that the shutdown hook sets before calling cache.stop(). Allows stop() to identify if it has been called
+ * from a shutdown hook.
+ */
+ private boolean invokedFromShutdownHook;
+
+ /**
+ * Creates an instance of the component registry. The configuration passed in is automatically registered.
+ *
+ * @param configuration configuration with which this is created
+ */
+ public ComponentRegistry(Configuration configuration, CacheSPI cache)
+ {
+ try
+ {
+ // bootstrap.
+ registerDefaultClassLoader(null);
+ registerComponent(this, ComponentRegistry.class);
+ registerComponent(configuration, Configuration.class);
+ registerComponent(new BootstrapFactory(cache, configuration, this), BootstrapFactory.class);
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("Unable to construct ComponentRegistry", e);
+ }
+ }
+
+ /**
+ * Retrieves the state of the registry
+ *
+ * @return state of the registry
+ */
+ public CacheStatus getState()
+ {
+ return state;
+ }
+
+ /**
+ * Wires an object instance with dependencies annotated with the {@link org.jboss.cache.factories.annotations.Inject} annotation, creating more components
+ * as needed based on the Configuration passed in if these additional components don't exist in the
+ * {@link ComponentRegistry}. Strictly for components that don't otherwise live in the registry and have a lifecycle, such as Nodes.
+ *
+ * @param target object to wire
+ * @throws ConfigurationException if there is a problem wiring the instance
+ */
+ public void wireDependencies(Object target) throws ConfigurationException
+ {
+ try
+ {
+ // don't use the reflection cache for wireDependencies calls since these are not managed by the ComponentRegistry
+ // and may be invoked at any time, even after the cache starts.
+ List<Method> methods = ReflectionUtil.getAllMethods(target.getClass(), Inject.class);
+
+ // search for anything we need to inject
+ for (Method method : methods) invokeInjectionMethod(target, method);
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Unable to configure component (type: " + target.getClass() + ", instance " + target + ")", e);
+ }
+ }
+
+ /**
+ * Registers the default class loader. This method *must* be called before any other components are registered,
+ * typically called by bootstrap code. Defensively, it is called in the constructor of ComponentRegistry with a null
+ * parameter.
+ *
+ * @param loader a class loader to use by default. If this is null, the class loader used to load this instance of ComponentRegistry is used.
+ */
+ public void registerDefaultClassLoader(ClassLoader loader)
+ {
+ registerComponent(loader == null ? getClass().getClassLoader() : loader, ClassLoader.class);
+ // make sure the class loader is non-volatile, so it survives restarts.
+ componentLookup.get(ClassLoader.class.getName()).nonVolatile = true;
+ }
+
+ /**
+ * This is hard coded for now, since scanning the classpath for factories annotated with {@link org.jboss.cache.factories.annotations.DefaultFactoryFor}
+ * does not work with all class loaders. This is a temporary solution until a more elegant one can be designed.
+ * <p/>
+ * BE SURE TO ADD ANY NEW FACTORY TYPES ANNOTATED WITH DefaultFactoryFor TO THIS SET!!
+ * <p/>
+ *
+ * @return set of known factory types.
+ */
+ private Set<Class<? extends ComponentFactory>> getHardcodedFactories()
+ {
+ Set<Class<? extends ComponentFactory>> s = new HashSet<Class<? extends ComponentFactory>>();
+ s.add(BootstrapFactory.class);
+ s.add(BuddyManagerFactory.class);
+ s.add(EmptyConstructorFactory.class);
+ s.add(InterceptorChainFactory.class);
+ s.add(RuntimeConfigAwareFactory.class);
+ s.add(TransactionManagerFactory.class);
+ s.add(ReplicationQueueFactory.class);
+ s.add(StateTransferManagerFactory.class);
+ s.add(StateTransferFactory.class);
+ return s;
+ }
+
+ /**
+ * Registers a component in the registry under the given type, and injects any dependencies needed. If a component
+ * of this type already exists, it is overwritten.
+ *
+ * @param component component to register
+ * @param type type of component
+ */
+ public void registerComponent(Object component, Class type)
+ {
+
+ String name = type.getName();
+ Component old = componentLookup.get(name);
+
+ if (old != null)
+ {
+ // if they are equal don't bother
+ if (old.instance.equals(component))
+ {
+ if (trace)
+ log.trace("Attempting to register a component equal to one that already exists under the same name (" + name + "). Not doing anything.");
+ return;
+ }
+ }
+
+ Component c;
+ if (old != null)
+ {
+ if (trace) log.trace("Replacing old component " + old + " with new instance " + component);
+ old.instance = component;
+ old.methodsScanned = false;
+ c = old;
+
+ if (state == CacheStatus.STARTED) populateLifecycleMethods();
+ }
+ else
+ {
+ c = new Component();
+ c.name = name;
+ c.instance = component;
+ if (trace) log.trace("Registering component " + c + " under name " + name);
+ componentLookup.put(name, c);
+ }
+ c.nonVolatile = component.getClass().isAnnotationPresent(NonVolatile.class);
+ addComponentDependencies(c);
+ // inject dependencies for this component
+ c.injectDependencies();
+ }
+
+ /**
+ * Adds component dependencies for a given component, by populating {@link Component#injectionMethods}.
+ *
+ * @param c component to add dependencies to
+ */
+ protected void addComponentDependencies(Component c)
+ {
+ Class type = c.instance.getClass();
+ List<Method> methods = ReflectionUtil.getAllMethods(type, Inject.class);
+ c.injectionMethods.clear();
+ c.injectionMethods.addAll(methods);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void invokeInjectionMethod(Object o, Method m)
+ {
+ Class[] dependencies = m.getParameterTypes();
+ Object[] params = new Object[dependencies.length];
+
+ for (int i = 0; i < dependencies.length; i++)
+ {
+ params[i] = getOrCreateComponent(dependencies[i]);
+ }
+
+ ReflectionUtil.invokeAccessibly(o, m, params);
+ }
+
+ /**
+ * Retrieves a component if one exists, and if not, attempts to find a factory capable of constructing the component
+ * (factories annotated with the {@link DefaultFactoryFor} annotation that is capable of creating the component class).
+ * <p/>
+ * If an instance needs to be constructed, dependencies are then automatically wired into the instance, based on methods
+ * on the component type annotated with {@link Inject}.
+ * <p/>
+ * Summing it up, component retrieval happens in the following order:<br />
+ * 1. Look for a component that has already been created and registered.
+ * 2. Look for an appropriate component that exists in the {@link Configuration} that may be injected from an external system.
+ * 3. Look for a class definition passed in to the {@link org.jboss.cache.config.Configuration} - such as an EvictionPolicy implementation
+ * 4. Attempt to create it by looking for an appropriate factory (annotated with {@link DefaultFactoryFor})
+ * <p/>
+ *
+ * @param componentClass type of component to be retrieved. Should not be null.
+ * @return a fully wired component instance, or null if one cannot be found or constructed.
+ * @throws ConfigurationException if there is a problem with consructing or wiring the instance.
+ */
+ protected <T> T getOrCreateComponent(Class<T> componentClass)
+ {
+
+ T component = getComponent(componentClass);
+
+ if (component == null)
+ {
+ // first see if this has been injected externally.
+ component = getFromConfiguration(componentClass);
+ boolean attemptedFactoryConstruction = false;
+
+ if (component == null)
+ {
+ // create this component and add it to the registry
+ ComponentFactory factory = getFactory(componentClass);
+ component = factory.construct(componentClass);
+ attemptedFactoryConstruction = true;
+
+ }
+
+ if (component != null)
+ {
+ registerComponent(component, componentClass);
+ }
+ else if (attemptedFactoryConstruction)
+ {
+ if (trace) log.trace("Registering a null for component " + componentClass.getSimpleName());
+ registerNullComponent(componentClass);
+ }
+ }
+
+ return component;
+ }
+
+ /**
+ * Retrieves a component factory instance capable of constructing components of a specified type. If the factory doesn't
+ * exist in the registry, one is created.
+ *
+ * @param componentClass type of component to construct
+ * @return component factory capable of constructing such components
+ */
+ protected ComponentFactory getFactory(Class componentClass)
+ {
+ if (defaultFactories == null) scanDefaultFactories();
+ Class<? extends ComponentFactory> cfClass = defaultFactories.get(componentClass);
+ if (cfClass == null)
+ throw new ConfigurationException("No registered default factory for component " + componentClass + " found!");
+ // a component factory is a component too! See if one has been created and exists in the registry
+ ComponentFactory cf = getComponent(cfClass);
+ if (cf == null)
+ {
+ // hasn't yet been created. Create and put in registry
+ cf = instantiateFactory(cfClass);
+ if (cf == null)
+ throw new ConfigurationException("Unable to locate component factory for component " + componentClass);
+ // we simply register this factory. Registration will take care of constructing any dependencies.
+ registerComponent(cf, cfClass);
+ }
+
+ // ensure the component factory is in the STARTED state!
+ Component c = componentLookup.get(cfClass.getName());
+ if (c.instance != cf)
+ throw new ConfigurationException("Component factory " + cfClass + " incorrectly registered!");
+ return cf;
+ }
+
+ /**
+ * Scans the class path for classes annotated with {@link org.jboss.cache.factories.annotations.DefaultFactoryFor}, and
+ * analyses which components can be created by such factories.
+ */
+ void scanDefaultFactories()
+ {
+ defaultFactories = new HashMap<Class, Class<? extends ComponentFactory>>();
+
+ Set<Class<? extends ComponentFactory>> factories = getHardcodedFactories();
+
+ for (Class<? extends ComponentFactory> factory : factories)
+ {
+ DefaultFactoryFor dFFAnnotation = factory.getAnnotation(DefaultFactoryFor.class);
+ for (Class targetClass : dFFAnnotation.classes()) defaultFactories.put(targetClass, factory);
+ }
+ }
+
+ /**
+ * No such thing as a meta factory yet. Factories are created using this method which attempts to use an empty public
+ * constructor.
+ *
+ * @param factory class of factory to be created
+ * @return factory instance
+ */
+ ComponentFactory instantiateFactory(Class<? extends ComponentFactory> factory)
+ {
+ try
+ {
+ return factory.newInstance();
+ }
+ catch (Exception e)
+ {
+ // unable to get a hold of an instance!!
+ throw new ConfigurationException("Unable to instantiate factory " + factory, e);
+ }
+ }
+
+ /**
+ * registers a special "null" component that has no dependencies.
+ *
+ * @param type type of component to register as a null
+ */
+ void registerNullComponent(Class type)
+ {
+ registerComponent(NULL_COMPONENT, type);
+ }
+
+ /**
+ * Retrieves a component from the {@link Configuration} or {@link RuntimeConfig}.
+ *
+ * @param componentClass component type
+ * @return component, or null if it cannot be found
+ */
+ @SuppressWarnings("unchecked")
+ protected <T> T getFromConfiguration(Class<T> componentClass)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Looking in configuration for an instance of " + componentClass + " that may have been injected from an external source.");
+ Method getter = BeanUtils.getterMethod(Configuration.class, componentClass);
+ T returnValue = null;
+
+ if (getter != null)
+ {
+ try
+ {
+ returnValue = (T) getter.invoke(getConfiguration());
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to invoke getter " + getter + " on Configuration.class!", e);
+ }
+ }
+
+ // now try the RuntimeConfig - a legacy "registry" of sorts.
+ if (returnValue == null)
+ {
+ getter = BeanUtils.getterMethod(RuntimeConfig.class, componentClass);
+ if (getter != null)
+ {
+ try
+ {
+ returnValue = (T) getter.invoke(getConfiguration().getRuntimeConfig());
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to invoke getter " + getter + " on RuntimeConfig.class!", e);
+ }
+ }
+ }
+ return returnValue;
+ }
+
+ /**
+ * Retrieves the configuration component.
+ *
+ * @return a Configuration object
+ */
+ protected Configuration getConfiguration()
+ {
+ // this is assumed to always be present as a part of the bootstrap/construction of a ComponentRegistry.
+ return getComponent(Configuration.class);
+ }
+
+ /**
+ * Retrieves a component of a specified type from the registry, or null if it cannot be found.
+ *
+ * @param type type to find
+ * @return component, or null
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T getComponent(Class<T> type)
+ {
+ Component wrapper = componentLookup.get(type.getName());
+ if (wrapper == null) return null;
+
+ return (T) (wrapper.instance == NULL_COMPONENT ? null : wrapper.instance);
+ }
+
+ /**
+ * Rewires components. Can only be called if the current state is WIRED or STARTED.
+ */
+ public void rewire()
+ {
+ // need to re-inject everything again.
+ for (Component c : new HashSet<Component>(componentLookup.values()))
+ {
+ // inject dependencies for this component
+ c.injectDependencies();
+ }
+ }
+
+ /**
+ * Scans each registered component for lifecycle methods, and adds them to the appropriate lists, and then sorts them
+ * by priority.
+ */
+ private void populateLifecycleMethods()
+ {
+ for (Component c : componentLookup.values())
+ {
+ if (!c.methodsScanned)
+ {
+ c.methodsScanned = true;
+ c.startMethods.clear();
+ c.stopMethods.clear();
+ c.destroyMethods.clear();
+
+ List<Method> methods = ReflectionUtil.getAllMethods(c.instance.getClass(), Start.class);
+ for (Method m : methods)
+ {
+ PrioritizedMethod em = new PrioritizedMethod();
+ em.component = c;
+ em.method = m;
+ em.priority = m.getAnnotation(Start.class).priority();
+ c.startMethods.add(em);
+ }
+
+ methods = ReflectionUtil.getAllMethods(c.instance.getClass(), Stop.class);
+ for (Method m : methods)
+ {
+ PrioritizedMethod em = new PrioritizedMethod();
+ em.component = c;
+ em.method = m;
+ em.priority = m.getAnnotation(Stop.class).priority();
+ c.stopMethods.add(em);
+ }
+
+ methods = ReflectionUtil.getAllMethods(c.instance.getClass(), Destroy.class);
+ for (Method m : methods)
+ {
+ PrioritizedMethod em = new PrioritizedMethod();
+ em.component = c;
+ em.method = m;
+ em.priority = m.getAnnotation(Destroy.class).priority();
+ c.destroyMethods.add(em);
+ }
+ }
+ }
+ }
+
+ /**
+ * Removes any components not annotated as @NonVolatile.
+ */
+ public void resetNonVolatile()
+ {
+ // destroy all components to clean up resources
+ for (Component c : new HashSet<Component>(componentLookup.values()))
+ {
+ // the component is volatile!!
+ if (!c.nonVolatile)
+ {
+ componentLookup.remove(c.name);
+ }
+ }
+
+ if (trace) log.trace("Reset volatile components. Registry now contains " + componentLookup.keySet());
+ }
+
+ // ------------------------------ START: Publicly available lifecycle methods -----------------------------
+ // These methods perform a check for appropriate transition and then delegate to similarly named internal methods.
+
+ /**
+ * Creates the components needed by a cache instance and sets the cache status to {@link org.jboss.cache.CacheStatus#CREATED}
+ * when it is done.
+ */
+ public void create()
+ {
+ if (!state.createAllowed())
+ {
+ if (state.needToDestroyFailedCache())
+ destroy();
+ else
+ return;
+ }
+
+ try
+ {
+ internalCreate();
+ }
+ catch (Throwable t)
+ {
+ handleLifecycleTransitionFailure(t);
+ }
+ }
+
+ /**
+ * This starts the components in the cache, connecting to channels, starting service threads, etc. If the cache is
+ * not in the {@link org.jboss.cache.CacheStatus#CREATED} state, {@link #create()} will be invoked first.
+ */
+ public void start()
+ {
+ boolean createdInStart = false;
+ if (!state.startAllowed())
+ {
+ if (state.needToDestroyFailedCache())
+ destroy(); // this will take us back to DESTROYED
+
+ if (state.needCreateBeforeStart())
+ {
+ create();
+ createdInStart = true;
+ }
+ else
+ return;
+ }
+
+ try
+ {
+ internalStart(createdInStart);
+ }
+ catch (Throwable t)
+ {
+ handleLifecycleTransitionFailure(t);
+ }
+ }
+
+ /**
+ * Stops the cache and sets the cache status to {@link org.jboss.cache.CacheStatus#STOPPED} once it is done. If the cache is not in
+ * the {@link org.jboss.cache.CacheStatus#STARTED} state, this is a no-op.
+ */
+ public void stop()
+ {
+ if (!state.stopAllowed())
+ {
+ return;
+ }
+
+ // Trying to stop() from FAILED is valid, but may not work
+ boolean failed = state == CacheStatus.FAILED;
+
+ try
+ {
+ internalStop();
+ }
+ catch (Throwable t)
+ {
+ if (failed)
+ {
+ log.warn("Attempted to stop() from FAILED state, but caught exception; try calling destroy()", t);
+ }
+ failed = true;
+ handleLifecycleTransitionFailure(t);
+ }
+ finally
+ {
+ if (!failed) state = CacheStatus.STOPPED;
+ }
+ }
+
+ /**
+ * Destroys the cache and frees up any resources. Sets the cache status to {@link CacheStatus#DESTROYED} when it is done.
+ * <p/>
+ * If the cache is in {@link org.jboss.cache.CacheStatus#STARTED} when this method is called, it will first call {@link #stop()}
+ * to stop the cache.
+ */
+ public void destroy()
+ {
+ if (!state.destroyAllowed())
+ {
+ if (state.needStopBeforeDestroy())
+ {
+ try
+ {
+ stop();
+ }
+ catch (CacheException e)
+ {
+ log.warn("Needed to call stop() before destroying but stop() threw exception. Proceeding to destroy", e);
+ }
+ }
+ else
+ return;
+ }
+
+ try
+ {
+ internalDestroy();
+ }
+ finally
+ {
+ // We always progress to destroyed
+ state = CacheStatus.DESTROYED;
+ }
+ }
+ // ------------------------------ END: Publicly available lifecycle methods -----------------------------
+
+ // ------------------------------ START: Actual internal lifecycle methods --------------------------------
+
+ /**
+ * Sets the cacheStatus to FAILED and rethrows the problem as one
+ * of the declared types. Converts any non-RuntimeException Exception
+ * to CacheException.
+ *
+ * @param t throwable thrown during failure
+ */
+ private void handleLifecycleTransitionFailure(Throwable t)
+ {
+ state = CacheStatus.FAILED;
+ if (t instanceof CacheException)
+ throw (CacheException) t;
+ else if (t instanceof RuntimeException)
+ throw (RuntimeException) t;
+ else if (t instanceof Error)
+ throw (Error) t;
+ else
+ throw new CacheException(t);
+ }
+
+ /**
+ * The actual create implementation.
+ */
+ private void internalCreate()
+ {
+ state = CacheStatus.CREATING;
+ resetNonVolatile();
+ rewire();
+ state = CacheStatus.CREATED;
+ }
+
+ private void internalStart(boolean createdInStart) throws CacheException, IllegalArgumentException
+ {
+ if (!createdInStart)
+ {
+ // re-wire all dependencies in case stuff has changed since the cache was created
+ // remove any components whose construction may have depended upon a configuration that may have changed.
+ resetNonVolatile();
+ rewire();
+ }
+
+ state = CacheStatus.STARTING;
+
+ // start all internal components
+ // first cache all start, stop and destroy methods.
+ populateLifecycleMethods();
+
+ List<PrioritizedMethod> startMethods = new ArrayList<PrioritizedMethod>(componentLookup.size());
+ for (Component c : componentLookup.values()) startMethods.addAll(c.startMethods);
+
+ // sort the start methods by priority
+ Collections.sort(startMethods);
+
+ // fire all START methods according to priority
+
+
+ for (PrioritizedMethod em : startMethods) em.invoke();
+
+ addShutdownHook();
+
+ log.info("JBoss Cache version: " + Version.printVersion());
+ state = CacheStatus.STARTED;
+ }
+
+ private void addShutdownHook()
+ {
+ ArrayList al = MBeanServerFactory.findMBeanServer(null);
+ boolean registerShutdownHook = (getConfiguration().getShutdownHookBehavior() == Configuration.ShutdownHookBehavior.DEFAULT && al.size() == 0)
+ || getConfiguration().getShutdownHookBehavior() == Configuration.ShutdownHookBehavior.REGISTER;
+
+ if (registerShutdownHook)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Registering a shutdown hook. Configured behavior = " + getConfiguration().getShutdownHookBehavior());
+ shutdownHook = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ invokedFromShutdownHook = true;
+ ComponentRegistry.this.stop();
+ }
+ finally
+ {
+ invokedFromShutdownHook = false;
+ }
+ }
+ };
+
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ }
+ else
+ {
+ if (log.isTraceEnabled())
+ log.trace("Not registering a shutdown hook. Configured behavior = " + getConfiguration().getShutdownHookBehavior());
+ }
+ }
+
+ /**
+ * Actual stop
+ */
+ private void internalStop()
+ {
+ state = CacheStatus.STOPPING;
+ // if this is called from a source other than the shutdown hook, deregister the shutdown hook.
+ if (!invokedFromShutdownHook && shutdownHook != null) Runtime.getRuntime().removeShutdownHook(shutdownHook);
+
+ List<PrioritizedMethod> stopMethods = new ArrayList<PrioritizedMethod>(componentLookup.size());
+ for (Component c : componentLookup.values()) stopMethods.addAll(c.stopMethods);
+
+ Collections.sort(stopMethods);
+
+ // fire all STOP methods according to priority
+ for (PrioritizedMethod em : stopMethods) em.invoke();
+
+ state = CacheStatus.STOPPED;
+ }
+
+ /**
+ * Actual destroy
+ */
+ private void internalDestroy()
+ {
+
+ state = CacheStatus.DESTROYING;
+
+ resetNonVolatile();
+
+ List<PrioritizedMethod> destroyMethods = new ArrayList<PrioritizedMethod>(componentLookup.size());
+ for (Component c : componentLookup.values()) destroyMethods.addAll(c.destroyMethods);
+
+ Collections.sort(destroyMethods);
+
+ // fire all DESTROY methods according to priority
+ for (PrioritizedMethod em : destroyMethods) em.invoke();
+
+ state = CacheStatus.DESTROYED;
+ }
+
+ // ------------------------------ END: Actual internal lifecycle methods --------------------------------
+
+ /**
+ * Asserts whether invocations are allowed on the cache or not. Returns <tt>true</tt> if invocations are to be allowed,
+ * <tt>false</tt> otherwise. If the origin of the call is remote and the cache status is {@link org.jboss.cache.CacheStatus#STARTING},
+ * this method will block for up to {@link org.jboss.cache.config.Configuration#getStateRetrievalTimeout()} millis, checking
+ * for a valid state.
+ *
+ * @param originLocal true if the call originates locally (i.e., from the {@link org.jboss.cache.invocation.CacheInvocationDelegate} or false if it originates remotely, i.e., from the {@link org.jboss.cache.marshall.CommandAwareRpcDispatcher}.
+ * @return true if invocations are allowed, false otherwise.
+ */
+ public boolean invocationsAllowed(boolean originLocal)
+ {
+ log.trace("Testing if invocations are allowed.");
+ if (state.allowInvocations()) return true;
+
+ // if this is a locally originating call and the cache is not in a valid state, return false.
+ if (originLocal) return false;
+
+ log.trace("Is remotely originating.");
+
+ // else if this is a remote call and the status is STARTING, wait until the cache starts.
+ if (state == CacheStatus.STARTING)
+ {
+ log.trace("Cache is starting; block.");
+ try
+ {
+ blockUntilCacheStarts();
+ return true;
+ }
+ catch (InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ else
+ {
+ log.warn("Received a remote call but the cache is not in STARTED state - ignoring call.");
+ }
+ return false;
+ }
+
+ /**
+ * Blocks until the current cache instance is in its {@link org.jboss.cache.CacheStatus#STARTED started} phase. Blocks
+ * for up to {@link org.jboss.cache.config.Configuration#getStateRetrievalTimeout()} milliseconds, throwing an IllegalStateException
+ * if the cache doesn't reach this state even after this maximum wait time.
+ *
+ * @throws InterruptedException if interrupted while waiting
+ * @throws IllegalStateException if even after waiting the cache has not started.
+ */
+ private void blockUntilCacheStarts() throws InterruptedException, IllegalStateException
+ {
+ int pollFrequencyMS = 100;
+ long startupWaitTime = getConfiguration().getStateRetrievalTimeout();
+ long giveUpTime = System.currentTimeMillis() + startupWaitTime;
+
+ while (System.currentTimeMillis() < giveUpTime)
+ {
+ if (state.allowInvocations()) break;
+ Thread.sleep(pollFrequencyMS);
+ }
+
+ // check if we have started.
+ if (!state.allowInvocations())
+ throw new IllegalStateException("Cache not in STARTED state, even after waiting " + getConfiguration().getStateRetrievalTimeout() + " millis.");
+ }
+
+ /**
+ * A wrapper representing a component in the registry
+ */
+ public class Component
+ {
+ /**
+ * A reference to the object instance for this component.
+ */
+ Object instance;
+ /**
+ * The name of the component
+ */
+ String name;
+ boolean methodsScanned;
+ /**
+ * List of injection methods used to inject dependencies into the component
+ */
+ List<Method> injectionMethods = new ArrayList<Method>(2);
+ List<PrioritizedMethod> startMethods = new ArrayList<PrioritizedMethod>(2);
+ List<PrioritizedMethod> stopMethods = new ArrayList<PrioritizedMethod>(2);
+ List<PrioritizedMethod> destroyMethods = new ArrayList<PrioritizedMethod>(2);
+ /**
+ * If true, then this component is not flushed before starting the ComponentRegistry.
+ */
+ boolean nonVolatile;
+
+ @Override
+ public String toString()
+ {
+ return "Component{" +
+ "instance=" + instance +
+ ", name=" + name +
+ ", nonVolatile=" + nonVolatile +
+ '}';
+ }
+
+ /**
+ * Injects dependencies into this component.
+ */
+ public void injectDependencies()
+ {
+ for (Method m : injectionMethods) invokeInjectionMethod(instance, m);
+ }
+
+ public Object getInstance()
+ {
+ return instance;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+ }
+
+
+ /**
+ * Wrapper to encapsulate a method along with a priority
+ */
+ static class PrioritizedMethod implements Comparable<PrioritizedMethod>
+ {
+ Method method;
+ Component component;
+ int priority;
+
+ public int compareTo(PrioritizedMethod o)
+ {
+ return (priority < o.priority ? -1 : (priority == o.priority ? 0 : 1));
+ }
+
+ void invoke()
+ {
+ ReflectionUtil.invokeAccessibly(component.instance, method, null);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "PrioritizedMethod{" +
+ "method=" + method +
+ ", priority=" + priority +
+ '}';
+ }
+ }
+
+ /**
+ * Returns an immutable set contating all the components that exists in the reporsitory at this moment.
+ */
+ public Set<Component> getRegiteredComponents()
+ {
+ HashSet<Component> defensiveCopy = new HashSet<Component>(componentLookup.values());
+ return Collections.unmodifiableSet(defensiveCopy);
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/EmptyConstructorFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/EmptyConstructorFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/EmptyConstructorFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+
+import org.jboss.cache.RegionRegistry;
+import org.jboss.cache.batch.BatchContainer;
+import org.jboss.cache.buddyreplication.BuddyFqnTransformer;
+import org.jboss.cache.invocation.CacheInvocationDelegate;
+import org.jboss.cache.loader.CacheLoaderManager;
+import org.jboss.cache.lock.LockStrategyFactory;
+import org.jboss.cache.marshall.Marshaller;
+import org.jboss.cache.marshall.VersionAwareMarshaller;
+import org.jboss.cache.mvcc.MVCCNodeHelper;
+import org.jboss.cache.notifications.Notifier;
+import org.jboss.cache.remoting.jgroups.ChannelMessageListener;
+import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+import org.jboss.starobrno.factories.context.ContextFactory;
+import org.jboss.starobrno.invocation.InvocationContextContainer;
+import org.jboss.starobrno.transaction.TransactionTable;
+
+/**
+ * Simple factory that just uses reflection and an empty constructor of the component type.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.1.0
+ */
+ at DefaultFactoryFor(classes = {Notifier.class, MVCCNodeHelper.class, RegionRegistry.class,
+ ChannelMessageListener.class, CacheLoaderManager.class, Marshaller.class, InvocationContextContainer.class,
+ CacheInvocationDelegate.class, TransactionTable.class, DataContainer.class,
+ LockStrategyFactory.class, BuddyFqnTransformer.class, BatchContainer.class,
+ ContextFactory.class, EntryFactory.class})
+public class EmptyConstructorFactory extends ComponentFactory
+{
+ @Override
+ protected <T> T construct(Class<T> componentType)
+ {
+ try
+ {
+ if (componentType.isInterface())
+ {
+ Class componentImpl;
+ if (componentType.equals(Marshaller.class))
+ {
+ componentImpl = VersionAwareMarshaller.class;
+ }
+ else
+ {
+ // add an "Impl" to the end of the class name and try again
+ componentImpl = getClass().getClassLoader().loadClass(componentType.getName() + "Impl");
+ }
+
+ return componentType.cast(componentImpl.newInstance());
+ }
+ else
+ {
+ return componentType.newInstance();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Unable to create component " + componentType, e);
+ }
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/EntryFactoryImpl.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -21,11 +21,11 @@
*/
package org.jboss.starobrno.factories;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.Start;
import org.jboss.starobrno.mvcc.EntryImpl;
import org.jboss.starobrno.mvcc.MVCCEntry;
import org.jboss.starobrno.mvcc.NullMarkerEntry;
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/InterceptorChainFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/InterceptorChainFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/InterceptorChainFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,212 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+
+import org.jboss.cache.interceptors.*;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.CustomInterceptorConfig;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+import org.jboss.starobrno.interceptors.InterceptorChain;
+import org.jboss.starobrno.interceptors.base.CommandInterceptor;
+
+import java.util.List;
+
+/**
+ * Factory class that builds an interceptor chain based on cache configuration.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ */
+ at DefaultFactoryFor(classes = InterceptorChain.class)
+public class InterceptorChainFactory extends ComponentFactory
+{
+ /**
+ * Note - this method used to return a singleton instance, and since 2.1.0 returns a new instance. The method is
+ * deprecated and you should use the no-arg constructor to create a new instance of this factory.
+ *
+ * @return a NEW instance of this class.
+ */
+ @Deprecated
+ public static InterceptorChainFactory getInstance()
+ {
+ return new InterceptorChainFactory();
+ }
+
+ private CommandInterceptor createInterceptor(Class clazz) throws IllegalAccessException, InstantiationException
+ {
+ return null; // todo - un-hack!
+// CommandInterceptor chainedInterceptor = componentRegistry.getComponent(clazz);
+// if (chainedInterceptor == null)
+// {
+// chainedInterceptor = clazz.newInstance();
+// componentRegistry.registerComponent(chainedInterceptor, clazz);
+// }
+// else
+// {
+// // wipe next/last chaining!!
+// chainedInterceptor.setNext(null);
+// }
+// return chainedInterceptor;
+ }
+
+ public InterceptorChain buildInterceptorChain() throws IllegalAccessException, InstantiationException, ClassNotFoundException
+ {
+ boolean invocationBatching = configuration.isInvocationBatchingEnabled();
+ // load the icInterceptor first
+ CommandInterceptor first = invocationBatching ? createInterceptor(BatchingInterceptor.class) : createInterceptor(InvocationContextInterceptor.class);
+ InterceptorChain interceptorChain = new InterceptorChain(first);
+
+ // add the interceptor chain to the registry first, since some interceptors may ask for it.
+ componentRegistry.registerComponent(interceptorChain, InterceptorChain.class);
+
+ // NOW add the ICI if we are using batching!
+ if (invocationBatching)
+ interceptorChain.appendIntereceptor(createInterceptor(InvocationContextInterceptor.class));
+
+ // load the cache management interceptor next
+ if (configuration.getExposeManagementStatistics())
+ interceptorChain.appendIntereceptor(createInterceptor(CacheMgmtInterceptor.class));
+
+ // load the tx interceptor
+ interceptorChain.appendIntereceptor(createInterceptor(TxInterceptor.class));
+
+ if (configuration.isUseLazyDeserialization())
+ interceptorChain.appendIntereceptor(createInterceptor(MarshalledValueInterceptor.class));
+ interceptorChain.appendIntereceptor(createInterceptor(NotificationInterceptor.class));
+
+ switch (configuration.getCacheMode())
+ {
+ case REPL_SYNC:
+ case REPL_ASYNC:
+ interceptorChain.appendIntereceptor(createInterceptor(ReplicationInterceptor.class));
+ break;
+ case INVALIDATION_SYNC:
+ case INVALIDATION_ASYNC:
+ interceptorChain.appendIntereceptor(createInterceptor(InvalidationInterceptor.class));
+ break;
+ case LOCAL:
+ //Nothing...
+ }
+
+ if (configuration.isUsingCacheLoaders())
+ {
+ if (configuration.getCacheLoaderConfig().isPassivation())
+ {
+ interceptorChain.appendIntereceptor(createInterceptor(ActivationInterceptor.class));
+ }
+ else
+ {
+ interceptorChain.appendIntereceptor(createInterceptor(CacheLoaderInterceptor.class));
+ }
+ }
+ interceptorChain.appendIntereceptor(createInterceptor(MVCCLockingInterceptor.class));
+
+ if (configuration.isUsingCacheLoaders())
+ {
+ if (configuration.getCacheLoaderConfig().isPassivation())
+ {
+
+ interceptorChain.appendIntereceptor(createInterceptor(PassivationInterceptor.class));
+
+ }
+ else
+ {
+
+ interceptorChain.appendIntereceptor(createInterceptor(CacheStoreInterceptor.class));
+
+ }
+ }
+
+ if (configuration.isUsingBuddyReplication())
+ {
+
+ interceptorChain.appendIntereceptor(createInterceptor(DataGravitatorInterceptor.class));
+
+ }
+
+ // eviction interceptor to come before the optimistic node interceptor
+ if (configuration.getEvictionConfig() != null && configuration.getEvictionConfig().isValidConfig())
+ interceptorChain.appendIntereceptor(createInterceptor(configuration.isUsingBuddyReplication() ? BuddyRegionAwareEvictionInterceptor.class : EvictionInterceptor.class));
+
+ CommandInterceptor callInterceptor = createInterceptor(CallInterceptor.class);
+ interceptorChain.appendIntereceptor(callInterceptor);
+ if (log.isTraceEnabled()) log.trace("Finished building default interceptor chain.");
+ buildCustomInterceptors(interceptorChain, configuration.getCustomInterceptors());
+ return interceptorChain;
+ }
+
+ private void buildCustomInterceptors(InterceptorChain interceptorChain, List<CustomInterceptorConfig> customInterceptors)
+ {
+ for (CustomInterceptorConfig config : customInterceptors)
+ {
+ if (interceptorChain.containsInstance(config.getInterceptor())) continue;
+ if (config.isFirst())
+ {
+ interceptorChain.addInterceptor(config.getInterceptor(), 0);
+ }
+ if (config.isLast()) interceptorChain.appendIntereceptor(config.getInterceptor());
+ if (config.getIndex() >= 0) interceptorChain.addInterceptor(config.getInterceptor(), config.getIndex());
+ if (config.getAfterClass() != null)
+ {
+ List<CommandInterceptor> withClassName = interceptorChain.getInterceptorsWithClassName(config.getAfterClass());
+ if (withClassName.isEmpty())
+ {
+ throw new ConfigurationException("Cannot add after class: " + config.getAfterClass()
+ + " as no such iterceptor exists in the default chain");
+ }
+ interceptorChain.addAfterInterceptor(config.getInterceptor(), withClassName.get(0).getClass());
+ }
+ if (config.getBeforeClass() != null)
+ {
+ List<CommandInterceptor> withClassName = interceptorChain.getInterceptorsWithClassName(config.getBeforeClass());
+ if (withClassName.isEmpty())
+ {
+ throw new ConfigurationException("Cannot add before class: " + config.getAfterClass()
+ + " as no such iterceptor exists in the default chain");
+ }
+ interceptorChain.addBeforeInterceptor(config.getInterceptor(), withClassName.get(0).getClass());
+ }
+ }
+ }
+
+ @Override
+ protected <T> T construct(Class<T> componentType)
+ {
+ try
+ {
+ return componentType.cast(buildInterceptorChain());
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Unable to build interceptor chain", e);
+ }
+ }
+
+ public static InterceptorChainFactory getInstance(ComponentRegistry componentRegistry, Configuration configuration)
+ {
+ InterceptorChainFactory icf = new InterceptorChainFactory();
+ icf.componentRegistry = componentRegistry;
+ icf.configuration = configuration;
+ return icf;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/ReplicationQueueFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/ReplicationQueueFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/ReplicationQueueFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.jboss.cache.cluster.ReplicationQueue;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+
+/**
+ * RPCManager factory
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.1.0
+ */
+ at DefaultFactoryFor(classes = ReplicationQueue.class)
+public class ReplicationQueueFactory extends EmptyConstructorFactory
+{
+ @Override
+ public <T> T construct(Class<T> componentType)
+ {
+ if ((configuration.getCacheMode() == Configuration.CacheMode.REPL_ASYNC || configuration.getCacheMode() == Configuration.CacheMode.INVALIDATION_ASYNC)
+ && configuration.isUseReplQueue())
+ {
+ return super.construct(componentType);
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/RuntimeConfigAwareFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/RuntimeConfigAwareFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/RuntimeConfigAwareFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.jboss.cache.RPCManager;
+import org.jboss.cache.util.BeanUtils;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.RuntimeConfig;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+
+import java.lang.reflect.Method;
+
+/**
+ * An extension of the EmptyConstructorFactory that places a component in the {@link RuntimeConfig} after creating it.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.1.0
+ */
+ at DefaultFactoryFor(classes = RPCManager.class)
+public class RuntimeConfigAwareFactory extends EmptyConstructorFactory
+{
+ @Override
+ protected <T> T construct(Class<T> componentType)
+ {
+ T component = super.construct(componentType);
+
+ Method setter = BeanUtils.setterMethod(RuntimeConfig.class, componentType);
+ if (setter != null)
+ {
+ try
+ {
+ setter.invoke(configuration.getRuntimeConfig(), component);
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Unable to put newly constructed component of type " + componentType + " in the RuntimeConfig", e);
+ }
+ }
+ return component;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/StateTransferFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/StateTransferFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/StateTransferFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.jboss.cache.statetransfer.DefaultStateTransferGenerator;
+import org.jboss.cache.statetransfer.DefaultStateTransferIntegrator;
+import org.jboss.cache.statetransfer.StateTransferGenerator;
+import org.jboss.cache.statetransfer.StateTransferIntegrator;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+
+/**
+ * Factory class able to create {@link org.jboss.cache.statetransfer.StateTransferGenerator} and
+ * {@link org.jboss.cache.statetransfer.StateTransferIntegrator} instances.
+ * <p/>
+ * Updated in 3.0.0 to extend ComponentFactory, etc.
+ * <p/>
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @author Manik Surtani
+ * @version $Revision: 6776 $
+ */
+ at DefaultFactoryFor(classes = {StateTransferGenerator.class, StateTransferIntegrator.class})
+public class StateTransferFactory extends ComponentFactory
+{
+ @SuppressWarnings("deprecation")
+ protected <T> T construct(Class<T> componentType)
+ {
+ if (componentType.equals(StateTransferIntegrator.class))
+ {
+ return componentType.cast(new DefaultStateTransferIntegrator());
+ }
+ else
+ {
+ return componentType.cast(new DefaultStateTransferGenerator());
+ }
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/StateTransferManagerFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/StateTransferManagerFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/StateTransferManagerFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.jboss.cache.statetransfer.DefaultStateTransferManager;
+import org.jboss.cache.statetransfer.StateTransferManager;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+
+/**
+ * Constructs {@link org.jboss.cache.statetransfer.StateTransferManager} instances.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+ at DefaultFactoryFor(classes = StateTransferManager.class)
+public class StateTransferManagerFactory extends ComponentFactory
+{
+ @SuppressWarnings("deprecation")
+ protected <T> T construct(Class<T> componentType)
+ {
+ return componentType.cast(new DefaultStateTransferManager());
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/factories/TransactionManagerFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/TransactionManagerFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/TransactionManagerFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.starobrno.factories;
+
+import org.jboss.cache.transaction.BatchModeTransactionManager;
+import org.jboss.cache.transaction.TransactionManagerLookup;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.factories.annotations.DefaultFactoryFor;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * Uses a number of mechanisms to retrieve a transaction manager.
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 2.1.0
+ */
+ at DefaultFactoryFor(classes = {TransactionManager.class})
+public class TransactionManagerFactory extends ComponentFactory
+{
+ protected <T> T construct(Class<T> componentType)
+ {
+ // See if we had a TransactionManager injected into our config
+ TransactionManager transactionManager = configuration.getRuntimeConfig().getTransactionManager();
+ TransactionManagerLookup lookup = null;
+
+ if (transactionManager == null)
+ {
+ // Nope. See if we can look it up from JNDI
+ if (configuration.getTransactionManagerLookupClass() != null)
+ {
+ try
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ if (cl == null) cl = getClass().getClassLoader();
+ Class clazz = cl.loadClass(configuration.getTransactionManagerLookupClass());
+ lookup = (TransactionManagerLookup) clazz.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Problems looking up transaction manager", e);
+ }
+ }
+
+ try
+ {
+ if (lookup != null)
+ {
+ transactionManager = lookup.getTransactionManager();
+ configuration.getRuntimeConfig().setTransactionManager(transactionManager);
+ }
+ }
+ catch (Exception e)
+ {
+ log.info("failed looking up TransactionManager, will not use transactions", e);
+ }
+ }
+
+ if (transactionManager == null && configuration.isInvocationBatchingEnabled())
+ {
+ log.info("Using a batchMode transaction manager");
+ transactionManager = BatchModeTransactionManager.getInstance();
+ }
+ return componentType.cast(transactionManager);
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -22,7 +22,9 @@
package org.jboss.starobrno.factories.context;
import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.context.InvocationContextImpl;
import org.jboss.starobrno.context.TransactionContext;
+import org.jboss.starobrno.context.TransactionContextImpl;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
@@ -35,12 +37,15 @@
* @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
* @since 3.0
*/
-public interface ContextFactory
+public class ContextFactory
{
/**
* @return a new invocation context
*/
- InvocationContext createInvocationContext();
+ public InvocationContext createInvocationContext()
+ {
+ return new InvocationContextImpl();
+ }
/**
* @param tx JTA transaction to associate the new context with
@@ -50,5 +55,8 @@
* @throws javax.transaction.SystemException
* in the event of an invalid transaction
*/
- TransactionContext createTransactionContext(Transaction tx) throws SystemException, RollbackException;
+ public TransactionContext createTransactionContext(Transaction tx) throws SystemException, RollbackException
+ {
+ return new TransactionContextImpl(tx);
+ }
}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/BaseTransactionalContextInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/BaseTransactionalContextInterceptor.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/BaseTransactionalContextInterceptor.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -21,7 +21,7 @@
*/
package org.jboss.starobrno.interceptors;
-import org.jboss.cache.config.Option;
+import org.jboss.starobrno.config.Option;
import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.context.TransactionContext;
import org.jboss.starobrno.factories.annotations.Inject;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InvocationContextInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InvocationContextInterceptor.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InvocationContextInterceptor.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -22,8 +22,8 @@
package org.jboss.starobrno.interceptors;
-import org.jboss.cache.config.Option;
import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.starobrno.RPCManager;
import org.jboss.starobrno.commands.VisitableCommand;
import org.jboss.starobrno.commands.tx.CommitCommand;
import org.jboss.starobrno.commands.tx.PrepareCommand;
@@ -32,10 +32,10 @@
import org.jboss.starobrno.commands.write.PutKeyValueCommand;
import org.jboss.starobrno.commands.write.PutMapCommand;
import org.jboss.starobrno.commands.write.RemoveCommand;
+import org.jboss.starobrno.config.Option;
import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.factories.annotations.Inject;
import org.jboss.starobrno.transaction.GlobalTransaction;
-import org.jboss.starobrno.RPCManager;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/loader/CacheLoader.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -21,19 +21,18 @@
*/
package org.jboss.starobrno.loader;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.List;
-import java.util.Map;
-
import net.jcip.annotations.ThreadSafe;
-
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.loader.AbstractCacheLoader;
+import org.jboss.starobrno.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.List;
+import java.util.Map;
+
/**
* A {@link org.jboss.cache.loader.CacheLoader} implementation persists and load keys to and from
* secondary storage, such as a database or filesystem. Typically,
@@ -90,7 +89,7 @@
*
* @param c The cache on which this loader works
*/
- void setCache(CacheSPI<K,V> c);
+ void setCache(CacheSPI<K, V> c);
/**
* Returns all keys and values from the persistent store, given a {@link org.jboss.cache.Fqn}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/lock/StripedLockManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/lock/StripedLockManager.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/lock/StripedLockManager.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -23,16 +23,16 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.invocation.InvocationContextContainer;
import org.jboss.cache.lock.MVCCLockManager;
import org.jboss.cache.util.concurrent.locks.LockContainer;
import org.jboss.cache.util.concurrent.locks.OwnableReentrantLock;
import org.jboss.cache.util.concurrent.locks.OwnableReentrantLockContainer;
import org.jboss.cache.util.concurrent.locks.ReentrantLockContainer;
+import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.Start;
import javax.transaction.TransactionManager;
import java.util.List;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntryWrapper.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntryWrapper.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntryWrapper.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -23,13 +23,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.Start;
import org.jboss.cache.lock.TimeoutException;
import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.config.Configuration;
import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.factories.EntryFactory;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.Start;
import org.jboss.starobrno.lock.LockManager;
import java.util.Map.Entry;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/RepeatableReadEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/RepeatableReadEntry.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/RepeatableReadEntry.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -24,7 +24,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.mvcc.RepeatableReadNode;
-import org.jboss.cache.optimistic.DataVersioningException;
+import org.jboss.starobrno.CacheException;
import org.jboss.starobrno.DataContainer;
import static org.jboss.starobrno.mvcc.ReadCommittedEntry.Flags.CHANGED;
@@ -62,7 +62,7 @@
{
String errormsg = new StringBuilder().append("Detected write skew on key [").append(getKey()).append("]. Another process has changed the node since we last read it!").toString();
if (log.isWarnEnabled()) log.warn(errormsg + ". Unable to copy node for update.");
- throw new DataVersioningException(errormsg);
+ throw new CacheException(errormsg);
}
}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionTable.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionTable.java 2008-10-08 16:22:51 UTC (rev 6883)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionTable.java 2008-10-08 16:24:08 UTC (rev 6884)
@@ -23,12 +23,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheException;
import org.jboss.cache.InvocationContext;
import org.jboss.cache.RPCManager;
-import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.factories.annotations.NonVolatile;
+import org.jboss.starobrno.CacheException;
import org.jboss.starobrno.context.TransactionContext;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.NonVolatile;
import org.jboss.starobrno.factories.context.ContextFactory;
import org.jgroups.Address;
More information about the jbosscache-commits
mailing list