public static ServiceController<SubsystemState> addService(ServiceTarget serviceTarget, Activation activation) { SubsystemState state = new SubsystemState(); state.setActivation(activation); ServiceBuilder<SubsystemState> builder = serviceTarget.addService(OSGiConstants.SUBSYSTEM_STATE_SERVICE_NAME, state); builder.setInitialMode(Mode.LAZY); return builder.install(); }
@Override public void handleRollback(OperationContext context, ModelNode operation) { subsystemState.addCapability(oldVal); } });
@Override public String getProperty(String key, String defaultValue) { SubsystemState subsystemState = injectedSubsystemState.getValue(); String value = subsystemState.getProperties().get(key); return value != null ? value : defaultValue; } };
@Override protected void rollbackRuntime(OperationContext context, ModelNode operation, ModelNode model, List<ServiceController<?>> controllers) { String propName = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.PROPERTY).asString(); SubsystemState subsystemState = SubsystemState.getSubsystemState(context); if (subsystemState != null) { subsystemState.setProperty(propName, null); } }
@Override protected void rollbackRuntime(OperationContext context, ModelNode operation, ModelNode model, List<ServiceController<?>> controllers) { String identifier = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.CAPABILITY).asString(); SubsystemState subsystemState = SubsystemState.getSubsystemState(context); if (subsystemState != null) { subsystemState.removeCapability(identifier); } } }
Object setProperty(String name, Object value) { try { if (value == null) return properties.remove(name); else return properties.put(name, value); } finally { notifyObservers(new ChangeEvent(ChangeType.PROPERTY, value == null, name)); } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) throws OperationFailedException { final Integer startLevel = (operation.hasDefined(ModelConstants.STARTLEVEL) ? FrameworkCapabilityResource.STARTLEVEL.resolveModelAttribute(context, model).asInt() : null); String identifier = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.CAPABILITY).asString(); OSGiCapability module = new OSGiCapability(identifier, startLevel); SubsystemState subsystemState = SubsystemState.getSubsystemState(context); if (subsystemState != null) { subsystemState.addCapability(module); } }
Map<String, Object> props = new HashMap<String, Object>(subsystemState.getProperties()); setupIntegrationProperties(context, props); RepositoryService.addService(serviceTarget); Activation activation = subsystemState.getActivationPolicy(); Mode initialMode = (activation == Activation.EAGER ? Mode.ACTIVE : Mode.LAZY);
@Override public synchronized void start(StartContext context) throws StartException { List<Deployment> deployments = new ArrayList<Deployment>(); try { ServerEnvironment serverEnvironment = injectedServerEnvironment.getValue(); bundlesPath = LayeredBundlePathFactory.resolveLayeredBundlePath(serverEnvironment); modulecaps = new ArrayList<OSGiCapability>(); List<OSGiCapability> configcaps = new ArrayList<OSGiCapability>(); for (String capspec : SystemPackagesIntegration.DEFAULT_CAPABILITIES) { configcaps.add(new OSGiCapability(capspec, null)); } configcaps.addAll(injectedSubsystemState.getValue().getCapabilities()); Iterator<OSGiCapability> iterator = configcaps.iterator(); while (iterator.hasNext()) { OSGiCapability configcap = iterator.next(); if (installInitialModuleCapability(configcap)) { modulecaps.add(configcap); iterator.remove(); } } for (OSGiCapability configcap : configcaps) { Deployment dep = getInitialBundleDeployment(configcap); deployments.add(dep); } } catch (Exception ex) { throw MESSAGES.startFailedToProcessInitialCapabilites(ex); } // Install the bundles from the given locations installBootstrapBundles(context.getChildTarget(), deployments); }
newControllers.add(SubsystemState.addService(serviceTarget, activation));
private boolean doUpdate(OperationContext context, ModelNode operation, ModelNode value) { String propName = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.PROPERTY).asString(); String propValue = value.asString(); SubsystemState subsystemState = SubsystemState.getSubsystemState(context); if (subsystemState != null) { subsystemState.setProperty(propName, propValue); } return true; } }
@Override protected void rollbackRuntime(OperationContext context, ModelNode operation, ModelNode model, List<ServiceController<?>> controllers) { String identifier = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.CAPABILITY).asString(); SubsystemState subsystemState = SubsystemState.getSubsystemState(context); if (subsystemState != null) { subsystemState.removeCapability(identifier); } } }
String setProperty(String name, String value) { try { if (value == null) return properties.remove(name); else return properties.put(name, value); } finally { notifyObservers(new ChangeEvent(ChangeType.PROPERTY, value == null, name)); } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model, ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers) throws OperationFailedException { final Integer startLevel = (operation.hasDefined(ModelConstants.STARTLEVEL) ? FrameworkCapabilityResource.STARTLEVEL.resolveModelAttribute(context, model).asInt() : null); String identifier = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.CAPABILITY).asString(); OSGiCapability module = new OSGiCapability(identifier, startLevel); SubsystemState subsystemState = SubsystemState.getSubsystemState(context); if (subsystemState != null) { subsystemState.addCapability(module); } }
Map<String, String> props = new HashMap<String, String>(subsystemState.getProperties()); setupIntegrationProperties(context, props); Activation activation = subsystemState.getActivationPolicy(); Mode initialMode = (activation == Activation.EAGER ? Mode.ACTIVE : Mode.LAZY);
configcaps.add(new OSGiCapability(capspec, null)); configcaps.addAll(injectedSubsystemState.getValue().getCapabilities()); Iterator<OSGiCapability> iterator = configcaps.iterator(); while (iterator.hasNext()) {
newControllers.add(SubsystemState.addService(serviceTarget, activation));
@Override protected void rollbackRuntime(OperationContext context, ModelNode operation, ModelNode model, List<ServiceController<?>> controllers) { String propName = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.PROPERTY).asString(); SubsystemState subsystemState = SubsystemState.getSubsystemState(context); if (subsystemState != null) { subsystemState.setProperty(propName, null); } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { final String identifier = operation.get(ModelDescriptionConstants.OP_ADDR).asObject().get(ModelConstants.CAPABILITY).asString(); final SubsystemState subsystemState = SubsystemState.getSubsystemState(context); if (subsystemState == null) { // cannot complete context.setRollbackOnly(); context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER); return; } final OSGiCapability oldVal = subsystemState.removeCapability(identifier); context.completeStep(new OperationContext.RollbackHandler() { @Override public void handleRollback(OperationContext context, ModelNode operation) { subsystemState.addCapability(oldVal); } }); } }
public OSGiCapability removeCapability(String id) { synchronized (capabilities) { for (Iterator<OSGiCapability> it = capabilities.iterator(); it.hasNext(); ) { OSGiCapability module = it.next(); if (module.getIdentifier().equals(id)) { it.remove(); notifyObservers(new ChangeEvent(ChangeType.CAPABILITY, true, id)); return module; } } return null; } }