org.rhq.enterprise.server.plugin.pc.content
Class ContentProviderManager

java.lang.Object
  extended by org.rhq.enterprise.server.plugin.pc.content.ContentProviderManager

public class ContentProviderManager
extends Object

Responsible for managing ContentProvider implementations. These implementations come from the content plugins themselves.

Author:
John Mazzitelli, Jason Dobies

Constructor Summary
ContentProviderManager()
           
 
Method Summary
protected  void createInitialAdaptersMap()
          This is protected so only the plugin container and subclasses can use it.
 Set<org.rhq.core.domain.content.ContentSource> getAllContentSources()
          Returns a set of all content sources whose adapters are managed by this object.
 ContentProvider getIsolatedContentProvider(int contentProviderId)
          Given a ID to a content source, this returns the adapter that is responsible for communicating with that content source where that adapter object will ensure invocations on it are isolated to its plugin classloader.
protected  ContentProvider getIsolatedContentSourceAdapter(org.rhq.core.domain.content.ContentSource contentSource)
          This returns the adapter that is responsible for communicating with the given content source where that adaptor object will ensure invocations on it are isolated to its plugin classloader.
protected  void initialize(ContentServerPluginManager pluginManager)
          Tells this manager to initialize itself which will initialize all the adapters.
protected  ContentProvider instantiateAdapter(org.rhq.core.domain.content.ContentSource contentSource)
          Creates a provider instance that will service the give ContentSource.
 InputStream loadDistributionFileBits(int contentSourceId, String location)
          Asks that the adapter responsible for the given content source return a stream to the DistributionFile bits for the DistributionFile at the given location.
 InputStream loadPackageBits(int contentSourceId, String location)
          Asks that the adapter responsible for the given content source return a stream to the package bits for the package at the given location.
 void restartAdapter(org.rhq.core.domain.content.ContentSource contentSource)
          Convienence method that simply shuts down the adapter and then restarts it.
protected  void shutdown()
          Tells this manager to shutdown.
 void shutdownAdapter(org.rhq.core.domain.content.ContentSource contentSource)
          Call this method when a content source is removed from the system during runtime or if you just want to shutdown the adapter for whatever reason.
 void startAdapter(org.rhq.core.domain.content.ContentSource contentSource)
          Call this method when a new content source is added to the system during runtime.
 boolean synchronizeContentProvider(int contentSourceId)
          Asks the provider responsible for the given content source to synchronize with its remote repository.
 boolean synchronizeRepo(int repoId)
          Asks each content source associated with the given repo to synchronize the following information for the given repo: Package Metadata Package Bits Distribution Tree Metadata Distribution Tree Bits
 void testConnection(int contentSourceId)
          Tests the connection to the content source that has the given ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentProviderManager

public ContentProviderManager()
Method Detail

loadPackageBits

public InputStream loadPackageBits(int contentSourceId,
                                   String location)
                            throws Exception
Asks that the adapter responsible for the given content source return a stream to the package bits for the package at the given location.

Parameters:
contentSourceId - the adapter for this content source will be used to stream the bits
location - where the adapter can find the package bits on the content source
Returns:
the stream to the package bits
Throws:
Exception - if the adapter failed to load the bits

loadDistributionFileBits

public InputStream loadDistributionFileBits(int contentSourceId,
                                            String location)
                                     throws Exception
Asks that the adapter responsible for the given content source return a stream to the DistributionFile bits for the DistributionFile at the given location.

Parameters:
contentSourceId - the adapter for this content source will be used to stream the bits
location - where the adapter can find the DistributionFile bits on the source
Returns:
the stream to the DistributionFile bits
Throws:
Exception - if the adapter failed to load the bits

synchronizeContentProvider

public boolean synchronizeContentProvider(int contentSourceId)
                                   throws Exception
Asks the provider responsible for the given content source to synchronize with its remote repository. This will not attempt to load any package bits - it only synchronizes the repos and package version information. Note that if a synchronization is already currently underway, this method will not do anything and will return false (in effect, will let the currently running synchronization continue; we try not to step on it). If this method does actually do a sync, true will be returned.

