incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Sling Website > Embedding Sling
Date Sun, 04 Sep 2011 17:25:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=SLINGxSITE&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Embedding+Sling">Embedding
Sling</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~fmeschbe">Felix
Meschberger</a>
    </h4>
        <br/>
                         <h4>Changes (5)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >* Encapsulates the OSGi Framework
in its own {{URLClassLoader}} <br>* Supports Framework restart <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">*
Allows propagation of core setup functionality depending on the environment <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Work
in progress .... <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h1.
Structure <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">*
Standalone Java App <br>* Sling Servlet <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">The
Launcher is based on three parts: <br># The external part which is for example the standalone
Java application&#39;s main class or the servlet deployed into the servlet container <br>#
The internal part which is the OSGi framework plus helper classes to control the framework
and run initial installations <br># The bridging part, which contains API common to
the external and internal part. <br> <br>The external part uses the bridging part
to create the class loader into which the internal part is loaded. The bidirectional communication
between the external and internal part is implement based on two interfaces: <br> <br>*
The {{Launcher}} interface is implemented by a class in the internal part which is loaded
through the bridge class loader. This interface allows setting, starting and stopping of the
framework. <br>* The {{Notifiable}} interface is implemented by a class in the external
part which instance is handed to the {{Launcher}} instance. This interface allows the internal
part to communicate back to the external part, most notably to indicate that the framework
has been stopped from within or that the framework has been updated and must be restarted.
<br> <br> <br>h1. The Bridging Part <br> <br>The bridging part
is provided in the {{org.apache.sling.launchpad.base.shared}} package: <br> <br>|
Class | Description | <br>| Launcher | The interface implemented by the internal class
matching the external class being called to start/stop the framework. | <br>| LauncherClassLoader
| {{URLClassLoader}} implementing the class loader to load the internal part (along with the
OSGi framework). This class loader only delegates to the parent class loader any packages
not contained in the launchpad library (primary artifact of the Launchpad Base project). |
<br>| Loader | Helper class to find the launchpad library and to create the {{LauncherClassLoader}}
with that library. This class is also used to actually load the {{Launcher}} implementation
to be called from the external launcher class. | <br>| Notifiable | The interface implemented
in the external part and handed over to the internal part. | <br>| SharedConstants |
Constants naming various properties and classes. | <br> <br> <br>h1. The
Internal Part <br> <br>The main class from the internal class directly used is
[{{Sling}}|http://svn.apache.org/repos/asf/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java]
which instantiated to start the OSGi Framework. This class is responsible for setting up the
environment to finally start the OSGi Framework: <br> <br>* Read the {{sling.properties}}
file <br>* Ensure the presence of the JMX MBeanServer service <br>* Execute the
bootstrap installations, updates and uninstallations <br> <br>The [{{SlingFelix}}|http://svn.apache.org/repos/asf/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java]
class extends the Apache Felix {{Felix}} class which is the actual OSGi framework implementation.
We extend the class to be able to notify the {{Notifiable}} implementation and update the
OSGi framework from within the OSGi framework by updating the system bundle. <br> <br>
<br>h2. The External Part <br> <br>The external part is comprised of a main
class started from the environment -- main class of the Java applicaction or the servlet deployed
in the servlet container -- and a corresponding delegate class located inside of the launchpad
base library. This delegate class is instantiated by the {{Loader}} loading from the {{LauncherClassLoader}}.
<br> <br> <br>h3 . Standalone Java Application <br> <br>The
standalone Java Application makes use of three classes: <br> <br>| Class | Description
| <br>| Main | This is the main class whose {{main}} method is called by the Java VM.
This class is itself the {{Notifiable}} and finds the {{sling.home}} location from the environment
(command line parameter, system property, or environment variable). | <br>| MainDelegate
| This class is loaded by the {{Loader}} from the {{LauncherClassLoader}} to actually complete
the initial setup before creating the {{Sling}} class to start the framework. | <br>|
ControlListener | This class is used by the {{Main}} class to open a server socket to be able
to start and stop Sling as a server. This class allows for starting (opening the server socket),
status check (connecting to the socket asking for status), and shutdown (connecting to the
socket asking for shutdown). | <br> <br>At the moment these classes are not directly
suitable to be embedded in an existing application (or custom application launcher framework)
unless that embedding prepares command line arguments in a {{String[]}} and calls the {{Main.main}}
method. To allow for custom embeddings or extensions, the work distriubtions between the three
classes should be refactored. <br> <br> <br>h3. Web Application <br>
<br>The web application makes use of 5 classes: <br> <br>| Class | Description
| <br>| SlingServlet | This is the servlet registered in the {{web.xml}} descriptor
and loaded by the servlet container into which Sling is deplyoed. This class locates the {{sling.home}}
folder and loads the {{SlingServletDelagate}} to actually launch the framework. | <br>|
SlingSessionListener | This -- somewhat inappropriately named -- class is registered as a
listener by the Sling {{web.xml}} descriptor. It is called by the servlet container and forwards
events to the {{SlingHttpSessionListenerDelegate}} which in turn forwards the events to the
respective Servlet API listener services registered in the OSGi Framework. | <br>| SlingBridge
| Simple extension of the {{Sling}} class which registers the system bundle&#39;s {{BundleContext}}
as a servlet context attribute of the Sling web application. This allows Servlet Container
bridging to properly work. | <br>| SlingHttpSessionListenerDelegate | This class is
loaded by the {{LauncherClassLoader}} called from the {{SlingSessionListener}}. It is called
by the {{SlingSessionListener}} to forward servlet container events to registered Servlet
API listener services. | <br>| SlingServletDelegate | This class is loaded by the {{Loader}}
from the {{LauncherClassLoader}} to actually complete the initial setup before creating the
{{SlingBridge}} class to start the framework. | <br> <br>At the moment these classes,
particularly the {{SlingServlet}} class, are not particularly well suited to be extended by
a servlet slightly modifying the launcher. <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="EmbeddingSling-EmbeddingSling"></a>Embedding Sling</h1>

<p>The Sling Launchpad Launcher can be used to embed the OSGi Framework startup in your
own Java application. This functionality is implemented in the <a href="http://svn.apache.org/repos/asf/sling/trunk/launchpad/base"
class="external-link" rel="nofollow">Sling Launchpad Base project</a>. This project
has the following features:</p>

<ul>
	<li>Builds three artifacts:
	<ul>
		<li>A standalone Java Application with the artifact qualifier <em>app</em>;
e.g. <tt>org.apache.sling.launchpad.base-2.3.1-SNAPSHOT-app.jar</tt></li>
		<li>A Web Application with the artifact qualifier <em>webapp</em>; e.g
<tt>org.apache.sling.launchpad.base-2.3.1-SNAPSHOT-wepabb.war</tt></li>
		<li>The primary artifact without an artifact qualifier; e.g. <tt>org.apache.sling.launchpad.base-2.3.1-SNAPSHOT.jar</tt></li>
	</ul>
	</li>
	<li>Embeds the OSGi Framework (Apache Felix) in the primary artifact</li>
	<li>Encapsulates the OSGi Framework in its own <tt>URLClassLoader</tt></li>
	<li>Supports Framework restart</li>
	<li>Allows propagation of core setup functionality depending on the environment</li>
</ul>



<h1><a name="EmbeddingSling-Structure"></a>Structure</h1>

<p>The Launcher is based on three parts:</p>
<ol>
	<li>The external part which is for example the standalone Java application's main class
or the servlet deployed into the servlet container</li>
	<li>The internal part which is the OSGi framework plus helper classes to control the
framework and run initial installations</li>
	<li>The bridging part, which contains API common to the external and internal part.</li>
</ol>


<p>The external part uses the bridging part to create the class loader into which the
internal part is loaded. The bidirectional communication between the external and internal
part is implement based on two interfaces:</p>

<ul>
	<li>The <tt>Launcher</tt> interface is implemented by a class in the internal
part which is loaded through the bridge class loader. This interface allows setting, starting
and stopping of the framework.</li>
	<li>The <tt>Notifiable</tt> interface is implemented by a class in the
external part which instance is handed to the <tt>Launcher</tt> instance. This
interface allows the internal part to communicate back to the external part, most notably
to indicate that the framework has been stopped from within or that the framework has been
updated and must be restarted.</li>
</ul>



<h1><a name="EmbeddingSling-TheBridgingPart"></a>The Bridging Part</h1>

<p>The bridging part is provided in the <tt>org.apache.sling.launchpad.base.shared</tt>
package:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'> Class </td>
<td class='confluenceTd'> Description </td>
</tr>
<tr>
<td class='confluenceTd'> Launcher </td>
<td class='confluenceTd'> The interface implemented by the internal class matching the
external class being called to start/stop the framework. </td>
</tr>
<tr>
<td class='confluenceTd'> LauncherClassLoader </td>
<td class='confluenceTd'> <tt>URLClassLoader</tt> implementing the class
loader to load the internal part (along with the OSGi framework). This class loader only delegates
to the parent class loader any packages not contained in the launchpad library (primary artifact
of the Launchpad Base project). </td>
</tr>
<tr>
<td class='confluenceTd'> Loader </td>
<td class='confluenceTd'> Helper class to find the launchpad library and to create the
<tt>LauncherClassLoader</tt> with that library. This class is also used to actually
load the <tt>Launcher</tt> implementation to be called from the external launcher
class. </td>
</tr>
<tr>
<td class='confluenceTd'> Notifiable </td>
<td class='confluenceTd'> The interface implemented in the external part and handed
over to the internal part. </td>
</tr>
<tr>
<td class='confluenceTd'> SharedConstants </td>
<td class='confluenceTd'> Constants naming various properties and classes. </td>
</tr>
</tbody></table>
</div>



<h1><a name="EmbeddingSling-TheInternalPart"></a>The Internal Part</h1>

<p>The main class from the internal class directly used is <a href="http://svn.apache.org/repos/asf/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java"
class="external-link" rel="nofollow"><tt>Sling</tt></a> which instantiated
to start the OSGi Framework. This class is responsible for setting up the environment to finally
start the OSGi Framework:</p>

<ul>
	<li>Read the <tt>sling.properties</tt> file</li>
	<li>Ensure the presence of the JMX MBeanServer service</li>
	<li>Execute the bootstrap installations, updates and uninstallations</li>
</ul>


<p>The <a href="http://svn.apache.org/repos/asf/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java"
class="external-link" rel="nofollow"><tt>SlingFelix</tt></a> class extends
the Apache Felix <tt>Felix</tt> class which is the actual OSGi framework implementation.
We extend the class to be able to notify the <tt>Notifiable</tt> implementation
and update the OSGi framework from within the OSGi framework by updating the system bundle.</p>


<h2><a name="EmbeddingSling-TheExternalPart"></a>The External Part</h2>

<p>The external part is comprised of a main class started from the environment &#8211;
main class of the Java applicaction or the servlet deployed in the servlet container &#8211;
and a corresponding delegate class located inside of the launchpad base library. This delegate
class is instantiated by the <tt>Loader</tt> loading from the <tt>LauncherClassLoader</tt>.</p>


<p>h3 . Standalone Java Application</p>

<p>The standalone Java Application makes use of three classes:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'> Class </td>
<td class='confluenceTd'> Description </td>
</tr>
<tr>
<td class='confluenceTd'> Main </td>
<td class='confluenceTd'> This is the main class whose <tt>main</tt> method
is called by the Java VM. This class is itself the <tt>Notifiable</tt> and finds
the <tt>sling.home</tt> location from the environment (command line parameter,
system property, or environment variable). </td>
</tr>
<tr>
<td class='confluenceTd'> MainDelegate </td>
<td class='confluenceTd'> This class is loaded by the <tt>Loader</tt> from
the <tt>LauncherClassLoader</tt> to actually complete the initial setup before
creating the <tt>Sling</tt> class to start the framework. </td>
</tr>
<tr>
<td class='confluenceTd'> ControlListener </td>
<td class='confluenceTd'> This class is used by the <tt>Main</tt> class
to open a server socket to be able to start and stop Sling as a server. This class allows
for starting (opening the server socket), status check (connecting to the socket asking for
status), and shutdown (connecting to the socket asking for shutdown). </td>
</tr>
</tbody></table>
</div>


<p>At the moment these classes are not directly suitable to be embedded in an existing
application (or custom application launcher framework) unless that embedding prepares command
line arguments in a <tt>String[]</tt> and calls the <tt>Main.main</tt>
method. To allow for custom embeddings or extensions, the work distriubtions between the three
classes should be refactored.</p>


<h3><a name="EmbeddingSling-WebApplication"></a>Web Application</h3>

<p>The web application makes use of 5 classes:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<td class='confluenceTd'> Class </td>
<td class='confluenceTd'> Description </td>
</tr>
<tr>
<td class='confluenceTd'> SlingServlet </td>
<td class='confluenceTd'> This is the servlet registered in the <tt>web.xml</tt>
descriptor and loaded by the servlet container into which Sling is deplyoed. This class locates
the <tt>sling.home</tt> folder and loads the <tt>SlingServletDelagate</tt>
to actually launch the framework. </td>
</tr>
<tr>
<td class='confluenceTd'> SlingSessionListener </td>
<td class='confluenceTd'> This &#8211; somewhat inappropriately named &#8211;
class is registered as a listener by the Sling <tt>web.xml</tt> descriptor. It
is called by the servlet container and forwards events to the <tt>SlingHttpSessionListenerDelegate</tt>
which in turn forwards the events to the respective Servlet API listener services registered
in the OSGi Framework. </td>
</tr>
<tr>
<td class='confluenceTd'> SlingBridge </td>
<td class='confluenceTd'> Simple extension of the <tt>Sling</tt> class which
registers the system bundle's <tt>BundleContext</tt> as a servlet context attribute
of the Sling web application. This allows Servlet Container bridging to properly work. </td>
</tr>
<tr>
<td class='confluenceTd'> SlingHttpSessionListenerDelegate </td>
<td class='confluenceTd'> This class is loaded by the <tt>LauncherClassLoader</tt>
called from the <tt>SlingSessionListener</tt>. It is called by the <tt>SlingSessionListener</tt>
to forward servlet container events to registered Servlet API listener services. </td>
</tr>
<tr>
<td class='confluenceTd'> SlingServletDelegate </td>
<td class='confluenceTd'> This class is loaded by the <tt>Loader</tt> from
the <tt>LauncherClassLoader</tt> to actually complete the initial setup before
creating the <tt>SlingBridge</tt> class to start the framework. </td>
</tr>
</tbody></table>
</div>


<p>At the moment these classes, particularly the <tt>SlingServlet</tt> class,
are not particularly well suited to be extended by a servlet slightly modifying the launcher.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Embedding+Sling">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27826084&revisedVersion=3&originalVersion=2">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/SLINGxSITE/Embedding+Sling?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message