use of org.osgi.framework.ServiceException in project aries by apache.
the class TrackingResourceProviderFactory method doGetResult.
protected T doGetResult(Callable<T> getter) {
synchronized (getter) {
if (closed) {
throw new IllegalStateException("This ResourceProvider has been reclaimed because the factory service that provided it was released");
}
}
T t;
try {
t = getter.call();
} catch (Exception e) {
LOG.warn("A failure occurred obtaining the resource provider", e);
throw new ServiceException("A failure occurred obtaining the resource provider", e);
}
boolean destroy = false;
synchronized (toClose) {
if (closed) {
destroy = true;
} else {
toClose.add(t);
}
}
if (destroy) {
try {
t.close();
} catch (Exception e) {
LOG.warn("A failure occurred closing the resource provider", e);
}
throw new IllegalStateException("This ResourceProvider has been reclaimed because the factory service that provided it was released");
}
return t;
}
use of org.osgi.framework.ServiceException in project felix by apache.
the class ServiceRegistryTest method testGetServiceThreadMarking2.
@SuppressWarnings("unchecked")
public void testGetServiceThreadMarking2() throws Exception {
ServiceRegistry sr = new ServiceRegistry(null, null);
String svc = "bar";
Bundle b = Mockito.mock(Bundle.class);
ServiceRegistrationImpl reg = (ServiceRegistrationImpl) sr.registerService(b, new String[] { String.class.getName() }, svc, null);
ServiceReferenceImpl ref = Mockito.mock(ServiceReferenceImpl.class);
Mockito.when(ref.getRegistration()).thenReturn(reg);
reg.markCurrentThread();
try {
sr.getService(b, ref, false);
fail("Should have thrown an exception to signal reentrant behaviour");
} catch (ServiceException se) {
assertEquals(ServiceException.FACTORY_ERROR, se.getType());
}
}
use of org.osgi.framework.ServiceException in project opencast by opencast.
the class SeriesServiceImpl method repopulate.
@Override
public void repopulate(final String indexName) {
final String destinationId = SeriesItem.SERIES_QUEUE_PREFIX + indexName.substring(0, 1).toUpperCase() + indexName.substring(1);
try {
final int total = persistence.countSeries();
logger.info("Re-populating '{}' index with series. There are {} series to add to the index.", indexName, total);
final int responseInterval = (total < 100) ? 1 : (total / 100);
List<SeriesEntity> databaseSeries = persistence.getAllSeries();
int current = 1;
for (SeriesEntity series : databaseSeries) {
Organization organization = orgDirectory.getOrganization(series.getOrganization());
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Function0.X<Void>() {
@Override
public Void xapply() throws Exception {
String id = series.getSeriesId();
logger.trace("Adding series '{}' for org '{}'", id, series.getOrganization());
DublinCoreCatalog catalog = DublinCoreXmlFormat.read(series.getDublinCoreXML());
messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateCatalog(catalog));
AccessControlList acl = AccessControlParser.parseAcl(series.getAccessControl());
if (acl != null) {
messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateAcl(id, acl));
}
messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateOptOut(id, series.isOptOut()));
for (Entry<String, String> property : persistence.getSeriesProperties(id).entrySet()) {
messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SeriesItem.updateProperty(id, property.getKey(), property.getValue()));
}
return null;
}
});
if ((current % responseInterval == 0) || (current == total)) {
logger.info("Initializing {} series index rebuild {}/{}: {} percent", indexName, current, total, current * 100 / total);
}
current++;
}
logger.info("Finished initializing '{}' index rebuild", indexName);
} catch (Exception e) {
logger.warn("Unable to index series instances:", e);
throw new ServiceException(e.getMessage());
}
Organization organization = new DefaultOrganization();
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Effect0() {
@Override
protected void run() {
messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Series));
}
});
}
use of org.osgi.framework.ServiceException in project opencast by opencast.
the class SchedulerServiceImpl method repopulate.
@Override
public void repopulate(final String indexName) {
notEmpty(indexName, "indexName");
final String destinationId = SchedulerItem.SCHEDULER_QUEUE_PREFIX + WordUtils.capitalize(indexName);
Organization organization = new DefaultOrganization();
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Effect0() {
@Override
protected void run() {
int current = 1;
AQueryBuilder query = assetManager.createQuery();
Props p = new Props(query);
AResult result = query.select(query.snapshot(), p.agent().target(), p.start().target(), p.end().target(), p.optOut().target(), p.presenters().target(), p.reviewDate().target(), p.reviewStatus().target(), p.recordingStatus().target(), p.recordingLastHeard().target(), query.propertiesOf(CA_NAMESPACE)).where(withOrganization(query).and(query.hasPropertiesOf(p.namespace())).and(withVersion(query))).run();
final int total = (int) Math.min(result.getSize(), Integer.MAX_VALUE);
logger.info("Re-populating '{}' index with scheduled events. There are {} scheduled events to add to the index.", indexName, total);
final int responseInterval = (total < 100) ? 1 : (total / 100);
try {
for (ARecord record : result.getRecords()) {
String agentId = record.getProperties().apply(Properties.getString(AGENT_CONFIG));
boolean optOut = record.getProperties().apply(Properties.getBoolean(OPTOUT_CONFIG));
Date start = record.getProperties().apply(Properties.getDate(START_DATE_CONFIG));
Date end = record.getProperties().apply(Properties.getDate(END_DATE_CONFIG));
Set<String> presenters = getPresenters(record.getProperties().apply(getStringOpt(PRESENTERS_CONFIG)).getOr(""));
boolean blacklisted = isBlacklisted(record.getMediaPackageId(), start, end, agentId, presenters);
Map<String, String> caMetadata = record.getProperties().filter(filterByNamespace._2(CA_NAMESPACE)).group(toKey, toValue);
ReviewStatus reviewStatus = record.getProperties().apply(getStringOpt(REVIEW_STATUS_CONFIG)).map(toReviewStatus).getOr(UNSENT);
Date reviewDate = record.getProperties().apply(Properties.getDateOpt(REVIEW_DATE_CONFIG)).orNull();
Opt<String> recordingStatus = record.getProperties().apply(Properties.getStringOpt(RECORDING_STATE_CONFIG));
Opt<Long> lastHeard = record.getProperties().apply(Properties.getLongOpt(RECORDING_LAST_HEARD_CONFIG));
Opt<AccessControlList> acl = loadEpisodeAclFromAsset(record.getSnapshot().get());
Opt<DublinCoreCatalog> dublinCore = loadEpisodeDublinCoreFromAsset(record.getSnapshot().get());
sendUpdateAddEvent(record.getMediaPackageId(), acl, dublinCore, Opt.some(start), Opt.some(end), Opt.some(presenters), Opt.some(agentId), Opt.some(caMetadata), Opt.some(optOut));
messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SchedulerItem.updateBlacklist(record.getMediaPackageId(), blacklisted));
messageSender.sendObjectMessage(destinationId, MessageSender.DestinationType.Queue, SchedulerItem.updateReviewStatus(record.getMediaPackageId(), reviewStatus, reviewDate));
if (((current % responseInterval) == 0) || (current == total)) {
messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.update(indexName, IndexRecreateObject.Service.Scheduler, total, current));
}
if (recordingStatus.isSome() && lastHeard.isSome())
sendRecordingUpdate(new RecordingImpl(record.getMediaPackageId(), recordingStatus.get(), lastHeard.get()));
current++;
}
} catch (Exception e) {
logger.warn("Unable to index scheduled instances:", e);
throw new ServiceException(e.getMessage());
}
}
});
SecurityUtil.runAs(securityService, organization, SecurityUtil.createSystemUser(systemUserName, organization), new Effect0() {
@Override
protected void run() {
messageSender.sendObjectMessage(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue, IndexRecreateObject.end(indexName, IndexRecreateObject.Service.Scheduler));
}
});
}
use of org.osgi.framework.ServiceException in project ecf by eclipse.
the class AbstractRSAClientService method invoke.
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
try {
Object resultObject = invokeObject(proxy, method, args);
if (resultObject != null)
return resultObject;
try {
// If return is async type (Future, IFuture, CompletableFuture, CompletionStage)
if (isReturnAsync(proxy, method, args)) {
if (isInterfaceAsync(method.getDeclaringClass()) && isMethodAsync(method.getName()))
return invokeAsync(createRemoteCall(proxy, method, getAsyncInvokeMethodName(method), args, getDefaultTimeout()));
// If OSGI Async then invoke method directly
if (isOSGIAsync())
return invokeAsync(createRemoteCall(proxy, method, method.getName(), args, getDefaultTimeout()));
}
} catch (Throwable t) {
// $NON-NLS-1$
handleProxyException("Exception invoking async method on remote service proxy=" + getRemoteServiceID(), t);
}
final String callMethod = getCallMethodNameForProxyInvoke(method, args);
final Object[] callParameters = getCallParametersForProxyInvoke(callMethod, method, args);
final long callTimeout = getCallTimeoutForProxyInvoke(callMethod, method, args);
return invokeSync(createRemoteCall(proxy, method, callMethod, callParameters, callTimeout));
} catch (Throwable t) {
if (t instanceof ServiceException)
throw t;
// $NON-NLS-1$
throw new ServiceException("Service exception on remote service proxy rsid=" + getRemoteServiceID(), ServiceException.REMOTE, t);
}
}
Aggregations