org.apache.tuscany.sca.host.embedded.impl
Class HotUpdatableSCADomain

java.lang.Object
  extended by org.apache.tuscany.sca.host.embedded.SCADomain
      extended by org.apache.tuscany.sca.host.embedded.impl.HotUpdatableSCADomain

public class HotUpdatableSCADomain
extends SCADomain

An SCADomain that starts a Tuscany runtime supporting multiple SCA contribution jars. All contribution jars found in a repository directory will be contributed to the SCA domain. Any changes to the contributions in that repository will be automatically detected and the SCADomain updated accordingly. TODO: find how to properly add/remove contributions and start/activate the SCADomain TODO: support contributions that are folders as well as jar's TODO: needs to restart the entire SCADomain when a contribution changes as the domain classpath includes all the contribution jar's, would be nice to find a way to avoid this TODO: hot update requires copying contribution jars to a temp location to avoid the classpath lock preventing updating the contribution jars, would be nice to find a way to avoid that


Field Summary
protected  java.io.File contributionRepository
           
protected  java.lang.String domainURI
           
protected  java.util.HashMap<java.net.URL,java.lang.Long> existingContributions
           
protected  boolean hotUpdateActive
           
protected  int hotUpdateInterval
           
protected  java.lang.Thread hotUpdateThread
           
protected  java.lang.ClassLoader originalCCL
           
protected static java.lang.String REPOSITORY_FOLDER
           
protected  EmbeddedSCADomain scaDomain
           
 
Fields inherited from class org.apache.tuscany.sca.host.embedded.SCADomain
theDomain
 
Constructor Summary
HotUpdatableSCADomain(java.lang.String domainURI, java.io.File contributionRepository, int hotupdateInterval)
           
 
Method Summary
protected  void activateHotUpdate()
           
protected  boolean areContributionsAltered(java.net.URL[] currentContrabutions)
           
<B,R extends org.osoa.sca.CallableReference<B>>
R
cast(B target)
          Cast a type-safe reference to a CallableReference.
protected  void checkForUpdates()
          Checks if any of the contributions have been updated and if so restarts the SCADomain TODO: Ideally just the altered contribution would be restarted but thats not possible as the ClassLoader used by the SCADomain includes the old contribution so need to restart the entire domain to use a new ClassLoader.
 void close()
          Close the SCA domain.
protected  java.net.URL[] copyContributionsToTemp(java.net.URL[] contributionJars)
          Copies Files to a temp location returning the URLs of the new temp files.
protected  java.util.List getAddedContributions(java.net.URL[] currentContrabutions)
           
 ComponentManager getComponentManager()
           
protected  java.net.URL[] getContributionJarURLs(java.io.File repositoryDir)
           
protected  java.util.HashMap<java.net.URL,java.lang.Long> getLastModified(java.net.URL[] contrabutions)
          Returns the last modified times of the files pointed to by the URLs
protected  java.util.List getRemovedContributions(java.net.URL[] currentContrabutions)
           
<B> B
getService(java.lang.Class<B> businessInterface, java.lang.String serviceName)
          Returns a proxy for a service provided by a component in the SCA domain.
<B> org.osoa.sca.ServiceReference<B>
getServiceReference(java.lang.Class<B> businessInterface, java.lang.String referenceName)
          Returns a ServiceReference for a service provided by a component in the SCA domain.
protected  java.util.List<java.net.URL> getUpdatedContributions(java.net.URL[] currentContrabutions)
           
 java.lang.String getURI()
          Returns the URI of the SCA Domain.
protected  void initContributions(EmbeddedSCADomain scaDomain, java.lang.ClassLoader cl, java.net.URL[] contributionJars)
          TODO: No idea what the 'correct' way to add/contribute and activate/start things to an scaDomain is but this seems to work.
protected  SCADomain initEmbeddedSCADomain()
           
protected  void start()
           
 
Methods inherited from class org.apache.tuscany.sca.host.embedded.SCADomain
connect, newInstance, newInstance, newInstance, removeInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

domainURI

protected java.lang.String domainURI

contributionRepository

protected java.io.File contributionRepository

scaDomain

protected EmbeddedSCADomain scaDomain

hotUpdateActive

protected boolean hotUpdateActive

hotUpdateThread

protected java.lang.Thread hotUpdateThread

hotUpdateInterval

protected int hotUpdateInterval

existingContributions

protected java.util.HashMap<java.net.URL,java.lang.Long> existingContributions

originalCCL

protected java.lang.ClassLoader originalCCL

REPOSITORY_FOLDER

protected static final java.lang.String REPOSITORY_FOLDER
See Also:
Constant Field Values
Constructor Detail

HotUpdatableSCADomain

