org.osgi.service.component.ComponentConstants Java Examples

The following examples show how to use org.osgi.service.component.ComponentConstants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PropertyDictionary.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *
 */
PropertyDictionary(Component comp,
                   Map<String,Object> cm,
                   Dictionary<String,Object> instance,
                   boolean service) {
  props = new Hashtable<String,Object>();
  final ComponentDescription cd = comp.compDesc;
  addDict(cd.getProperties(), service);
  if (cm != null) {
    addDict(cm, service);
  }
  if (instance != null) {
    addDict(instance, service);
  }
  props.put(ComponentConstants.COMPONENT_ID, comp.id);
  props.put(ComponentConstants.COMPONENT_NAME, cd.getName());
}
 
Example #2
Source File: Component.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Disable component. Dispose of all ComponentConfigurations and
 * stop listening for constraint changes.
 */
void disable(int reason, Deferred<Void> d) {
  Activator.logInfo(bc, "Disable " + toString());
  synchronized (lock) {
     final boolean dispose =  reason == ComponentConstants.DEACTIVATION_REASON_DISPOSED ||
       reason == ComponentConstants.DEACTIVATION_REASON_BUNDLE_STOPPED;
    if (d != null || isEnabled()) {
      state = dispose ? STATE_DISPOSING : STATE_DISABLING;
      disposeComponentConfigs(reason);
      untrackConstraints();
      refs = null;
      id = Long.valueOf(-1);
      state = dispose ? STATE_DISPOSED : STATE_DISABLED;
    } else if (dispose && state == STATE_DISABLED) {
      state = STATE_DISPOSED;
    }
  }
  if (d != null) {
    d.resolve(null);
  }
}
 
Example #3
Source File: SCR.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Process bundle components when it starts.
 */
public void bundleChanged(BundleEvent event) {
  postponeCheckin();
  try {
    final Bundle bundle = event.getBundle();

    switch (event.getType()) {
    case BundleEvent.LAZY_ACTIVATION:
      lazy.add(bundle);
      processBundle(bundle);
      break;
    case BundleEvent.STARTED:
      if (!lazy.remove(bundle)) {
        processBundle(bundle);
      }
      break;
    case BundleEvent.STOPPING:
      lazy.remove(bundle);
      removeBundle(bundle, ComponentConstants.DEACTIVATION_REASON_BUNDLE_STOPPED);
      break;
    }
  } finally {
    postponeCheckout();
  }
}
 
Example #4
Source File: ThreadPoolManager.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void modified(Map<String, Object> properties) {
    for (Entry<String, Object> entry : properties.entrySet()) {
        if (Constants.SERVICE_PID.equals(entry.getKey()) || ComponentConstants.COMPONENT_ID.equals(entry.getKey())
                || ComponentConstants.COMPONENT_NAME.equals(entry.getKey())) {
            continue;
        }
        String poolName = entry.getKey();
        Object config = entry.getValue();
        if (config == null) {
            configs.remove(poolName);
        }
        if (config instanceof String) {
            try {
                Integer poolSize = Integer.valueOf((String) config);
                configs.put(poolName, poolSize);
                ThreadPoolExecutor pool = (ThreadPoolExecutor) pools.get(poolName);
                if (pool instanceof ScheduledThreadPoolExecutor) {
                    pool.setCorePoolSize(poolSize);
                    LOGGER.debug("Updated scheduled thread pool '{}' to size {}", poolName, poolSize);
                } else if (pool instanceof QueueingThreadPoolExecutor) {
                    pool.setMaximumPoolSize(poolSize);
                    LOGGER.debug("Updated queuing thread pool '{}' to size {}", poolName, poolSize);
                }
            } catch (NumberFormatException e) {
                LOGGER.warn("Ignoring invalid configuration for pool '{}': {} - value must be an integer", poolName,
                        config);
                continue;
            }
        }
    }
}
 
Example #5
Source File: ConfigurableServiceResource.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private String getServiceId(ServiceReference<?> serviceReference) {
    Object pid = serviceReference.getProperty(Constants.SERVICE_PID);
    if (pid != null) {
        return (String) pid;
    } else {
        return (String) serviceReference.getProperty(ComponentConstants.COMPONENT_NAME);
    }
}
 
Example #6
Source File: ReferenceListener.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get service, but activate before so that we will
 * get any ComponentExceptions.
 */
