org.apache.felix.ipojo.handler.temporal
Class TemporalDependency

java.lang.Object
  extended by org.apache.felix.ipojo.util.DependencyModel
      extended by org.apache.felix.ipojo.handler.temporal.TemporalDependency
All Implemented Interfaces:
FieldInterceptor, MethodInterceptor, TrackerCustomizer

public class TemporalDependency
extends DependencyModel
implements FieldInterceptor, MethodInterceptor

Temporal dependency. A temporal dependency waits (block) for the availability of the service. If no provider arrives in the specified among of time, a runtime exception is thrown.

Author:
Felix Project Team

Nested Class Summary
private  class TemporalDependency.ProxyFactory
          Creates proxy object for proxied scalar dependencies.
 
Field Summary
private  boolean m_collection
          The dependency is injected as a collection.
private  java.lang.String m_di
          The default implementation.
private  PrimitiveHandler m_handler
          The handler managing this dependency.
private  java.lang.Object m_nullableObject
          The Nullable object or Default-Implementation instance if used.
private  int m_policy
          The timeout policy.
private  boolean m_proxy
          Enables the proxy mode.
private  java.lang.Object m_proxyObject
          The proxy object.
private  long m_timeout
          The timeout.
private  ServiceUsage m_usage
          Service Usage (Thread Local).
 
Fields inherited from class org.apache.felix.ipojo.util.DependencyModel
BROKEN, DYNAMIC_BINDING_POLICY, DYNAMIC_PRIORITY_BINDING_POLICY, RESOLVED, STATIC_BINDING_POLICY, UNRESOLVED
 
Constructor Summary
TemporalDependency(java.lang.Class spec, boolean agg, boolean collection, boolean proxy, org.osgi.framework.Filter filter, org.osgi.framework.BundleContext context, long timeout, int policy, java.lang.String defaultImpl, TemporalHandler handler)
          Creates a temporal dependency.
 
Method Summary
 java.lang.Object getService()
          Called by the proxy to get a service object to delegate a method.
private  java.lang.Object getServiceObjects(org.osgi.framework.ServiceReference[] refs)
          Creates and returns object to inject in the dependency.
(package private)  long getTimeout()
           
 void onDependencyReconfiguration(org.osgi.framework.ServiceReference[] arg0, org.osgi.framework.ServiceReference[] arg1)
          The dependency has been reconfigured.
 void onEntry(java.lang.Object pojo, java.lang.reflect.Method method, java.lang.Object[] args)
          A POJO method will be invoked.
 void onError(java.lang.Object pojo, java.lang.reflect.Method method, java.lang.Throwable throwable)
          A POJO method has thrown an error.
 void onExit(java.lang.Object pojo, java.lang.reflect.Method method, java.lang.Object returnedObj)
          A POJO method has returned.
 void onFinally(java.lang.Object pojo, java.lang.reflect.Method method)
          A POJO method is finished.
 java.lang.Object onGet(java.lang.Object arg0, java.lang.String arg1, java.lang.Object arg2)
          The code require a value of the monitored field.
 void onServiceArrival(org.osgi.framework.ServiceReference ref)
          A provider arrives.
 void onServiceDeparture(org.osgi.framework.ServiceReference arg0)
          A provider leaves.
 void onServiceModification(org.osgi.framework.ServiceReference arg0)
          A provider is modified.
 void onSet(java.lang.Object arg0, java.lang.String arg1, java.lang.Object arg2)
          The monitored field receives a value.
(package private)  java.lang.Object onTimeout()
          Implements the timeout policy according to the specified configuration.
 void start()
          Start method.
 void stop()
          Stop method.
 
Methods inherited from class org.apache.felix.ipojo.util.DependencyModel
addedService, addingService, getBindingPolicy, getComparator, getComparator, getFilter, getPolicy, getService, getServiceReference, getServiceReferences, getSize, getSpecification, getState, getUsedServiceReferences, isAggregate, isFrozen, isOptional, loadSpecification, manageModification, match, modifiedService, removedService, setAggregate, setBindingPolicy, setBundleContext, setComparator, setFilter, setOptionality, setSpecification, unfreeze, ungetService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_timeout

private long m_timeout
The timeout.


m_di

private java.lang.String m_di
The default implementation.


m_nullableObject

private java.lang.Object m_nullableObject
The Nullable object or Default-Implementation instance if used.


m_handler

private PrimitiveHandler m_handler
The handler managing this dependency.


m_policy

private int m_policy
The timeout policy. Null injects null, Nullable injects a nullable object or an array with a nullable object, Default-Implementation injects an object created from the specified injected implementation or an array with it Empty array inject an empty array (must be an aggregate dependency) No policy (0) throw a runtime exception when the timeout occurs *


m_collection

private boolean m_collection
The dependency is injected as a collection. The field must be of the Collection type


m_proxy

private boolean m_proxy
Enables the proxy mode.


m_usage

private ServiceUsage m_usage
Service Usage (Thread Local).


m_proxyObject

private java.lang.Object m_proxyObject
The proxy object. This field is used for scalar proxied temporal dependency.

Constructor Detail

TemporalDependency

public TemporalDependency(java.lang.Class spec,
                          boolean agg,
                          boolean collection,
                          boolean proxy,
                          org.osgi.framework.Filter filter,
                          org.osgi.framework.BundleContext context,
                          long timeout,
                          int policy,
                          java.lang.String defaultImpl,
                          TemporalHandler handler)
