org.jboss.dna.repository
Class RepositoryLibrary

java.lang.Object
  extended by org.jboss.dna.repository.RepositoryLibrary
All Implemented Interfaces:
RepositoryConnectionFactory, Observable

@ThreadSafe
public class RepositoryLibrary
extends Object
implements RepositoryConnectionFactory, Observable

A library of RepositorySource instances and the RepositoryConnectionPool used to manage the connections for each.

Author:
Randall Hauch

Constructor Summary
RepositoryLibrary(RepositorySource configurationSource, String configurationWorkspaceName, Path pathToSourcesConfigurationRoot, ExecutionContext context)
          Create a new manager instance.
 
Method Summary
 boolean addSource(RepositorySource source)
          Add the supplied federated source.
 RepositoryConnection createConnection(String sourceName)
          Create a RepositoryConnection using the given RepositorySource name.
 ServiceAdministrator getAdministrator()
           
 RepositoryConnectionPool getConnectionPool(String sourceName)
          Get the connection pool managing the RepositorySource with the specified name managed by this instance.
 ExecutionContext getExecutionContext()
           
 RepositorySource getSource(String sourceName)
          Get the RepositorySource with the specified name managed by this instance.
 Collection<String> getSourceNames()
          Get an unmodifiable collection of RepositorySource names.
 Collection<RepositorySource> getSources()
          Get an unmodifiable collection of RepositorySource instances managed by this instance.
 boolean isTerminated()
          Return true if this federated repository has completed its termination and no longer has any open connections.
 boolean isTerminating()
          Returns true if this federated repository is in the process of terminating after ServiceAdministrator.shutdown() has been called on the administrator, but the federated repository has connections that have not yet normally been closed.
 boolean register(ChangeObserver observer)
          Register the supplied observer.
 boolean removeSource(RepositorySource source, long timeToAwait, TimeUnit unit)
          Remove from this federated repository the supplied source (or a source with the same name as that supplied).
 RepositorySource removeSource(String name, long timeToAwait, TimeUnit unit)
          Remove from this federated repository the source with the supplied name.
 boolean unregister(ChangeObserver observer)
          Unregister the supplied observer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RepositoryLibrary

public RepositoryLibrary(RepositorySource configurationSource,
                         String configurationWorkspaceName,
                         Path pathToSourcesConfigurationRoot,
                         ExecutionContext context)
Create a new manager instance.

Parameters:
configurationSource - the RepositorySource that is the configuration repository
configurationWorkspaceName - the name of the workspace in the RepositorySource that is the configuration repository, or null if the default workspace of the source should be used (if there is one)
pathToSourcesConfigurationRoot - the path of the node in the configuration source repository that should be treated by this service as the root of the service's configuration; if null, then "/dna:system" is used
context - the execution context in which this service should run
Throws:
IllegalArgumentException - if the executionContextFactory reference is null
Method Detail

register

public boolean register(ChangeObserver observer)
Register the supplied observer. This method does nothing if the observer reference is null.

Specified by:
register in interface Observable
Parameters:
observer - the observer to be added; may be null
Returns:
true if the observer was added, or false if the observer was null, if the observer was already registered, or if the observer could not be added
See Also:
Observable.register(org.jboss.dna.graph.observe.ChangeObserver)

unregister

public boolean unregister(ChangeObserver observer)
Unregister the supplied observer. This method does nothing if the observer reference is null.

Specified by:
unregister in interface Observable
Parameters:
observer - the observer to be removed; may not be null
Returns:
true if the observer was removed, or false if the observer was null or if the observer was not registered on this source
See Also:
Observable.unregister(org.jboss.dna.graph.observe.ChangeObserver)

getExecutionContext

public ExecutionContext getExecutionContext()
Returns:
executionContextFactory

getAdministrator

public ServiceAdministrator getAdministrator()
Returns:
administrator

isTerminating

public boolean isTerminating()
Returns true if this federated repository is in the process of terminating after ServiceAdministrator.shutdown() has been called on the administrator, but the federated repository has connections that have not yet normally been closed. This method may be useful for debugging. A return of true reported a sufficient period after shutdown may indicate that connection users have ignored or suppressed interruption, causing this repository not to properly terminate.

Returns:
true if terminating but not yet terminated, or false otherwise
See Also:
isTerminated()

isTerminated

public boolean isTerminated()
Return true if this federated repository has completed its termination and no longer has any open connections.

Returns:
true if terminated, or false otherwise
See Also:
isTerminating()

getSourceNames

public Collection<String> getSourceNames()
Get an unmodifiable collection of RepositorySource names.

Returns:
the pools

getSources

public Collection<RepositorySource> getSources()
Get an unmodifiable collection of RepositorySource instances managed by this instance.

Returns:
the pools

getSource

public RepositorySource getSource(String sourceName)
Get the RepositorySource with the specified name managed by this instance.

Parameters:
sourceName - the name of the source
Returns:
the source, or null if no such source exists in this instance

getConnectionPool

public RepositoryConnectionPool getConnectionPool(String sourceName)
Get the connection pool managing the RepositorySource with the specified name managed by this instance.

Parameters:
sourceName - the name of the source
Returns:
the pool, or null if no such pool exists in this instance

addSource

public boolean addSource(RepositorySource source)
Add the supplied federated source. This method returns false if the source is null.

Parameters:
source - the source to add
Returns:
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.

removeSource

public boolean removeSource(RepositorySource source,
                            long timeToAwait,
                            TimeUnit unit)
                     throws InterruptedException
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.

This method can safely be called while the federation repository is in use.

Parameters:
source - the source to be removed
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
unit - the time unit to be used for timeToAwait
Returns:
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

removeSource

public RepositorySource removeSource(String name,
                                     long timeToAwait,
                                     TimeUnit unit)
                              throws InterruptedException
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.

Parameters:
name - the name of the source to be removed
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
unit - the time unit to be used for timeToAwait
Returns:
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

createConnection

public RepositoryConnection createConnection(String sourceName)
Create a RepositoryConnection using the given RepositorySource name.

Specified by:
createConnection in interface RepositoryConnectionFactory
Parameters:
sourceName - the name of the source from which a connection should be obtained
Returns:
the source, or null if no such source could be found (or created)
See Also:
RepositoryConnectionFactory.createConnection(java.lang.String)


Copyright © 2008-Present JBoss a division of Red Hat. All Rights Reserved.