org.osgi.service.cm.Configuration.getFactoryPid()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(102)

本文整理了Java中org.osgi.service.cm.Configuration.getFactoryPid()方法的一些代码示例,展示了Configuration.getFactoryPid()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getFactoryPid()方法的具体详情如下:
包路径:org.osgi.service.cm.Configuration
类名称:Configuration
方法名:getFactoryPid

Configuration.getFactoryPid介绍

[英]For a factory configuration return the PID of the corresponding Managed Service Factory, else return null.
[中]对于工厂配置,返回相应托管服务工厂的PID,否则返回null。

代码示例

代码示例来源:origin: apache/felix

/**
 * @see org.osgi.service.cm.Configuration#getFactoryPid()
 */
public String getFactoryPid() {
  return configuration.getFactoryPid();
}

代码示例来源:origin: io.snamp/internal-services

@Override
String getType(final Configuration config) {
  return SUPERVISOR_PID_REPLACEMENT.matcher(config.getFactoryPid()).replaceFirst("");
}

代码示例来源:origin: io.snamp/internal-services

@Override
String getType(final Configuration config) {
  return GATEWAY_PID_REPLACEMENT.matcher(config.getFactoryPid()).replaceFirst("");
}

代码示例来源:origin: io.snamp/internal-services

@Override
String getType(final Configuration config) {
  return CONNECTOR_PID_REPLACEMENT.matcher(config.getFactoryPid()).replaceFirst("");
}

代码示例来源:origin: apache/felix

private String getObjectName(Configuration configuration) {
    StringBuffer posfix = new StringBuffer();
    posfix.append("pid=" + configuration.getPid());
    if (configuration.getFactoryPid() != null)
      posfix.append(
        ",isFactory=true,FactoryPid=" + configuration.getFactoryPid());
    else
      posfix.append(",isFactory=false");
    String oname = ObjectNames.CM_OBJECT + posfix.toString();
    return oname;
  }
}

代码示例来源:origin: org.apache.karaf.services/org.apache.karaf.services.staticcm

@Override
public Configuration getConfiguration(String pid) throws IOException {
  for (Configuration config : configurations) {
    if (config.getPid().equals(pid) && config.getFactoryPid() == null) {
      return config;
    }
  }
  Hashtable<String, Object> cfg = new Hashtable<>();
  cfg.put(Constants.SERVICE_PID, pid);
  return new StaticConfigurationImpl(pid, null, cfg);
}

代码示例来源:origin: apache/karaf

@Override
public Configuration getConfiguration(String pid) throws IOException {
  for (Configuration config : configurations) {
    if (config.getPid().equals(pid) && config.getFactoryPid() == null) {
      return config;
    }
  }
  Hashtable<String, Object> cfg = new Hashtable<>();
  cfg.put(Constants.SERVICE_PID, pid);
  return new StaticConfigurationImpl(pid, null, cfg);
}

代码示例来源:origin: org.apache.servicemix.kernel.gshell/org.apache.servicemix.kernel.gshell.config

@PostConstruct
public void init() {
  Configuration[] configs;
  try {
    configs = admin.listConfigurations(null);
  } catch (Exception e) {
    return;
  }
  Collection<String> pids = new ArrayList<String>();
  for (Configuration config : configs) {
    if (config.getFactoryPid() != null) {
      pids.add(config.getFactoryPid());
    } else {
      pids.add(config.getPid());
    }
  }
  delegate.getStrings().addAll(pids);
}

代码示例来源:origin: org.apache.felix.karaf.shell/org.apache.felix.karaf.shell.config

protected void doExecute(ConfigurationAdmin admin) throws Exception {
    Configuration[] configs = admin.listConfigurations(query);
    for (Configuration config : configs) {
      System.out.println("----------------------------------------------------------------");
      System.out.println("Pid:            " + config.getPid());
      if (config.getFactoryPid() != null) {
        System.out.println("FactoryPid:     " + config.getFactoryPid());
      }
      System.out.println("BundleLocation: " + config.getBundleLocation());
      if (config.getProperties() != null) {
        System.out.println("Properties:");
        Dictionary props = config.getProperties();
        for (Enumeration e = props.keys(); e.hasMoreElements();) {
          Object key = e.nextElement();
          System.out.println("   " + key + " = " + props.get(key));
        }
      }
    }
  }
}