private Object getServiceCheckActivate(ServiceReference<?> sr, ComponentContextImpl cci) {
  Object s = getBound(sr, cci);
  if (s == null) {
    final Object o = sr.getProperty(ComponentConstants.COMPONENT_NAME);
    if (o != null && o instanceof String) {
      final Component [] cs = ref.comp.scr.getComponent((String)o);
      if (cs != null) {
        ref.comp.scr.postponeCheckin();
        try {
          for (final Component element : cs) {
            final ComponentConfiguration cc = element.getComponentConfiguration(sr);
            if (cc != null) {
              if (cc.getState() != ComponentConfiguration.STATE_DEACTIVATING ||
                  !cc.isUnregistering()) {
                cc.activate(ref.comp.bc.getBundle(), false);
              }
              break;
            }
          }
        } finally {
          ref.comp.scr.postponeCheckout();
        }
      }
    }
    if (ref.isScopeBundle()) {
      s = ref.comp.bc.getService(sr);
    }
  }
  bound(sr, s, cci);
  return s;
}
 
Example #7
Source File: ComponentConfiguration.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * CM data for this component has changed. Check if we need to change state
 * for the component configuration. Also call modified method when its is specified.
 *
 */
void cmConfigUpdated(String ccid, Map<String, Object> dict)
{
  Activator.logDebug("CC.cmConfigUpdated, " + toString() + ", ccid=" + ccid
                     + ", activeCount=" + activeCount);
  int disposeReason = -1;
  List<ComponentContextImpl> ccis = null;
  synchronized (this) {
    if (state == STATE_ACTIVE) { // TODO check this for FactoryComponents
      ccId = ccid;
      if (dict == null && component.compDesc.getScrNSminor() < 3) {
        disposeReason = ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_DELETED;
      } else if (component.modifiedMethod == null
          || component.modifiedMethod.isMissing(true)) {
        // Dispose when we have no modify method
        disposeReason = dict == null ? ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_DELETED
                        : ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_MODIFIED;
      } else {
        cmDict = dict;
        ccProps = null;
        ccis = getActiveContexts();
      }
    } else {
      cmDict = dict;
      ccProps = null;
      return;
    }
  }
  if (ccis != null) {
    for (final ComponentContextImpl cci : ccis) {
      component.modifiedMethod.invoke(cci);
    }
    modifyService();
  } else {
    dispose(disposeReason, true);
  }
}
 
Example #8
Source File: SCR.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Disabled named component or all components owned by
 * specified bundle.
 *
 * @param name Component to disable or null if we want all
 * @param b Bundle owning component
 */
void disableComponent(String name, Bundle b) {
  final Component [] ca = bundleComponents.get(b);
  if (ca != null) {
    for (final Component element : ca) {
      if (name == null || name.equals(element.compDesc.getName())) {
        element.disable(ComponentConstants.DEACTIVATION_REASON_DISABLED, null);
      }
    }
  }
}
 
Example #9
Source File: SCR.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Stop SCR.
 *
 */
void stop() {
  bc.removeBundleListener(this);
  cmHandler.stop();
  final Bundle [] b = bundleComponents.keySet().toArray(new Bundle[bundleComponents.size()]);
  for (final Bundle element : b) {
    removeBundle(element, ComponentConstants.DEACTIVATION_REASON_DISPOSED);
  }
}
 
Example #10
Source File: Component.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * The tracked reference has become unavailable.
 */
boolean refUnavailable(Reference r) {
  Activator.logDebug("Reference unavailable, unresolved=" + unresolvedConstraints);
  if (!r.isRefOptional()) {
    synchronized (lock) {
      if (unresolvedConstraints++ == 0) {
        // TODO do we need to move this outside synchronized
        unsatisfied(ComponentConstants.DEACTIVATION_REASON_REFERENCE);
        return true;
      }
    }
  }
  return false;
}
 
Example #11
Source File: FactoryComponent.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *
 */
@Override
void cmConfigDeleted(String ccid) {
  Activator.logDebug("cmConfigDeleted for ccid = " + ccid);
  resetCMRev(ccid);
  for (final ComponentConfiguration [] componentConfigurations : compConfigs.values()) {
    for (final ComponentConfiguration cc : componentConfigurations) {
      cc.cmConfigUpdated(ccid, null);
    }
  }
  if (cmConfig.isRequired()) {
    unresolvedConstraint(ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_DELETED);
  }
}
 
Example #12
Source File: FactoryComponent.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Factory component satisfied, register component factory service.
 *
 */
