net.sourceforge.fluxion.spi
Class SPIManager

java.lang.Object
  extended by net.sourceforge.fluxion.spi.SPIManager
All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean

public class SPIManager
extends java.lang.Object
implements org.springframework.beans.factory.InitializingBean

A Manager class for Service Provider utilities. This Manager is backed by a Raven repository, which is a dynamic version of Maven that employs runtime loading and deployment of jars. Utility methods are provided for conveniently committing jars, discovering meta data about Maven artifacts, and looking up available artifacts from the repository.

Spring configuration of an SPIManager bean is possible, using properties localRepository, remoteRepositories (a set) and offlineMode (false by default).

If you are using spring configuration, this bean will automatically initialise once all properties have been set, as it implements InitializingBean. If you are not using spring configuration but are instead using this class standalone, you should remember to call the init() method before use to ensure the Raven repository is correctly initialiased.

Author:
Tony Burdett

Constructor Summary
SPIManager()
           
 
Method Summary
 void addMavenRemoteRepository(java.lang.String remoteRepository)
          Add a Maven remote repository Raven can use to download artifacts from.
 void afterPropertiesSet()
          Initialises SPIManager once any properties managed by Spring have been set in an application context.
 java.lang.String getMavenLocalRepository()
          Get the local repository used by Maven.
 java.util.Set<java.lang.String> getMavenRemoteRepositories()
          Get the set of remote repositories used by Maven.
 boolean getOfflineMode()
          Get offline mode - whether Raven can connect to the internet to download artifacts
 java.lang.String getRavenRepository()
          Get the local repository used by Raven
<SPI> java.util.Set<java.lang.Class<? extends SPI>>
getServiceProviderClasses(java.lang.Class<SPI> spi)
          Get a set of service provider classes that implement the given SPI class.
<SPI> java.util.Set<SPI>
getServiceProviders(java.lang.Class<SPI> spi)
          Get a set of service provider instances that implement the given SPI class.
 boolean hotloadArtifact(java.io.File jarFile)
          Add a new Maven artifact from a jar file.
 boolean hotloadArtifact(java.lang.String groupId, java.lang.String artifactId, java.lang.String version)
          Add a new artifact from one of the cofigured repositories.
 boolean init()
          Initialise the SPIManager.
 void removeMavenRemoteRepository(java.lang.String remoteRepository)
          Remove a Maven remote repository that Raven has been using to download artifacts from.
 void setMavenLocalRepository(java.lang.String mavenLocalRepository)
          Set the local repository used by Maven for this system.
 void setMavenRemoteRepositories(java.util.Set<java.lang.String> remoteRepositories)
          Set a Set of Maven remote repositories Raven can use to download artifacts from.
 void setOfflineMode(boolean offlineMode)
          Set offline mode - when this is true, Raven will never download artifacts from remote repositories.
 void setRavenRepository(java.lang.String localRepository)
          Set the local repository Raven will use
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SPIManager

public SPIManager()
Method Detail

setRavenRepository

public void setRavenRepository(java.lang.String localRepository)
Set the local repository Raven will use

Parameters:
localRepository - the location (on-disk) Raven will store artifacts

getRavenRepository

public java.lang.String getRavenRepository()
Get the local repository used by Raven

Returns:
the location (on-disk) Raven stores artifacts

setMavenLocalRepository

public void setMavenLocalRepository(java.lang.String mavenLocalRepository)
Set the local repository used by Maven for this system. This will normally be ~/.m2/repository.

Parameters:
mavenLocalRepository - the maven local repository

getMavenLocalRepository

public java.lang.String getMavenLocalRepository()
Get the local repository used by Maven.

Returns:
the Maven local repository

setMavenRemoteRepositories

public void setMavenRemoteRepositories(java.util.Set<java.lang.String> remoteRepositories)
Set a Set of Maven remote repositories Raven can use to download artifacts from. This should include at least the Maven central repository.

Parameters:
remoteRepositories - a set of remote repositories

getMavenRemoteRepositories

public java.util.Set<java.lang.String> getMavenRemoteRepositories()
Get the set of remote repositories used by Maven.

Returns:
a set of the remote repos used

addMavenRemoteRepository

public void addMavenRemoteRepository(java.lang.String remoteRepository)
Add a Maven remote repository Raven can use to download artifacts from.

Parameters:
remoteRepository - a remote repository url to add

removeMavenRemoteRepository

public void removeMavenRemoteRepository(java.lang.String remoteRepository)
Remove a Maven remote repository that Raven has been using to download artifacts from.

Parameters:
remoteRepository - a remote repository url to remove

setOfflineMode

public void setOfflineMode(boolean offlineMode)
Set offline mode - when this is true, Raven will never download artifacts from remote repositories.

Parameters:
offlineMode - true if Raven should never connect to the internet

getOfflineMode

public boolean getOfflineMode()
Get offline mode - whether Raven can connect to the internet to download artifacts

Returns:
true if Raven can download from remote repos

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Initialises SPIManager once any properties managed by Spring have been set in an application context.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception - if there is a problem initialising this bean

init

public boolean init()
Initialise the SPIManager. This will create a Raven repository and will use any configured Maven repositories that have been set up, both local or remote.

This will be called automatically if you are using Spring configuration.

Returns:
true if initialisation succeeds, false otherwise

hotloadArtifact

public boolean hotloadArtifact(java.io.File jarFile)
Add a new Maven artifact from a jar file. This method will install the given file as a maven artifact, in the maven local repository on the server. If Maven is not installed on the server, this method will fail, returning false, and no artifact will be added. The jar file to hotload must be present or accessible from the server - there is no facility to upload and dynamically load files from another location, for security reasons. The file will first be inspected for Maven metadata files, it's parameters determined, and finally the artifact will be added to the Raven repository. If this artifact contains any @Spi annotations, these classes will be discoverable using a Raven SpiRegistry, or by calling getServiceProviders(Class)

Parameters:
jarFile - the jar file to hotload
Returns:
true if successful, false otherwise

hotloadArtifact

public boolean hotloadArtifact(java.lang.String groupId,
                               java.lang.String artifactId,
                               java.lang.String version)
Add a new artifact from one of the cofigured repositories. This artifact will be downloaded and added to the Raven repository. If this artifact contains any @Spi annotations, these classes will be discoverable using a Raven SpiRegistry, or by calling getServiceProviders(Class)

Parameters:
groupId - the group id of the maven artifact to import
artifactId - the artifact id of the artifact to import
version - the version of the artifact to import
Returns:
true if successful, false otherwise

getServiceProviders

public <SPI> java.util.Set<SPI> getServiceProviders(java.lang.Class<SPI> spi)
Get a set of service provider instances that implement the given SPI class. This method inspects the runtime environment for any classes that are designated as a service, and creates a new instance for each one that implements that SPI interface specified as a parameter.

Type Parameters:
SPI - the type of the service provider interface
Parameters:
spi - the service provider interface for services to discover
Returns:
a set of instances of all available services that implement the given interface

getServiceProviderClasses

public <SPI> java.util.Set<java.lang.Class<? extends SPI>> getServiceProviderClasses(java.lang.Class<SPI> spi)
Get a set of service provider classes that implement the given SPI class. This method inspects the runtime environment for any classes that are designated as a service, and returns a set of these classes.

Type Parameters:
SPI - the type of the service provider interface
Parameters:
spi - the service provider interface for services to discover
Returns:
a set of classes of all available services that implement the given interface


Copyright © 2010. All Rights Reserved.