代码示例来源:origin: org.apache.servicemix.kernel.gshell/org.apache.servicemix.kernel.gshell.config

protected void doExecute(ConfigurationAdmin admin) throws Exception {
    Configuration[] configs = admin.listConfigurations(query);
    for (Configuration config : configs) {
      io.out.println("----------------------------------------------------------------");
      io.out.println("Pid:            " + config.getPid());
      if (config.getFactoryPid() != null) {
        io.out.println("FactoryPid:     " + config.getFactoryPid());
      }
      io.out.println("BundleLocation: " + config.getBundleLocation());
      if (config.getProperties() != null) {
        io.out.println("Properties:");
        Dictionary props = config.getProperties();
        for (Enumeration e = props.keys(); e.hasMoreElements();) {
          Object key = e.nextElement();
          io.out.println("   " + key + " = " + props.get(key));
        }
      }
    }
  }
}

代码示例来源:origin: org.apache.karaf.services/org.apache.karaf.services.staticcm

@Override
public ManagedServiceFactory addingService(ServiceReference<ManagedServiceFactory> reference) {
  ManagedServiceFactory factory = context.getService(reference);
  Object pidObj = reference.getProperty(Constants.SERVICE_PID);
  if (pidObj instanceof String) {
    String pid = (String) pidObj;
    for (Configuration config : configurations) {
      if (config.getPid().equals(pid) && config.getFactoryPid() != null) {
        try {
          factory.updated(config.getFactoryPid(), config.getProperties());
        } catch (ConfigurationException e) {
          e.printStackTrace();
        }
      }
    }
  } else {
    System.err.println("Unsupported pid: " + pidObj);
  }
  return factory;
}

代码示例来源:origin: org.apache.felix.karaf.shell/org.apache.felix.karaf.shell.config

public void init() {
  Configuration[] configs;
  try {
    configs = admin.listConfigurations(null);
    if (configs == null) {
      return;
    }
  } catch (Exception e) {
    return;
  }
  Collection<String> pids = new ArrayList<String>();
  for (Configuration config : configs) {
    if (config.getFactoryPid() != null) {
      pids.add(config.getFactoryPid());
    } else {
      pids.add(config.getPid());
    }
  }
  delegate.getStrings().addAll(pids);
}

代码示例来源:origin: apache/karaf

@Override
public ManagedServiceFactory addingService(ServiceReference<ManagedServiceFactory> reference) {
  ManagedServiceFactory factory = context.getService(reference);
  Object pidObj = reference.getProperty(Constants.SERVICE_PID);
  if (pidObj instanceof String) {
    String pid = (String) pidObj;
    for (Configuration config : configurations) {
      if (config.getPid().equals(pid) && config.getFactoryPid() != null) {
        try {
          factory.updated(config.getFactoryPid(), config.getProperties());
        } catch (ConfigurationException e) {
          e.printStackTrace();
        }
      }
    }
  } else {
    System.err.println("Unsupported pid: " + pidObj);
  }
  return factory;
}

代码示例来源:origin: org.apache.tamaya.ext/tamaya-osgi

@Override
public String getName() {
  return "OSGIConfig:pid="+
      (osgiConfiguration.getPid()!=null?osgiConfiguration.getPid():osgiConfiguration.getFactoryPid());
}

代码示例来源:origin: org.eclipse.equinox/ds