public HotUpdatableSCADomain(java.lang.String domainURI,
                             java.io.File contributionRepository,
                             int hotupdateInterval)
Method Detail

start

protected void start()

close

public void close()
Description copied from class: SCADomain
Close the SCA domain.

Overrides:
close in class SCADomain

initEmbeddedSCADomain

protected SCADomain initEmbeddedSCADomain()
                                   throws ActivationException
Throws:
ActivationException

getContributionJarURLs

protected java.net.URL[] getContributionJarURLs(java.io.File repositoryDir)

initContributions

protected void initContributions(EmbeddedSCADomain scaDomain,
                                 java.lang.ClassLoader cl,
                                 java.net.URL[] contributionJars)
TODO: No idea what the 'correct' way to add/contribute and activate/start things to an scaDomain is but this seems to work. Doesn't seem to start s or s which are outside of a so something is missing/wrong. Also this doesn't seem to be picking up composites located in META-INF/deployables or specified in the sca-deployables.xml. Maybe the EmbeddedSCADomain and ContributionService APIs should make all this easier?


copyContributionsToTemp

protected java.net.URL[] copyContributionsToTemp(java.net.URL[] contributionJars)
Copies Files to a temp location returning the URLs of the new temp files. For hot update to work need to be able to delete/update the contribution jar's but as they're in the classpath the URLClassLoader has an open lock on the jar's so you can't update them. This solution copies each contribution to a temp location for use on the classpath, nicer would be a ClassLoder impl that doesn't lock the jar's.


getLastModified

protected java.util.HashMap<java.net.URL,java.lang.Long> getLastModified(java.net.URL[] contrabutions)
Returns the last modified times of the files pointed to by the URLs


activateHotUpdate

protected void activateHotUpdate()

checkForUpdates

protected void checkForUpdates()
Checks if any of the contributions have been updated and if so restarts the SCADomain TODO: Ideally just the altered contribution would be restarted but thats not possible as the ClassLoader used by the SCADomain includes the old contribution so need to restart the entire domain to use a new ClassLoader. Should there be separate ClassLoader per contribution? But then have all the issues with sharing classes across contributions.


areContributionsAltered

protected boolean areContributionsAltered(java.net.URL[] currentContrabutions)

getUpdatedContributions

protected java.util.List<java.net.URL> getUpdatedContributions(java.net.URL[] currentContrabutions)
                                                        throws java.net.URISyntaxException
Throws:
java.net.URISyntaxException

getRemovedContributions

protected java.util.List getRemovedContributions(java.net.URL[] currentContrabutions)
                                          throws java.net.URISyntaxException
Throws:
java.net.URISyntaxException

getAddedContributions

protected java.util.List getAddedContributions(java.net.URL[] currentContrabutions)
                                        throws java.net.URISyntaxException
Throws:
java.net.URISyntaxException

cast

public <B,R extends org.osoa.sca.CallableReference<B>> R cast(B target)
                                                 throws java.lang.IllegalArgumentException
Description copied from class: SCADomain
Cast a type-safe reference to a CallableReference. Converts a type-safe reference to an equivalent CallableReference; if the target refers to a service then a ServiceReference will be returned, if the target refers to a callback then a CallableReference will be returned.

Specified by:
cast in class SCADomain
Type Parameters:
B - the Java type of the business interface for the reference
R - the type of reference to be returned
Parameters:
target - a reference proxy provided by the SCA runtime
Returns:
a CallableReference equivalent for the proxy
Throws:
java.lang.IllegalArgumentException - if the supplied instance is not a reference supplied by the SCA runtime

getService

public <B> B getService(java.lang.Class<B> businessInterface,
                        java.lang.String serviceName)
Description copied from class: SCADomain
Returns a proxy for a service provided by a component in the SCA domain.

Specified by:
getService in class SCADomain
Type Parameters:
B - the Java type of the business interface for the service
Parameters:
businessInterface - the interface that will be used to invoke the service
serviceName - the name of the service
Returns:
an object that implements the business interface

getServiceReference

public <B> org.osoa.sca.ServiceReference<B> getServiceReference(java.lang.Class<B> businessInterface,
                                                                java.lang.String referenceName)
Description copied from class: SCADomain
Returns a ServiceReference for a service provided by a component in the SCA domain.

Specified by:
getServiceReference in class SCADomain
Type Parameters:
B - the Java type of the business interface for the service
Parameters:
businessInterface - the interface that will be used to invoke the service
referenceName - the name of the service
Returns:
a ServiceReference for the designated service

getURI

public java.lang.String getURI()
Description copied from class: SCADomain
Returns the URI of the SCA Domain.

Specified by:
getURI in class SCADomain
Returns:
the URI of the SCA Domain

getComponentManager

public ComponentManager getComponentManager()
Overrides:
getComponentManager in class SCADomain