org.modeshape.repository
Class RepositoryLibrary

java.lang.Object
  extended by org.modeshape.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.


Nested Class Summary
protected  class RepositoryLibrary.Administrator
          The administrative component for this service.
 
Constructor Summary
RepositoryLibrary(RepositorySource configurationSource, String configurationWorkspaceName, Path pathToSourcesConfigurationRoot, ExecutionContext context, ObservationBus observationBus)
          Create a new manager instance.
 
Method Summary
 boolean addSource(RepositorySource source)
          Add the supplied source.
 boolean addSource(RepositorySource source, boolean replaceIfExisting)
          Add the supplied source.
protected  boolean awaitTermination(long timeout, TimeUnit unit)
          Utility method called by the administrator.
 RepositoryConnection createConnection(String sourceName)
          Create a RepositoryConnection using the given RepositorySource name.
 ServiceAdministrator getAdministrator()
           
protected  RepositorySource getConfigurationSource()
           
protected  String getConfigurationWorkspaceName()
           
 RepositoryConnectionPool getConnectionPool(String sourceName)
          Get the connection pool managing the RepositorySource with the specified name managed by this instance.
 ExecutionContext getExecutionContext()
           
protected  Path getPathToConfigurationRoot()
          Get the path to the top-level of the configuration root.
 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 library has completed its termination and no longer has any open connections.
 boolean isTerminating()
          Returns true if this library is in the process of terminating after ServiceAdministrator.shutdown() has been called on the administrator, but the library has connections that have not yet normally been closed.
 boolean register(Observer observer)
          Register the supplied observer.
 boolean removeSource(RepositorySource source, long timeToAwait, TimeUnit unit)
          Remove from this library the supplied source (or a source with the same name as that supplied).
 RepositorySource removeSource(String name)
          Remove from this library the source with the supplied name.
 RepositorySource removeSource(String name, long timeToAwait, TimeUnit unit)
          Remove from this library the source with the supplied name.
protected  void shutdown()
          Utility method called by the administrator.
protected  void start()
          Utility method called by the administrator.
 boolean unregister(Observer observer)
          Unregister the supplied observer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RepositoryLibrary

public RepositoryLibrary(RepositorySource configurationSource,
                         String configurationWorkspaceName,
                         Path pathToSourcesConfigurationRoot,
                         ExecutionContext context,
                         ObservationBus observationBus)
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
context - the execution context in which this service should run
observationBus - the ObservationBus instance that should be used for changes in the sources
Throws:
IllegalArgumentException - if any of the configurationSource, pathToSourcesConfigurationRoot, observationBus, or context references are null
Method Detail

getPathToConfigurationRoot

protected Path getPathToConfigurationRoot()
Get the path to the top-level of the configuration root.

Returns:
pathToConfigurationRoot

getConfigurationSource

protected RepositorySource getConfigurationSource()
Returns:
configurationSource

getConfigurationWorkspaceName

protected String getConfigurationWorkspaceName()
Returns:
configurationWorkspaceName

register

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

This can be used to register observers for all of the repository sources managed by this library. The supplied observer will receive all of the changes originating from these sources.

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.modeshape.graph.observe.Observer)

unregister

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

This can be used to unregister observers for all of the repository sources managed by this library.

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.modeshape.graph.observe.Observer)

getExecutionContext

public ExecutionContext getExecutionContext()
Returns:
executionContextFactory

getAdministrator

public ServiceAdministrator getAdministrator()
Returns:
administrator

start

protected void start()
Utility method called by the administrator.


shutdown

protected void shutdown()
Utility method called by the administrator.


awaitTermination

protected boolean awaitTermination(long timeout,
                                   TimeUnit unit)
                            throws InterruptedException
Utility method called by the administrator.

Parameters:
timeout -
unit -
Returns:
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

isTerminating

public boolean isTerminating()
Returns true if this library is in the process of terminating after ServiceAdministrator.shutdown() has been called on the administrator, but the library 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 library 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 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.

addSource

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

If a source with the same name already exists, it will be replaced only if replaceIfExisting is true. If this is the case, then the existing source will be removed from the connection pool, and that pool will be shutdown (allowing any in-use connections to be used and finished normally).

Parameters:
source - the source to add
replaceIfExisting - true if an existing source should be replaced, or false if this method should return false if there is already an existing source with the supplied name.
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 library 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)
Remove from this library 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. However, this method never waits until the connections are all closed, and is equivalent to calling removeSource(name,0,TimeUnit.SECONDS).

Parameters:
name - the name of the source to be removed
Returns:
the source with the supplied name that was removed, or null if no existing source matching the supplied name could be found
See Also:
removeSource(String, long, TimeUnit)

removeSource

public RepositorySource removeSource(String name,
                                     long timeToAwait,
                                     TimeUnit unit)
                              throws InterruptedException
Remove from this library 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
See Also:
removeSource(String)

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-2010 JBoss, a division of Red Hat. All Rights Reserved.