protected ServiceComponentProp map(ServiceComponent component, Configuration config) {
  Dictionary configProps = null;
  if (config != null) {
    try {
      configProps = config.getProperties();
    } catch (IllegalStateException ise) {
      // the configuration may have beed deleted already
    }
  }
  ServiceComponentProp scp = map(component, configProps);
  if (config != null) {
    // set the service PID & Factory Pid
    String pid = config.getPid();
    String fpid = config.getFactoryPid();
    if (pid != null)
      scp.properties.put(Constants.SERVICE_PID, pid);
    if (fpid != null)
      scp.properties.put(ConfigurationAdmin.SERVICE_FACTORYPID, fpid);
  }
  return scp;
}

代码示例来源:origin: jboss-fuse/fabric8

@Override
  public void configurationEvent(ConfigurationEvent event) {
    if (event.getType() == ConfigurationEvent.CM_UPDATED && event.getFactoryPid() != null
        && event.getFactoryPid().startsWith(config.getFactoryPid())) {
      latch.countDown();
    }
  }
}, null);

代码示例来源:origin: org.knopflerfish.bundle/cm

public static void writeConfigurations(final Configuration[] cs,
                    final PrintWriter w)
{
 writeLines(PRE, w);
 for (final Configuration cfg : cs) {
  if (cfg.getFactoryPid() != null) {
   w.println("<factoryconfiguration factorypid=\"" + cfg.getFactoryPid()
        + "\" mode=\"update\">");
   writeProperties(cfg.getProperties(), w);
   w.println("</factoryconfiguration>");
  } else {
   w.println("<configuration pid=\"" + cfg.getPid() + "\" mode=\"new\">");
   writeProperties(cfg.getProperties(), w);
   w.println("</configuration>");
  }
 }
 writeLines(POST, w);
}

代码示例来源:origin: org.knopflerfish.bundle/cm-IMPL

public static void writeConfigurations(final Configuration[] cs,
                    final PrintWriter w)
{
 writeLines(PRE, w);
 for (final Configuration cfg : cs) {
  if (cfg.getFactoryPid() != null) {
   w.println("<factoryconfiguration factorypid=\"" + cfg.getFactoryPid()
        + "\" mode=\"update\">");
   writeProperties(cfg.getProperties(), w);
   w.println("</factoryconfiguration>");
  } else {
   w.println("<configuration pid=\"" + cfg.getPid() + "\" mode=\"new\">");
   writeProperties(cfg.getProperties(), w);
   w.println("</configuration>");
  }
 }
 writeLines(POST, w);
}

代码示例来源:origin: apache/felix

public synchronized void registerFactory(IPojoFactory factory) {
  m_factories.put(factory.getFactoryName(), factory);
  ServiceLocator<ConfigurationAdmin> locator = new ServiceLocator<ConfigurationAdmin>(ConfigurationAdmin
      .class, m_context);
  final ConfigurationAdmin admin = locator.get();
  if (admin == null) {
    return;
  }
  List<Configuration> configurations = findFactoryConfiguration(admin, factory);
  for (Configuration configuration : configurations) {
    try {
      factory.updated(configuration.getPid(), configuration.getProperties());
    } catch (ConfigurationException e) {
      m_logger.log(Log.ERROR, "Cannot reconfigure instance " + configuration.getPid() + " from " +
          configuration.getFactoryPid() + " with the configuration : " + configuration.getProperties(),
          e);
    }
  }
}

代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo

public synchronized void registerFactory(IPojoFactory factory) {
  m_factories.put(factory.getFactoryName(), factory);
  ServiceLocator<ConfigurationAdmin> locator = new ServiceLocator<ConfigurationAdmin>(ConfigurationAdmin
      .class, m_context);
  final ConfigurationAdmin admin = locator.get();
  if (admin == null) {
    return;
  }
  List<Configuration> configurations = findFactoryConfiguration(admin, factory);
  for (Configuration configuration : configurations) {
    try {
      factory.updated(configuration.getPid(), configuration.getProperties());
    } catch (ConfigurationException e) {
      m_logger.log(Log.ERROR, "Cannot reconfigure instance " + configuration.getPid() + " from " +
          configuration.getFactoryPid() + " with the configuration : " + configuration.getProperties(),
          e);
    }
  }
}

相关文章