@Override
ComponentConfiguration [] satisfied(ComponentConfiguration old) {
  Activator.logInfo(bc, "Satisfied: " + toString());
  state = STATE_SATISFIED;
  componentFactory = new ComponentFactoryImpl(this);
  final Hashtable<String, String> p = new Hashtable<String, String>();
  p.put(ComponentConstants.COMPONENT_NAME, compDesc.getName());
  p.put(ComponentConstants.COMPONENT_FACTORY, compDesc.getFactory());
  factoryService = bc.registerService(ComponentFactory.class.getName(), componentFactory, p);
  return null;
}
 
Example #13
Source File: ComponentContextImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *
 */
void dispose() {
  cc.deactivate(this, ComponentConstants.DEACTIVATION_REASON_DISPOSED, true, true);
}
 
Example #14
Source File: ComponentMethod.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 *
 */
private Operation prepare(Object instance,
                          ComponentContextImpl cci,
                          int reason,
                          ServiceReference<?> s,
                          ReferenceListener rl) {
  method.setAccessible(true);
  final Object [] args = new Object[params.length];
  for (int i = 0; i < params.length; i++) {
    if (params[i] == ComponentContext.class) {
      args[i] = cci;
    } else if (params[i] == BundleContext.class) {
      args[i] = comp.bc;
    } else if (params[i] == ComponentServiceObjects.class) {
      args[i] = cci.getComponentServiceObjects(s, rl);
    } else if (params[i].isAnnotation()) {
      args[i] = Proxy.newProxyInstance(params[i].getClassLoader(),
                                       new Class[] { params[i] },
                                       new ComponentPropertyProxy(cci));
  
    } else if (params[i] == Map.class) {
      if (ref != null) {
        args[i] = new PropertyDictionary(s);
      } else {
        args[i] =  cci.getProperties();
      }
    } else if (params[i] == int.class || params[i] == Integer.class) {
      args[i] = new Integer(reason > Component.KF_DEACTIVATION_REASON_BASE ?
                            ComponentConstants.DEACTIVATION_REASON_UNSPECIFIED :
                            reason);
    } else if (params[i] == ServiceReference.class) {
      args[i] = s;
    } else {
      try {
        // TODO think about exceptions and circular activations
        args[i] = rl.getService(s, cci);
        if (args[i] == null) {
          Activator.logDebug("Got null service argument for " + method +
                             " in " + instance.getClass() +  " for component " +
                             comp.compDesc.getName() + " registered for " +
                             comp.compDesc.bundle);
          throw new ComponentException("Got null service, " + Activator.srInfo(s));
        }
      } catch (final Exception e) {
        Activator.logDebug("Got " + e + " when getting service argument for " + method +
                           " in " + instance.getClass() +  " for component " +
                           comp.compDesc.getName() + " registered for " +
                           comp.compDesc.bundle);
        if (e instanceof ComponentException) {
          throw (ComponentException)e;
        } else {
          throw new ComponentException("Failed to get service, " + Activator.srInfo(s), e);
        }
      }
    }
  }
  return new Operation(instance, args);
}
 
Example #15
Source File: ComponentVImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public String getProp(String p) {
  System.out.println("VImpl: getProp from: " + props.get(ComponentConstants.COMPONENT_ID));
  return (String) props.get(p);
}
 
Example #16
Source File: Component.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Check if component still is satisfied and the deactivation reason is
 * one of REFERENCE, CONFIGURATION_MODIFIED, CONFIGURATION_DELETED or
 * COMPONENT_DEACTIVATED.
 *
 * @param reason Deactivation reason code
 * @return True if we should keep component configuration service.
 */
boolean keepService(int reason) {
  return isSatisfied() &&
      (reason == ComponentConstants.DEACTIVATION_REASON_REFERENCE ||
       reason == ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_MODIFIED ||
       reason == ComponentConstants.DEACTIVATION_REASON_CONFIGURATION_DELETED ||
       reason == KF_DEACTIVATION_REASON_COMPONENT_DEACTIVATED);
}
 
Example #17
Source File: ConfigUtil.java    From openhab-core with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * We do not want to handle or try to normalize OSGi provided configuration parameters
 *
 * @param name The configuration parameter name
 */
private static boolean isOSGiConfigParameter(String name) {
    return Constants.OBJECTCLASS.equals(name) || ComponentConstants.COMPONENT_NAME.equals(name)
            || ComponentConstants.COMPONENT_ID.equals(name);
}