All Downloads are FREE. Search and download functionalities are using the official Maven repository.

domino.java.ServiceWatching Maven / Gradle / Ivy

There is a newer version: 0.3.1
Show newest version
package domino.java;

import org.osgi.util.tracker.ServiceTracker;

import de.tototec.utils.functional.Procedure1;
import de.tototec.utils.functional.Procedure2;
import de.tototec.utils.functional.Procedure3;

/**
 * Provides convenient methods to add a service watcher to the current scope or
 * wait until services are present.
 */
public interface ServiceWatching {

	/**
	 * Lets you react to service events for services with the specified type which
	 * match the given filter.
	 *
	 * @param f
	 *            Service event handler
	 * @tparam S Service type
	 * @return Underlying service tracker
	 */
	 ServiceTracker watchAdvancedServices(Class type, String filter, Procedure1> f);

	/**
	 * Activates the given inner logic as long as the first service of the given
	 * type is present. This implements the concept of required services. The inner
	 * logic is started as soon as a service s of the given type gets present and
	 * stopped when s is removed.
	 */
	 ServiceTracker whenAdvancedServicePresent(Class type, String filter, Procedure1 f);

	/**
	 * Waits until a service of the specified type is available and executes the
	 * given event handler with it. When the service disappears, the capsules added
	 * in the handlers are stopped. You can wait on a bunch of services if you nest
	 * `whenServicePresent` methods.
	 *
	 * @param f
	 *            Handler
	 * @tparam S Service type
	 * @return Underlying service tracker
	 */
	 ServiceTracker whenServicePresent(Class type, Procedure1 f);

	 ServiceTracker whenServicesPresent(Class type1, Class type2, Procedure2 f);

	 ServiceTracker whenServicesPresent(
			Class type1,
			Class type2,
			Class type3,
			Procedure3 f);

	// FIXME re-incomment when procedure 4 becomes available
	//  ServiceTracker whenServicesPresent(
	// final Class type1,
	// final Class type2,
	// final Class type3,
	// final Class type4,
	// final Procedure4 f);
}