org.eclipse.osgi.internal.serviceregistry.ServiceConsumer Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (c) 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.osgi.internal.serviceregistry;
/**
* Closure to allow sharing the same code for getting and ungetting a service.
* The {@link #prototypeConsumer} closure must be used for calls from
* ServiceObjects and the {@link #singletonConsumer} closure must be used
* for calls from BundleContext.
*
* The closure instance calls the correct method on the specified ServiceUse
* object for the current service consumer type.
*/
public interface ServiceConsumer {
/**
* Used for calls from ServiceObjects.
*/
static ServiceConsumer prototypeConsumer = new ServiceConsumer() {
@Override
public S getService(ServiceUse use) {
return use.newServiceObject();
}
@Override
public boolean ungetService(ServiceUse use, S service) {
return use.releaseServiceObject(service);
}
};
/**
* Used for calls from BundleContext.
*/
static ServiceConsumer singletonConsumer = new ServiceConsumer() {
@Override
public S getService(ServiceUse use) {
return use.getService();
}
@Override
public boolean ungetService(ServiceUse use, S service) {
return use.ungetService();
}
};
/**
* Get a service for the consumer.
*
* @param use Service Use object to get the service from.
* @return The obtained service.
*/
S getService(ServiceUse use);
/**
* Unget the service for the consumer.
*
* @param use Service Use object to unget the service from.
* @param service The Service to unget.
* @return true if the service was ungotten, false otherwise.
*/
boolean ungetService(ServiceUse use, S service);
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy