Author: rhauch
Date: 2008-09-16 15:03:58 -0400 (Tue, 16 Sep 2008)
New Revision: 521
Added:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryContext.java
trunk/docs/examples/gettingstarted/repositories/src/test/resources/log4j.properties
Removed:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/TimeDelayingRepositorySource.java
trunk/docs/examples/gettingstarted/repositories/pom.xml
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java
trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.xml
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml
trunk/docs/examples/gettingstarted/repositories/src/main/resources/log4j.properties
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositoryConnection.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
trunk/extensions/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryConnection.java
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
Log:
DNA-222 - Create Getting Started example application for repositories
http://jira.jboss.com/jira/browse/DNA-222
Changed how the RepositorySource instances are initialized, removing the need to use JNDI
for the FederatedRepositorySource (since the ExecutionContextFactory and
RepositoryConnectionFactory are not serializable and could not be placed inside JNDI);
instead, RepositoryLibrary (formerly RepositorySourceManager) now initializes each
RepositorySource with a RepositoryContext when the RepositorySource is added to the
library. This completely removes the need to use JNDI to look up DNA components, since
they are all injected into the correct locations as needed.
Completed more unit testing. Still lacking tests that use JCR implementation, but that
will follow shortly.
Copied: trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java
(from rev 516,
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java)
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java
(rev 0)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryLibrary.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -0,0 +1,453 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.dna.repository;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.util.ArgCheck;
+import org.jboss.dna.repository.services.AbstractServiceAdministrator;
+import org.jboss.dna.repository.services.ServiceAdministrator;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.ExecutionContextFactory;
+import org.jboss.dna.spi.connector.BasicExecutionContextFactory;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.RepositoryConnectionPool;
+import org.jboss.dna.spi.connector.RepositoryContext;
+import org.jboss.dna.spi.connector.RepositorySource;
+
+/**
+ * A library of {@link RepositorySource} instances and the {@link
RepositoryConnectionPool} used to manage the connections for
+ * each.
+ *
+ * @author Randall Hauch
+ */
+@ThreadSafe
+public class RepositoryLibrary implements RepositoryConnectionFactory {
+
+ /**
+ * The administrative component for this service.
+ *
+ * @author Randall Hauch
+ */
+ protected class Administrator extends AbstractServiceAdministrator {
+
+ protected Administrator() {
+ super(RepositoryI18n.federationServiceName, State.STARTED);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doStart( State fromState ) {
+ super.doStart(fromState);
+ RepositoryLibrary.this.start();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doShutdown( State fromState ) {
+ super.doShutdown(fromState);
+ RepositoryLibrary.this.shutdown();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean awaitTermination( long timeout,
+ TimeUnit unit ) throws InterruptedException {
+ return RepositoryLibrary.this.awaitTermination(timeout, unit);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean doCheckIsTerminated() {
+ return RepositoryLibrary.this.isTerminated();
+ }
+
+ }
+
+ private final ServiceAdministrator administrator = new Administrator();
+ private final ReadWriteLock sourcesLock = new ReentrantReadWriteLock();
+ private final CopyOnWriteArrayList<RepositoryConnectionPool> pools = new
CopyOnWriteArrayList<RepositoryConnectionPool>();
+ private RepositoryConnectionFactory delegate;
+ private final ExecutionContextFactory executionContextFactory;
+ private final RepositoryContext repositoryContext;
+
+ /**
+ * Create a new manager instance.
+ */
+ public RepositoryLibrary() {
+ this(new BasicExecutionContextFactory(), null);
+ }
+
+ /**
+ * Create a new manager instance.
+ *
+ * @param delegate the connection factory to which this instance should delegate in
the event that a source is not found in
+ * this manager; may be null if there is no delegate
+ */
+ public RepositoryLibrary( RepositoryConnectionFactory delegate ) {
+ this(new BasicExecutionContextFactory(), delegate);
+ }
+
+ /**
+ * Create a new manager instance.
+ *
+ * @param executionContextFactory the execution context factory, used by sources to
create {@link ExecutionContext} instances
+ * @throws IllegalArgumentException if the
<code>executionContextFactory</code> reference is null
+ */
+ public RepositoryLibrary( ExecutionContextFactory executionContextFactory ) {
+ this(executionContextFactory, null);
+ }
+
+ /**
+ * Create a new manager instance.
+ *
+ * @param executionContextFactory the execution context factory, used by sources to
create {@link ExecutionContext} instances
+ * @param delegate the connection factory to which this instance should delegate in
the event that a source is not found in
+ * this manager; may be null if there is no delegate
+ * @throws IllegalArgumentException if the
<code>executionContextFactory</code> reference is null
+ */
+ public RepositoryLibrary( ExecutionContextFactory executionContextFactory,
+ RepositoryConnectionFactory delegate ) {
+ ArgCheck.isNotNull(executionContextFactory,
"executionContextFactory");
+ this.delegate = delegate;
+ this.executionContextFactory = executionContextFactory;
+ this.repositoryContext = new RepositoryContext() {
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.connector.RepositoryContext#getExecutionContextFactory()
+ */
+ public ExecutionContextFactory getExecutionContextFactory() {
+ return RepositoryLibrary.this.getExecutionContextFactory();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.connector.RepositoryContext#getRepositoryConnectionFactory()
+ */
+ public RepositoryConnectionFactory getRepositoryConnectionFactory() {
+ return RepositoryLibrary.this;
+ }
+ };
+ }
+
+ /**
+ * @return executionContextFactory
+ */
+ public ExecutionContextFactory getExecutionContextFactory() {
+ return executionContextFactory;
+ }
+
+ /**
+ * Get the delegate connection factory.
+ *
+ * @return the connection factory to which this instance should delegate in the event
that a source is not found in this
+ * manager, or null if there is no delegate
+ */
+ public RepositoryConnectionFactory getDelegate() {
+ return delegate;
+ }
+
+ /**
+ * Set the delegate connection factory.
+ *
+ * @param delegate the connection factory to which this instance should delegate in
the event that a source is not found in
+ * this manager; may be null if there is no delegate
+ */
+ public void setDelegate( RepositoryConnectionFactory delegate ) {
+ this.delegate = delegate;
+ }
+
+ /**
+ * @return administrator
+ */
+ public ServiceAdministrator getAdministrator() {
+ return this.administrator;
+ }
+
+ /**
+ * Utility method called by the administrator.
+ */
+ protected void start() {
+ // Do not establish connections to the pools; these will be established as
needed
+
+ }
+
+ /**
+ * Utility method called by the administrator.
+ */
+ protected void shutdown() {
+ // Close all connections to the pools. This is done inside the pools write lock.
+ try {
+ this.sourcesLock.readLock().lock();
+ for (RepositoryConnectionPool pool : this.pools) {
+ pool.shutdown();
+ }
+ } finally {
+ this.sourcesLock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Utility method called by the administrator.
+ *
+ * @param timeout
+ * @param unit
+ * @return true if all pools were terminated in the supplied time (or were already
terminated), or false if the timeout
+ * occurred before all the connections were closed
+ * @throws InterruptedException
+ */
+ protected boolean awaitTermination( long timeout,
+ TimeUnit unit ) throws InterruptedException {
+ // Check whether all source pools are shut down. This is done inside the pools
write lock.
+ try {
+ this.sourcesLock.readLock().lock();
+ for (RepositoryConnectionPool pool : this.pools) {
+ if (!pool.awaitTermination(timeout, unit)) return false;
+ }
+ return true;
+ } finally {
+ this.sourcesLock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Returns true if this federated repository is in the process of terminating after
{@link ServiceAdministrator#shutdown()}
+ * has been called on the {@link #getAdministrator() administrator}, but the
federated repository has connections that have
+ * not yet normally been {@link RepositoryConnection#close() closed}. This method may
be useful for debugging. A return of
+ * <tt>true</tt> reported a sufficient period after shutdown may indicate
that connection users have ignored or suppressed
+ * interruption, causing this repository not to properly terminate.
+ *
+ * @return true if terminating but not yet terminated, or false otherwise
+ * @see #isTerminated()
+ */
+ public boolean isTerminating() {
+ try {
+ this.sourcesLock.readLock().lock();
+ for (RepositoryConnectionPool pool : this.pools) {
+ if (pool.isTerminating()) return true;
+ }
+ return false;
+ } finally {
+ this.sourcesLock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Return true if this federated repository has completed its termination and no
longer has any open connections.
+ *
+ * @return true if terminated, or false otherwise
+ * @see #isTerminating()
+ */
+ public boolean isTerminated() {
+ try {
+ this.sourcesLock.readLock().lock();
+ for (RepositoryConnectionPool pool : this.pools) {
+ if (!pool.isTerminated()) return false;
+ }
+ return true;
+ } finally {
+ this.sourcesLock.readLock().unlock();
+ }
+ }
+
+ /**
+ * Get an unmodifiable collection of {@link RepositorySource} names.
+ *
+ * @return the pools
+ */
+ public Collection<String> getSourceNames() {
+ Set<String> sourceNames = new HashSet<String>();
+ for (RepositoryConnectionPool pool : this.pools) {
+ sourceNames.add(pool.getRepositorySource().getName());
+ }
+ return Collections.unmodifiableCollection(sourceNames);
+ }
+
+ /**
+ * Get an unmodifiable collection of {@link RepositorySource} instances managed by
this instance.
+ *
+ * @return the pools
+ */
+ public Collection<RepositorySource> getSources() {
+ List<RepositorySource> sources = new LinkedList<RepositorySource>();
+ for (RepositoryConnectionPool pool : this.pools) {
+ sources.add(pool.getRepositorySource());
+ }
+ return Collections.unmodifiableCollection(sources);
+ }
+
+ /**
+ * Get the RepositorySource with the specified name managed by this instance.
+ *
+ * @param sourceName the name of the source
+ * @return the source, or null if no such source exists in this instance
+ */
+ public RepositorySource getSource( String sourceName ) {
+ try {
+ this.sourcesLock.readLock().lock();
+ for (RepositoryConnectionPool existingPool : this.pools) {
+ RepositorySource source = existingPool.getRepositorySource();
+ if (source.getName().equals(sourceName)) return source;
+ }
+ } finally {
+ this.sourcesLock.readLock().unlock();
+ }
+ return null;
+ }
+
+ /**
+ * Get the connection pool managing the {@link RepositorySource} with the specified
name managed by this instance.
+ *
+ * @param sourceName the name of the source
+ * @return the pool, or null if no such pool exists in this instance
+ */
+ public RepositoryConnectionPool getConnectionPool( String sourceName ) {
+ try {
+ this.sourcesLock.readLock().lock();
+ for (RepositoryConnectionPool existingPool : this.pools) {
+ RepositorySource source = existingPool.getRepositorySource();
+ if (source.getName().equals(sourceName)) return existingPool;
+ }
+ } finally {
+ this.sourcesLock.readLock().unlock();
+ }
+ return null;
+ }
+
+ /**
+ * Add the supplied federated source. This method returns false if the source is
null.
+ *
+ * @param source the source to add
+ * @return true if the source is added, or false if the reference is null or if there
is already an existing source with the
+ * supplied name.
+ */
+ public boolean addSource( RepositorySource source ) {
+ if (source == null) return false;
+ try {
+ this.sourcesLock.writeLock().lock();
+ for (RepositoryConnectionPool existingPool : this.pools) {
+ if
(existingPool.getRepositorySource().getName().equals(source.getName())) return false;
+ }
+ source.initialize(repositoryContext);
+ RepositoryConnectionPool pool = new RepositoryConnectionPool(source);
+ this.pools.add(pool);
+ return true;
+ } finally {
+ this.sourcesLock.writeLock().unlock();
+ }
+ }
+
+ /**
+ * Remove from this federated repository the supplied source (or a source with the
same name as that supplied). This call
+ * shuts down the connections in the source in an orderly fashion, allowing those
connection currently in use to be used and
+ * closed normally, but preventing further connections from being used.
+ * <p>
+ * This method can safely be called while the federation repository is in use.
+ * </p>
+ *
+ * @param source the source to be removed
+ * @param timeToAwait the amount of time to wait while all of the source's
connections are closed, or non-positive if the call
+ * should not wait at all
+ * @param unit the time unit to be used for <code>timeToAwait</code>
+ * @return true if the source was removed, or false if the source was not a source
for this repository.
+ * @throws InterruptedException if the thread is interrupted while awaiting closing
of the connections
+ */
+ public boolean removeSource( RepositorySource source,
+ long timeToAwait,
+ TimeUnit unit ) throws InterruptedException {
+ // Use the name; don't use the object equality ...
+ return removeSource(source.getName(), timeToAwait, unit) != null;
+ }
+
+ /**
+ * Remove from this federated repository the source with the supplied name. This call
shuts down the connections in the source
+ * in an orderly fashion, allowing those connection currently in use to be used and
closed normally, but preventing further
+ * connections from being used.
+ *
+ * @param name the name of the source to be removed
+ * @param timeToAwait the amount of time to wait while all of the source's
connections are closed, or non-positive if the call
+ * should not wait at all
+ * @param unit the time unit to be used for <code>timeToAwait</code>
+ * @return the source with the supplied name that was removed, or null if no existing
source matching the supplied name could
+ * be found
+ * @throws InterruptedException if the thread is interrupted while awaiting closing
of the connections
+ */
+ public RepositorySource removeSource( String name,
+ long timeToAwait,
+ TimeUnit unit ) throws InterruptedException {
+ try {
+ this.sourcesLock.writeLock().lock();
+ for (RepositoryConnectionPool existingPool : this.pools) {
+ if (existingPool.getRepositorySource().getName().equals(name)) {
+ // Shut down the source ...
+ existingPool.shutdown();
+ if (timeToAwait > 0L) existingPool.awaitTermination(timeToAwait,
unit);
+ }
+ return existingPool.getRepositorySource();
+ }
+ } finally {
+ this.sourcesLock.writeLock().unlock();
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.connector.RepositoryConnectionFactory#createConnection(java.lang.String)
+ */
+ public RepositoryConnection createConnection( String sourceName ) {
+ try {
+ this.sourcesLock.readLock().lock();
+ for (RepositoryConnectionPool existingPool : this.pools) {
+ RepositorySource source = existingPool.getRepositorySource();
+ if (source.getName().equals(sourceName)) return
existingPool.getConnection();
+ }
+ RepositoryConnectionFactory delegate = this.delegate;
+ if (delegate != null) {
+ return delegate.createConnection(sourceName);
+ }
+ } finally {
+ this.sourcesLock.readLock().unlock();
+ }
+ return null;
+ }
+}
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositoryService.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -101,7 +101,7 @@
private final ClassLoaderFactory classLoaderFactory;
private final ExecutionContext context;
- private final RepositorySourceManager sources;
+ private final RepositoryLibrary sources;
private final String configurationSourceName;
private final Path pathToConfigurationRoot;
private final Administrator administrator = new Administrator();
@@ -120,7 +120,7 @@
* loaded this class.
* @throws IllegalArgumentException if the bootstrap source is null or the execution
context is null
*/
- public RepositoryService( RepositorySourceManager sources,
+ public RepositoryService( RepositoryLibrary sources,
String configurationSourceName,
ExecutionContext context,
ClassLoaderFactory classLoaderFactory ) {
@@ -142,7 +142,7 @@
* loaded this class.
* @throws IllegalArgumentException if the bootstrap source is null or the execution
context is null
*/
- public RepositoryService( RepositorySourceManager sources,
+ public RepositoryService( RepositoryLibrary sources,
String configurationSourceName,
Path pathToConfigurationRoot,
ExecutionContext context,
@@ -175,7 +175,7 @@
/**
* @return sources
*/
- public RepositorySourceManager getRepositorySourceManager() {
+ public RepositoryLibrary getRepositorySourceManager() {
return sources;
}
Deleted:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/RepositorySourceManager.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -1,394 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 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.dna.repository;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.repository.services.AbstractServiceAdministrator;
-import org.jboss.dna.repository.services.ServiceAdministrator;
-import org.jboss.dna.spi.connector.RepositoryConnection;
-import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
-import org.jboss.dna.spi.connector.RepositoryConnectionPool;
-import org.jboss.dna.spi.connector.RepositorySource;
-
-/**
- * A manager of {@link RepositorySource} instances and the {@link
RepositoryConnectionPool} used to manage the connections for
- * each.
- *
- * @author Randall Hauch
- */
-@ThreadSafe
-public class RepositorySourceManager implements RepositoryConnectionFactory {
-
- /**
- * The administrative component for this service.
- *
- * @author Randall Hauch
- */
- protected class Administrator extends AbstractServiceAdministrator {
-
- protected Administrator() {
- super(RepositoryI18n.federationServiceName, State.STARTED);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void doStart( State fromState ) {
- super.doStart(fromState);
- RepositorySourceManager.this.start();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void doShutdown( State fromState ) {
- super.doShutdown(fromState);
- RepositorySourceManager.this.shutdown();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean awaitTermination( long timeout,
- TimeUnit unit ) throws InterruptedException {
- return RepositorySourceManager.this.awaitTermination(timeout, unit);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected boolean doCheckIsTerminated() {
- return RepositorySourceManager.this.isTerminated();
- }
-
- }
-
- private final ServiceAdministrator administrator = new Administrator();
- private final ReadWriteLock sourcesLock = new ReentrantReadWriteLock();
- private final CopyOnWriteArrayList<RepositoryConnectionPool> pools = new
CopyOnWriteArrayList<RepositoryConnectionPool>();
- private RepositoryConnectionFactory delegate;
-
- /**
- * Create a new manager instance.
- */
- public RepositorySourceManager() {
- this(null);
- }
-
- /**
- * Create a new manager instance.
- *
- * @param delegate the connection factory to which this instance should delegate in
the event that a source is not found in
- * this manager; may be null if there is no delegate
- */
- public RepositorySourceManager( RepositoryConnectionFactory delegate ) {
- this.delegate = delegate;
- }
-
- /**
- * Get the delegate connection factory.
- *
- * @return the connection factory to which this instance should delegate in the event
that a source is not found in this
- * manager, or null if there is no delegate
- */
- public RepositoryConnectionFactory getDelegate() {
- return delegate;
- }
-
- /**
- * Set the delegate connection factory.
- *
- * @param delegate the connection factory to which this instance should delegate in
the event that a source is not found in
- * this manager; may be null if there is no delegate
- */
- public void setDelegate( RepositoryConnectionFactory delegate ) {
- this.delegate = delegate;
- }
-
- /**
- * @return administrator
- */
- public ServiceAdministrator getAdministrator() {
- return this.administrator;
- }
-
- /**
- * Utility method called by the administrator.
- */
- protected void start() {
- // Do not establish connections to the pools; these will be established as
needed
-
- }
-
- /**
- * Utility method called by the administrator.
- */
- protected void shutdown() {
- // Close all connections to the pools. This is done inside the pools write lock.
- try {
- this.sourcesLock.readLock().lock();
- for (RepositoryConnectionPool pool : this.pools) {
- pool.shutdown();
- }
- } finally {
- this.sourcesLock.readLock().unlock();
- }
- }
-
- /**
- * Utility method called by the administrator.
- *
- * @param timeout
- * @param unit
- * @return true if all pools were terminated in the supplied time (or were already
terminated), or false if the timeout
- * occurred before all the connections were closed
- * @throws InterruptedException
- */
- protected boolean awaitTermination( long timeout,
- TimeUnit unit ) throws InterruptedException {
- // Check whether all source pools are shut down. This is done inside the pools
write lock.
- try {
- this.sourcesLock.readLock().lock();
- for (RepositoryConnectionPool pool : this.pools) {
- if (!pool.awaitTermination(timeout, unit)) return false;
- }
- return true;
- } finally {
- this.sourcesLock.readLock().unlock();
- }
- }
-
- /**
- * Returns true if this federated repository is in the process of terminating after
{@link ServiceAdministrator#shutdown()}
- * has been called on the {@link #getAdministrator() administrator}, but the
federated repository has connections that have
- * not yet normally been {@link RepositoryConnection#close() closed}. This method may
be useful for debugging. A return of
- * <tt>true</tt> reported a sufficient period after shutdown may indicate
that connection users have ignored or suppressed
- * interruption, causing this repository not to properly terminate.
- *
- * @return true if terminating but not yet terminated, or false otherwise
- * @see #isTerminated()
- */
- public boolean isTerminating() {
- try {
- this.sourcesLock.readLock().lock();
- for (RepositoryConnectionPool pool : this.pools) {
- if (pool.isTerminating()) return true;
- }
- return false;
- } finally {
- this.sourcesLock.readLock().unlock();
- }
- }
-
- /**
- * Return true if this federated repository has completed its termination and no
longer has any open connections.
- *
- * @return true if terminated, or false otherwise
- * @see #isTerminating()
- */
- public boolean isTerminated() {
- try {
- this.sourcesLock.readLock().lock();
- for (RepositoryConnectionPool pool : this.pools) {
- if (!pool.isTerminated()) return false;
- }
- return true;
- } finally {
- this.sourcesLock.readLock().unlock();
- }
- }
-
- /**
- * Get an unmodifiable collection of {@link RepositorySource} names.
- *
- * @return the pools
- */
- public Collection<String> getSourceNames() {
- Set<String> sourceNames = new HashSet<String>();
- for (RepositoryConnectionPool pool : this.pools) {
- sourceNames.add(pool.getRepositorySource().getName());
- }
- return Collections.unmodifiableCollection(sourceNames);
- }
-
- /**
- * Get an unmodifiable collection of {@link RepositorySource} instances managed by
this instance.
- *
- * @return the pools
- */
- public Collection<RepositorySource> getSources() {
- List<RepositorySource> sources = new LinkedList<RepositorySource>();
- for (RepositoryConnectionPool pool : this.pools) {
- sources.add(pool.getRepositorySource());
- }
- return Collections.unmodifiableCollection(sources);
- }
-
- /**
- * Get the RepositorySource with the specified name managed by this instance.
- *
- * @param sourceName the name of the source
- * @return the source, or null if no such source exists in this instance
- */
- public RepositorySource getSource( String sourceName ) {
- try {
- this.sourcesLock.readLock().lock();
- for (RepositoryConnectionPool existingPool : this.pools) {
- RepositorySource source = existingPool.getRepositorySource();
- if (source.getName().equals(sourceName)) return source;
- }
- } finally {
- this.sourcesLock.readLock().unlock();
- }
- return null;
- }
-
- /**
- * Get the connection pool managing the {@link RepositorySource} with the specified
name managed by this instance.
- *
- * @param sourceName the name of the source
- * @return the pool, or null if no such pool exists in this instance
- */
- public RepositoryConnectionPool getConnectionPool( String sourceName ) {
- try {
- this.sourcesLock.readLock().lock();
- for (RepositoryConnectionPool existingPool : this.pools) {
- RepositorySource source = existingPool.getRepositorySource();
- if (source.getName().equals(sourceName)) return existingPool;
- }
- } finally {
- this.sourcesLock.readLock().unlock();
- }
- return null;
- }
-
- /**
- * Add the supplied federated source. This method returns false if the source is
null.
- *
- * @param source the source to add
- * @return true if the source is added, or false if the reference is null or if there
is already an existing source with the
- * supplied name.
- */
- public boolean addSource( RepositorySource source ) {
- if (source == null) return false;
- try {
- this.sourcesLock.writeLock().lock();
- for (RepositoryConnectionPool existingPool : this.pools) {
- if
(existingPool.getRepositorySource().getName().equals(source.getName())) return false;
- }
- RepositoryConnectionPool pool = new RepositoryConnectionPool(source);
- this.pools.add(pool);
- return true;
- } finally {
- this.sourcesLock.writeLock().unlock();
- }
- }
-
- /**
- * Remove from this federated repository the supplied source (or a source with the
same name as that supplied). This call
- * shuts down the connections in the source in an orderly fashion, allowing those
connection currently in use to be used and
- * closed normally, but preventing further connections from being used.
- * <p>
- * This method can safely be called while the federation repository is in use.
- * </p>
- *
- * @param source the source to be removed
- * @param timeToAwait the amount of time to wait while all of the source's
connections are closed, or non-positive if the call
- * should not wait at all
- * @param unit the time unit to be used for <code>timeToAwait</code>
- * @return true if the source was removed, or false if the source was not a source
for this repository.
- * @throws InterruptedException if the thread is interrupted while awaiting closing
of the connections
- */
- public boolean removeSource( RepositorySource source,
- long timeToAwait,
- TimeUnit unit ) throws InterruptedException {
- // Use the name; don't use the object equality ...
- return removeSource(source.getName(), timeToAwait, unit) != null;
- }
-
- /**
- * Remove from this federated repository the source with the supplied name. This call
shuts down the connections in the source
- * in an orderly fashion, allowing those connection currently in use to be used and
closed normally, but preventing further
- * connections from being used.
- *
- * @param name the name of the source to be removed
- * @param timeToAwait the amount of time to wait while all of the source's
connections are closed, or non-positive if the call
- * should not wait at all
- * @param unit the time unit to be used for <code>timeToAwait</code>
- * @return the source with the supplied name that was removed, or null if no existing
source matching the supplied name could
- * be found
- * @throws InterruptedException if the thread is interrupted while awaiting closing
of the connections
- */
- public RepositorySource removeSource( String name,
- long timeToAwait,
- TimeUnit unit ) throws InterruptedException {
- try {
- this.sourcesLock.writeLock().lock();
- for (RepositoryConnectionPool existingPool : this.pools) {
- if (existingPool.getRepositorySource().getName().equals(name)) {
- // Shut down the source ...
- existingPool.shutdown();
- if (timeToAwait > 0L) existingPool.awaitTermination(timeToAwait,
unit);
- }
- return existingPool.getRepositorySource();
- }
- } finally {
- this.sourcesLock.writeLock().unlock();
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see
org.jboss.dna.spi.connector.RepositoryConnectionFactory#createConnection(java.lang.String)
- */
- public RepositoryConnection createConnection( String sourceName ) {
- try {
- this.sourcesLock.readLock().lock();
- for (RepositoryConnectionPool existingPool : this.pools) {
- RepositorySource source = existingPool.getRepositorySource();
- if (source.getName().equals(sourceName)) return
existingPool.getConnection();
- }
- RepositoryConnectionFactory delegate = this.delegate;
- if (delegate != null) {
- return delegate.createConnection(sourceName);
- }
- } finally {
- this.sourcesLock.readLock().unlock();
- }
- return null;
- }
-}
Modified:
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java
===================================================================
---
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/dna-repository/src/test/java/org/jboss/dna/repository/RepositoryServiceTest.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -65,7 +65,7 @@
private ExecutionContext context;
private Path root;
@Mock
- private RepositorySourceManager sources;
+ private RepositoryLibrary sources;
@Before
public void beforeEach() throws Exception {
@@ -149,7 +149,7 @@
@Test
public void shouldStartUpUsingConfigurationRepositoryThatContainsSomeSources() throws
Exception {
// Use a real source manager for this test ...
- sources = new RepositorySourceManager(sources);
+ sources = new RepositoryLibrary(sources);
sources.addSource(configRepositorySource);
assertThat(sources.getSources(),
hasItems((RepositorySource)configRepositorySource));
assertThat(sources.getSources().size(), is(1));
Added: trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryContext.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryContext.java
(rev 0)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryContext.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 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.dna.spi.connector;
+
+import org.jboss.dna.spi.ExecutionContextFactory;
+
+/**
+ * The context for a repository. This interface need not be implemented by a {@link
RepositorySource}, as it is normally provided
+ * to the source when {@link RepositorySource#initialize(RepositoryContext)
initialized}.
+ *
+ * @author Randall Hauch
+ */
+public interface RepositoryContext {
+
+ /**
+ * Get the factory that can be used to create execution contexts.
+ *
+ * @return the execution context factory
+ */
+ ExecutionContextFactory getExecutionContextFactory();
+
+ /**
+ * Get the factory for {@link RepositoryConnection connections} to other sources.
+ *
+ * @return the connection factory
+ */
+ RepositoryConnectionFactory getRepositoryConnectionFactory();
+
+}
Property changes on:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositoryContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/connector/RepositorySource.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -51,6 +51,16 @@
public interface RepositorySource extends Referenceable, Serializable {
/**
+ * Initialize this source to use the supplied {@link RepositoryContext}, from which
this source can obtain
+ * {@link RepositoryContext#getRepositoryConnectionFactory() connections} to other
{@link RepositorySource sources} as well as
+ * {@link RepositoryContext#getExecutionContextFactory() execution contexts}.
+ *
+ * @param context
+ * @throws RepositorySourceException
+ */
+ void initialize( RepositoryContext context ) throws RepositorySourceException;
+
+ /**
* Get the name for this repository source.
*
* @return the name; never null or empty
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -66,6 +66,7 @@
private String name;
private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
private CachePolicy defaultCachePolicy;
+ private transient RepositoryContext repositoryContext;
public SimpleRepositorySource() {
super();
@@ -74,6 +75,22 @@
/**
* {@inheritDoc}
*
+ * @see
org.jboss.dna.spi.connector.RepositorySource#initialize(org.jboss.dna.spi.connector.RepositoryContext)
+ */
+ public void initialize( RepositoryContext context ) throws RepositorySourceException
{
+ this.repositoryContext = context;
+ }
+
+ /**
+ * @return repositoryContext
+ */
+ public RepositoryContext getRepositoryContext() {
+ return repositoryContext;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.spi.connector.RepositorySource#getName()
*/
public String getName() {
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/TimeDelayingRepositorySource.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/TimeDelayingRepositorySource.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/TimeDelayingRepositorySource.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -62,6 +62,7 @@
private final AtomicLong pingDelay = new AtomicLong(0);
private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
private CachePolicy defaultCachePolicy;
+ private transient RepositoryContext repositoryContext;
public TimeDelayingRepositorySource( String identifier ) {
super();
@@ -70,7 +71,23 @@
/**
* {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.connector.RepositorySource#initialize(org.jboss.dna.spi.connector.RepositoryContext)
*/
+ public void initialize( RepositoryContext context ) throws RepositorySourceException
{
+ this.repositoryContext = context;
+ }
+
+ /**
+ * @return repositoryContext
+ */
+ public RepositoryContext getRepositoryContext() {
+ return repositoryContext;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public String getName() {
return this.name;
}
Modified: trunk/docs/examples/gettingstarted/repositories/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/pom.xml 2008-09-16 16:39:31 UTC (rev
520)
+++ trunk/docs/examples/gettingstarted/repositories/pom.xml 2008-09-16 19:03:58 UTC (rev
521)
@@ -42,7 +42,7 @@
<groupId>org.jboss.dna</groupId>
<artifactId>dna-connector-inmemory</artifactId>
<version>${dna-version}</version>
- <scope>runtime</scope>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
Modified:
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -32,14 +32,15 @@
import javax.jcr.PropertyIterator;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
+import javax.naming.NamingException;
import javax.security.auth.callback.PasswordCallback;
import org.jboss.dna.common.component.ClassLoaderFactory;
import org.jboss.dna.common.component.StandardClassLoaderFactory;
import org.jboss.dna.connector.inmemory.InMemoryRepositorySource;
import org.jboss.dna.jcr.JcrRepository;
import org.jboss.dna.repository.RepositoryImporter;
+import org.jboss.dna.repository.RepositoryLibrary;
import org.jboss.dna.repository.RepositoryService;
-import org.jboss.dna.repository.RepositorySourceManager;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.ExecutionContextFactory;
import org.jboss.dna.spi.connector.BasicExecutionContextFactory;
@@ -78,7 +79,7 @@
}
private ClassLoaderFactory classLoaderFactory;
- private RepositorySourceManager sources;
+ private RepositoryLibrary sources;
private ExecutionContextFactory contextFactory;
private RepositoryService repositoryService;
private Api api = Api.DNA;
@@ -138,8 +139,9 @@
* repositories.
*
* @throws IOException if there is a problem initializing the repositories from the
files.
+ * @throws NamingException if there is a problem registering or looking up objects in
JNDI
*/
- public void startRepositories() throws IOException {
+ public void startRepositories() throws IOException, NamingException {
if (repositoryService != null) return; // already started
// Create the class loader factory, which for this example will simply use this
class' class loader...
@@ -152,8 +154,8 @@
// by supply LoginContext, AccessControlContext, or even Subject with
CallbackHandlers. But no JAAS in this example.
ExecutionContext context = contextFactory.create();
- // Create the manager for the RepositorySource instances ...
- sources = new RepositorySourceManager();
+ // Create the library for the RepositorySource instances ...
+ sources = new RepositoryLibrary(contextFactory);
// Load into the source manager the repository source for the configuration
repository ...
InMemoryRepositorySource configSource = new InMemoryRepositorySource();
Modified: trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.xml
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.xml 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/resources/aircraft.xml 2008-09-16
19:03:58 UTC (rev 521)
@@ -35,7 +35,7 @@
<aircraft jcr:name="Airbus A380" maker="Airbus"
model="A380-800" introduced="2007" numberBuilt="18"
range="8200nm" maxWeight="1235000lb" cruiseSpeed="647mph"
url="http://en.wikipedia.org/wiki/Airbus_a380"/>
<aircraft jcr:name="Airbus A340" maker="Airbus"
model="A340-200" introduced="1993" numberBuilt="354"
range="8000nm" maxWeight="606300lb" cruiseSpeed="557mph"
url="http://en.wikipedia.org/wiki/Airbus_A-340"/>
<aircraft jcr:name="Airbus A310" maker="Airbus"
model="A310-200" introduced="1983" numberBuilt="255"
cruiseSpeed="850km/h" emptyWeight="176312lb" range="3670nm"
url="http://en.wikipedia.org/wiki/Airbus_A-310"/>
- <aircraft jcr:name="Embraer " maker="Embraer"
model="ERJ170-200" introduced="2004" range="3334km"
cruiseSpeed="481kt" emptyWeight="21810kg"
url="http://en.wikipedia.org/wiki/EMBRAER_170"/>
+ <aircraft jcr:name="Embraer RJ-175" maker="Embraer"
model="ERJ170-200" introduced="2004" range="3334km"
cruiseSpeed="481kt" emptyWeight="21810kg"
url="http://en.wikipedia.org/wiki/EMBRAER_170"/>
</Commercial>
<Vintage>
<aircraft jcr:name="Fokker Trimotor" maker="Fokker"
model="F.VII" introduced="1925" cruiseSpeed="170km/h"
emptyWeight="3050kg" crew="2"
url="http://en.wikipedia.org/wiki/Fokker_trimotor"/>
Modified:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml 2008-09-16
19:03:58 UTC (rev 521)
@@ -25,28 +25,35 @@
<dna:system
xmlns:dna="http://www.jboss.org/dna"
xmlns:jcr="http://www.jcp.org/jcr/1.0">
<!-- Define the sources from which content is made available -->
<dna:sources>
- <sourceA name="Cars"
dna:classname="org.jboss.dna.connector.inmemory.InMemoryRepositorySource"
retryLimit="3" />
- <sourceB name="Aircraft"
dna:classname="org.jboss.dna.connector.inmemory.InMemoryRepositorySource" />
- <sourceC name="Vehicles"
dna:classname="org.jboss.dna.connector.federation.FederatedRepositorySource"
configurationSourceName="Configuration"
configurationSourcePath="/dna:system/dna:federatedRepositories/Vehicles" />
- <sourceD name="Cache"
dna:classname="org.jboss.dna.connector.inmemory.InMemoryRepositorySource" />
+ <dna:source jcr:name="SourceA" dna:name="Cars"
dna:classname="org.jboss.dna.connector.inmemory.InMemoryRepositorySource"
dna:retryLimit="3" />
+ <dna:source jcr:name="SourceB" dna:name="Aircraft"
dna:classname="org.jboss.dna.connector.inmemory.InMemoryRepositorySource" />
+ <dna:source jcr:name="SourceC" dna:name="Vehicles"
dna:classname="org.jboss.dna.connector.federation.FederatedRepositorySource"
+ dna:repositoryName="Configuration Repository"
+ dna:configurationSourceName="Configuration"
+
dna:configurationSourcePath="/dna:system/dna:federatedRepositories/Vehicles"
+
dna:repositoryConnectionFactoryJndiName="/dna/connectionFactory"
+
dna:executionContextFactoryJndiName="/dna/contextFactory"/>
+ <dna:source jcr:name="SourceD" dna:name="Cache"
dna:classname="org.jboss.dna.connector.inmemory.InMemoryRepositorySource" />
</dna:sources>
<dna:federatedRepositories>
- <Vehicles>
- <!-- This section defines from where the content of the 'Vehicles'
federated repository is obtained -->
+ <!-- This section defines from where the content of the 'Vehicles'
federated repository is obtained.
+ The name of this node must match the 'name' of the source listed
above. -->
+ <dna:federatedRepository jcr:name="Vehicles">
+ <!-- Define the federation configuration. -->
<dna:federation dna:timeToCache="100000">
+ <!-- Define how the content in the 'Cache' source is to map to
the federated cache -->
<dna:cache>
- <!-- Define how the content in the 'Cache' source is to
map to the federated cache -->
- <Cache dna:projectionRules="/ => /" />
+ <dna:projection jcr:name="Cache"
dna:projectionRules="/ => /" />
</dna:cache>
+ <!-- Define how the content in the difference sources maps to the
federated/unified repository.
+ This example puts the 'Cars' and 'Aircraft' content
underneath '/vehicles', but the
+ 'Configuration' content (which is defined by this file) will
appear under '/'. -->
<dna:projections>
- <!-- Define how the content in the difference sources maps to the
federated/unified repository.
- This example puts the 'Cars' and 'Aircraft'
content underneath '/vehicles', but the
- 'Configuration' content (which is defined by this file)
will appear under '/'. -->
- <Cars dna:projectionRules="/vehicles => /" />
- <Aircraft dna:projectionRules="/vehicles => /" />
- <Configuration dna:projectionRules="/ => /" />
+ <dna:projection jcr:name="Cars"
dna:projectionRules="/Vehicles => /" />
+ <dna:projection jcr:name="Aircraft"
dna:projectionRules="/Vehicles => /" />
+ <dna:projection jcr:name="Configuration"
dna:projectionRules="/ => /" />
</dna:projections>
</dna:federation>
- </Vehicles>
+ </dna:federatedRepository>
</dna:federatedRepositories>
</dna:system>
\ No newline at end of file
Modified:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/log4j.properties
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/resources/log4j.properties 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/resources/log4j.properties 2008-09-16
19:03:58 UTC (rev 521)
@@ -9,9 +9,5 @@
# Set up the default logging to be INFO level, then override specific units
log4j.logger.org.jboss.dna=INFO
-#log4j.logger.org.jboss.dna.repository.sequencers=TRACE
-#log4j.logger.org.jboss.dna.sequencer=DEBUG
-#log4j.logger.org.jboss.dna.connector=TRACE
-#log4j.logger.org.jboss.dna.spi.connector.RepositoryConnectionPool=TRACE
-#log4j.logger.org.jboss.dna.spi=DEBUG
+log4j.logger.org.jboss.example.dna=INFO
Modified:
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -30,10 +30,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.jboss.dna.common.util.StringUtil;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations.Mock;
@@ -56,6 +54,7 @@
children = new ArrayList<String>();
client = new RepositoryClient();
client.setUserInterface(userInterface);
+ client.setApi(getApi());
stub(userInterface.getLocationOfRepositoryFiles()).toReturn(new
File("src/main/resources").getAbsolutePath());
}
@@ -64,6 +63,10 @@
client.shutdown();
}
+ protected RepositoryClient.Api getApi() {
+ return RepositoryClient.Api.DNA;
+ }
+
protected void assertProperty( String propertyName,
Object... values ) {
Object[] actualValues = properties.get(propertyName);
@@ -82,7 +85,6 @@
assertThat(client.getNamesOfRepositories(), hasItems("Aircraft",
"Cars", "Configuration", "Vehicles", "Cache"));
}
- @Ignore
@Test
public void shouldHaveContentFromConfigurationRepository() throws Throwable {
client.startRepositories();
@@ -95,22 +97,21 @@
properties.clear();
children.clear();
assertThat(client.getNodeInfo("Configuration",
"/dna:system/dna:sources", properties, children), is(true));
- assertThat(children, hasItems("sourceA", "sourceB",
"sourceC", "sourceD"));
+ assertThat(children, hasItems("SourceA", "SourceB",
"SourceC", "SourceD"));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertThat(properties.size(), is(2));
properties.clear();
children.clear();
- assertThat(client.getNodeInfo("Configuration",
"/dna:system/dna:sources/sourceA", properties, children), is(true));
+ assertThat(client.getNodeInfo("Configuration",
"/dna:system/dna:sources/SourceA", properties, children), is(true));
assertThat(children.size(), is(0));
- System.out.println(StringUtil.readableString(properties));
assertThat(properties.containsKey("jcr:primaryType"), is(true));
assertThat(properties.containsKey("dna:uuid"), is(true));
assertProperty("dna:classname",
"org.jboss.dna.connector.inmemory.InMemoryRepositorySource");
- assertProperty("name", "Cars");
- assertProperty("retryLimit", "3");
- assertThat(properties.size(), is(4));
+ assertProperty("dna:name", "Cars");
+ assertProperty("dna:retryLimit", "3");
+ assertThat(properties.size(), is(5));
}
@Test
@@ -151,6 +152,96 @@
}
@Test
+ public void shouldLoadAircraftRepository() throws Throwable {
+ client.startRepositories();
+ assertThat(client.getNodeInfo("Aircraft", "/Aircraft",
properties, children), is(true));
+ assertThat(children, hasItems("Business", "Commercial",
"Vintage", "Homebuilt"));
+ assertThat(properties.containsKey("jcr:primaryType"), is(true));
+ assertThat(properties.containsKey("dna:uuid"), is(true));
+ assertThat(properties.size(), is(2));
+
+ properties.clear();
+ children.clear();
+ assertThat(client.getNodeInfo("Aircraft",
"/Aircraft/Commercial", properties, children), is(true));
+ assertThat(children, hasItems("Boeing 777",
+ "Boeing 767",
+ "Boeing 787",
+ "Boeing 757",
+ "Airbus A380",
+ "Airbus A340",
+ "Airbus A310",
+ "Embraer RJ-175"));
+ assertThat(properties.containsKey("jcr:primaryType"), is(true));
+ assertThat(properties.containsKey("dna:uuid"), is(true));
+ assertThat(properties.size(), is(2));
+
+ properties.clear();
+ children.clear();
+ assertThat(client.getNodeInfo("Aircraft",
"/Aircraft/Vintage/Wright Flyer", properties, children), is(true));
+ assertThat(children.size(), is(0));
+ assertThat(properties.containsKey("jcr:primaryType"), is(true));
+ assertThat(properties.containsKey("dna:uuid"), is(true));
+ assertProperty("maker", "Wright Brothers");
+ assertProperty("introduced", "1903");
+ assertProperty("range", "852ft");
+ assertProperty("maxSpeed", "30mph");
+ assertProperty("emptyWeight", "605lb");
+ assertProperty("crew", "1");
+ assertThat(properties.size(), is(8));
+ }
+
+ @Test
+ public void shouldLoadVehiclesRepository() throws Throwable {
+ client.startRepositories();
+ assertThat(client.getNodeInfo("Vehicles", "/Vehicles",
properties, children), is(true));
+ assertThat(children, hasItems("Cars", "Aircraft"));
+ assertThat(properties.containsKey("jcr:primaryType"), is(false));
+ assertThat(properties.containsKey("dna:uuid"), is(true));
+ assertThat(properties.size(), is(1));
+
+ properties.clear();
+ children.clear();
+ assertThat(client.getNodeInfo("Vehicles",
"/Vehicles/Cars/Hybrid", properties, children), is(true));
+ assertThat(children, hasItems("Toyota Prius", "Toyota
Highlander", "Nissan Altima"));
+ assertThat(properties.containsKey("jcr:primaryType"), is(true));
+ assertThat(properties.containsKey("dna:uuid"), is(true));
+ assertThat(properties.size(), is(2));
+
+ properties.clear();
+ children.clear();
+ assertThat(client.getNodeInfo("Vehicles",
"/Vehicles/Cars/Sports/Aston Martin DB9", properties, children), is(true));
+ assertThat(children.size(), is(0));
+ assertThat(properties.containsKey("jcr:primaryType"), is(true));
+ assertThat(properties.containsKey("dna:uuid"), is(true));
+ assertProperty("maker", "Aston Martin");
+ assertProperty("maker", "Aston Martin");
+ assertProperty("model", "DB9");
+ assertProperty("year", "2008");
+ assertProperty("msrp", "$171,600");
+ assertProperty("userRating", "5");
+ assertProperty("mpgCity", "12");
+ assertProperty("mpgHighway", "19");
+ assertProperty("lengthInInches", "185.5");
+ assertProperty("wheelbaseInInches", "108.0");
+ assertProperty("engine", "5,935 cc 5.9 liters V 12");
+ assertThat(properties.size(), is(12));
+
+ properties.clear();
+ children.clear();
+ assertThat(client.getNodeInfo("Vehicles",
"/Vehicles/Aircraft/Vintage/Wright Flyer", properties, children), is(true));
+ assertThat(children.size(), is(0));
+ assertThat(properties.containsKey("jcr:primaryType"), is(true));
+ assertThat(properties.containsKey("dna:uuid"), is(true));
+ assertProperty("maker", "Wright Brothers");
+ assertProperty("introduced", "1903");
+ assertProperty("range", "852ft");
+ assertProperty("maxSpeed", "30mph");
+ assertProperty("emptyWeight", "605lb");
+ assertProperty("crew", "1");
+ assertThat(properties.size(), is(8));
+ }
+
+ @Test
public void shouldReturnNullForNonExistantNode() throws Throwable {
client.startRepositories();
assertThat(client.getNodeInfo("Cars", "/Cars/Sports/Non Existant
Car", properties, children), is(false));
Added:
trunk/docs/examples/gettingstarted/repositories/src/test/resources/log4j.properties
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/test/resources/log4j.properties
(rev 0)
+++
trunk/docs/examples/gettingstarted/repositories/src/test/resources/log4j.properties 2008-09-16
19:03:58 UTC (rev 521)
@@ -0,0 +1,18 @@
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %m%n
+
+# Root logger option
+log4j.rootLogger=INFO, stdout
+
+# Set up the default logging to be INFO level, then override specific units
+log4j.logger.org.jboss.dna=INFO
+#log4j.logger.org.jboss.dna.repository.sequencers=TRACE
+#log4j.logger.org.jboss.dna.sequencer=DEBUG
+#log4j.logger.org.jboss.dna.connector=TRACE
+#log4j.logger.org.jboss.dna.spi.connector.RepositoryConnectionPool=TRACE
+#log4j.logger.org.jboss.dna.spi=DEBUG
+#log4j.logger.org.jboss.example.dna=TRACE
+
Property changes on:
trunk/docs/examples/gettingstarted/repositories/src/test/resources/log4j.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositoryConnection.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositoryConnection.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositoryConnection.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -119,9 +119,13 @@
if (commands == null || commands.length == 0) return;
CommandExecutor executor = this.repository.getExecutor(context, sourceName);
- assert executor != null;
- for (GraphCommand command : commands) {
- executor.execute(command);
+ try {
+ assert executor != null;
+ for (GraphCommand command : commands) {
+ executor.execute(command);
+ }
+ } finally {
+ executor.close();
}
}
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -31,7 +31,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.naming.Context;
-import javax.naming.InitialContext;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
@@ -55,6 +54,7 @@
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.connector.RepositoryConnection;
import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.RepositoryContext;
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceCapabilities;
import org.jboss.dna.spi.connector.RepositorySourceException;
@@ -97,9 +97,6 @@
protected static final String PASSWORD = "password";
protected static final String CONFIGURATION_SOURCE_NAME =
"configurationSourceName";
protected static final String CONFIGURATION_SOURCE_PATH =
"configurationSourcePath";
- protected static final String REPOSITORY_CONNECTION_FACTORY_JNDI_NAME =
"repositoryConnectionFactoryJndiName";
- protected static final String EXECUTION_CONTEXT_FACTORY_JNDI_NAME =
"executionContextFactoryJndiName";
- protected static final String REPOSITORY_JNDI_NAME = "repositoryJndiName";
protected static final String SECURITY_DOMAIN = "securityDomain";
protected static final String RETRY_LIMIT = "retryLimit";
@@ -115,13 +112,10 @@
private String password;
private String configurationSourceName;
private String configurationSourcePath = DEFAULT_CONFIGURATION_SOURCE_PATH;
- private String repositoryConnectionFactoryJndiName;
- private String executionContextFactoryJndiName;
private String securityDomain;
- private String repositoryJndiName;
private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
private transient FederatedRepository repository;
- private transient Context jndiContext;
+ private transient RepositoryContext repositoryContext;
/**
* Create a new instance of the source, which must still be properly initialized with
a {@link #setRepositoryName(String)
@@ -145,7 +139,23 @@
/**
* {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.connector.RepositorySource#initialize(org.jboss.dna.spi.connector.RepositoryContext)
*/
+ public void initialize( RepositoryContext context ) throws RepositorySourceException
{
+ this.repositoryContext = context;
+ }
+
+ /**
+ * @return repositoryContext
+ */
+ public RepositoryContext getRepositoryContext() {
+ return repositoryContext;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public synchronized String getName() {
return sourceName;
}
@@ -158,12 +168,10 @@
*
* @param sourceName the name of this repository source
* @see #setConfigurationSourceName(String)
- * @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setConfigurationSourcePath(String)
* @see #setPassword(String)
* @see #setUsername(String)
* @see #setRepositoryName(String)
- * @see #setExecutionContextFactoryJndiName(String)
* @see #setPassword(String)
* @see #setUsername(String)
* @see #setName(String)
@@ -193,47 +201,10 @@
}
/**
- * Get the name in JNDI of a {@link FederatedRepository} instance that should be
used. If this is set (and an instance can be
- * found at that location), few of the remaining properties on this instance may not
be used (basically just
- * {@link #getUsername() username}, {@link #getPassword() password}, and {@link
#getName() source name}).
- * <p>
- * This is an optional property.
- * </p>
- *
- * @return the location in JNDI of the {@link FederatedRepository} that should be
used by this source, or null if the
- * {@link FederatedRepository} instance will be created from the properties
of this instance
- * @see #setRepositoryJndiName(String)
- */
- public String getRepositoryJndiName() {
- return repositoryJndiName;
- }
-
- /**
- * Set the name in JNDI of a {@link FederatedRepository} instance that should be
used. If this is set (and an instance can be
- * found at that location), few of the remaining properties on this instance may not
be used (basically just
- * {@link #getUsername() username}, {@link #getPassword() password}, and {@link
#getName() source name}).
- * <p>
- * This is an optional property.
- * </p>
- *
- * @param jndiName the JNDI name where the {@link FederatedRepository} instance can
be found, or null if the instance is not
- * to be found in JNDI but one should be instantiated from this instance's
properties
- * @see #getRepositoryJndiName()
- * @see #setPassword(String)
- * @see #setUsername(String)
- * @see #setName(String)
- */
- public void setRepositoryJndiName( String jndiName ) {
- if (this.repositoryJndiName == jndiName || this.repositoryJndiName != null
&& this.repositoryJndiName.equals(jndiName)) return; // unchanged
- this.repositoryJndiName = jndiName;
- changeRepositoryConfig();
- }
-
- /**
* Get the name in JNDI of a {@link RepositorySource} instance that should be used by
the {@link FederatedRepository federated
* repository} as the configuration repository.
* <p>
- * This is a required property (unless the {@link #getRepositoryJndiName() federated
repository is to be found in JDNI}).
+ * This is a required property.
* </p>
*
* @return the JNDI name of the {@link RepositorySource} instance that should be used
for the configuration, or null if the
@@ -247,20 +218,19 @@
/**
* Get the name of a {@link RepositorySource} instance that should be used by the
{@link FederatedRepository federated
* repository} as the configuration repository. The instance will be retrieved from
the {@link RepositoryConnectionFactory}
- * instance {@link #getRepositoryConnectionFactoryJndiName() found in JDNI}.
+ * instance from the {@link RepositoryContext#getRepositoryConnectionFactory()
repository context} supplied during
+ * {@link RepositorySource#initialize(RepositoryContext) initialization}.
* <p>
- * This is a required property (unless the {@link #getRepositoryJndiName() federated
repository is to be found in JDNI}).
+ * This is a required property.
* </p>
*
* @param sourceName the name of the {@link RepositorySource} instance that should be
used for the configuration, or null if
* the federated repository instance is to be found in JNDI
* @see #getConfigurationSourceName()
- * @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setConfigurationSourcePath(String)
* @see #setPassword(String)
* @see #setUsername(String)
* @see #setRepositoryName(String)
- * @see #setExecutionContextFactoryJndiName(String)
* @see #setName(String)
*/
public void setConfigurationSourceName( String sourceName ) {
@@ -273,7 +243,7 @@
/**
* Get the path in the source that will be subgraph below the
<code>/dna:system</code> branch of the repository.
* <p>
- * This is a required property (unless the {@link #getRepositoryJndiName() federated
repository is to be found in JDNI}).
+ * This is a required property.
* </p>
*
* @return the string array of projection rules, or null if the projection rules
haven't yet been set or if the federated
@@ -287,19 +257,17 @@
/**
* Set the path in the source that will be subgraph below the
<code>/dna:system</code> branch of the repository.
* <p>
- * This is a required property (unless the {@link #getRepositoryJndiName() federated
repository is to be found in JDNI}).
+ * This is a required property.
* </p>
*
* @param pathInSourceToConfigurationRoot the path within the configuration source to
the node that should be the root of the
* configuration information, or null if the path hasn't yet been set or
if the federated repository instance is to be
* found in JNDI
* @see #setConfigurationSourcePath(String)
- * @see #setRepositoryConnectionFactoryJndiName(String)
* @see #setConfigurationSourceName(String)
* @see #setPassword(String)
* @see #setUsername(String)
* @see #setRepositoryName(String)
- * @see #setExecutionContextFactoryJndiName(String)
* @see #setName(String)
*/
public void setConfigurationSourcePath( String pathInSourceToConfigurationRoot ) {
@@ -310,87 +278,6 @@
}
/**
- * Get the name in JNDI of a {@link ExecutionContextFactory} instance that should be
used to obtain the
- * {@link ExecutionContext execution context} used by the {@link FederatedRepository
federated repository}.
- * <p>
- * This is a required property (unless the {@link #getRepositoryJndiName() federated
repository is to be found in JDNI}).
- * </p>
- *
- * @return the JNDI name of the {@link ExecutionContextFactory} instance that should
be used, or null if the federated
- * repository instance is to be found in JNDI
- * @see #setExecutionContextFactoryJndiName(String)
- */
- public String getExecutionContextFactoryJndiName() {
- return executionContextFactoryJndiName;
- }
-
- /**
- * Set the name in JNDI of a {@link ExecutionContextFactory} instance that should be
used to obtain the
- * {@link ExecutionContext execution context} used by the {@link FederatedRepository
federated repository}.
- * <p>
- * This is a required property (unless the {@link #getRepositoryJndiName() federated
repository is to be found in JDNI}).
- * </p>
- *
- * @param jndiName the JNDI name where the {@link ExecutionContextFactory} instance
can be found, or null if the federated
- * repository instance is to be found in JNDI
- * @see #getExecutionContextFactoryJndiName()
- * @see #setConfigurationSourceName(String)
- * @see #setConfigurationSourcePath(String)
- * @see #setRepositoryConnectionFactoryJndiName(String)
- * @see #setPassword(String)
- * @see #setUsername(String)
- * @see #setRepositoryName(String)
- * @see #setName(String)
- */
- public synchronized void setExecutionContextFactoryJndiName( String jndiName ) {
- if (this.repositoryJndiName == jndiName || this.repositoryJndiName != null
&& this.repositoryJndiName.equals(jndiName)) return;
- this.executionContextFactoryJndiName = jndiName; // unchanged
- changeRepositoryConfig();
- }
-
- /**
- * Get the name in JNDI where the {@link RepositoryConnectionFactory} instance that
can be used by the
- * {@link FederatedRepository federated repository} can find any {@link
RepositorySource} sources it needs, including those
- * used for {@link Projection sources} and that used for it's {@link
#getConfigurationSourceName() configuration}.
- * <p>
- * This is a required property (unless the {@link #getRepositoryJndiName() federated
repository is to be found in JDNI}).
- * </p>
- *
- * @return the JNDI name where the {@link RepositoryConnectionFactory} instance can
be found, or null if the federated
- * repository instance is to be found in JNDI
- * @see #setRepositoryConnectionFactoryJndiName(String)
- */
- public String getRepositoryConnectionFactoryJndiName() {
- return repositoryConnectionFactoryJndiName;
- }
-
- /**
- * Set the name in JNDI where the {@link RepositoryConnectionFactory} instance that
can be used by the
- * {@link FederatedRepository federated repository} can find any {@link
RepositorySource} sources it needs, including those
- * used for {@link Projection sources} and that used for it's {@link
#getConfigurationSourceName() configuration}.
- * <p>
- * This is a required property (unless the {@link #getRepositoryJndiName() federated
repository is to be found in JDNI}).
- * </p>
- *
- * @param jndiName the JNDI name where the {@link RepositoryConnectionFactory}
instance can be found, or null if the federated
- * repository instance is to be found in JNDI
- * @see #getRepositoryConnectionFactoryJndiName()
- * @see #setConfigurationSourceName(String)
- * @see #setConfigurationSourcePath(String)
- * @see #setPassword(String)
- * @see #setUsername(String)
- * @see #setRepositoryName(String)
- * @see #setExecutionContextFactoryJndiName(String)
- * @see #setName(String)
- */
- public synchronized void setRepositoryConnectionFactoryJndiName( String jndiName ) {
- if (this.repositoryConnectionFactoryJndiName == jndiName ||
this.repositoryConnectionFactoryJndiName != null
- && this.repositoryConnectionFactoryJndiName.equals(jndiName)) return;
// unchanged
- this.repositoryConnectionFactoryJndiName = jndiName;
- changeRepositoryConfig();
- }
-
- /**
* Get the name of the security domain that should be used by JAAS to identify the
application or security context. This
* should correspond to the JAAS login configuration located within the JAAS login
configuration file.
*
@@ -415,7 +302,7 @@
/**
* Get the name of the federated repository.
* <p>
- * This is a required property (unless the {@link #getRepositoryJndiName() federated
repository is to be found in JDNI}).
+ * This is a required property.
* </p>
*
* @return the name of the repository
@@ -428,7 +315,7 @@
/**
* Get the name of the federated repository.
* <p>
- * This is a required property (unless the {@link #getRepositoryJndiName() federated
repository is to be found in JDNI}).
+ * This is a required property.
* </p>
*
* @param repositoryName the new name of the repository
@@ -438,8 +325,6 @@
* @see #setConfigurationSourcePath(String)
* @see #setPassword(String)
* @see #setUsername(String)
- * @see #setRepositoryConnectionFactoryJndiName(String)
- * @see #setExecutionContextFactoryJndiName(String)
* @see #setName(String)
*/
public synchronized void setRepositoryName( String repositoryName ) {
@@ -475,8 +360,6 @@
* @see #setConfigurationSourcePath(String)
* @see #setPassword(String)
* @see #setRepositoryName(String)
- * @see #setRepositoryConnectionFactoryJndiName(String)
- * @see #setExecutionContextFactoryJndiName(String)
* @see #setName(String)
*/
public void setUsername( String username ) {
@@ -510,8 +393,6 @@
* @see #setConfigurationSourcePath(String)
* @see #setUsername(String)
* @see #setRepositoryName(String)
- * @see #setRepositoryConnectionFactoryJndiName(String)
- * @see #setExecutionContextFactoryJndiName(String)
* @see #setName(String)
*/
public void setPassword( String password ) {
@@ -528,12 +409,15 @@
*/
protected synchronized void changeRepositoryConfig() {
if (this.repository != null) {
- // Find in JNDI the repository source registry and the environment ...
- ExecutionContext context = getExecutionContext();
- RepositoryConnectionFactory factory = getConnectionFactory();
- // Compute a new repository config and set it on the repository ...
- FederatedRepositoryConfig newConfig = getRepositoryConfiguration(context,
factory);
- this.repository.setConfiguration(newConfig);
+ RepositoryContext repositoryContext = getRepositoryContext();
+ if (repositoryContext != null) {
+ // Find in JNDI the repository source registry and the environment ...
+ ExecutionContext context = getExecutionContext();
+ RepositoryConnectionFactory factory =
getRepositoryContext().getRepositoryConnectionFactory();
+ // Compute a new repository config and set it on the repository ...
+ FederatedRepositoryConfig newConfig = getRepositoryConfiguration(context,
factory);
+ this.repository.setConfiguration(newConfig);
+ }
}
}
@@ -547,18 +431,14 @@
I18n msg = FederationI18n.propertyIsRequired;
throw new RepositorySourceException(getName(), msg.text("name"));
}
- if (getExecutionContextFactoryJndiName() == null) {
+ if (getRepositoryContext() == null) {
I18n msg = FederationI18n.propertyIsRequired;
- throw new RepositorySourceException(getName(), msg.text("execution
context factory JNDI name"));
+ throw new RepositorySourceException(getName(), msg.text("repository
context"));
}
- if (getSecurityDomain() == null) {
+ if (getUsername() != null && getSecurityDomain() == null) {
I18n msg = FederationI18n.propertyIsRequired;
throw new RepositorySourceException(getName(), msg.text("security
domain"));
}
- if (getRepositoryConnectionFactoryJndiName() == null) {
- I18n msg = FederationI18n.propertyIsRequired;
- throw new RepositorySourceException(getName(), msg.text("repository
source registry JNDI name"));
- }
// Find the repository ...
FederatedRepository repository = getRepository();
// Authenticate the user ...
@@ -588,105 +468,30 @@
*/
protected synchronized FederatedRepository getRepository() throws
RepositorySourceException {
if (repository == null) {
- String jndiName = this.getRepositoryJndiName();
- Context jndiContext = getContext();
- if (jndiName != null && jndiName.trim().length() != 0) {
- // Look for an existing repository in JNDI ...
- Object object = null;
- try {
- if (jndiContext == null) jndiContext = new InitialContext();
- object = jndiContext.lookup(jndiName);
- if (object != null) repository = (FederatedRepository)object;
- } catch (ClassCastException err) {
- I18n msg = FederationI18n.objectFoundInJndiWasNotOfExpectedType;
- String className = object != null ? object.getClass().getName() :
"null";
- throw new RepositorySourceException(getName(), msg.text(jndiName,
-
this.getName(),
-
FederatedRepository.class.getName(),
- className),
err);
- } catch (Throwable err) {
- I18n msg = FederationI18n.unableToFindFederatedRepositoryInJndi;
- throw new RepositorySourceException(getName(),
msg.text(this.sourceName, jndiName), err);
- }
- }
-
- if (repository == null) {
- // Find in JNDI the repository source registry and the environment ...
- ExecutionContext context = getExecutionContext();
- RepositoryConnectionFactory connectionFactory = getConnectionFactory();
- // And create the configuration and the repository ...
- FederatedRepositoryConfig config = getRepositoryConfiguration(context,
connectionFactory);
- repository = new FederatedRepository(context, connectionFactory,
config);
- }
+ ExecutionContext context = getExecutionContext();
+ RepositoryConnectionFactory connectionFactory =
getRepositoryContext().getRepositoryConnectionFactory();
+ // And create the configuration and the repository ...
+ FederatedRepositoryConfig config = getRepositoryConfiguration(context,
connectionFactory);
+ repository = new FederatedRepository(context, connectionFactory, config);
}
return repository;
}
protected ExecutionContext getExecutionContext() {
- ExecutionContextFactory factory = null;
- Context context = getContext();
- String jndiName = getExecutionContextFactoryJndiName();
- if (jndiName != null && jndiName.trim().length() != 0) {
- Object object = null;
- try {
- if (context == null) context = new InitialContext();
- object = context.lookup(jndiName);
- if (object != null) factory = (ExecutionContextFactory)object;
- } catch (ClassCastException err) {
- I18n msg = FederationI18n.objectFoundInJndiWasNotOfExpectedType;
- String className = object != null ? object.getClass().getName() :
"null";
- throw new RepositorySourceException(getName(), msg.text(jndiName,
- this.getName(),
-
ExecutionContextFactory.class.getName(),
- className),
err);
- } catch (Throwable err) {
- I18n msg = FederationI18n.unableToFindExecutionContextFactoryInJndi;
- throw new RepositorySourceException(getName(), msg.text(this.sourceName,
jndiName), err);
- }
- }
- if (factory == null) {
- I18n msg = FederationI18n.unableToFindExecutionContextFactoryInJndi;
- throw new RepositorySourceException(getName(), msg.text(this.sourceName,
jndiName));
- }
- String securityDomain = getSecurityDomain();
+ ExecutionContextFactory factory =
getRepositoryContext().getExecutionContextFactory();
CallbackHandler handler = createCallbackHandler();
try {
- return factory.create(securityDomain, handler);
+ String securityDomain = getSecurityDomain();
+ if (securityDomain != null || getUsername() != null) {
+ return factory.create(securityDomain, handler);
+ }
+ return factory.create();
} catch (LoginException e) {
I18n msg = FederationI18n.unableToCreateExecutionContext;
- throw new RepositorySourceException(getName(), msg.text(this.sourceName,
jndiName, securityDomain), e);
+ throw new RepositorySourceException(getName(), msg.text(this.sourceName,
securityDomain), e);
}
}
- protected RepositoryConnectionFactory getConnectionFactory() {
- RepositoryConnectionFactory factories = null;
- Context context = getContext();
- String jndiName = getRepositoryConnectionFactoryJndiName();
- if (jndiName != null && jndiName.trim().length() != 0) {
- Object object = null;
- try {
- if (context == null) context = new InitialContext();
- object = context.lookup(jndiName);
- if (object != null) factories = (RepositoryConnectionFactory)object;
- } catch (ClassCastException err) {
- I18n msg = FederationI18n.objectFoundInJndiWasNotOfExpectedType;
- String className = object != null ? object.getClass().getName() :
"null";
- throw new RepositorySourceException(getName(), msg.text(jndiName,
- this.getName(),
-
RepositoryConnectionFactory.class.getName(),
- className),
err);
- } catch (Throwable err) {
- I18n msg =
FederationI18n.unableToFindRepositoryConnectionFactoriesInJndi;
- throw new RepositorySourceException(getName(), msg.text(this.sourceName,
jndiName), err);
- }
- }
- if (factories == null) {
- I18n msg = FederationI18n.noRepositoryConnectionFactories;
- throw new RepositorySourceException(getName(),
msg.text(this.repositoryName));
- }
- return factories;
- }
-
protected CallbackHandler createCallbackHandler() {
return new CallbackHandler() {
public void handle( Callback[] callbacks ) {
@@ -704,14 +509,6 @@
};
}
- protected Context getContext() {
- return this.jndiContext;
- }
-
- protected synchronized void setContext( Context context ) {
- this.jndiContext = context;
- }
-
/**
* Create a {@link FederatedRepositoryConfig} instance from the current properties of
this instance. This method does
* <i>not</i> modify the state of this instance.
@@ -752,7 +549,7 @@
executor = new FederatingCommandExecutor(context, configurationSourceName,
projections, connectionFactory);
}
// Wrap the executor with a logging executor ...
- executor = new LoggingCommandExecutor(executor, context.getLogger(getClass()),
Logger.Level.INFO);
+ executor = new LoggingCommandExecutor(executor, context.getLogger(getClass()),
Logger.Level.DEBUG);
// The configuration projection (via "executor") will convert this path
into a path that exists in the configuration
// repository
@@ -824,7 +621,7 @@
if (projection != null) {
Logger logger = context.getLogger(getClass());
if (logger.isTraceEnabled()) {
- logger.trace("Adding projection to federated
repository {1}: {2}",
+ logger.trace("Adding projection to federated
repository {0}: {1}",
getRepositoryName(),
projection);
}
@@ -845,6 +642,8 @@
} catch (InvalidPathException err) {
I18n msg = FederationI18n.federatedRepositoryCannotBeFound;
throw new FederationException(msg.text(repositoryName));
+ } finally {
+ executor.close();
}
}
@@ -911,18 +710,9 @@
if (getConfigurationSourcePath() != null) {
ref.add(new StringRefAddr(CONFIGURATION_SOURCE_PATH,
getConfigurationSourcePath()));
}
- if (getRepositoryConnectionFactoryJndiName() != null) {
- ref.add(new StringRefAddr(REPOSITORY_CONNECTION_FACTORY_JNDI_NAME,
getRepositoryConnectionFactoryJndiName()));
- }
- if (getExecutionContextFactoryJndiName() != null) {
- ref.add(new StringRefAddr(EXECUTION_CONTEXT_FACTORY_JNDI_NAME,
getExecutionContextFactoryJndiName()));
- }
if (getSecurityDomain() != null) {
ref.add(new StringRefAddr(SECURITY_DOMAIN, getSecurityDomain()));
}
- if (getRepositoryJndiName() != null) {
- ref.add(new StringRefAddr(REPOSITORY_JNDI_NAME, getRepositoryJndiName()));
- }
ref.add(new StringRefAddr(RETRY_LIMIT, Integer.toString(getRetryLimit())));
return ref;
}
@@ -952,9 +742,6 @@
String password = values.get(FederatedRepositorySource.PASSWORD);
String configurationSourceName =
values.get(FederatedRepositorySource.CONFIGURATION_SOURCE_NAME);
String configurationSourcePath =
values.get(FederatedRepositorySource.CONFIGURATION_SOURCE_PATH);
- String connectionFactoriesJndiName =
values.get(FederatedRepositorySource.REPOSITORY_CONNECTION_FACTORY_JNDI_NAME);
- String environmentJndiName =
values.get(FederatedRepositorySource.EXECUTION_CONTEXT_FACTORY_JNDI_NAME);
- String repositoryJndiName =
values.get(FederatedRepositorySource.REPOSITORY_JNDI_NAME);
String securityDomain =
values.get(FederatedRepositorySource.SECURITY_DOMAIN);
String retryLimit = values.get(FederatedRepositorySource.RETRY_LIMIT);
@@ -966,9 +753,6 @@
if (password != null) source.setPassword(password);
if (configurationSourceName != null)
source.setConfigurationSourceName(configurationSourceName);
if (configurationSourcePath != null)
source.setConfigurationSourcePath(configurationSourcePath);
- if (connectionFactoriesJndiName != null)
source.setRepositoryConnectionFactoryJndiName(connectionFactoriesJndiName);
- if (environmentJndiName != null)
source.setExecutionContextFactoryJndiName(environmentJndiName);
- if (repositoryJndiName != null)
source.setRepositoryJndiName(repositoryJndiName);
if (securityDomain != null) source.setSecurityDomain(securityDomain);
if (retryLimit != null) source.setRetryLimit(Integer.parseInt(retryLimit));
return source;
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederationI18n.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -35,12 +35,7 @@
public static I18n nodeDoesNotExistAtPath;
public static I18n errorRemovingNodeFromCache;
- public static I18n unableToFindFederatedRepositoryInJndi;
- public static I18n unableToFindExecutionContextFactoryInJndi;
public static I18n unableToCreateExecutionContext;
- public static I18n unableToFindRepositoryConnectionFactoriesInJndi;
- public static I18n objectFoundInJndiWasNotOfExpectedType;
- public static I18n noRepositoryConnectionFactories;
public static I18n federatedRepositoryCannotBeFound;
public static I18n unableToAuthenticateConnectionToFederatedRepository;
public static I18n repositoryHasBeenShutDown;
Modified:
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -200,6 +200,11 @@
}
}
connectionsBySourceName.clear();
+ try {
+ if (this.cacheConnection != null) this.cacheConnection.close();
+ } finally {
+ this.cacheConnection = null;
+ }
}
}
@@ -427,92 +432,88 @@
if (sourceNames != null && !sourceNames.contains(source)) continue;
final RepositoryConnection sourceConnection = getConnection(projection);
if (sourceConnection == null) continue; // No source exists by this name
- try {
- // Get the cached information ...
- CachePolicy cachePolicy = sourceConnection.getDefaultCachePolicy();
- if (cachePolicy == null) cachePolicy = this.defaultCachePolicy;
- DateTime expirationTime = null;
- if (cachePolicy != null) {
- expirationTime =
getCurrentTimeInUtc().plus(cachePolicy.getTimeToLive(), TimeUnit.MILLISECONDS);
- }
- // Get the paths-in-source where we should fetch node contributions ...
- Set<Path> pathsInSource = projection.getPathsInSource(path,
pathFactory);
- if (pathsInSource.isEmpty()) {
- // The source has no contributions, but see whether the project
exists BELOW this path.
- // We do this by getting the top-level repository paths of the
projection, and then
- // use those to figure out the children of the nodes.
- Contribution contribution = null;
- List<Path> topLevelPaths =
projection.getTopLevelPathsInRepository(pathFactory);
- switch (topLevelPaths.size()) {
- case 0:
- break;
- case 1: {
- Path topLevelPath = topLevelPaths.iterator().next();
+ // Get the cached information ...
+ CachePolicy cachePolicy = sourceConnection.getDefaultCachePolicy();
+ if (cachePolicy == null) cachePolicy = this.defaultCachePolicy;
+ DateTime expirationTime = null;
+ if (cachePolicy != null) {
+ expirationTime = getCurrentTimeInUtc().plus(cachePolicy.getTimeToLive(),
TimeUnit.MILLISECONDS);
+ }
+ // Get the paths-in-source where we should fetch node contributions ...
+ Set<Path> pathsInSource = projection.getPathsInSource(path,
pathFactory);
+ if (pathsInSource.isEmpty()) {
+ // The source has no contributions, but see whether the project exists
BELOW this path.
+ // We do this by getting the top-level repository paths of the
projection, and then
+ // use those to figure out the children of the nodes.
+ Contribution contribution = null;
+ List<Path> topLevelPaths =
projection.getTopLevelPathsInRepository(pathFactory);
+ switch (topLevelPaths.size()) {
+ case 0:
+ break;
+ case 1: {
+ Path topLevelPath = topLevelPaths.iterator().next();
+ if (path.isAncestorOf(topLevelPath)) {
+ assert topLevelPath.size() > path.size();
+ Path.Segment child = topLevelPath.getSegment(path.size());
+ contribution = Contribution.create(source, path,
expirationTime, null, child);
+ }
+ break;
+ }
+ default: {
+ // We assume that the top-level paths do not overlap ...
+ List<Path.Segment> children = new
ArrayList<Path.Segment>(topLevelPaths.size());
+ for (Path topLevelPath : topLevelPaths) {
if (path.isAncestorOf(topLevelPath)) {
assert topLevelPath.size() > path.size();
Path.Segment child =
topLevelPath.getSegment(path.size());
- contribution = Contribution.create(source, path,
expirationTime, null, child);
+ children.add(child);
}
- break;
}
- default: {
- // We assume that the top-level paths do not overlap ...
- List<Path.Segment> children = new
ArrayList<Path.Segment>(topLevelPaths.size());
- for (Path topLevelPath : topLevelPaths) {
- if (path.isAncestorOf(topLevelPath)) {
- assert topLevelPath.size() > path.size();
- Path.Segment child =
topLevelPath.getSegment(path.size());
- children.add(child);
- }
- }
- if (children.size() > 0) {
- contribution = Contribution.create(source, path,
expirationTime, null, children);
- }
+ if (children.size() > 0) {
+ contribution = Contribution.create(source, path,
expirationTime, null, children);
}
}
- if (contribution == null) contribution = Contribution.create(source,
expirationTime);
- contributions.add(contribution);
- } else {
- // There is at least one (real) contribution ...
+ }
+ if (contribution == null) contribution = Contribution.create(source,
expirationTime);
+ contributions.add(contribution);
+ } else {
+ // There is at least one (real) contribution ...
- // Get the contributions ...
- final int numPaths = pathsInSource.size();
- if (numPaths == 1) {
- Path pathInSource = pathsInSource.iterator().next();
- BasicGetNodeCommand fromSource = new
BasicGetNodeCommand(pathInSource);
- sourceConnection.execute(getExecutionContext(), fromSource);
- if (!fromSource.hasError()) {
- Collection<Property> properties =
fromSource.getProperties();
- List<Segment> children = fromSource.getChildren();
- DateTime expTime = fromSource.getCachePolicy() == null ?
expirationTime : getCurrentTimeInUtc().plus(fromSource.getCachePolicy().getTimeToLive(),
-
TimeUnit.MILLISECONDS);
- Contribution contribution = Contribution.create(source,
pathInSource, expTime, properties, children);
- contributions.add(contribution);
- }
- } else {
- BasicGetNodeCommand[] fromSourceCommands = new
BasicGetNodeCommand[numPaths];
- int i = 0;
- for (Path pathInSource : pathsInSource) {
- fromSourceCommands[i++] = new
BasicGetNodeCommand(pathInSource);
- }
- sourceConnection.execute(context, fromSourceCommands);
- for (BasicGetNodeCommand fromSource : fromSourceCommands) {
- if (fromSource.hasError()) continue;
- Collection<Property> properties =
fromSource.getProperties();
- List<Segment> children = fromSource.getChildren();
- DateTime expTime = fromSource.getCachePolicy() == null ?
expirationTime : getCurrentTimeInUtc().plus(fromSource.getCachePolicy().getTimeToLive(),
-
TimeUnit.MILLISECONDS);
- Contribution contribution = Contribution.create(source,
-
fromSource.getPath(),
- expTime,
- properties,
- children);
- contributions.add(contribution);
- }
+ // Get the contributions ...
+ final int numPaths = pathsInSource.size();
+ if (numPaths == 1) {
+ Path pathInSource = pathsInSource.iterator().next();
+ BasicGetNodeCommand fromSource = new
BasicGetNodeCommand(pathInSource);
+ sourceConnection.execute(getExecutionContext(), fromSource);
+ if (!fromSource.hasError()) {
+ Collection<Property> properties =
fromSource.getProperties();
+ List<Segment> children = fromSource.getChildren();
+ DateTime expTime = fromSource.getCachePolicy() == null ?
expirationTime : getCurrentTimeInUtc().plus(fromSource.getCachePolicy().getTimeToLive(),
+
TimeUnit.MILLISECONDS);
+ Contribution contribution = Contribution.create(source,
pathInSource, expTime, properties, children);
+ contributions.add(contribution);
}
+ } else {
+ BasicGetNodeCommand[] fromSourceCommands = new
BasicGetNodeCommand[numPaths];
+ int i = 0;
+ for (Path pathInSource : pathsInSource) {
+ fromSourceCommands[i++] = new BasicGetNodeCommand(pathInSource);
+ }
+ sourceConnection.execute(context, fromSourceCommands);
+ for (BasicGetNodeCommand fromSource : fromSourceCommands) {
+ if (fromSource.hasError()) continue;
+ Collection<Property> properties =
fromSource.getProperties();
+ List<Segment> children = fromSource.getChildren();
+ DateTime expTime = fromSource.getCachePolicy() == null ?
expirationTime : getCurrentTimeInUtc().plus(fromSource.getCachePolicy().getTimeToLive(),
+
TimeUnit.MILLISECONDS);
+ Contribution contribution = Contribution.create(source,
+
fromSource.getPath(),
+ expTime,
+ properties,
+ children);
+ contributions.add(contribution);
+ }
}
- } finally {
- sourceConnection.close();
}
}
}
Modified:
trunk/extensions/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties
===================================================================
---
trunk/extensions/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/extensions/dna-connector-federation/src/main/resources/org/jboss/dna/connector/federation/FederationI18n.properties 2008-09-16
19:03:58 UTC (rev 521)
@@ -24,12 +24,7 @@
nodeDoesNotExistAtPath = No node exists at {0} (or below {1})
errorRemovingNodeFromCache = Error while removing {0} from cache
-unableToFindFederatedRepositoryInJndi = Unable to find a FederatedRepository instance in
JNDI under "{1}" when creating connection to federated source "{0}"
-unableToFindExecutionContextFactoryInJndi = Unable to find an ExecutionContextFactory
instance in JNDI under "{1}" when creating connection to federated source
"{0}"
-unableToCreateExecutionContext = Unable to create ExecutionContext for connection to
federated source "{0}" when using factory in JNDI under "{1}" and
security domain "{2}"
-unableToFindRepositoryConnectionFactoriesInJndi = Unable to find an
RepositoryConnectionFactories instance in JNDI under "{1}" when creating
connection to federated source "{0}"
-objectFoundInJndiWasNotOfExpectedType = Object in JNDI at {0} found by
FederatedRepositorySource {1} was expected to be a {2} but instead was a {2}
-noRepositoryConnectionFactories = No RepositoryConnectionFactories instance was specified
directly or indirectly found in JNDI when creating connection to federated source
"{0}"
+unableToCreateExecutionContext = Unable to create ExecutionContext for connection to
federated source "{0}" when using security domain "{1}"
federatedRepositoryCannotBeFound = The federated repository "{0}" cannot be
found
unableToAuthenticateConnectionToFederatedRepository = Unable to authenticate
"{1}" for repository "{0}"
repositoryHasBeenShutDown = The "{0}" repository has been shut down and may no
longer be used.
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -40,6 +40,7 @@
import org.jboss.dna.spi.connector.BasicExecutionContext;
import org.jboss.dna.spi.connector.RepositoryConnection;
import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.RepositoryContext;
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.SimpleRepository;
import org.jboss.dna.spi.connector.SimpleRepositorySource;
@@ -90,6 +91,8 @@
private RepositoryConnectionFactory connectionFactory;
@Mock
private ExecutionContextFactory executionContextFactory;
+ @Mock
+ private RepositoryContext repositoryContext;
@Before
public void beforeEach() throws Exception {
@@ -105,6 +108,8 @@
stub(jndiContext.lookup(executionContextFactoryJndiName)).toReturn(executionContextFactory);
stub(jndiContext.lookup(repositoryConnectionFactoryJndiName)).toReturn(connectionFactory);
stub(executionContextFactory.create(eq(securityDomain),
anyCallbackHandler())).toReturn(context);
+
stub(repositoryContext.getExecutionContextFactory()).toReturn(executionContextFactory);
+
stub(repositoryContext.getRepositoryConnectionFactory()).toReturn(connectionFactory);
// Set up the federated repository source ...
source = new FederatedRepositorySource("Test Repository");
@@ -116,10 +121,8 @@
source.setPassword(credentials);
source.setConfigurationSourceName(configurationSourceName);
source.setConfigurationSourcePath("/repos/RepoX");
-
source.setRepositoryConnectionFactoryJndiName(repositoryConnectionFactoryJndiName);
- source.setExecutionContextFactoryJndiName(executionContextFactoryJndiName);
- source.setContext(jndiContext);
source.setSecurityDomain(securityDomain);
+ source.initialize(repositoryContext);
// Set up the configuration repository with its content ...
config = SimpleRepository.get("Configuration Repository");
Modified:
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java
===================================================================
---
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceTest.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -46,6 +46,7 @@
import org.jboss.dna.spi.connector.BasicExecutionContext;
import org.jboss.dna.spi.connector.RepositoryConnection;
import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.RepositoryContext;
import org.jboss.dna.spi.connector.RepositorySourceException;
import org.jboss.dna.spi.connector.SimpleRepository;
import org.jboss.dna.spi.connector.SimpleRepositorySource;
@@ -66,8 +67,6 @@
private String repositoryName;
private String username;
private String credentials;
- private String executionContextFactoryJndiName;
- private String repositoryConnectionFactoryJndiName;
private String configurationSourceName;
private String securityDomain;
private SimpleRepository configRepository;
@@ -77,11 +76,11 @@
@Mock
private RepositoryConnection connection;
@Mock
- private Context jndiContext;
- @Mock
private RepositoryConnectionFactory connectionFactory;
@Mock
private ExecutionContextFactory executionContextFactory;
+ @Mock
+ private RepositoryContext repositoryContext;
/**
* @throws java.lang.Exception
@@ -91,8 +90,6 @@
MockitoAnnotations.initMocks(this);
context = new BasicExecutionContext();
context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX,
DnaLexicon.Namespace.URI);
- executionContextFactoryJndiName = "context factory jndi name";
- repositoryConnectionFactoryJndiName = "repository connection factory jndi
name";
configurationSourceName = "configuration source name";
repositoryName = "Test Repository";
securityDomain = "security domain";
@@ -105,10 +102,8 @@
source.setPassword(credentials);
source.setConfigurationSourceName(configurationSourceName);
source.setConfigurationSourcePath("/dna:repositories/Test
Repository");
-
source.setRepositoryConnectionFactoryJndiName(repositoryConnectionFactoryJndiName);
- source.setExecutionContextFactoryJndiName(executionContextFactoryJndiName);
- source.setContext(jndiContext);
source.setSecurityDomain(securityDomain);
+ source.initialize(repositoryContext);
configRepository = SimpleRepository.get("Configuration Repository");
configRepository.setProperty(context, "/dna:repositories/Test
Repository/dna:federation/", "dna:timeToExpire", "100000");
configRepository.setProperty(context, "/dna:repositories/Test
Repository/dna:federation/", "dna:timeToCache", "100000");
@@ -128,9 +123,9 @@
configRepositorySource.setRepositoryName(configRepository.getRepositoryName());
configRepositorySource.setName(configurationSourceName);
configRepositoryConnection = configRepositorySource.getConnection();
+
stub(repositoryContext.getExecutionContextFactory()).toReturn(executionContextFactory);
+
stub(repositoryContext.getRepositoryConnectionFactory()).toReturn(connectionFactory);
stub(connectionFactory.createConnection(configurationSourceName)).toReturn(configRepositoryConnection);
-
stub(jndiContext.lookup(executionContextFactoryJndiName)).toReturn(executionContextFactory);
-
stub(jndiContext.lookup(repositoryConnectionFactoryJndiName)).toReturn(connectionFactory);
stub(executionContextFactory.create(eq(securityDomain),
anyCallbackHandler())).toReturn(context);
}
@@ -272,9 +267,6 @@
source.setName("Some source");
source.setConfigurationSourceName("config source");
source.setConfigurationSourcePath("/a/b/c");
- source.setRepositoryConnectionFactoryJndiName("repository connection factory
jndi name");
- source.setRepositoryJndiName("repository jndi name");
- source.setExecutionContextFactoryJndiName("env jndi name");
Reference ref = source.getReference();
assertThat(ref.getClassName(), is(FederatedRepositorySource.class.getName()));
@@ -295,12 +287,6 @@
assertThat((String)refAttributes.remove(FederatedRepositorySource.CONFIGURATION_SOURCE_NAME),
is(source.getConfigurationSourceName()));
assertThat((String)refAttributes.remove(FederatedRepositorySource.CONFIGURATION_SOURCE_PATH),
is("/a/b/c"));
-
assertThat((String)refAttributes.remove(FederatedRepositorySource.REPOSITORY_CONNECTION_FACTORY_JNDI_NAME),
- is(source.getRepositoryConnectionFactoryJndiName()));
-
assertThat((String)refAttributes.remove(FederatedRepositorySource.EXECUTION_CONTEXT_FACTORY_JNDI_NAME),
- is(source.getExecutionContextFactoryJndiName()));
-
assertThat((String)refAttributes.remove(FederatedRepositorySource.REPOSITORY_JNDI_NAME),
- is(source.getRepositoryJndiName()));
assertThat((String)refAttributes.remove(FederatedRepositorySource.SECURITY_DOMAIN),
is(securityDomain));
assertThat(refAttributes.isEmpty(), is(true));
@@ -319,9 +305,6 @@
assertThat(recoveredSource.getRetryLimit(), is(source.getRetryLimit()));
assertThat(recoveredSource.getConfigurationSourceName(),
is(source.getConfigurationSourceName()));
assertThat(recoveredSource.getConfigurationSourcePath(),
is(source.getConfigurationSourcePath()));
- assertThat(recoveredSource.getRepositoryConnectionFactoryJndiName(),
is(source.getRepositoryConnectionFactoryJndiName()));
- assertThat(recoveredSource.getExecutionContextFactoryJndiName(),
is(source.getExecutionContextFactoryJndiName()));
- assertThat(recoveredSource.getRepositoryJndiName(),
is(source.getRepositoryJndiName()));
assertThat(recoveredSource.getSecurityDomain(), is(source.getSecurityDomain()));
assertThat(recoveredSource.equals(source), is(true));
Modified:
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryConnection.java
===================================================================
---
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryConnection.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryConnection.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -129,15 +129,19 @@
}
}
+ CommandExecutor executor = this.content.getCommandExecutor(context,
this.getSourceName());
try {
// Obtain the lock and execute the commands ...
- CommandExecutor executor = this.content.getCommandExecutor(context,
this.getSourceName());
lock.lock();
for (GraphCommand command : commands) {
executor.execute(command);
}
} finally {
- lock.unlock();
+ try {
+ executor.close();
+ } finally {
+ lock.unlock();
+ }
}
if (logger.isTraceEnabled()) {
assert sw != null;
Modified:
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java
===================================================================
---
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/extensions/dna-connector-inmemory/src/main/java/org/jboss/dna/connector/inmemory/InMemoryRepositorySource.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -45,6 +45,7 @@
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryContext;
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceCapabilities;
import org.jboss.dna.spi.connector.RepositorySourceException;
@@ -78,6 +79,7 @@
private CachePolicy defaultCachePolicy;
private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
private transient InMemoryRepository repository;
+ private transient RepositoryContext repositoryContext;
/**
* Create a repository source instance.
@@ -89,6 +91,22 @@
/**
* {@inheritDoc}
*
+ * @see
org.jboss.dna.spi.connector.RepositorySource#initialize(org.jboss.dna.spi.connector.RepositoryContext)
+ */
+ public void initialize( RepositoryContext context ) throws RepositorySourceException
{
+ this.repositoryContext = context;
+ }
+
+ /**
+ * @return repositoryContext
+ */
+ public RepositoryContext getRepositoryContext() {
+ return repositoryContext;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.spi.connector.RepositorySource#getRetryLimit()
*/
public int getRetryLimit() {
Modified:
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
---
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-09-16
16:39:31 UTC (rev 520)
+++
trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java 2008-09-16
19:03:58 UTC (rev 521)
@@ -48,6 +48,7 @@
import org.jboss.dna.spi.DnaLexicon;
import org.jboss.dna.spi.cache.CachePolicy;
import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryContext;
import org.jboss.dna.spi.connector.RepositorySource;
import org.jboss.dna.spi.connector.RepositorySourceCapabilities;
import org.jboss.dna.spi.connector.RepositorySourceException;
@@ -99,6 +100,7 @@
private final AtomicInteger retryLimit = new AtomicInteger(DEFAULT_RETRY_LIMIT);
private transient Cache<Name, Object> cache;
private transient Context jndiContext;
+ private transient RepositoryContext repositoryContext;
/**
* Create a repository source instance.
@@ -108,7 +110,23 @@
/**
* {@inheritDoc}
+ *
+ * @see
org.jboss.dna.spi.connector.RepositorySource#initialize(org.jboss.dna.spi.connector.RepositoryContext)
*/
+ public void initialize( RepositoryContext context ) throws RepositorySourceException
{
+ this.repositoryContext = context;
+ }
+
+ /**
+ * @return repositoryContext
+ */
+ public RepositoryContext getRepositoryContext() {
+ return repositoryContext;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public String getName() {
return this.name;
}