use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class BasicSubsystem method removedContent.
synchronized void removedContent(Collection<DeployedContentHeader.Clause> content) {
DeploymentManifest manifest = getDeploymentManifest();
DeployedContentHeader header = manifest.getDeployedContentHeader();
if (header == null)
return;
Collection<DeployedContentHeader.Clause> clauses = new ArrayList<DeployedContentHeader.Clause>(header.getClauses());
for (Iterator<DeployedContentHeader.Clause> i = clauses.iterator(); i.hasNext(); ) if (content.contains(i.next())) {
i.remove();
break;
}
DeploymentManifest.Builder builder = new DeploymentManifest.Builder();
for (Entry<String, Header<?>> entry : manifest.getHeaders().entrySet()) {
if (DeployedContentHeader.NAME.equals(entry.getKey()))
continue;
builder.header(entry.getValue());
}
if (!clauses.isEmpty())
builder.header(new DeployedContentHeader(clauses));
try {
setDeploymentManifest(builder.build());
} catch (Exception e) {
throw new SubsystemException(e);
}
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class BasicSubsystem method setState.
void setState(State value) {
if (logger.isDebugEnabled())
logger.debug("Setting state of subsystem {} to {}", getSymbolicName(), value);
State state = getState();
if (value.equals(state)) {
if (logger.isDebugEnabled())
logger.debug("Requested state {} equals current state {}", value, state);
return;
}
try {
if (logger.isDebugEnabled())
logger.debug("Setting the deployment manifest...");
synchronized (this) {
setDeploymentManifest(new DeploymentManifest.Builder().manifest(getDeploymentManifest()).state(value).build());
}
} catch (Exception e) {
throw new SubsystemException(e);
}
Activator.getInstance().getSubsystemServiceRegistrar().update(this);
synchronized (this) {
if (logger.isDebugEnabled())
logger.debug("Notifying all waiting for state change of subsystem {}", getSymbolicName());
notifyAll();
}
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class StartAction method resolve.
private static void resolve(BasicSubsystem instigator, BasicSubsystem target, BasicSubsystem subsystem, Coordination coordination, Collection<BasicSubsystem> subsystems) {
emitResolvingEvent(subsystem);
try {
// actually doing the resolution work.
if (!subsystem.isRoot()) {
setExportIsolationPolicy(subsystem, coordination);
resolveSubsystems(instigator, target, coordination, subsystems);
resolveBundles(subsystem);
}
emitResolvedEvent(subsystem);
} catch (Throwable t) {
subsystem.setState(State.INSTALLED);
if (t instanceof SubsystemException)
throw (SubsystemException) t;
throw new SubsystemException(t);
}
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class StopAction method run.
@Override
public Object run() {
// Protect against re-entry now that cycles are supported.
if (!Activator.getInstance().getLockingStrategy().set(State.STOPPING, target)) {
return null;
}
try {
// We are now protected against re-entry.
// Acquire the global read lock to prevent installs and uninstalls
// but allow starts and stops.
Activator.getInstance().getLockingStrategy().readLock();
try {
// We are now protected against installs and uninstalls.
checkRoot();
// Compute affected subsystems. This is safe to do while only
// holding the read lock since we know that nothing can be added
// or removed.
LinkedHashSet<BasicSubsystem> subsystems = new LinkedHashSet<BasicSubsystem>();
subsystems.add(target);
List<Resource> resources = new ArrayList<Resource>(Activator.getInstance().getSubsystems().getResourcesReferencedBy(target));
for (Resource resource : resources) {
if (resource instanceof BasicSubsystem) {
subsystems.add((BasicSubsystem) resource);
}
}
// Acquire the global mutual exclusion lock while acquiring the
// state change locks of affected subsystems.
Activator.getInstance().getLockingStrategy().lock();
try {
// We are now protected against cycles.
// Acquire the state change locks of affected subsystems.
Activator.getInstance().getLockingStrategy().lock(subsystems);
} finally {
// Release the global mutual exclusion lock as soon as possible.
Activator.getInstance().getLockingStrategy().unlock();
}
try {
// We are now protected against other starts and stops of the affected subsystems.
State state = target.getState();
if (EnumSet.of(State.INSTALLED, State.INSTALLING, State.RESOLVED).contains(state)) {
// apache-aries-provision-dependencies:=resolve.
return null;
} else if (EnumSet.of(State.INSTALL_FAILED, State.UNINSTALLED).contains(state)) {
throw new IllegalStateException("Cannot stop from state " + state);
}
target.setState(State.STOPPING);
SubsystemContentHeader header = target.getSubsystemManifest().getSubsystemContentHeader();
if (header != null) {
Collections.sort(resources, new StartResourceComparator(target.getSubsystemManifest().getSubsystemContentHeader()));
Collections.reverse(resources);
}
for (Resource resource : resources) {
// Don't stop the region context bundle.
if (Utils.isRegionContextBundle(resource))
continue;
try {
stopResource(resource);
} catch (Exception e) {
logger.error("An error occurred while stopping resource " + resource + " of subsystem " + target, e);
}
}
// TODO Can we automatically assume it actually is resolved?
target.setState(State.RESOLVED);
try {
synchronized (target) {
target.setDeploymentManifest(new DeploymentManifest(target.getDeploymentManifest(), null, target.isAutostart(), target.getSubsystemId(), SubsystemIdentifier.getLastId(), target.getLocation(), false, false));
}
} catch (Exception e) {
throw new SubsystemException(e);
}
} finally {
// Release the state change locks of affected subsystems.
Activator.getInstance().getLockingStrategy().unlock(subsystems);
}
} finally {
// Release the read lock.
Activator.getInstance().getLockingStrategy().readUnlock();
}
} finally {
// Protection against re-entry no longer required.
Activator.getInstance().getLockingStrategy().unset(State.STOPPING, target);
}
return null;
}
use of org.osgi.service.subsystem.SubsystemException in project aries by apache.
the class RepositoryServiceRepository method findProviders.
@SuppressWarnings("unchecked")
public Collection<Capability> findProviders(Requirement requirement) {
Set<Capability> result = new HashSet<Capability>();
ServiceReference<?>[] references;
try {
references = context.getAllServiceReferences("org.osgi.service.repository.Repository", null);
if (references == null)
return result;
} catch (InvalidSyntaxException e) {
throw new IllegalStateException(e);
}
for (ServiceReference<?> reference : references) {
Object repository = context.getService(reference);
if (repository == null)
continue;
try {
// Reflection is used here to allow the service to work with a mixture of
// Repository services implementing different versions of the API.
Class<?> clazz = repository.getClass();
Class<?> repoInterface = null;
while (clazz != null && repoInterface == null) {
for (Class<?> intf : clazz.getInterfaces()) {
if (Repository.class.getName().equals(intf.getName())) {
// Compare interfaces by name so that we can work with different versions of the
// interface.
repoInterface = intf;
break;
}
}
clazz = clazz.getSuperclass();
}
if (repoInterface == null) {
continue;
}
Map<Requirement, Collection<Capability>> map;
try {
Method method = repoInterface.getMethod("findProviders", Collection.class);
map = (Map<Requirement, Collection<Capability>>) method.invoke(repository, Collections.singleton(requirement));
} catch (Exception e) {
throw new SubsystemException(e);
}
Collection<Capability> capabilities = map.get(requirement);
if (capabilities == null)
continue;
result.addAll(capabilities);
} finally {
context.ungetService(reference);
}
}
return result;
}
Aggregations