Author: jwross
Date: Thu Jun 13 16:50:32 2013
New Revision: 1492750
URL: http://svn.apache.org/r1492750
Log:
[aries-1050] Revisit the use of coordinations in order to take advantage of the
deployment manifest optimizations.
Remove unnecessary constructor and fields from InstallAction. These were
originally necessary when InstallAction called itself during
an embedded operation (i.e. a subsystem with children is being installed).
Optimize coordination use when starting subsystems. The same coordination is
now shared by all children of the subsystem being started.
Reuse existing coordination when installing region context bundle.
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/InstallAction.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/InstallAction.java
URL:
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/InstallAction.java?rev=1492750&r1=1492749&r2=1492750&view=diff
==============================================================================
---
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/InstallAction.java
(original)
+++
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/InstallAction.java
Thu Jun 13 16:50:32 2013
@@ -31,31 +31,21 @@ import org.osgi.service.subsystem.Subsys
public class InstallAction implements PrivilegedAction<BasicSubsystem> {
private final IDirectory content;
private final AccessControlContext context;
- private final Coordination coordination;
- private final boolean embedded;
private final String location;
private final BasicSubsystem parent;
public InstallAction(String location, IDirectory content,
BasicSubsystem parent, AccessControlContext context) {
- this(location, content, parent, context, null, false);
- }
-
- public InstallAction(String location, IDirectory content,
BasicSubsystem parent, AccessControlContext context, Coordination coordination,
boolean embedded) {
this.location = location;
this.content = content;
this.parent = parent;
this.context = context;
- this.coordination = coordination;
- this.embedded = embedded;
}
@Override
public BasicSubsystem run() {
// Initialization of a null coordination must be privileged and,
// therefore, occur in the run() method rather than in the
constructor.
- Coordination coordination = this.coordination;
- if (coordination == null)
- coordination = Utils.createCoordination(parent);
+ Coordination coordination = Utils.createCoordination(parent);
BasicSubsystem result = null;
try {
TargetRegion region = new TargetRegion(parent);
@@ -88,26 +78,22 @@ public class InstallAction implements Pr
coordination.fail(t);
}
finally {
- if (!embedded) {
- try {
- coordination.end();
- }
- catch (CoordinationException e) {
- Throwable t = e.getCause();
- if (t instanceof SubsystemException)
- throw (SubsystemException)t;
- if (t instanceof SecurityException)
- throw (SecurityException)t;
- throw new SubsystemException(t);
- }
+ try {
+ coordination.end();
+ }
+ catch (CoordinationException e) {
+ Throwable t = e.getCause();
+ if (t instanceof SubsystemException)
+ throw (SubsystemException)t;
+ if (t instanceof SecurityException)
+ throw (SecurityException)t;
+ throw new SubsystemException(t);
}
}
return result;
}
private void checkLifecyclePermission(final BasicSubsystem subsystem) {
- if (embedded)
- return;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java
URL:
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java?rev=1492750&r1=1492749&r2=1492750&view=diff
==============================================================================
---
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java
(original)
+++
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java
Thu Jun 13 16:50:32 2013
@@ -26,12 +26,13 @@ import org.osgi.framework.BundleExceptio
import org.osgi.framework.Version;
import org.osgi.framework.startlevel.BundleStartLevel;
import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.service.coordinator.Coordination;
public class RegionContextBundleHelper {
public static final String SYMBOLICNAME_PREFIX =
Constants.RegionContextBundleSymbolicNamePrefix;
public static final Version VERSION = Version.parseVersion("1.0.0");
- public static void installRegionContextBundle(BasicSubsystem subsystem)
throws BundleException, IOException {
+ public static void installRegionContextBundle(final BasicSubsystem
subsystem, Coordination coordination) throws Exception {
String symbolicName = SYMBOLICNAME_PREFIX +
subsystem.getSubsystemId();
String location = subsystem.getLocation() + '/' +
subsystem.getSubsystemId();
Bundle b = subsystem.getRegion().getBundle(symbolicName,
VERSION);
@@ -42,7 +43,7 @@ public class RegionContextBundleHelper {
// context bundle, should be 1.
b.adapt(BundleStartLevel.class).setStartLevel(1);
}
- Utils.installResource(b.adapt(BundleRevision.class), subsystem);
+ ResourceInstaller.newInstance(coordination,
b.adapt(BundleRevision.class), subsystem).install();
// The region context bundle must be started persistently.
b.start();
}
@@ -51,7 +52,7 @@ public class RegionContextBundleHelper {
String symbolicName = SYMBOLICNAME_PREFIX +
subsystem.getSubsystemId();
Bundle bundle = subsystem.getRegion().getBundle(symbolicName,
VERSION);
if (bundle == null)
- throw new IllegalStateException("Missing region context
bundle: " + symbolicName);
+ return;
ThreadLocalSubsystem.set(subsystem);
BundleRevision revision = bundle.adapt(BundleRevision.class);
try {
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
URL:
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java?rev=1492750&r1=1492749&r2=1492750&view=diff
==============================================================================
---
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
(original)
+++
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
Thu Jun 13 16:50:32 2013
@@ -53,11 +53,17 @@ import org.slf4j.LoggerFactory;
public class StartAction extends AbstractAction {
private static final Logger logger =
LoggerFactory.getLogger(BasicSubsystem.class);
+ private final Coordination coordination;
private final BasicSubsystem instigator;
public StartAction(BasicSubsystem instigator, BasicSubsystem requestor,
BasicSubsystem target) {
+ this(instigator, requestor, target, null);
+ }
+
+ public StartAction(BasicSubsystem instigator, BasicSubsystem requestor,
BasicSubsystem target, Coordination coordination) {
super(requestor, target, false);
this.instigator = instigator;
+ this.coordination = coordination;
}
@Override
@@ -69,7 +75,7 @@ public class StartAction extends Abstrac
// The following states must wait.
if (EnumSet.of(State.INSTALLING, State.RESOLVING,
State.STARTING, State.STOPPING).contains(state)) {
waitForStateChange(state);
- return new StartAction(instigator, requestor,
target).run();
+ return new StartAction(instigator, requestor, target,
coordination).run();
}
// The following states mean the requested state has already
been attained.
if (State.ACTIVE.equals(state))
@@ -87,17 +93,17 @@ public class StartAction extends Abstrac
}
}
}
- // Resolve if necessary.
- if (State.INSTALLED.equals(state))
- resolve(target);
- target.setState(State.STARTING);
- // TODO Need to hold a lock here to guarantee that another start
- // operation can't occur when the state goes to RESOLVED.
- // Start the subsystem.
- Coordination coordination = Activator.getInstance()
- .getCoordinator()
- .create(target.getSymbolicName() + '-' +
target.getSubsystemId(), 0);
+ Coordination coordination = this.coordination;
+ if (coordination == null)
+ coordination = Utils.createCoordination(target);
try {
+ // Resolve if necessary.
+ if (State.INSTALLED.equals(state))
+ resolve(target);
+ target.setState(State.STARTING);
+ // TODO Need to hold a lock here to guarantee that
another start
+ // operation can't occur when the state goes to
RESOLVED.
+ // Start the subsystem.
List<Resource> resources = new
ArrayList<Resource>(Activator.getInstance().getSubsystems().getResourcesReferencedBy(target));
SubsystemContentHeader header =
target.getSubsystemManifest().getSubsystemContentHeader();
if (header != null)
@@ -111,7 +117,10 @@ public class StartAction extends Abstrac
// region and transition to INSTALLED.
} finally {
try {
- coordination.end();
+ // Don't end the coordination if the subsystem
being started
+ // (i.e. the target) did not begin it.
+ if
(coordination.getName().equals(Utils.computeCoordinationName(target)))
+ coordination.end();
} catch (CoordinationException e) {
target.setState(State.RESOLVED);
Throwable t = e.getCause();
@@ -221,7 +230,7 @@ public class StartAction extends Abstrac
builder.allow(policy, filter.toString());
}
}
-
+
private static void setExportIsolationPolicy(RegionFilterBuilder
builder, SubsystemExportServiceHeader header, BasicSubsystem subsystem) throws
InvalidSyntaxException {
if (header == null)
return;
@@ -281,7 +290,7 @@ public class StartAction extends Abstrac
// their autostart setting set to started.
if (Utils.isContent(this.target, subsystem))
subsystem.setAutostart(true);
- new StartAction(instigator, target, subsystem).run();
+ new StartAction(instigator, target, subsystem,
coordination).run();
if (coordination == null)
return;
coordination.addParticipant(new Participant() {
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java
URL:
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java?rev=1492750&r1=1492749&r2=1492750&view=diff
==============================================================================
---
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java
(original)
+++
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java
Thu Jun 13 16:50:32 2013
@@ -13,14 +13,12 @@
*/
package org.apache.aries.subsystem.core.internal;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.apache.aries.util.filesystem.FileSystem;
-import org.osgi.framework.BundleException;
import org.osgi.resource.Resource;
import org.osgi.service.coordinator.Coordination;
import org.osgi.service.coordinator.Participant;
@@ -130,10 +128,10 @@ public class SubsystemResourceInstaller
return installSubsystemResource(subsystemResource);
}
- private void installRegionContextBundle(final BasicSubsystem subsystem)
throws BundleException, IOException {
+ private void installRegionContextBundle(final BasicSubsystem subsystem)
throws Exception {
if (!subsystem.isScoped())
return;
- RegionContextBundleHelper.installRegionContextBundle(subsystem);
+ RegionContextBundleHelper.installRegionContextBundle(subsystem,
coordination);
coordination.addParticipant(new Participant() {
@Override
public void ended(Coordination coordination) throws
Exception {
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
URL:
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java?rev=1492750&r1=1492749&r2=1492750&view=diff
==============================================================================
---
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
(original)
+++
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
Thu Jun 13 16:50:32 2013
@@ -30,12 +30,16 @@ import org.slf4j.LoggerFactory;
public class Utils {
private static final Logger logger =
LoggerFactory.getLogger(Utils.class);
+ public static String computeCoordinationName(Subsystem subsystem) {
+ return subsystem.getSymbolicName() + '-' +
subsystem.getSubsystemId();
+ }
+
public static Coordination createCoordination() {
return
Activator.getInstance().getCoordinator().begin(BasicSubsystem.ROOT_SYMBOLIC_NAME
+ "-0", 0);
}
public static Coordination createCoordination(BasicSubsystem subsystem)
{
- return
Activator.getInstance().getCoordinator().begin(subsystem.getSymbolicName() +
'-' + subsystem.getSubsystemId(), 0);
+ return
Activator.getInstance().getCoordinator().begin(computeCoordinationName(subsystem),
0);
}
public static BasicSubsystem
findFirstSubsystemAcceptingDependenciesStartingFrom(BasicSubsystem subsystem) {