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 java.lang.Object

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

Author:
John Mazzitelli

Constructor Summary
ContentProviderManager()
           
 
Method Summary
protected  void createInitialAdaptersMap()
          This is protected so only the plugin container and subclasses can use it.
 java.util.Set<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(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.
 java.io.InputStream loadDistributionFileBits(int contentSourceId, java.lang.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.
 java.io.InputStream loadPackageBits(int contentSourceId, java.lang.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(ContentSource contentSource)
          Convienence method that simply shuts down the adapter and then restarts it.
protected  void shutdown()
          Tells this manager to shutdown.
 void shutdownAdapter(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(ContentSource contentSource)
          Call this method when a new content source is added to the system during runtime.
 boolean synchronizeContentSource(int contentSourceId)
          Asks the provider responsible for the given content source to synchronize with its remote repository.
 boolean 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 java.io.InputStream loadPackageBits(int contentSourceId,
                                           java.lang.String location)
                                    throws java.lang.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:
java.lang.Exception - if the adapter failed to load the bits

loadDistributionFileBits

public java.io.InputStream loadDistributionFileBits(int contentSourceId,
                                                    java.lang.String location)
                                             throws java.lang.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 content source
Returns:
the stream to the DistributionFile bits
Throws:
java.lang.Exception - if the adapter failed to load the bits

synchronizeContentSource

public boolean synchronizeContentSource(int contentSourceId)
                                 throws java.lang.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:
java.lang.Exception

testConnection

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

Parameters:
contentSourceId -
Returns:
true if there is an adapter that can successfully connect to the given content source false if there is an adapter but it cannot successfully connect
Throws:
java.lang.Exception - if failed to get an adapter to attempt the connection

getAllContentSources

public java.util.Set<ContentSource> getAllContentSources()
Returns a set of all content sources whose adapters are managed by this object.

Returns:
all content sources

startAdapter

public void startAdapter(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(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(ContentSource contentSource)
                    throws java.lang.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:
java.lang.Exception - if there is an error asking the provider to shutdown or start

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)
Throws:
InitializationException - if any of the providers throw an error on startup

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.


getIsolatedContentProvider

public ContentProvider getIsolatedContentProvider(int contentProviderId)
                                           throws java.lang.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:
java.lang.RuntimeException - if there is no content source with the given ID

getIsolatedContentSourceAdapter

protected ContentProvider getIsolatedContentSourceAdapter(ContentSource contentSource)
                                                   throws java.lang.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:
java.lang.RuntimeException - if there is no content source adapter available


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