本文整理汇总了Java中org.osgi.framework.ServiceException类的典型用法代码示例。如果您正苦于以下问题:Java ServiceException类的具体用法?Java ServiceException怎么用?Java ServiceException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceException类属于org.osgi.framework包,在下文中一共展示了ServiceException类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getService
import org.osgi.framework.ServiceException; //导入依赖的package包/类
/**
* Looks up an OSGi service. If the service is not yet available, this method will wait for 60 seconds for the service to become available. If the service
* does not appear in this period, a ServiceException is thrown.
*
* @param serviceClass
* The service interface of the service to look up
* @param timeoutInMillis
* The amount of time in milliseconds to wait for the service to become available
* @return an implementation of the given service interface
* @throws a
* ServiceException, if the service couldn't be found in the OSGi service registry
*/
public static <T> T getService(Class<T> serviceClass, long timeoutInMillis) {
BundleContext ctx = FrameworkUtil.getBundle(ServiceUtil.class).getBundleContext();
ServiceTracker<T, T> tracker = new ServiceTracker<>(ctx, serviceClass, null);
tracker.open();
T service = null;
try {
service = tracker.waitForService(timeoutInMillis);
} catch (InterruptedException e) {
throw new ServiceException("Interrupted while waiting for the service " + serviceClass.getName(), e);
}
tracker.close();
if (service != null) {
return service;
} else {
throw new ServiceException("Service " + serviceClass.getName() + " not available");
}
}
开发者ID:VisuFlow,项目名称:visuflow-plugin,代码行数:31,代码来源:ServiceUtil.java
示例2: handleInvalidRequest
import org.osgi.framework.ServiceException; //导入依赖的package包/类
protected void handleInvalidRequest(SerializationStrategy serializationStrategy, ClassLoader loader, Method method, Object target, DataByteArrayOutputStream responseStream, Runnable onComplete) {
//client made an invalid request
int pos = responseStream.position();
try {
Object value = null;
Throwable error = (Throwable)target;
serializationStrategy.encodeResponse(loader, null, value, error, responseStream);
} catch(Exception e) {
LOGGER.warn("Initial Encoding response for method "+method+" failed. Retrying",e);
// we failed to encode the response.. reposition and write that error.
try {
responseStream.position(pos);
serializationStrategy.encodeResponse(loader, null, null, new ServiceException(e.toString()), responseStream);
} catch (Exception unexpected) {
LOGGER.error("Error while servicing "+method,unexpected);
}
} finally {
onComplete.run();
}
}
开发者ID:apache,项目名称:aries-rsa,代码行数:25,代码来源:AbstractInvocationStrategy.java
示例3: send
import org.osgi.framework.ServiceException; //导入依赖的package包/类
public void send(Throwable error, Object value) {
if( responded.compareAndSet(false, true) ) {
Class resultType = getResultType(method);
try {
serializationStrategy.encodeResponse(loader, resultType, value, error, responseStream);
} catch (Exception e) {
// we failed to encode the response.. reposition and write that error.
try {
responseStream.position(pos);
serializationStrategy.encodeResponse(loader, resultType, value, new ServiceException(e.toString()), responseStream);
} catch (Exception unexpected) {
LOGGER.error("Error while servicing "+method,unexpected);
}
} finally {
onComplete.run();
}
}
}
开发者ID:apache,项目名称:aries-rsa,代码行数:19,代码来源:AbstractInvocationStrategy.java
示例4: invoke
import org.osgi.framework.ServiceException; //导入依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
if(method.getDeclaringClass()==Object.class) {
//shortcut for equals, hashcode,...
return method.invoke(this, args);
}
return request(this, address, service, classLoader, method, args);
}
catch (Throwable e) {
if (e instanceof ExecutionException) {
ExecutionException executionException = (ExecutionException)e;
e = executionException.getCause();
}
if (e instanceof RuntimeException) {
RuntimeException runtimeException = (RuntimeException)e;
throw runtimeException;
}
Class< ? >[] exceptionTypes = method.getExceptionTypes();
for (Class< ? > exceptionType : exceptionTypes) {
if(exceptionType.isAssignableFrom(e.getClass()))
throw e;
}
throw new ServiceException(e.getMessage(), e);
}
}
开发者ID:apache,项目名称:aries-rsa,代码行数:26,代码来源:ClientInvokerImpl.java
示例5: activate
import org.osgi.framework.ServiceException; //导入依赖的package包/类
@Activate
protected void activate(final Map<String, Object> props) throws ServiceException {
logger.debug("activate(): props = {}", props);
this.filterRoots = PropertiesUtil.toStringArray(props.get(PROP_FILTER_ROOTS), null);
if (this.filterRoots == null) {
throw new ServiceException(PROP_FILTER_ROOTS + " is mandatory!");
}
final String localDirValue = StringUtils.trim(PropertiesUtil.toString(props.get(PROP_LOCAL_PATH), null));
if (localDirValue == null) {
throw new ServiceException(PROP_LOCAL_PATH + " is mandatory!");
}
this.localDir = new File(localDirValue);
this.overwriteConfigFiles = PropertiesUtil.toBoolean(props.get(PROP_OVERWRITE_CONFIG_FILES),
DEFAULT_OVERWRITE_CONFIG_FILES);
this.syncOnceType = PropertiesUtil.toString(props.get(PROP_SYNC_ONCE_TYPE), SYNC_ONCE_DISABLED);
generateFiles();
Long expectedSyncOnceTime = null;
if (this.willSyncOnce) {
expectedSyncOnceTime = PropertiesUtil.toLong(props.get(PROP_SYNC_ONCE_EXPECTED_TIME),
DEFAULT_SYNC_ONCE_EXPECTED_TIME);
}
this.serviceSettings.addSyncRoot(this.localDir, expectedSyncOnceTime);
}
开发者ID:daniel-lima,项目名称:aem-vltsync,代码行数:31,代码来源:InitialRegistrationImpl.java
示例6: testActivateMissingProperties
import org.osgi.framework.ServiceException; //导入依赖的package包/类
@Test
public void testActivateMissingProperties() {
expectedEx.expect(ServiceException.class);
expectedEx.expectMessage(" is mandatory!");
this.initialRegistration.activate(new LinkedHashMap<String, Object>());
}
开发者ID:daniel-lima,项目名称:aem-vltsync,代码行数:8,代码来源:InitialRegistrationImplTest.java
示例7: service
import org.osgi.framework.ServiceException; //导入依赖的package包/类
@Override
public final void service(SerializationStrategy serializationStrategy, ClassLoader loader, Method method, Object target, DataByteArrayInputStream requestStream, DataByteArrayOutputStream responseStream, Runnable onComplete) {
if(method==null && target instanceof ServiceException) {
handleInvalidRequest(serializationStrategy, loader, method, target, responseStream, onComplete);
return;
}
doService(serializationStrategy, loader, method, target, requestStream, responseStream, onComplete);
}
开发者ID:apache,项目名称:aries-rsa,代码行数:10,代码来源:AbstractInvocationStrategy.java
示例8: SendTask
import org.osgi.framework.ServiceException; //导入依赖的package包/类
private SendTask(DataByteArrayInputStream bais, long correlation, Transport transport, String errorMessage) {
this(new ServiceException(errorMessage), bais, null, correlation, new MethodData(new BlockingInvocationStrategy(), ObjectSerializationStrategy.INSTANCE, null),transport);
}
开发者ID:apache,项目名称:aries-rsa,代码行数:4,代码来源:ServerInvokerImpl.java
注:本文中的org.osgi.framework.ServiceException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论