org.eclipse.jetty.osgi.boot
Class OSGiAppProvider

java.lang.Object
  extended by org.eclipse.jetty.util.component.AbstractLifeCycle
      extended by org.eclipse.jetty.deploy.providers.ScanningAppProvider
          extended by org.eclipse.jetty.osgi.boot.OSGiAppProvider
All Implemented Interfaces:
AppProvider, LifeCycle

public class OSGiAppProvider
extends ScanningAppProvider
implements AppProvider

AppProvider for OSGi. Supports the configuration of ContextHandlers and WebApps. Extends the AbstractAppProvider to support the scanning of context files located outside of the bundles.

This provider must not be called outside of jetty.boot: it should always be called via the OSGi service listener.

This provider supports the same set of parameters than the WebAppProvider as it supports the deployment of WebAppContexts. Except for the scanning of the webapps directory.

When the parameter autoInstallOSGiBundles is set to true, OSGi bundles that are located in the monitored directory are installed and started after the framework as finished auto-starting all the other bundles. Warning: only use this for development.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
 
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
 
Field Summary
 
Fields inherited from class org.eclipse.jetty.deploy.providers.ScanningAppProvider
_filenameFilter
 
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
 
Constructor Summary
OSGiAppProvider()
          Default OSGiAppProvider consutructed when none are defined in the jetty.xml configuration.
OSGiAppProvider(File contextsDir)
          Default OSGiAppProvider consutructed when none are defined in the jetty.xml configuration.
 
Method Summary
 void addContext(org.osgi.framework.Bundle contributor, String pathInBundle, ContextHandler context)
           
 void addContext(String originId, ContextHandler context)
           
protected  App createApp(String filename)
          Called by the scanner of the context files directory.
 ContextHandler createContextHandler(App app)
          Returns the ContextHandler that was created by WebappRegistractionHelper
protected  void doStart()
          Overridden to install the OSGi bundles found in the monitored folder.
protected  void fileAdded(String filename)
          When the file is a jar or a folder, we look if it looks like an OSGi bundle.
protected  void fileChanged(String filename)
           
protected  void fileRemoved(String filename)
           
protected  org.osgi.framework.Bundle getBundle(org.osgi.framework.BundleContext bc, String location)
          Returns a bundle according to its location.
 String[] getConfigurationClasses()
           
 String getContextXmlDir()
          The context xml directory.
 File getContextXmlDirAsFile()
          The context xml directory.
 String getDefaultsDescriptor()
          Get the defaultsDescriptor.
 String getTldBundles()
           
protected  org.osgi.framework.Bundle installBundle(File file, boolean start)
           
 boolean isAutoInstallOSGiBundles()
           
 boolean isExtract()
           
 boolean isParentLoaderPriority()
          Get the parentLoaderPriority.
 void removeContext(ContextHandler context)
           
 void setAutoInstallOSGiBundles(boolean installingOSGiBundles)
          <autoInstallOSGiBundles>true</autoInstallOSGiBundles>
 void setConfigurationClasses(String[] configurations)
           
 void setContextXmlDir(String contextsDir)
          Set the directory in which to look for context XML files.
 void setDefaultsDescriptor(String defaultsDescriptor)
          Set the defaultsDescriptor.
 void setDeploymentManager(DeploymentManager deploymentManager)
          Set the Deployment Manager
 void setExtract(boolean extract)
           
 void setParentLoaderPriority(boolean parentLoaderPriority)
          Set the parentLoaderPriority.
 void setTldBundles(String tldBundles)
           
protected  void uninstallBundle(File file)
           
protected  void updateBundle(File file)
           
 
Methods inherited from class org.eclipse.jetty.deploy.providers.ScanningAppProvider
addScannerListener, doStop, getDeployedApps, getDeploymentManager, getMonitoredDirName, getMonitoredDirResource, getScanInterval, isRecursive, setMonitoredDir, setMonitoredDirName, setMonitoredDirResource, setRecursive, setScanInterval
 
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 

Constructor Detail

OSGiAppProvider

public OSGiAppProvider()
Default OSGiAppProvider consutructed when none are defined in the jetty.xml configuration.


OSGiAppProvider

public OSGiAppProvider(File contextsDir)
                throws IOException
Default OSGiAppProvider consutructed when none are defined in the jetty.xml configuration.

Parameters:
contextsDir -
Throws:
IOException
Method Detail

createContextHandler

public ContextHandler createContextHandler(App app)
                                    throws Exception
Returns the ContextHandler that was created by WebappRegistractionHelper

Specified by:
createContextHandler in interface AppProvider
Parameters:
app - The App
Returns:
A ContextHandler
Throws:
IOException
Exception
See Also:
AppProvider

setDeploymentManager

public void setDeploymentManager(DeploymentManager deploymentManager)
Description copied from interface: AppProvider
Set the Deployment Manager

Specified by:
setDeploymentManager in interface AppProvider
Overrides:
setDeploymentManager in class ScanningAppProvider
See Also:
AppProvider

addContext

public void addContext(org.osgi.framework.Bundle contributor,
                       String pathInBundle,
                       ContextHandler context)
                throws Exception
Parameters:
context -
Throws:
Exception

addContext

public void addContext(String originId,
                       ContextHandler context)
                throws Exception
Parameters:
context -
Throws:
Exception

createApp

protected App createApp(String filename)
Called by the scanner of the context files directory. If we find the corresponding deployed App we reload it by returning the App. Otherwise we return null and nothing happens: presumably the corresponding OSGi webapp is not ready yet.

Overrides:
createApp in class ScanningAppProvider
Parameters:
filename - The file that is the context.xml. It is resolved by Resource.newResource(String)
Returns:
the corresponding already deployed App so that it will be reloaded. Otherwise returns null.

removeContext

public void removeContext(ContextHandler context)
                   throws Exception
Throws:
Exception

isParentLoaderPriority

public boolean isParentLoaderPriority()
Get the parentLoaderPriority.

Returns:
the parentLoaderPriority

setParentLoaderPriority

public void setParentLoaderPriority(boolean parentLoaderPriority)
Set the parentLoaderPriority.

Parameters:
parentLoaderPriority - the parentLoaderPriority to set

getDefaultsDescriptor

public String getDefaultsDescriptor()
Get the defaultsDescriptor.

Returns:
the defaultsDescriptor

setDefaultsDescriptor

public void setDefaultsDescriptor(String defaultsDescriptor)
Set the defaultsDescriptor.

Parameters:
defaultsDescriptor - the defaultsDescriptor to set

getContextXmlDirAsFile

public File getContextXmlDirAsFile()
The context xml directory. In fact it is the directory watched by the scanner.


getContextXmlDir

public String getContextXmlDir()
The context xml directory. In fact it is the directory watched by the scanner.


isExtract

public boolean isExtract()

setExtract

public void setExtract(boolean extract)

isAutoInstallOSGiBundles

public boolean isAutoInstallOSGiBundles()
Returns:
true when this app provider locates osgi bundles and features in its monitored directory and installs them. By default true if there is a folder to monitor.

setAutoInstallOSGiBundles

public void setAutoInstallOSGiBundles(boolean installingOSGiBundles)
<autoInstallOSGiBundles>true</autoInstallOSGiBundles>

Parameters:
installingOSGiBundles -

setContextXmlDir

public void setContextXmlDir(String contextsDir)
Set the directory in which to look for context XML files.

If a webapp call "foo/" or "foo.war" is discovered in the monitored directory, then the ContextXmlDir is examined to see if a foo.xml file exists. If it does, then this deployer will not deploy the webapp and the ContextProvider should be used to act on the foo.xml file.

Also if this directory contains some osgi bundles, it will install them.

Parameters:
contextsDir -
See Also:
ContextProvider

setTldBundles

public void setTldBundles(String tldBundles)
Parameters:
tldBundles - Comma separated list of bundles that contain tld jars that should be setup on the jetty instances created here.

getTldBundles

public String getTldBundles()
Returns:
The list of bundles that contain tld jars that should be setup on the jetty instances created here.

setConfigurationClasses

public void setConfigurationClasses(String[] configurations)
Parameters:
configurations - The configuration class names.

getConfigurationClasses

public String[] getConfigurationClasses()

doStart

protected void doStart()
                throws Exception
Overridden to install the OSGi bundles found in the monitored folder.

Overrides:
doStart in class ScanningAppProvider
Throws:
Exception

fileAdded

protected void fileAdded(String filename)
                  throws Exception
When the file is a jar or a folder, we look if it looks like an OSGi bundle. In that case we install it and start it.

Really a simple trick to get going quickly with development.

Overrides:
fileAdded in class ScanningAppProvider
Throws:
Exception

fileChanged

protected void fileChanged(String filename)
                    throws Exception
Overrides:
fileChanged in class ScanningAppProvider
Throws:
Exception

fileRemoved

protected void fileRemoved(String filename)
                    throws Exception
Overrides:
fileRemoved in class ScanningAppProvider
Throws:
Exception

getBundle

protected org.osgi.framework.Bundle getBundle(org.osgi.framework.BundleContext bc,
                                              String location)
Returns a bundle according to its location. In the version 1.6 of org.osgi.framework, BundleContext.getBundle(String) is what we want. However to support older versions of OSGi. We use our own local refrence mechanism.

Parameters:
location -
Returns:

installBundle

protected org.osgi.framework.Bundle installBundle(File file,
                                                  boolean start)

uninstallBundle

protected void uninstallBundle(File file)

updateBundle

protected void updateBundle(File file)


Copyright © 1995-2011 Mort Bay Consulting. All Rights Reserved.