Java Reference
In-Depth Information
private CounterThread thread;
protected void activate(ComponentContext cc)
{
System.out.println(getClass().getName() + ".activate");
}
protected void passivate(ComponentContext cc)
{
System.out.println(getClass().getName() + ".passivate");
}
protected void startCounterThread(Counter counter)
{
if(thread == null)
{
thread = new CounterThread(counter);
thread.start();
}
}
protected void stopCounterThread(Counter counter)
{
if(thread != null)
{
thread.interrupt();
thread = null;
}
}
}
class CounterThread extends Thread
{
//unverändert wie bisher
...
}
Die Wiedergabe der Manifest-Datei für die Client-Komponente können wir uns sparen. Sie
unterscheidet sich von der Manifest-Datei der Service-Komponente lediglich dadurch, dass
die Komponente einen anderen Namen hat und der Name der XML-Datei anders ist. Auch in
diesem Fall gibt es keinen Bundle-Activator und keine Exports. Die Imports sind ebenfalls
identisch.
Die XML-Datei für die Client-Komponente ist allerdings deutlich anders:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
activate="activate" deactivate="passivate" immediate="true"
name="DeclarativeCounterClient">
<implementation
class="javacomp.osgi.bundle5.CounterClient"/>
<reference bind="startCounterThread" cardinality="1..1"
interface="javacomp.osgi.bundle0.Counter"
name="Counter" policy="dynamic" unbind="stopCounterThread"/>
/>
</scr:component>
 
Search WWH ::




Custom Search