Index: docs/reference/src/main/docbook/en-US/content/connectors/infinispan.xml
===================================================================
--- docs/reference/src/main/docbook/en-US/content/connectors/infinispan.xml (revision 0)
+++ docs/reference/src/main/docbook/en-US/content/connectors/infinispan.xml (revision 0)
@@ -0,0 +1,93 @@
+
+
+
+%CustomDTD;
+]>
+
+ Infinispan Connector
+
+ The Infinispan repository connector allows a Infinispan instance to be
+ used as a JBoss DNA (and thus JCR) repository. This provides a repository that is an effective, scalable, and distributed cache,
+ and is often paired with other repository sources to provide a local or federated
+ repository.
+
+
+ The &InfinispanSource; class provides a number of JavaBean properties that control its behavior:
+
+
+ &InfinispanSource; properties
+
+
+
+
+
+ Property
+ Description
+
+
+
+
+ name
+ The name of the repository source, which is used by the &RepositoryService; when obtaining a &RepositoryConnection; by name.
+
+
+ cacheManagerJndiName
+ Optional property that, if used, specifies the name in JNDI where an existing Infinispan Cache Manager instance can be found.
+ That factory would then be used if needed to create an Infinispan Cache instance. If no value is provided, then the
+ Infinispan DefaultCacheManager class is used.
+
+
+ cacheConfigurationName
+ Optional property that, if used, specifies the name of the configuration that is supplied to the cache manager
+ when creating a new Infinispan CacheManager instance.
+
+
+ retryLimit
+ Optional property that, if used, defines the number of times that any single operation on a &RepositoryConnection; to this source should be retried
+ following a communication failure. The default value is '0'.
+
+
+ defaultCachePolicy
+ Optional property that, if used, defines the default for how long this information provided by this source may to be
+ cached by other, higher-level components. The default value of null implies that this source does not define a specific
+ duration for caching information provided by this repository source.
+
+
+ nameOfDefaultWorkspace
+ Optional property that is initialized to an empty string and which defines the name for the workspace that will be used by default
+ if none is specified.
+
+
+ predefinedWorkspaceNames
+ Optional property that defines the names of the workspaces that exist and that are available for use without having to create them.
+
+
+
+
+
+
Property changes on: docs\reference\src\main\docbook\en-US\content\connectors\infinispan.xml
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: docs/reference/src/main/docbook/en-US/content/developers/tools.xml
===================================================================
--- docs/reference/src/main/docbook/en-US/content/developers/tools.xml (revision 1072)
+++ docs/reference/src/main/docbook/en-US/content/developers/tools.xml (working copy)
@@ -488,9 +488,9 @@
$ svn checkout https://anonsvn.jboss.org/repos/dna/tags/dna-{release-number}/
Then, go into the new directory, and perform a Maven deploy:
+
+ $ mvn clean deploy
- $ mvn clean deploy
-
This will rebuild all the artifacts (from your local copy of the tagged source) and deploy them
to the local file system, which is comprised of a local checkout of the JBoss Maven2 repository
in a location specified by a combination of the <distributionManagement> section of several pom.xml
Index: docs/reference/src/main/docbook/en-US/custom.dtd
===================================================================
--- docs/reference/src/main/docbook/en-US/custom.dtd (revision 1072)
+++ docs/reference/src/main/docbook/en-US/custom.dtd (working copy)
@@ -188,6 +188,7 @@
SVNRepositorySource">
JBossCacheRepository">
JBossCacheSource">
+InfinispanSource">
ImageMetadataSequencer">
ImageMetadata">
ImageSequencerI18n">
Index: docs/reference/src/main/docbook/en-US/master.xml
===================================================================
--- docs/reference/src/main/docbook/en-US/master.xml (revision 1072)
+++ docs/reference/src/main/docbook/en-US/master.xml (working copy)
@@ -115,6 +115,7 @@
+
Index: extensions/dna-connector-federation/.project
===================================================================
--- extensions/dna-connector-federation/.project (revision 1064)
+++ extensions/dna-connector-federation/.project (working copy)
@@ -1,23 +1,29 @@
-
-
- dna-connector-federation
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.maven.ide.eclipse.maven2Builder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
- org.maven.ide.eclipse.maven2Nature
-
-
+
+
+ dna-connector-federation
+
+
+
+
+
+ org.eclipse.wst.common.project.facet.core.builder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.maven.ide.eclipse.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.maven.ide.eclipse.maven2Nature
+ org.eclipse.wst.common.project.facet.core.nature
+
+
Index: extensions/dna-connector-infinispan/.classpath
===================================================================
--- extensions/dna-connector-infinispan/.classpath (revision 0)
+++ extensions/dna-connector-infinispan/.classpath (revision 0)
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
Index: extensions/dna-connector-infinispan/.project
===================================================================
--- extensions/dna-connector-infinispan/.project (revision 0)
+++ extensions/dna-connector-infinispan/.project (revision 0)
@@ -0,0 +1,23 @@
+
+
+ dna-connector-infinispan
+
+
+
+
+
+ org.maven.ide.eclipse.maven2Builder
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.maven.ide.eclipse.maven2Nature
+
+
Index: extensions/dna-connector-infinispan/pom.xml
===================================================================
--- extensions/dna-connector-infinispan/pom.xml (revision 0)
+++ extensions/dna-connector-infinispan/pom.xml (revision 0)
@@ -0,0 +1,97 @@
+
+
+ 4.0.0
+
+ org.jboss.dna
+ dna
+ 0.6-SNAPSHOT
+ ../..
+
+
+ dna-connector-infinispan
+ jar
+ JBoss DNA Connector to JBoss Infinispan
+ JBoss DNA Connector that accesses an in-process JBoss Infinispan instance.
+ http://labs.jboss.org/dna
+
+
+
+
+
+ org.jboss.dna
+ dna-common
+
+
+ org.jboss.dna
+ dna-graph
+
+
+ org.jboss.dna
+ dna-common
+ ${pom.version}
+ test-jar
+ test
+
+
+ org.jboss.dna
+ dna-graph
+ ${pom.version}
+ test-jar
+ test
+
+
+
+ org.infinispan
+ infinispan-core
+ 4.0.0.ALPHA5
+
+
+
+ junit
+ junit
+
+
+ org.mockito
+ mockito-all
+
+
+
+ org.slf4j
+ slf4j-api
+
+
+ org.slf4j
+ slf4j-log4j12
+
+
+ log4j
+ log4j
+
+
+
+ net.jcip
+ jcip-annotations
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-report-plugin
+
+
+
+
\ No newline at end of file
Property changes on: extensions\dna-connector-infinispan\pom.xml
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-infinispan/src/main/java/org/jboss/dna/connector/infinispan/InfinispanConnectorI18n.java
===================================================================
--- extensions/dna-connector-infinispan/src/main/java/org/jboss/dna/connector/infinispan/InfinispanConnectorI18n.java (revision 0)
+++ extensions/dna-connector-infinispan/src/main/java/org/jboss/dna/connector/infinispan/InfinispanConnectorI18n.java (revision 0)
@@ -0,0 +1,43 @@
+package org.jboss.dna.connector.infinispan;
+
+import java.util.Locale;
+import java.util.Set;
+import org.jboss.dna.common.i18n.I18n;
+
+public final class InfinispanConnectorI18n {
+
+ public static I18n connectorName;
+ public static I18n nodeDoesNotExist;
+ public static I18n propertyIsRequired;
+ public static I18n errorSerializingCachePolicyInSource;
+ public static I18n objectFoundInJndiWasNotCacheManager;
+ // public static I18n unableToCloneWorkspaces;
+ // public static I18n unableToCreateWorkspaces;
+ public static I18n unableToCreateWorkspace;
+ public static I18n workspaceAlreadyExists;
+ public static I18n workspaceDoesNotExist;
+ public static I18n workspaceNameWasNotValidConfiguration;
+ public static I18n defaultCacheManagerConfigurationNameWasNotValidConfiguration;
+
+
+ static {
+ try {
+ I18n.initialize(InfinispanConnectorI18n.class);
+ } catch (final Exception err) {
+ System.err.println(err);
+ }
+ }
+
+ public static Set getLocalizationProblemLocales() {
+ return I18n.getLocalizationProblemLocales(InfinispanConnectorI18n.class);
+ }
+
+ public static Set getLocalizationProblems() {
+ return I18n.getLocalizationProblems(InfinispanConnectorI18n.class);
+ }
+
+ public static Set getLocalizationProblems( Locale locale ) {
+ return I18n.getLocalizationProblems(InfinispanConnectorI18n.class, locale);
+ }
+
+}
Property changes on: extensions\dna-connector-infinispan\src\main\java\org\jboss\dna\connector\infinispan\InfinispanConnectorI18n.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-infinispan/src/main/java/org/jboss/dna/connector/infinispan/InfinispanRepository.java
===================================================================
--- extensions/dna-connector-infinispan/src/main/java/org/jboss/dna/connector/infinispan/InfinispanRepository.java (revision 0)
+++ extensions/dna-connector-infinispan/src/main/java/org/jboss/dna/connector/infinispan/InfinispanRepository.java (revision 0)
@@ -0,0 +1,82 @@
+package org.jboss.dna.connector.infinispan;
+
+import java.util.UUID;
+import org.infinispan.Cache;
+import org.infinispan.manager.CacheManager;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.connector.map.AbstractMapWorkspace;
+import org.jboss.dna.graph.connector.map.MapNode;
+import org.jboss.dna.graph.connector.map.MapRepository;
+import org.jboss.dna.graph.connector.map.MapWorkspace;
+
+public class InfinispanRepository extends MapRepository {
+
+ private final CacheManager cacheManager;
+
+ public InfinispanRepository( String sourceName,
+ UUID rootNodeUuid,
+ CacheManager cacheManager ) {
+ super(sourceName, rootNodeUuid, null);
+ assert cacheManager != null;
+ this.cacheManager = cacheManager;
+ initialize();
+ }
+
+ public InfinispanRepository( String sourceName,
+ UUID rootNodeUuid,
+ String defaultWorkspaceName,
+ CacheManager cacheManager ) {
+ super(sourceName, rootNodeUuid, defaultWorkspaceName);
+
+ assert cacheManager != null;
+ this.cacheManager = cacheManager;
+
+ initialize();
+ }
+
+ @Override
+ protected MapWorkspace createWorkspace( ExecutionContext context,
+ String name ) {
+ assert name != null;
+ assert cacheManager != null;
+ Cache newWorkspaceCache = cacheManager.getCache(name);
+ return new Workspace(this, name, newWorkspaceCache);
+ }
+
+ protected class Workspace extends AbstractMapWorkspace {
+ private final Cache workspaceCache;
+
+ public Workspace( MapRepository repository,
+ String name,
+ Cache workspaceCache ) {
+ super(repository, name);
+
+ this.workspaceCache = workspaceCache;
+ initialize();
+ }
+
+ @Override
+ protected void addNodeToMap( MapNode node ) {
+ assert node != null;
+ workspaceCache.put(node.getUuid(), node);
+ }
+
+ @Override
+ protected MapNode removeNodeFromMap( UUID nodeUuid ) {
+ assert nodeUuid != null;
+ return workspaceCache.remove(nodeUuid);
+ }
+
+ @Override
+ protected void removeAllNodesFromMap() {
+ workspaceCache.clear();
+ }
+
+ @Override
+ public MapNode getNode( UUID nodeUuid ) {
+ assert nodeUuid != null;
+ return workspaceCache.get(nodeUuid);
+ }
+ }
+
+}
Property changes on: extensions\dna-connector-infinispan\src\main\java\org\jboss\dna\connector\infinispan\InfinispanRepository.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-infinispan/src/main/java/org/jboss/dna/connector/infinispan/InfinispanSource.java
===================================================================
--- extensions/dna-connector-infinispan/src/main/java/org/jboss/dna/connector/infinispan/InfinispanSource.java (revision 0)
+++ extensions/dna-connector-infinispan/src/main/java/org/jboss/dna/connector/infinispan/InfinispanSource.java (revision 0)
@@ -0,0 +1,555 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.infinispan;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.naming.BinaryRefAddr;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.naming.StringRefAddr;
+import javax.naming.spi.ObjectFactory;
+import net.jcip.annotations.ThreadSafe;
+import org.infinispan.Cache;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.manager.DefaultCacheManager;
+import org.jboss.dna.common.i18n.I18n;
+import org.jboss.dna.common.util.StringUtil;
+import org.jboss.dna.graph.cache.CachePolicy;
+import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositoryContext;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.RepositorySourceCapabilities;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+import org.jboss.dna.graph.connector.map.MapRepositoryConnection;
+import org.jboss.dna.graph.connector.map.MapRepositorySource;
+import org.jboss.dna.graph.observe.Observer;
+import org.jboss.dna.graph.request.CreateWorkspaceRequest.CreateConflictBehavior;
+
+/**
+ * A repository source that uses an Infinispan instance to manage the content. This source is capable of using an existing
+ * {@link CacheManager} or creating a new cache manager. This process is controlled entirely by the JavaBean properties of the
+ * InfinispanSource instance.
+ *
+ * This source first attempts to find an existing cache manager found in {@link #getCacheManagerJndiName() JNDI} (or the
+ * {@link DefaultCacheManager} if no such manager is available) and the {@link #getCacheConfigurationName() cache configuration
+ * name} if supplied or the default configuration if not set.
+ *
+ *
+ * Like other {@link RepositorySource} classes, instances of JBossCacheSource can be placed into JNDI and do support the creation
+ * of {@link Referenceable JNDI referenceable} objects and resolution of references into JBossCacheSource.
+ *
+ */
+@ThreadSafe
+public class InfinispanSource implements MapRepositorySource, ObjectFactory {
+
+ private static final long serialVersionUID = 2L;
+ /**
+ * The default limit is {@value} for retrying {@link RepositoryConnection connection} calls to the underlying source.
+ */
+ public static final int DEFAULT_RETRY_LIMIT = 0;
+
+ /**
+ * The initial {@link #getNameOfDefaultWorkspace() name of the default workspace} is "{@value} ", unless otherwise specified.
+ */
+ public static final String DEFAULT_NAME_OF_DEFAULT_WORKSPACE = "default";
+
+ protected static final String ROOT_NODE_UUID = "rootNodeUuid";
+ protected static final String SOURCE_NAME = "sourceName";
+ protected static final String DEFAULT_CACHE_POLICY = "defaultCachePolicy";
+ protected static final String CACHE_CONFIGURATION_NAME = "cacheConfigurationName";
+ protected static final String CACHE_FACTORY_JNDI_NAME = "cacheManagerJndiName";
+ protected static final String RETRY_LIMIT = "retryLimit";
+ protected static final String DEFAULT_WORKSPACE = "defaultWorkspace";
+ protected static final String PREDEFINED_WORKSPACE_NAMES = "predefinedWorkspaceNames";
+ protected static final String ALLOW_CREATING_WORKSPACES = "allowCreatingWorkspaces";
+
+ private volatile String name;
+ private volatile UUID rootNodeUuid = UUID.randomUUID();
+ private volatile CachePolicy defaultCachePolicy;
+ private volatile String cacheConfigurationName;
+ private volatile String cacheManagerJndiName;
+ private volatile int retryLimit = DEFAULT_RETRY_LIMIT;
+ private volatile String defaultWorkspace;
+ private volatile String[] predefinedWorkspaces = new String[] {};
+ private volatile RepositorySourceCapabilities capabilities = new RepositorySourceCapabilities(true, true, false, true, false);
+ private transient InfinispanRepository repository;
+ private transient Context jndiContext;
+ private transient RepositoryContext repositoryContext;
+
+ /**
+ * Create a repository source instance.
+ */
+ public InfinispanSource() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#initialize(org.jboss.dna.graph.connector.RepositoryContext)
+ */
+ public void initialize( RepositoryContext context ) throws RepositorySourceException {
+ this.repositoryContext = context;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getCapabilities()
+ */
+ public RepositorySourceCapabilities getCapabilities() {
+ return capabilities;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getRetryLimit()
+ */
+ public int getRetryLimit() {
+ return retryLimit;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#setRetryLimit(int)
+ */
+ public synchronized void setRetryLimit( int limit ) {
+ retryLimit = limit < 0 ? 0 : limit;
+ }
+
+ /**
+ * Set the name of this source
+ *
+ * @param name the name for this source
+ */
+ public synchronized void setName( String name ) {
+ if (this.name == name || this.name != null && this.name.equals(name)) return; // unchanged
+ this.name = name;
+ }
+
+ /**
+ * Get the default cache policy for this source, or null if the global default cache policy should be used
+ *
+ * @return the default cache policy, or null if this source has no explicit default cache policy
+ */
+ public CachePolicy getDefaultCachePolicy() {
+ return defaultCachePolicy;
+ }
+
+ /**
+ * @param defaultCachePolicy Sets defaultCachePolicy to the specified value.
+ */
+ public synchronized void setDefaultCachePolicy( CachePolicy defaultCachePolicy ) {
+ if (this.defaultCachePolicy == defaultCachePolicy || this.defaultCachePolicy != null
+ && this.defaultCachePolicy.equals(defaultCachePolicy)) return; // unchanged
+ this.defaultCachePolicy = defaultCachePolicy;
+ }
+
+ /**
+ * Get the name in JNDI of a {@link CacheManager} instance that should be used to create the cache for this source.
+ *
+ * This source first attempts to find a cache instance using the {@link CacheManager} found in
+ * {@link #getCacheManagerJndiName() JNDI} (or the {@link DefaultCacheManager} if no such manager is available) and the
+ * {@link #getCacheConfigurationName() cache configuration name} if supplied or the default configuration if not set.
+ *
+ *
+ * @return the JNDI name of the {@link CacheManager} instance that should be used, or null if the {@link DefaultCacheManager}
+ * should be used if a cache is to be created
+ * @see #setCacheManagerJndiName(String)
+ * @see #getCacheConfigurationName()
+ */
+ public String getCacheManagerJndiName() {
+ return cacheManagerJndiName;
+ }
+
+ /**
+ * Set the name in JNDI of a {@link CacheManager} instance that should be used to obtain the {@link Cache} instance used by
+ * this source.
+ *
+ * This source first attempts to find a cache instance using the {@link CacheManager} found in
+ * {@link #getCacheManagerJndiName() JNDI} (or the {@link DefaultCacheManager} if no such manager is available) and the
+ * {@link #getCacheConfigurationName() cache configuration name} if supplied or the default configuration if not set.
+ *
+ *
+ * @param jndiName the JNDI name of the {@link CacheManager} instance that should be used, or null if the
+ * {@link DefaultCacheManager} should be used if a cache is to be created
+ * @see #setCacheManagerJndiName(String)
+ * @see #getCacheConfigurationName()
+ */
+ public synchronized void setCacheManagerJndiName( String jndiName ) {
+ if (this.cacheManagerJndiName == jndiName || this.cacheManagerJndiName != null
+ && this.cacheManagerJndiName.equals(jndiName)) return; // unchanged
+ this.cacheManagerJndiName = jndiName;
+ }
+
+ /**
+ * Get the name of the configuration that should be used if a {@link Cache cache} is to be created using the
+ * {@link CacheManager} found in JNDI or the {@link DefaultCacheManager} if needed.
+ *
+ * This source first attempts to find a cache instance using the {@link CacheManager} found in
+ * {@link #getCacheManagerJndiName() JNDI} (or the {@link DefaultCacheManager} if no such manager is available) and the
+ * {@link #getCacheConfigurationName() cache configuration name} if supplied or the default configuration if not set.
+ *
+ *
+ * @return the name of the configuration that should be passed to the {@link CacheManager}, or null if the default
+ * configuration should be used
+ * @see #setCacheConfigurationName(String)
+ * @see #getCacheManagerJndiName()
+ */
+ public String getCacheConfigurationName() {
+ return cacheConfigurationName;
+ }
+
+ /**
+ * Get the name of the configuration that should be used if a {@link Cache cache} is to be created using the
+ * {@link CacheManager} found in JNDI or the {@link DefaultCacheManager} if needed.
+ *
+ * This source first attempts to find a cache instance using the {@link CacheManager} found in
+ * {@link #getCacheManagerJndiName() JNDI} (or the {@link DefaultCacheManager} if no such manager is available) and the
+ * {@link #getCacheConfigurationName() cache configuration name} if supplied or the default configuration if not set.
+ *
+ *
+ * @param cacheConfigurationName the name of the configuration that should be passed to the {@link CacheManager}, or null if
+ * the default configuration should be used
+ * @see #getCacheConfigurationName()
+ * @see #getCacheManagerJndiName()
+ */
+ public synchronized void setCacheConfigurationName( String cacheConfigurationName ) {
+ if (this.cacheConfigurationName == cacheConfigurationName || this.cacheConfigurationName != null
+ && this.cacheConfigurationName.equals(cacheConfigurationName)) return; // unchanged
+ this.cacheConfigurationName = cacheConfigurationName;
+ }
+
+ /**
+ * Get the UUID of the root node for the cache. If the cache exists, this UUID is not used but is instead set to the UUID of
+ * the existing root node.
+ *
+ * @return the UUID of the root node for the cache.
+ */
+ public String getRootNodeUuid() {
+ return this.rootNodeUuid.toString();
+ }
+
+ /**
+ * Get the UUID of the root node for the cache. If the cache exists, this UUID is not used but is instead set to the UUID of
+ * the existing root node.
+ *
+ * @return the UUID of the root node for the cache.
+ */
+ public UUID getRootNodeUuidObject() {
+ return this.rootNodeUuid;
+ }
+
+ /**
+ * Set the UUID of the root node in this repository. If the cache exists, this UUID is not used but is instead set to the UUID
+ * of the existing root node.
+ *
+ * @param rootNodeUuid the UUID of the root node for the cache, or null if the UUID should be randomly generated
+ */
+ public synchronized void setRootNodeUuid( String rootNodeUuid ) {
+ UUID uuid = null;
+ if (rootNodeUuid == null) uuid = UUID.randomUUID();
+ else uuid = UUID.fromString(rootNodeUuid);
+ if (this.rootNodeUuid.equals(uuid)) return; // unchanged
+ this.rootNodeUuid = uuid;
+ }
+
+ /**
+ * Get the name of the default workspace.
+ *
+ * @return the name of the workspace that should be used by default; never null
+ */
+ public String getNameOfDefaultWorkspace() {
+ return defaultWorkspace;
+ }
+
+ /**
+ * Set the name of the workspace that should be used when clients don't specify a workspace.
+ *
+ * @param nameOfDefaultWorkspace the name of the workspace that should be used by default, or null if the
+ * {@link #DEFAULT_NAME_OF_DEFAULT_WORKSPACE default name} should be used
+ */
+ public synchronized void setNameOfDefaultWorkspace( String nameOfDefaultWorkspace ) {
+ this.defaultWorkspace = nameOfDefaultWorkspace != null ? nameOfDefaultWorkspace : DEFAULT_NAME_OF_DEFAULT_WORKSPACE;
+ }
+
+ /**
+ * Gets the names of the workspaces that are available when this source is created.
+ *
+ * @return the names of the workspaces that this source starts with, or null if there are no such workspaces
+ * @see #setPredefinedWorkspaceNames(String[])
+ * @see #setCreatingWorkspacesAllowed(boolean)
+ */
+ public synchronized String[] getPredefinedWorkspaceNames() {
+ String[] copy = new String[predefinedWorkspaces.length];
+ System.arraycopy(predefinedWorkspaces, 0, copy, 0, predefinedWorkspaces.length);
+ return copy;
+ }
+
+ /**
+ * Sets the names of the workspaces that are available when this source is created.
+ *
+ * @param predefinedWorkspaceNames the names of the workspaces that this source should start with, or null if there are no
+ * such workspaces
+ * @see #setCreatingWorkspacesAllowed(boolean)
+ * @see #getPredefinedWorkspaceNames()
+ */
+ public synchronized void setPredefinedWorkspaceNames( String[] predefinedWorkspaceNames ) {
+ this.predefinedWorkspaces = predefinedWorkspaceNames;
+ }
+
+ /**
+ * Get whether this source allows workspaces to be created dynamically.
+ *
+ * @return true if this source allows workspaces to be created by clients, or false if the
+ * {@link #getPredefinedWorkspaceNames() set of workspaces} is fixed
+ * @see #setPredefinedWorkspaceNames(String[])
+ * @see #getPredefinedWorkspaceNames()
+ * @see #setCreatingWorkspacesAllowed(boolean)
+ */
+ public boolean isCreatingWorkspacesAllowed() {
+ return capabilities.supportsCreatingWorkspaces();
+ }
+
+ /**
+ * Set whether this source allows workspaces to be created dynamically.
+ *
+ * @param allowWorkspaceCreation true if this source allows workspaces to be created by clients, or false if the
+ * {@link #getPredefinedWorkspaceNames() set of workspaces} is fixed
+ * @see #setPredefinedWorkspaceNames(String[])
+ * @see #getPredefinedWorkspaceNames()
+ * @see #isCreatingWorkspacesAllowed()
+ */
+ public synchronized void setCreatingWorkspacesAllowed( boolean allowWorkspaceCreation ) {
+ capabilities = new RepositorySourceCapabilities(true, capabilities.supportsUpdates(), false, allowWorkspaceCreation,
+ capabilities.supportsReferences());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.RepositorySource#getConnection()
+ */
+ public synchronized RepositoryConnection getConnection() throws RepositorySourceException {
+ if (getName() == null) {
+ I18n msg = InfinispanConnectorI18n.propertyIsRequired;
+ throw new RepositorySourceException(getName(), msg.text("name"));
+ }
+ if (this.repository == null) {
+ Context context = getContext();
+ if (context == null) {
+ try {
+ context = new InitialContext();
+ } catch (NamingException err) {
+ throw new RepositorySourceException(name, err);
+ }
+ }
+
+ // Look for a cache manager in JNDI ...
+ CacheManager cacheManager = null;
+ String jndiName = getCacheManagerJndiName();
+ if (jndiName != null && jndiName.trim().length() != 0) {
+ Object object = null;
+ try {
+ object = context.lookup(jndiName);
+ if (object != null) cacheManager = (CacheManager)object;
+ } catch (ClassCastException err) {
+ I18n msg = InfinispanConnectorI18n.objectFoundInJndiWasNotCacheManager;
+ String className = object != null ? object.getClass().getName() : "null";
+ throw new RepositorySourceException(getName(), msg.text(jndiName, this.getName(), className), err);
+ } catch (Throwable err) {
+ if (err instanceof RuntimeException) throw (RuntimeException)err;
+ throw new RepositorySourceException(getName(), err);
+ }
+ }
+ if (cacheManager == null) cacheManager = new DefaultCacheManager();
+
+ // Now create the repository ...
+ this.repository = new InfinispanRepository(this.name, this.rootNodeUuid, cacheManager);
+
+ // Create the set of initial names ...
+ for (String initialName : getPredefinedWorkspaceNames())
+ repository.createWorkspace(null, initialName, CreateConflictBehavior.DO_NOT_CREATE);
+
+ }
+
+ return new MapRepositoryConnection(this, this.repository);
+ }
+
+ /**
+ * @return repositoryContext
+ */
+ public RepositoryContext getRepositoryContext() {
+ return repositoryContext;
+ }
+
+ protected Observer getObserver() {
+ return repositoryContext != null ? repositoryContext.getObserver() : null;
+ }
+
+ protected Context getContext() {
+ return this.jndiContext;
+ }
+
+ protected synchronized void setContext( Context context ) {
+ this.jndiContext = context;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals( Object obj ) {
+ if (obj == this) return true;
+ if (obj instanceof InfinispanSource) {
+ InfinispanSource that = (InfinispanSource)obj;
+ if (this.getName() == null) {
+ if (that.getName() != null) return false;
+ } else {
+ if (!this.getName().equals(that.getName())) return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized Reference getReference() {
+ String className = getClass().getName();
+ String managerClassName = this.getClass().getName();
+ Reference ref = new Reference(className, managerClassName, null);
+
+ ref.add(new StringRefAddr(SOURCE_NAME, getName()));
+ ref.add(new StringRefAddr(ROOT_NODE_UUID, getRootNodeUuid().toString()));
+ ref.add(new StringRefAddr(CACHE_FACTORY_JNDI_NAME, getCacheManagerJndiName()));
+ ref.add(new StringRefAddr(CACHE_CONFIGURATION_NAME, getCacheConfigurationName()));
+ ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
+ ref.add(new StringRefAddr(DEFAULT_WORKSPACE, getNameOfDefaultWorkspace()));
+ ref.add(new StringRefAddr(ALLOW_CREATING_WORKSPACES, Boolean.toString(isCreatingWorkspacesAllowed())));
+ String[] workspaceNames = getPredefinedWorkspaceNames();
+ if (workspaceNames != null && workspaceNames.length != 0) {
+ ref.add(new StringRefAddr(PREDEFINED_WORKSPACE_NAMES, StringUtil.combineLines(workspaceNames)));
+ }
+ if (getDefaultCachePolicy() != null) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ CachePolicy policy = getDefaultCachePolicy();
+ try {
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(policy);
+ ref.add(new BinaryRefAddr(DEFAULT_CACHE_POLICY, baos.toByteArray()));
+ } catch (IOException e) {
+ I18n msg = InfinispanConnectorI18n.errorSerializingCachePolicyInSource;
+ throw new RepositorySourceException(getName(), msg.text(policy.getClass().getName(), getName()), e);
+ }
+ }
+ return ref;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getObjectInstance( Object obj,
+ javax.naming.Name name,
+ Context nameCtx,
+ Hashtable, ?> environment ) throws Exception {
+ if (obj instanceof Reference) {
+ Map values = new HashMap();
+ Reference ref = (Reference)obj;
+ Enumeration> en = ref.getAll();
+ while (en.hasMoreElements()) {
+ RefAddr subref = (RefAddr)en.nextElement();
+ if (subref instanceof StringRefAddr) {
+ String key = subref.getType();
+ Object value = subref.getContent();
+ if (value != null) values.put(key, value.toString());
+ } else if (subref instanceof BinaryRefAddr) {
+ String key = subref.getType();
+ Object value = subref.getContent();
+ if (value instanceof byte[]) {
+ // Deserialize ...
+ ByteArrayInputStream bais = new ByteArrayInputStream((byte[])value);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ value = ois.readObject();
+ values.put(key, value);
+ }
+ }
+ }
+ String sourceName = (String)values.get(SOURCE_NAME);
+ String rootNodeUuidString = (String)values.get(ROOT_NODE_UUID);
+ String cacheManagerJndiName = (String)values.get(CACHE_FACTORY_JNDI_NAME);
+ String cacheConfigurationName = (String)values.get(CACHE_CONFIGURATION_NAME);
+ Object defaultCachePolicy = values.get(DEFAULT_CACHE_POLICY);
+ String retryLimit = (String)values.get(RETRY_LIMIT);
+ String defaultWorkspace = (String)values.get(DEFAULT_WORKSPACE);
+ String createWorkspaces = (String)values.get(ALLOW_CREATING_WORKSPACES);
+
+ String combinedWorkspaceNames = (String)values.get(PREDEFINED_WORKSPACE_NAMES);
+ String[] workspaceNames = null;
+ if (combinedWorkspaceNames != null) {
+ List paths = StringUtil.splitLines(combinedWorkspaceNames);
+ workspaceNames = paths.toArray(new String[paths.size()]);
+ }
+
+ // Create the source instance ...
+ InfinispanSource source = new InfinispanSource();
+ if (sourceName != null) source.setName(sourceName);
+ if (rootNodeUuidString != null) source.setRootNodeUuid(rootNodeUuidString);
+ if (cacheManagerJndiName != null) source.setCacheManagerJndiName(cacheManagerJndiName);
+ if (cacheConfigurationName != null) source.setCacheConfigurationName(cacheConfigurationName);
+ if (defaultCachePolicy instanceof CachePolicy) {
+ source.setDefaultCachePolicy((CachePolicy)defaultCachePolicy);
+ }
+ if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
+ if (defaultWorkspace != null) source.setNameOfDefaultWorkspace(defaultWorkspace);
+ if (createWorkspaces != null) source.setCreatingWorkspacesAllowed(Boolean.parseBoolean(createWorkspaces));
+ if (workspaceNames != null && workspaceNames.length != 0) source.setPredefinedWorkspaceNames(workspaceNames);
+ return source;
+ }
+ return null;
+ }
+}
Property changes on: extensions\dna-connector-infinispan\src\main\java\org\jboss\dna\connector\infinispan\InfinispanSource.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-infinispan/src/main/resources/org/jboss/dna/connector/infinispan/InfinispanConnectorI18n.properties
===================================================================
--- extensions/dna-connector-infinispan/src/main/resources/org/jboss/dna/connector/infinispan/InfinispanConnectorI18n.properties (revision 0)
+++ extensions/dna-connector-infinispan/src/main/resources/org/jboss/dna/connector/infinispan/InfinispanConnectorI18n.properties (revision 0)
@@ -0,0 +1,36 @@
+#
+# JBoss DNA (http://www.jboss.org/dna)
+# See the COPYRIGHT.txt file distributed with this work for information
+# regarding copyright ownership. Some portions may be licensed
+# to Red Hat, Inc. under one or more contributor license agreements.
+# See the AUTHORS.txt file in the distribution for a full listing of
+# individual contributors.
+#
+# JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+# is licensed to you 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.
+#
+# JBoss DNA 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.
+#
+
+connectorName = Infinispan Connector
+nodeDoesNotExist = Could not find an existing node at {0}
+propertyIsRequired = The {0} property is required but has no value
+errorSerializingCachePolicyInSource = Error serializing a {0} instance owned by the {1} InfinispanSource
+objectFoundInJndiWasNotCacheManager = Object in JNDI at {0} found by InfinispanSource {1} was expected to be a org.infinispan.CacheManager but instead was {2}
+#unableToCloneWorkspaces = The InfinispanSource {0} does not allow creating workspaces, so unable to clone workspace "{1}" into "{2}"
+#unableToCreateWorkspaces = The InfinispanSource {0} does not allow creating workspaces, so unable to create workspace "{1}"
+unableToCreateWorkspace = Unable to create new workspace "{1}" in the InfinispanSource {0}
+workspaceAlreadyExists = The workspace "{1}" already exists in the InfinispanSource {0}
+workspaceDoesNotExist = The workspace "{1}" does not exist in the InfinispanSource {0}
+workspaceNameWasNotValidConfiguration = The workspace name "{0}" was not a valid Infinispan Cache Manager configuration name: {1}
+defaultCacheManagerConfigurationNameWasNotValidConfiguration = "{0}" is not a valid Infinispan Cache Manager configuration name
Index: extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanConnectorI18nTest.java
===================================================================
--- extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanConnectorI18nTest.java (revision 0)
+++ extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanConnectorI18nTest.java (revision 0)
@@ -0,0 +1,36 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.infinispan;
+
+import org.jboss.dna.common.AbstractI18nTest;
+
+/**
+ * @author Randall Hauch
+ */
+public class InfinispanConnectorI18nTest extends AbstractI18nTest {
+
+ public InfinispanConnectorI18nTest() {
+ super(InfinispanConnectorI18n.class);
+ }
+}
Property changes on: extensions\dna-connector-infinispan\src\test\java\org\jboss\dna\connector\infinispan\InfinispanConnectorI18nTest.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanConnectorReadableTest.java
===================================================================
--- extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanConnectorReadableTest.java (revision 0)
+++ extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanConnectorReadableTest.java (revision 0)
@@ -0,0 +1,58 @@
+package org.jboss.dna.connector.infinispan;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.io.File;
+import java.io.IOException;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.test.ReadableConnectorTest;
+import org.xml.sax.SAXException;
+
+public class InfinispanConnectorReadableTest extends ReadableConnectorTest {
+
+ private Context mockJndi;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws NamingException {
+ // Set the connection properties to be use the content of "./src/test/resources/repositories" as a repository ...
+ String[] predefinedWorkspaceNames = new String[] {"aircraft", "cars"};
+ InfinispanSource source = new InfinispanSource();
+ source.setName("Test Repository");
+ source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
+ source.setNameOfDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setCreatingWorkspacesAllowed(false);
+
+ // Set up the mock JNDI ...
+ mockJndi = mock(Context.class);
+ stub(mockJndi.lookup(anyString())).toReturn(null);
+ source.setContext(mockJndi);
+
+ return source;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws SAXException
+ * @throws IOException
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#initializeContent(org.jboss.dna.graph.Graph)
+ */
+ @Override
+ protected void initializeContent( Graph graph ) throws IOException, SAXException {
+ graph.useWorkspace("aircraft");
+ graph.importXmlFrom(new File("src/test/resources/aircraft.xml")).into("/");
+
+ graph.useWorkspace("cars");
+ graph.importXmlFrom(new File("src/test/resources/cars.xml")).into("/");
+ }
+
+}
Property changes on: extensions\dna-connector-infinispan\src\test\java\org\jboss\dna\connector\infinispan\InfinispanConnectorReadableTest.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanConnectorWritableTest.java
===================================================================
--- extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanConnectorWritableTest.java (revision 0)
+++ extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanConnectorWritableTest.java (revision 0)
@@ -0,0 +1,53 @@
+package org.jboss.dna.connector.infinispan;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.io.IOException;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.connector.RepositorySource;
+import org.jboss.dna.graph.connector.test.WritableConnectorTest;
+import org.xml.sax.SAXException;
+
+public class InfinispanConnectorWritableTest extends WritableConnectorTest {
+
+ private Context mockJndi;
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#setUpSource()
+ */
+ @Override
+ protected RepositorySource setUpSource() throws NamingException {
+ String[] predefinedWorkspaceNames = new String[] {"default"};
+ InfinispanSource source = new InfinispanSource();
+ source.setName("Test Repository");
+ source.setPredefinedWorkspaceNames(predefinedWorkspaceNames);
+ source.setNameOfDefaultWorkspace(predefinedWorkspaceNames[0]);
+ source.setCreatingWorkspacesAllowed(true);
+
+ // Set up the mock JNDI ...
+ mockJndi = mock(Context.class);
+ stub(mockJndi.lookup(anyString())).toReturn(null);
+ source.setContext(mockJndi);
+
+ Graph graph = Graph.create(source, context);
+ graph.useWorkspace("default");
+
+ return source;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @throws SAXException
+ * @throws IOException
+ * @see org.jboss.dna.graph.connector.test.AbstractConnectorTest#initializeContent(org.jboss.dna.graph.Graph)
+ */
+ @Override
+ protected void initializeContent( Graph graph ) throws IOException, SAXException {
+ }
+}
Property changes on: extensions\dna-connector-infinispan\src\test\java\org\jboss\dna\connector\infinispan\InfinispanConnectorWritableTest.java
___________________________________________________________________
Added: svn:keywords
+ Id Revision
Added: svn:eol-style
+ LF
Index: extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanSourceTest.java
===================================================================
--- extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanSourceTest.java (revision 0)
+++ extensions/dna-connector-infinispan/src/test/java/org/jboss/dna/connector/infinispan/InfinispanSourceTest.java (revision 0)
@@ -0,0 +1,218 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ *
+ * JBoss DNA 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.dna.connector.infinispan;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.stub;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import org.infinispan.manager.CacheManager;
+import org.jboss.dna.graph.cache.BasicCachePolicy;
+import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ */
+public class InfinispanSourceTest {
+
+ private InfinispanSource source;
+ private RepositoryConnection connection;
+ private String validName;
+ private String validCacheConfigurationName;
+ private String validCacheManagerJndiName;
+ private UUID validRootNodeUuid;
+ @Mock
+ private Context jndiContext;
+ @Mock
+ private CacheManager cacheManager;
+
+ @Before
+ public void beforeEach() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ validName = "cache source";
+ validCacheConfigurationName = "cache config name";
+ validCacheManagerJndiName = "cache factory jndi name";
+ validRootNodeUuid = UUID.randomUUID();
+ source = new InfinispanSource();
+
+ // Set up the fake JNDI context ...
+ source.setContext(jndiContext);
+ stub(jndiContext.lookup(validCacheManagerJndiName)).toReturn(cacheManager);
+ }
+
+ @After
+ public void afterEach() throws Exception {
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ @Test
+ public void shouldReturnNonNullCapabilities() {
+ assertThat(source.getCapabilities(), is(notNullValue()));
+ }
+
+ @Test
+ public void shouldSupportSameNameSiblings() {
+ assertThat(source.getCapabilities().supportsSameNameSiblings(), is(true));
+ }
+
+ @Test
+ public void shouldSupportUpdates() {
+ assertThat(source.getCapabilities().supportsUpdates(), is(true));
+ }
+
+ @Test
+ public void shouldHaveNullSourceNameUponConstruction() {
+ source = new InfinispanSource();
+ assertThat(source.getName(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldAllowSettingName() {
+ source.setName("Something");
+ assertThat(source.getName(), is("Something"));
+ source.setName("another name");
+ assertThat(source.getName(), is("another name"));
+ }
+
+ @Test
+ public void shouldAllowSettingNameToNull() {
+ source.setName("some name");
+ source.setName(null);
+ assertThat(source.getName(), is(nullValue()));
+ }
+
+ @Test
+ public void shouldHaveDefaultRetryLimit() {
+ assertThat(source.getRetryLimit(), is(InfinispanSource.DEFAULT_RETRY_LIMIT));
+ }
+
+ @Test
+ public void shouldSetRetryLimitToZeroWhenSetWithNonPositiveValue() {
+ source.setRetryLimit(0);
+ assertThat(source.getRetryLimit(), is(0));
+ source.setRetryLimit(-1);
+ assertThat(source.getRetryLimit(), is(0));
+ source.setRetryLimit(-100);
+ assertThat(source.getRetryLimit(), is(0));
+ }
+
+ @Test
+ public void shouldAllowRetryLimitToBeSet() {
+ for (int i = 0; i != 100; ++i) {
+ source.setRetryLimit(i);
+ assertThat(source.getRetryLimit(), is(i));
+ }
+ }
+
+ @Test
+ public void shouldCreateJndiReferenceAndRecreatedObjectFromReference() throws Exception {
+ BasicCachePolicy cachePolicy = new BasicCachePolicy();
+ cachePolicy.setTimeToLive(1000L, TimeUnit.MILLISECONDS);
+ convertToAndFromJndiReference(validName,
+ validRootNodeUuid,
+ validCacheConfigurationName,
+ validCacheManagerJndiName,
+ cachePolicy,
+ 100);
+ }
+
+ @Test
+ public void shouldCreateJndiReferenceAndRecreatedObjectFromReferenceWithNullProperties() throws Exception {
+ BasicCachePolicy cachePolicy = new BasicCachePolicy();
+ cachePolicy.setTimeToLive(1000L, TimeUnit.MILLISECONDS);
+ convertToAndFromJndiReference("some source", null, null, null, null, 100);
+ convertToAndFromJndiReference(null, null, null, null, null, 100);
+ }
+
+ private void convertToAndFromJndiReference( String sourceName,
+ UUID rootNodeUuid,
+ String cacheConfigName,
+ String cacheManagerJndiName,
+ BasicCachePolicy cachePolicy,
+ int retryLimit ) throws Exception {
+ source.setRetryLimit(retryLimit);
+ source.setName(sourceName);
+ source.setCacheConfigurationName(cacheConfigName);
+ source.setCacheManagerJndiName(cacheManagerJndiName);
+ source.setDefaultCachePolicy(cachePolicy);
+ source.setRootNodeUuid(rootNodeUuid != null ? rootNodeUuid.toString() : null);
+
+ Reference ref = source.getReference();
+ assertThat(ref.getClassName(), is(InfinispanSource.class.getName()));
+ assertThat(ref.getFactoryClassName(), is(InfinispanSource.class.getName()));
+
+ Map refAttributes = new HashMap();
+ Enumeration enumeration = ref.getAll();
+ while (enumeration.hasMoreElements()) {
+ RefAddr addr = enumeration.nextElement();
+ refAttributes.put(addr.getType(), addr.getContent());
+ }
+
+ // Recreate the object, use a newly constructed source ...
+ ObjectFactory factory = new InfinispanSource();
+ Name name = mock(Name.class);
+ Context context = mock(Context.class);
+ Hashtable, ?> env = new Hashtable