Creates a temporal dependency.

Parameters:
spec - the service specification
agg - is the dependency aggregate ?
collection - the dependency field is a collection
proxy - enable the proxy-mode
filter - the LDAP filter
context - service context
timeout - timeout
handler - Handler managing this dependency
defaultImpl - class used as default-implementation
policy - onTimeout policy
Method Detail

onDependencyReconfiguration

public void onDependencyReconfiguration(org.osgi.framework.ServiceReference[] arg0,
                                        org.osgi.framework.ServiceReference[] arg1)
The dependency has been reconfigured.

Specified by:
onDependencyReconfiguration in class DependencyModel
Parameters:
arg0 - new service references
arg1 - old service references
See Also:
DependencyModel.onDependencyReconfiguration(org.osgi.framework.ServiceReference[], org.osgi.framework.ServiceReference[])

onServiceArrival

public void onServiceArrival(org.osgi.framework.ServiceReference ref)
A provider arrives.

Specified by:
onServiceArrival in class DependencyModel
Parameters:
ref - service reference of the new provider.
See Also:
DependencyModel.onServiceArrival(org.osgi.framework.ServiceReference)

onServiceDeparture

public void onServiceDeparture(org.osgi.framework.ServiceReference arg0)
A provider leaves.

Specified by:
onServiceDeparture in class DependencyModel
Parameters:
arg0 - leaving service references.
See Also:
DependencyModel.onServiceDeparture(org.osgi.framework.ServiceReference)

onServiceModification

public void onServiceModification(org.osgi.framework.ServiceReference arg0)
A provider is modified.

Specified by:
onServiceModification in class DependencyModel
Parameters:
arg0 - leaving service references.
See Also:
DependencyModel.onServiceDeparture(org.osgi.framework.ServiceReference)

onGet

public java.lang.Object onGet(java.lang.Object arg0,
                              java.lang.String arg1,
                              java.lang.Object arg2)
The code require a value of the monitored field. If providers are available, the method return service object(s) immediately. Else, the thread is blocked until an arrival. If no provider arrives during the among of time specified, the method throws a Runtime Exception.

Specified by:
onGet in interface FieldInterceptor
Parameters:
arg0 - POJO instance asking for the service
arg1 - field name
arg2 - previous value
Returns:
the object to inject.
See Also:
FieldInterceptor.onGet(java.lang.Object, java.lang.String, java.lang.Object)

onEntry

public void onEntry(java.lang.Object pojo,
                    java.lang.reflect.Method method,
                    java.lang.Object[] args)
A POJO method will be invoked.

Specified by:
onEntry in interface MethodInterceptor
Parameters:
pojo - : Pojo object
method - : called method
args - : arguments
See Also:
MethodInterceptor.onEntry(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])

onError

public void onError(java.lang.Object pojo,
                    java.lang.reflect.Method method,
                    java.lang.Throwable throwable)
A POJO method has thrown an error. This method does nothing and wait for the finally.

Specified by:
onError in interface MethodInterceptor
Parameters:
pojo - : POJO object.
method - : Method object.
throwable - : thrown error
See Also:
MethodInterceptor.onError(java.lang.Object, java.lang.reflect.Method, java.lang.Throwable)

onExit

public void onExit(java.lang.Object pojo,
                   java.lang.reflect.Method method,
                   java.lang.Object returnedObj)
A POJO method has returned.

Specified by:
onExit in interface MethodInterceptor
Parameters:
pojo - : POJO object.
method - : Method object.
returnedObj - : returned object (null for void method)
See Also:
MethodInterceptor.onExit(java.lang.Object, java.lang.reflect.Method, java.lang.Object)

onFinally

public void onFinally(java.lang.Object pojo,
                      java.lang.reflect.Method method)
A POJO method is finished.

Specified by:
onFinally in interface MethodInterceptor
Parameters:
pojo - : POJO object.
method - : Method object.
See Also:
MethodInterceptor.onFinally(java.lang.Object, java.lang.reflect.Method)

getServiceObjects

private java.lang.Object getServiceObjects(org.osgi.framework.ServiceReference[] refs)
Creates and returns object to inject in the dependency. This method handles aggregate, collection and proxy cases.

Parameters:
refs - the available service references
Returns:
the object to inject. Can be a 'simple' object, a proxy, a collection or an array.

getService

public java.lang.Object getService()
Called by the proxy to get a service object to delegate a method. This methods manages the waited time and on timeout policies.

Returns:
a service object or a nullable/default-implmentation object.

start

public void start()
Start method. Initializes the nullable object.

Overrides:
start in class DependencyModel
See Also:
DependencyModel.start()

stop

public void stop()
Stop method. Just releases the reference on the nullable object.

Overrides:
stop in class DependencyModel
See Also:
DependencyModel.stop()

onSet

public void onSet(java.lang.Object arg0,
                  java.lang.String arg1,
                  java.lang.Object arg2)
The monitored field receives a value. Nothing to do.

Specified by:
onSet in interface FieldInterceptor
Parameters:
arg0 - POJO setting the value.
arg1 - field name
arg2 - received value
See Also:
FieldInterceptor.onSet(java.lang.Object, java.lang.String, java.lang.Object)

onTimeout

java.lang.Object onTimeout()
Implements the timeout policy according to the specified configuration.

Returns:
the object to return when the timeout occurs.

getTimeout

long getTimeout()


Copyright © 2006-2010 The Apache Software Foundation. All Rights Reserved.