blob: 6bf8e2f42d3110b88074c0b943f087114abde0f6 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_102) on Tue Feb 14 08:05:47 CET 2017 -->
<title>ResourceAdapterService</title>
<meta name="date" content="2017-02-14">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="ResourceAdapterService";
}
}
catch(err) {
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../org/apache/felix/dm/annotation/api/package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../../org/apache/felix/dm/annotation/api/RepeatableProperty.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceDependency.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../../index.html?org/apache/felix/dm/annotation/api/ResourceAdapterService.html" target="_top">Frames</a></li>
<li><a href="ResourceAdapterService.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.required.element.summary">Required</a>&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.felix.dm.annotation.api</div>
<h2 title="Annotation Type ResourceAdapterService" class="title">Annotation Type ResourceAdapterService</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>@Retention(value=CLASS)
@Target(value=TYPE)
public @interface <span class="memberNameLabel">ResourceAdapterService</span></pre>
<div class="block">Annotates a class as a Resource adapter service. Resource adapters are things that
adapt a resource instead of a service, and provide an adapter service on top of this resource.
Resources are an abstraction that is introduced by the dependency manager, represented as a URL.
They can be implemented to serve resources embedded in bundles, somewhere on a file system or in
an http content repository server, or database.<p>
The adapter will be applied to any resource that matches the specified filter condition, which can
match some part of the resource URL (with "path", "protocol", "port", or "host" filters).
For each matching resource an adapter will be created based on the adapter implementation class.
The adapter will be registered with the specified interface and with any extra service properties
you supply here. Moreover, the following service properties will be propagated from the resource URL:
<ul><li> "host": this property exposes the host part of the resource URL
<li>"path": the resource URL path
<li>"protocol": the resource URL protocol
<li>"port": the resource URL port
</ul>
<h3>Usage Examples</h3>
Here, the "VideoPlayer" service provides a video service on top of any movie resources, with service
properties "host"/"port"/"protocol"/"path" extracted from the resource URL:
<blockquote>
<pre>
&#64;ResourceAdapterService(filter = "(&#38;(path=/videos/*.mkv)(host=localhost))", propagate = true)
public class VideoPlayerImpl implements VideoPlayer {
// Injected by reflection
URL resource;
void play() {} // play video referenced by this.resource
void stop() {} // stop playing the video
void transcode() {} // ...
}
</pre>
</blockquote>
And here is an example of a VideoProvider, which provides some videos using a web URL.
Notice that Resource providers need to depend on the DependencyManager API:
<blockquote>
<pre>
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.apache.felix.dm.ResourceHandler;
import org.apache.felix.dm.ResourceUtil;
import org.apache.felix.dm.annotation.api.Component;
import org.apache.felix.dm.annotation.api.Init;
import org.apache.felix.dm.annotation.api.ServiceDependency;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
&#64;Component
public class VideoProvider
{
// Injected by reflection
private volatile BundleContext context;
// List of known resource handlers
private Map&#60;ResourceHandler, Filter&#62; m_handlers = new HashMap&#60;ResourceHandler, Filter&#62;();
// List of known video resources
private URL[] m_videos;
&#64;Init
void init() throws MalformedURLException
{
m_videos = new URL[] {
new URL("http://localhost:8080/videos/video1.mkv"),
new URL("http://localhost:8080/videos/video2.mkv"),
};
}
// Track resource handlers
&#64;ServiceDependency(required = false)
public void add(Map&#60;String, String&#62; serviceProperties, ResourceHandler handler) throws InvalidSyntaxException
{
String filterString = serviceProperties.get("filter");
filterString = (filterString != null) ? filterString : "(path=*)";
Filter filter = context.createFilter(filterString);
synchronized (this)
{
m_handlers.put(handler, filter);
}
for (URL video : m_videos)
{
if (filter.match(ResourceUtil.createProperties(video)))
{
handler.added(video);
}
}
}
}
</pre>
</blockquote></div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- =========== ANNOTATION TYPE REQUIRED MEMBER SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.required.element.summary">
<!-- -->
</a>
<h3>Required Element Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Required Element Summary table, listing required elements, and an explanation">
<caption><span>Required Elements</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Required Element and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceAdapterService.html#filter--">filter</a></span></code>
<div class="block">The filter condition to use with the resource.</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- =========== ANNOTATION TYPE OPTIONAL MEMBER SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.optional.element.summary">
<!-- -->
</a>
<h3>Optional Element Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Optional Element Summary table, listing optional elements, and an explanation">
<caption><span>Optional Elements</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Optional Element and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceAdapterService.html#changed--">changed</a></span></code>
<div class="block">The callback method to be invoked when the Resource has changed.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>java.lang.String</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceAdapterService.html#factoryMethod--">factoryMethod</a></span></code>
<div class="block">Sets the static method used to create the AdapterService implementation instance.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>boolean</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceAdapterService.html#propagate--">propagate</a></span></code>
<div class="block"><code>true</code> if properties from the resource should be propagated to the service properties.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code><a href="../../../../../../org/apache/felix/dm/annotation/api/Property.html" title="annotation in org.apache.felix.dm.annotation.api">Property</a>[]</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceAdapterService.html#properties--">properties</a></span></code>
<div class="block">Additional properties to use with the adapter service registration</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.Class&lt;?&gt;[]</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceAdapterService.html#provides--">provides</a></span></code>
<div class="block">The interface(s) to use when registering adapters</div>
</td>
</tr>
</table>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="annotation.type.element.detail">
<!-- -->
</a>
<h3>Element Detail</h3>
<a name="filter--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>filter</h4>
<pre>public abstract&nbsp;java.lang.String&nbsp;filter</pre>
<div class="block">The filter condition to use with the resource.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the filter</dd>
</dl>
</li>
</ul>
</li>
</ul>
<!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== -->
<ul class="blockList">
<li class="blockList"><a name="provides--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>provides</h4>
<pre>public abstract&nbsp;java.lang.Class&lt;?&gt;[]&nbsp;provides</pre>
<div class="block">The interface(s) to use when registering adapters</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the provided interfaces</dd>
</dl>
<dl>
<dt>Default:</dt>
<dd>{}</dd>
</dl>
</li>
</ul>
</li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="properties--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>properties</h4>
<pre>public abstract&nbsp;<a href="../../../../../../org/apache/felix/dm/annotation/api/Property.html" title="annotation in org.apache.felix.dm.annotation.api">Property</a>[]&nbsp;properties</pre>
<div class="block">Additional properties to use with the adapter service registration</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the properties</dd>
</dl>
<dl>
<dt>Default:</dt>
<dd>{}</dd>
</dl>
</li>
</ul>
</li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="propagate--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>propagate</h4>
<pre>public abstract&nbsp;boolean&nbsp;propagate</pre>
<div class="block"><code>true</code> if properties from the resource should be propagated to the service properties.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the propagate flag</dd>
</dl>
<dl>
<dt>Default:</dt>
<dd>false</dd>
</dl>
</li>
</ul>
</li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="changed--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>changed</h4>
<pre>public abstract&nbsp;java.lang.String&nbsp;changed</pre>
<div class="block">The callback method to be invoked when the Resource has changed.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the changed callback</dd>
</dl>
<dl>
<dt>Default:</dt>
<dd>""</dd>
</dl>
</li>
</ul>
</li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="factoryMethod--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>factoryMethod</h4>
<pre>public abstract&nbsp;java.lang.String&nbsp;factoryMethod</pre>
<div class="block">Sets the static method used to create the AdapterService implementation instance.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the factory method</dd>
</dl>
<dl>
<dt>Default:</dt>
<dd>""</dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../org/apache/felix/dm/annotation/api/package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../../org/apache/felix/dm/annotation/api/RepeatableProperty.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../../../org/apache/felix/dm/annotation/api/ResourceDependency.html" title="annotation in org.apache.felix.dm.annotation.api"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../../../index.html?org/apache/felix/dm/annotation/api/ResourceAdapterService.html" target="_top">Frames</a></li>
<li><a href="ResourceAdapterService.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.required.element.summary">Required</a>&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>