org.apache.felix.dm
Interface TemporalServiceDependency

All Superinterfaces:
ComponentDependencyDeclaration, Dependency, ServiceDependency
All Known Implementing Classes:
TemporalServiceDependencyImpl

public interface TemporalServiceDependency
extends ServiceDependency

A Temporal Service dependency that can block the caller thread between service updates. Only useful for required stateless dependencies that can be replaced transparently. A Dynamic Proxy is used to wrap the actual service dependency. When the dependency goes away, an attempt is made to replace it with another one which satisfies the service dependency criteria. If no service replacement is available, then any method invocation (through the dynamic proxy) will block during a configurable timeout. On timeout, an unchecked IllegalStateException exception is raised (but the service is not deactivated).

This class only supports required dependencies, and temporal dependencies must be accessed outside the Activator (OSGi) thread, because method invocations may block the caller thread when dependencies are not satisfied.

Sample Code:

 import org.apache.felix.dependencymanager.*;
 
 public class Activator extends DependencyActivatorBase {
   public void init(BundleContext ctx, DependencyManager dm) throws Exception {
     dm.add(createService()
            .setImplementation(MyServer.class)
            .add(createTemporalServiceDependency()
                .setTimeout(15000)
                .setService(MyDependency.class)));
   }
 
   public void destroy(BundleContext ctx, DependencyManager dm) throws Exception {
   }
 }
 
 class MyServer implements Runnable {
   MyDependency _dependency; // Auto-Injected by reflection.
   void start() {
     (new Thread(this)).start();
   }
   
   public void run() {
     try {
       _dependency.doWork();
     } catch (IllegalStateException e) {
       t.printStackTrace();
     }
   }   
 


Field Summary
 
Fields inherited from interface org.apache.felix.dm.ComponentDependencyDeclaration
STATE_AVAILABLE_OPTIONAL, STATE_AVAILABLE_REQUIRED, STATE_NAMES, STATE_UNAVAILABLE_OPTIONAL, STATE_UNAVAILABLE_REQUIRED
 
Method Summary
 TemporalServiceDependency setTimeout(long timeout)
          Sets the timeout for this temporal dependency.
 
Methods inherited from interface org.apache.felix.dm.ServiceDependency
setAutoConfig, setAutoConfig, setCallbacks, setCallbacks, setCallbacks, setCallbacks, setDefaultImplementation, setInstanceBound, setPropagate, setPropagate, setRequired, setService, setService, setService, setService
 
Methods inherited from interface org.apache.felix.dm.Dependency
createCopy, getAutoConfigInstance, getAutoConfigName, getAutoConfigType, getProperties, invokeAdded, invokeRemoved, isAutoConfig, isAvailable, isInstanceBound, isPropagated, isRequired
 
Methods inherited from interface org.apache.felix.dm.ComponentDependencyDeclaration
getName, getState, getType
 

Method Detail

setTimeout

TemporalServiceDependency setTimeout(long timeout)
Sets the timeout for this temporal dependency. Specifying a timeout value of zero means that there is no timeout period, and an invocation on a missing service will fail immediately.

Parameters:
timeout - the dependency timeout value greater or equals to 0
Returns:
this temporal dependency
Throws:
IllegalArgumentException - if the timeout is negative


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.