Parameters:
contentSourceId - identifies the database entry of the provider
Returns:
true if the synchronization completed; false if there was already a synchronization happening and this method aborted
Throws:
Exception

synchronizeRepo

public boolean synchronizeRepo(int repoId)
Asks each content source associated with the given repo to synchronize the following information for the given repo:

Parameters:
repoId - must indicate a valid repo in the database
Returns:
true if the synchronize took place; false if it did not (for instance, if there is already a sync taking place for this repo)
Throws:
Exception - if the data required to perform the sync is missing or invalid

testConnection

public void testConnection(int contentSourceId)
                    throws Exception
Tests the connection to the content source that has the given ID.

Parameters:
contentSourceId - the id of the content source to be tested
Throws:
Exception - if the test connection to the specified content source failed

getAllContentSources

public Set<org.rhq.core.domain.content.ContentSource> getAllContentSources()
Returns a set of all content sources whose adapters are managed by this object.

Returns:
all content sources

startAdapter

public void startAdapter(org.rhq.core.domain.content.ContentSource contentSource)
                  throws InitializationException
Call this method when a new content source is added to the system during runtime. This can also be used to restart an adapter that was previously shutdown.

If there is already an adapter currently started for the given content source, this returns silently.

Parameters:
contentSource - the new content source that was added
Throws:
InitializationException - if the provider throws an error on its startup

shutdownAdapter

public void shutdownAdapter(org.rhq.core.domain.content.ContentSource contentSource)
Call this method when a content source is removed from the system during runtime or if you just want to shutdown the adapter for whatever reason. You can restart the adapter by calling startAdapter(ContentSource).

If there are no adapters currently started for the given content source, this returns silently.

Parameters:
contentSource - the content source being deleted

restartAdapter

public void restartAdapter(org.rhq.core.domain.content.ContentSource contentSource)
                    throws Exception
Convienence method that simply shuts down the adapter and then restarts it. Call this when, for example, a content source's configuration has changed.

Parameters:
contentSource - the content source whose adapter is to be restarted
Throws:
Exception - if there is an error asking the provider to shutdown or start

getIsolatedContentProvider

public ContentProvider getIsolatedContentProvider(int contentProviderId)
                                           throws RuntimeException
Given a ID to a content source, this returns the adapter that is responsible for communicating with that content source where that adapter object will ensure invocations on it are isolated to its plugin classloader.

Parameters:
contentProviderId - an ID to a ContentSource
Returns:
the adapter that is communicating with the content source, isolated to its classloader
Throws:
RuntimeException - if there is no content source with the given ID

initialize

protected void initialize(ContentServerPluginManager pluginManager)
Tells this manager to initialize itself which will initialize all the adapters.

This is protected so only the plugin container and subclasses can use it.

Parameters:
pluginManager - the plugin manager this object can use to obtain information from (like classloaders)

shutdown

protected void shutdown()
Tells this manager to shutdown. This will effectively shutdown all of its adapters.

This is protected so only the plugin container and subclasses can use it.


createInitialAdaptersMap

protected void createInitialAdaptersMap()
This is protected so only the plugin container and subclasses can use it.


getIsolatedContentSourceAdapter

protected ContentProvider getIsolatedContentSourceAdapter(org.rhq.core.domain.content.ContentSource contentSource)
                                                   throws RuntimeException
This returns the adapter that is responsible for communicating with the given content source where that adaptor object will ensure invocations on it are isolated to its plugin classloader.

Parameters:
contentSource - the returned adapter communicates with this content source
Returns:
the adapter that is communicating with the content source, isolated to its classloader
Throws:
RuntimeException - if there is no content source adapter available

instantiateAdapter

protected ContentProvider instantiateAdapter(org.rhq.core.domain.content.ContentSource contentSource)
Creates a provider instance that will service the give ContentSource.

Parameters:
contentSource - the source that the adapter will connect to
Returns:
an adapter instance; will be null if failed to create adapter


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.