use of org.osgi.service.coordinator.Coordination in project tesb-rt-se by Talend.
the class CoordinationEndInterceptor method handleMessage.
@Override
public void handleMessage(Message message) throws Fault {
Coordination coordination = message.getExchange().get(Coordination.class);
coordination.end();
}
use of org.osgi.service.coordinator.Coordination in project tesb-rt-se by Talend.
the class BookRepositoryTest method testEMLifecycleWithCoordination.
/**
* Test EntityManager life cycle can be extended by outer Coordination
*/
@Test
public void testEMLifecycleWithCoordination() throws Exception {
Coordination coordination = coordinator.begin("coord", 10000);
Book book = createBook("My title");
try {
bookRepository.add(book);
Book book2 = bookRepository.getBook(book.getId());
Format format = book2.getFormats().get(0);
Assert.assertEquals(book.getFormats().get(0).getFile().toString(), format.getFile().toString());
} finally {
bookRepository.delete(book.getId());
coordination.end();
}
}
use of org.osgi.service.coordinator.Coordination in project aries by apache.
the class StartAction method run.
@Override
public Object run() {
// Protect against re-entry now that cycles are supported.
if (!Activator.getInstance().getLockingStrategy().set(State.STARTING, target)) {
return null;
}
try {
AffectedResources affectedResources;
// If necessary, install the dependencies.
if (State.INSTALLING.equals(target.getState()) && !Utils.isProvisionDependenciesInstall(target)) {
// Acquire the global write lock while installing dependencies.
Activator.getInstance().getLockingStrategy().writeLock();
try {
// We are now protected against installs, starts, stops, and uninstalls.
// We need a separate coordination when installing
// dependencies because cleaning up the temporary export
// sharing policies must be done while holding the write lock.
Coordination c = Utils.createCoordination(target);
try {
installDependencies(target, c);
// Associated subsystems must be computed after all dependencies
// are installed because some of the dependencies may be
// subsystems. This is safe to do while only holding the read
// lock since we know that nothing can be added or removed.
affectedResources = computeAffectedResources(target);
for (BasicSubsystem subsystem : affectedResources.subsystems()) {
if (State.INSTALLING.equals(subsystem.getState()) && !Utils.isProvisionDependenciesInstall(subsystem)) {
installDependencies(subsystem, c);
}
}
// Downgrade to the read lock in order to prevent
// installs and uninstalls but allow starts and stops.
Activator.getInstance().getLockingStrategy().readLock();
} catch (Throwable t) {
c.fail(t);
} finally {
// This will clean up the temporary export sharing
// policies. Must be done while holding the write lock.
c.end();
}
} finally {
// Release the global write lock as soon as possible.
Activator.getInstance().getLockingStrategy().writeUnlock();
}
} else {
// Acquire the read lock in order to prevent installs and
// uninstalls but allow starts and stops.
Activator.getInstance().getLockingStrategy().readLock();
}
try {
// and uninstalls.
if (Restriction.INSTALL_ONLY.equals(restriction)) {
return null;
}
// Compute associated subsystems here in case (1) they weren't
// computed previously while holding the write lock or (2) they
// were computed previously and more were subsequently added.
// This is safe to do while only holding the read lock since we
// know that nothing can be added or removed.
affectedResources = computeAffectedResources(target);
// 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(affectedResources.subsystems());
} finally {
// Release the global mutual exclusion lock as soon as possible.
Activator.getInstance().getLockingStrategy().unlock();
}
Coordination coordination = this.coordination;
try {
coordination = createCoordination();
// We are now protected against other starts and stops of the affected subsystems.
if (!isTargetStartable(instigator, requestor, target)) {
return null;
}
// Resolve if necessary.
if (State.INSTALLED.equals(target.getState()))
resolve(instigator, target, target, coordination, affectedResources.subsystems());
if (Restriction.RESOLVE_ONLY.equals(restriction))
return null;
target.setState(State.STARTING);
// Be sure to set the state back to RESOLVED if starting fails.
coordination.addParticipant(new Participant() {
@Override
public void ended(Coordination coordination) throws Exception {
// Nothing.
}
@Override
public void failed(Coordination coordination) throws Exception {
target.setState(State.RESOLVED);
}
});
SubsystemContentHeader header = target.getSubsystemManifest().getSubsystemContentHeader();
if (header != null)
Collections.sort(affectedResources.resources(), new StartResourceComparator(header));
for (Resource resource : affectedResources.resources()) startResource(resource, coordination);
target.setState(State.ACTIVE);
} catch (Throwable t) {
// We catch exceptions and fail the coordination here to
// ensure we are still holding the state change locks when
// the participant sets the state to RESOLVED.
coordination.fail(t);
} finally {
try {
// of this start action.
if (coordination.getName().equals(Utils.computeCoordinationName(target))) {
coordination.end();
}
} finally {
// Release the state change locks of affected subsystems.
Activator.getInstance().getLockingStrategy().unlock(affectedResources.subsystems());
}
}
} finally {
// Release the read lock.
Activator.getInstance().getLockingStrategy().readUnlock();
}
} catch (CoordinationException e) {
Throwable t = e.getCause();
if (t == null) {
throw new SubsystemException(e);
}
if (t instanceof SecurityException) {
throw (SecurityException) t;
}
if (t instanceof SubsystemException) {
throw (SubsystemException) t;
}
throw new SubsystemException(t);
} finally {
// Protection against re-entry no longer required.
Activator.getInstance().getLockingStrategy().unset(State.STARTING, target);
}
return null;
}
use of org.osgi.service.coordinator.Coordination in project aries by apache.
the class BasicSubsystem method setDeploymentManifest.
synchronized void setDeploymentManifest(DeploymentManifest value) throws IOException {
deploymentManifest = value;
Coordination coordination = Activator.getInstance().getCoordinator().peek();
if (logger.isDebugEnabled())
logger.debug("Setting deployment manifest for subsystem {} using coordination {}", getSymbolicName(), coordination == null ? null : coordination.getName());
if (coordination == null) {
saveDeploymentManifest();
} else {
Map<Class<?>, Object> variables = coordination.getVariables();
synchronized (variables) {
@SuppressWarnings("unchecked") Set<BasicSubsystem> dirtySubsystems = (Set<BasicSubsystem>) variables.get(SaveManifestParticipant.class);
if (dirtySubsystems == null) {
// currently no dirty subsystems found;
// create a list to hold them and store it as a variable
dirtySubsystems = new HashSet<BasicSubsystem>();
variables.put(SaveManifestParticipant.class, dirtySubsystems);
// add the save manifest participant
coordination.addParticipant(new SaveManifestParticipant());
}
dirtySubsystems.add(this);
}
}
}
use of org.osgi.service.coordinator.Coordination in project felix by apache.
the class CoordinationImpl method getEnclosingCoordination.
/**
* @see org.osgi.service.coordinator.Coordination#getEnclosingCoordination()
*/
public Coordination getEnclosingCoordination() {
this.owner.checkPermission(name, CoordinationPermission.ADMIN);
Coordination c = this.owner.getEnclosingCoordination(this);
if (c != null) {
c = ((CoordinationImpl) c).holderRef.get();
}
return c;
}
Aggregations