Skip to content

Commit

Permalink
[AS7-5215] Deployments unecessarily trigger Framework create service
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Diesler authored and stuartwdouglas committed Jul 31, 2012
1 parent 16550e6 commit 446bfbe
Show file tree
Hide file tree
Showing 14 changed files with 363 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.jboss.osgi.framework.BundleManager;
import org.jboss.osgi.metadata.OSGiMetaData;
import org.jboss.osgi.resolver.XBundle;
import org.jboss.osgi.resolver.XBundleRevision;
import org.jboss.osgi.resolver.XEnvironment;
import org.jboss.osgi.resolver.XResolver;
import org.jboss.osgi.spi.BundleInfo;
Expand Down Expand Up @@ -56,9 +55,6 @@ public interface OSGiConstants {
/** Attachment key for a bundle deployment. */
AttachmentKey<Deployment> DEPLOYMENT_KEY = AttachmentKey.create(Deployment.class);

/** Attachment key for a registered {@link XBundleRevision}. */
AttachmentKey<XBundleRevision> REGISTERED_MODULE_KEY = AttachmentKey.create(XBundleRevision.class);

/** Attachment key for {@link OSGiMetaData} */
AttachmentKey<OSGiMetaData> OSGI_METADATA_KEY = AttachmentKey.create(OSGiMetaData.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public interface OSGiMessages {
//StartException startFailedToInstallDeployment(@Cause Throwable th, Deployment deployment);

@Message(id = 11958, value = "Failed to register module: %s")
DeploymentUnitProcessingException deploymentFailedToRegisterModule(@Cause Throwable th, Module module);
IllegalStateException illegalStateFailedToRegisterModule(@Cause Throwable th, Module module);

@Message(id = 11959, value = "StartLevel service not available")
String startLevelServiceNotAvailable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static org.jboss.as.osgi.OSGiLogger.LOGGER;

import org.jboss.as.osgi.OSGiConstants;
import org.jboss.as.osgi.service.PersistentBundlesIntegration.InitialDeploymentTracker;
import org.jboss.as.osgi.service.InitialDeploymentTracker;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
* @author [email protected]
* @since 03-Aug-2011
*/
public class BundleContextDependencyProcessor implements DeploymentUnitProcessor {
public class BundleContextBindingProcessor implements DeploymentUnitProcessor {

private static final ModuleIdentifier ORG_JBOSS_OSGI_RESOLVER = ModuleIdentifier.create("org.jboss.osgi.resolver");
private static final ModuleIdentifier ORG_OSGI_CORE = ModuleIdentifier.create("org.osgi.core");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static org.jboss.as.server.deployment.Attachments.BUNDLE_STATE_KEY;

import org.jboss.as.osgi.OSGiConstants;
import org.jboss.as.osgi.service.PersistentBundlesIntegration.InitialDeploymentTracker;
import org.jboss.as.osgi.service.InitialDeploymentTracker;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.Attachments.BundleState;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
package org.jboss.as.osgi.deployment;

import static org.jboss.as.osgi.OSGiLogger.LOGGER;
import static org.jboss.osgi.framework.IntegrationServices.BOOTSTRAP_BUNDLES_COMPLETE;
import static org.jboss.as.osgi.service.ModuleRegistrationTracker.MODULE_REGISTRATION_COMPLETE;
import static org.jboss.osgi.framework.Services.FRAMEWORK_ACTIVE;

import java.util.List;

import org.jboss.as.controller.ServiceVerificationHandler;
import org.jboss.as.osgi.OSGiConstants;
import org.jboss.as.osgi.service.FrameworkActivationService;
import org.jboss.as.osgi.service.PersistentBundlesIntegration.InitialDeploymentTracker;
import org.jboss.as.osgi.service.InitialDeploymentTracker;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
Expand All @@ -44,6 +44,7 @@
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.msc.service.ServiceName;
import org.jboss.osgi.deployment.deployer.Deployment;
import org.jboss.osgi.framework.Services;

/**
Expand All @@ -63,41 +64,41 @@ public FrameworkActivateProcessor(InitialDeploymentTracker deploymentTracker) {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

// Always make the system context & the environment available
// [TODO] [AS7-5215] Deployments unecessarily trigger Framework create service
phaseContext.addDeploymentDependency(Services.SYSTEM_CONTEXT, OSGiConstants.SYSTEM_CONTEXT_KEY);
phaseContext.addDeploymentDependency(Services.ENVIRONMENT, OSGiConstants.ENVIRONMENT_KEY);

// Check whether this is an OSGi deployment or whether it wants to have an OSGi type injected
DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
if (!depUnit.hasAttachment(OSGiConstants.DEPLOYMENT_KEY) && !hasValidInjectionPoint(depUnit))
Deployment deployment = depUnit.getAttachment(OSGiConstants.DEPLOYMENT_KEY);
boolean hasInjectionPoint = hasValidInjectionPoint(depUnit);
if (deployment == null && hasInjectionPoint == false)
return;

// Install the {@link FrameworkActivationService} if not done so already
ServiceVerificationHandler verificationHandler = depUnit.getAttachment(Attachments.SERVICE_VERIFICATION_HANDLER);
FrameworkActivationService.activateOnce(verificationHandler);

// Setup a dependency on the the next phase. Persistent bundles have a dependency on the bootstrap bundles
ServiceName phaseDependency = deploymentTracker.isComplete() ? FRAMEWORK_ACTIVE : BOOTSTRAP_BUNDLES_COMPLETE;
ServiceName phaseDependency = deploymentTracker.isComplete() ? FRAMEWORK_ACTIVE : MODULE_REGISTRATION_COMPLETE;
phaseContext.addDeploymentDependency(phaseDependency, AttachmentKey.create(Object.class));

// Make these services available for a bundle deployment only
phaseContext.addDeploymentDependency(Services.BUNDLE_MANAGER, OSGiConstants.BUNDLE_MANAGER_KEY);
phaseContext.addDeploymentDependency(Services.RESOLVER, OSGiConstants.RESOLVER_KEY);
phaseContext.addDeploymentDependency(Services.SYSTEM_CONTEXT, OSGiConstants.SYSTEM_CONTEXT_KEY);
phaseContext.addDeploymentDependency(Services.ENVIRONMENT, OSGiConstants.ENVIRONMENT_KEY);
}

@Override
public void undeploy(final DeploymentUnit depUnit) {
}

/*
* Check for injection target fields of type org.osgi.framework.*
*/
private boolean hasValidInjectionPoint(DeploymentUnit depUnit) {
return hasInjectionPoint(depUnit, "javax.inject.Inject") || hasInjectionPoint(depUnit, "javax.annotation.Resource");
}

// Check for injection target fields of type org.osgi.framework.*
private boolean hasInjectionPoint(DeploymentUnit depUnit, String anName) {
boolean result = false;
DotName dotName = DotName.createSimple("javax.inject.Inject");
CompositeIndex compositeIndex = depUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
List<AnnotationInstance> annotationList = compositeIndex.getAnnotations(dotName);
List<AnnotationInstance> annotationList = compositeIndex.getAnnotations(DotName.createSimple(anName));
for (AnnotationInstance instance : annotationList) {
AnnotationTarget target = instance.target();
if (target instanceof FieldInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,19 @@

package org.jboss.as.osgi.deployment;

import static org.jboss.as.osgi.OSGiLogger.LOGGER;
import static org.jboss.as.osgi.OSGiMessages.MESSAGES;

import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.osgi.OSGiConstants;
import org.jboss.as.osgi.service.ModuleRegistrationTracker;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.module.ModuleSpecification;
import org.jboss.modules.Module;
import org.jboss.osgi.framework.AbstractBundleRevisionAdaptor;
import org.jboss.osgi.metadata.OSGiMetaData;
import org.jboss.osgi.resolver.XBundleRevision;
import org.jboss.osgi.resolver.XBundleRevisionBuilderFactory;
import org.jboss.osgi.resolver.XEnvironment;
import org.jboss.osgi.resolver.XResourceBuilder;
import org.osgi.framework.BundleContext;

/**
* Processes deployments that have a Module attached.
Expand All @@ -53,6 +46,12 @@
*/
public class ModuleRegisterProcessor implements DeploymentUnitProcessor {

private final ModuleRegistrationTracker registrationTracker;

public ModuleRegisterProcessor(ModuleRegistrationTracker tracker) {
this.registrationTracker = tracker;
}

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

Expand All @@ -71,38 +70,13 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
if (module == null || moduleSpecification.isPrivateModule())
return;

LOGGER.infoRegisterModule(module.getIdentifier());
try {
final BundleContext context = depUnit.getAttachment(OSGiConstants.SYSTEM_CONTEXT_KEY);
XBundleRevisionBuilderFactory factory = new XBundleRevisionBuilderFactory() {
@Override
public XBundleRevision createResource() {
return new AbstractBundleRevisionAdaptor(context, module);
}
};
OSGiMetaData metadata = depUnit.getAttachment(OSGiConstants.OSGI_METADATA_KEY);
XEnvironment env = depUnit.getAttachment(OSGiConstants.ENVIRONMENT_KEY);
XResourceBuilder builder = XBundleRevisionBuilderFactory.create(factory);
if (metadata != null) {
builder.loadFrom(metadata);
} else {
builder.loadFrom(module);
}
XBundleRevision brev = (XBundleRevision) builder.getResource();
env.installResources(brev);
depUnit.putAttachment(OSGiConstants.REGISTERED_MODULE_KEY, brev);
} catch (Throwable th) {
throw MESSAGES.deploymentFailedToRegisterModule(th, module);
}
OSGiMetaData metadata = depUnit.getAttachment(OSGiConstants.OSGI_METADATA_KEY);
registrationTracker.registerModule(module, metadata);
}

@Override
public void undeploy(final DeploymentUnit depUnit) {
final XBundleRevision brev = depUnit.removeAttachment(OSGiConstants.REGISTERED_MODULE_KEY);
if (brev != null) {
LOGGER.infoUnregisterModule(brev.getModuleIdentifier());
XEnvironment env = depUnit.getAttachment(OSGiConstants.ENVIRONMENT_KEY);
env.uninstallResources(brev);
}
final Module module = depUnit.getAttachment(Attachments.MODULE);
registrationTracker.unregisterModule(module);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.osgi.OSGiSubsystemExtension;
import org.jboss.as.osgi.deployment.BundleActivateProcessor;
import org.jboss.as.osgi.deployment.BundleContextDependencyProcessor;
import org.jboss.as.osgi.deployment.BundleContextBindingProcessor;
import org.jboss.as.osgi.deployment.BundleDeploymentProcessor;
import org.jboss.as.osgi.deployment.BundleInstallProcessor;
import org.jboss.as.osgi.deployment.BundleResolveProcessor;
Expand All @@ -51,7 +51,8 @@
import org.jboss.as.osgi.management.OSGiRuntimeResource;
import org.jboss.as.osgi.parser.SubsystemState.Activation;
import org.jboss.as.osgi.service.FrameworkBootstrapService;
import org.jboss.as.osgi.service.PersistentBundlesIntegration.InitialDeploymentTracker;
import org.jboss.as.osgi.service.InitialDeploymentTracker;
import org.jboss.as.osgi.service.ModuleRegistrationTracker;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.as.server.deployment.Phase;
Expand Down Expand Up @@ -99,11 +100,13 @@ protected void performBoottime(final OperationContext context, final ModelNode o
final ServiceTarget serviceTarget = context.getServiceTarget();
final Activation activationMode = getActivationMode(operation);
final InitialDeploymentTracker deploymentTracker = new InitialDeploymentTracker(context, verificationHandler);
final ModuleRegistrationTracker registrationTracker = new ModuleRegistrationTracker();

context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
newControllers.add(FrameworkBootstrapService.addService(serviceTarget, resource, verificationHandler));
newControllers.add(registrationTracker.install(serviceTarget, verificationHandler));
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
}, OperationContext.Stage.RUNTIME);
Expand All @@ -117,11 +120,11 @@ protected void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_OSGI_PROPERTIES, new OSGiXServiceParseProcessor());
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_OSGI_DEPLOYMENT, new BundleDeploymentProcessor());
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_OSGI_SUBSYSTEM_ACTIVATOR, new FrameworkActivateProcessor(deploymentTracker));
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_BUNDLE_CONTEXT, new BundleContextDependencyProcessor());
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_BUNDLE_CONTEXT, new BundleContextBindingProcessor());
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.REGISTER, Phase.REGISTER_BUNDLE_INSTALL, new BundleInstallProcessor(deploymentTracker));
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.CONFIGURE_MODULE, Phase.CONFIGURE_RESOLVE_BUNDLE, new BundleResolveProcessor());
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.CONFIGURE_MODULE, Phase.CONFIGURE_RESOLVE_SUB_BUNDLE, new BundleResolveSubProcessor());
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_RESOLVER_MODULE, new ModuleRegisterProcessor());
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_RESOLVER_MODULE, new ModuleRegisterProcessor(registrationTracker));
processorTarget.addDeploymentProcessor(OSGiExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_BUNDLE_ACTIVATE, new BundleActivateProcessor(deploymentTracker));
}
}, OperationContext.Stage.RUNTIME);
Expand Down
Loading

0 comments on commit 446bfbe

Please sign in to comment.