项目:visuflow-plugin
文件:ServiceUtil.java
/**
* 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");
}
}
项目:aries-rsa
文件:AbstractInvocationStrategy.java
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,new ServiceException(e.toString()),responseStream);
} catch (Exception unexpected) {
LOGGER.error("Error while servicing "+method,unexpected);
}
} finally {
onComplete.run();
}
}
项目:aries-rsa
文件:AbstractInvocationStrategy.java
public void send(Throwable error,Object value) {
if( responded.compareAndSet(false,true) ) {
Class resultType = getResultType(method);
try {
serializationStrategy.encodeResponse(loader,resultType,responseStream);
} catch (Exception e) {
// we Failed to encode the response.. reposition and write that error.
try {
responseStream.position(pos);
serializationStrategy.encodeResponse(loader,responseStream);
} catch (Exception unexpected) {
LOGGER.error("Error while servicing "+method,unexpected);
}
} finally {
onComplete.run();
}
}
}
项目:aries-rsa
文件:ClientInvokerImpl.java
public Object invoke(Object proxy,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);
}
}
项目:aem-vltsync
文件:InitialRegistrationImpl.java
@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);
}
@Test
public void testActivateMissingProperties() {
expectedEx.expect(ServiceException.class);
expectedEx.expectMessage(" is mandatory!");
this.initialRegistration.activate(new LinkedHashMap<String,Object>());
}
项目:aries-rsa
文件:AbstractInvocationStrategy.java
@Override
public final void service(SerializationStrategy serializationStrategy,DataByteArrayInputStream requestStream,Runnable onComplete) {
if(method==null && target instanceof ServiceException) {
handleInvalidRequest(serializationStrategy,loader,target,responseStream,onComplete);
return;
}
doService(serializationStrategy,requestStream,onComplete);
}
项目:aries-rsa
文件:ServerInvokerImpl.java
private SendTask(DataByteArrayInputStream bais,long correlation,Transport transport,String errorMessage) {
this(new ServiceException(errorMessage),bais,correlation,new MethodData(new BlockingInvocationStrategy(),ObjectSerializationStrategy.INSTANCE,null),transport);
}