本文整理匯總了Java中org.osgi.service.cm.Configuration類的典型用法代碼示例。如果您正苦於以下問題:Java Configuration類的具體用法?Java Configuration怎麽用?Java Configuration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Configuration類屬於org.osgi.service.cm包,在下文中一共展示了Configuration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addSyncRoot
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
/**
* Add the specified directory to the sync roots, enabling the service when
* necessary.
*
* @param syncRoot
* directory to add
* @param expectedSyncTime
* the expected sync time as result of adding this directory
*/
protected void addSyncRoot(final File syncRoot, final Long expectedSyncTime) throws IllegalStateException {
logger.debug("addSyncRoot(): syncRoot = {}, expectedSyncTime = {}", syncRoot, expectedSyncTime);
final Configuration configuration = getConfiguration();
final Dictionary<String, Object> properties = getProperties(configuration);
final Set<String> syncRoots = getSyncRoots(properties);
syncRoots.add(syncRoot.getAbsolutePath());
if (syncRoots.size() == 1) {
enableSync(properties);
}
properties.put(PROP_SYNCROOTS, syncRoots.toArray(new String[syncRoots.size()]));
update(configuration, properties, expectedSyncTime);
}
示例2: removeSyncRoot
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
/**
* Remove the specified directory from the sync roots, disabling the service
* when necessary.
*
* @param syncRoot
* directory to remove
*/
protected void removeSyncRoot(final File syncRoot) throws IllegalStateException {
logger.debug("removeSyncRoot(): syncRoot = {}", syncRoot);
final Configuration configuration = getConfiguration();
final Dictionary<String, Object> properties = getProperties(configuration);
final Set<String> syncRoots = getSyncRoots(properties);
syncRoots.remove(syncRoot.getAbsolutePath());
properties.put(PROP_SYNCROOTS, syncRoots.toArray(new String[syncRoots.size()]));
if (syncRoots.size() == 0) {
disableSync(properties);
}
update(configuration, properties, null);
}
示例3: update
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
private void update(final Configuration configuration, final Dictionary<String, Object> properties,
final Long timeToWaitBeforeNextUpdate) throws IllegalStateException {
logger.debug("update(): configuration = {}, properties = {}", configuration, properties);
waitBeforeUpdate(timeToWaitBeforeNextUpdate);
/*
* Now, change its configuration!
*/
try {
configuration.update(properties);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例4: handleChangeDiscoveryValue
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
private void handleChangeDiscoveryValue(ChangedValue event) {
DiscoveryNode node = event.getNode();
DiscoveryPath path = node.getPath();
// Only do something with config paths
if (path.isConfigPath()) {
try {
Configuration config = this.getConfig(path);
logger.debug("Updating configuration {} with new value for key {} and value " + event.getNewValue(), config.getPid(), event.getKey());
if(event.getNewValue() == null) {
// Value should be removed
config.getProperties().remove(event.getKey());
} else {
// Value should be set
config.getProperties().put(event.getKey(), event.getNewValue());
}
} catch (IOException e) {
logger.error("Error while updating configuration {}", path.toString(), e);
}
}
}
示例5: loadExistingValues
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
private void loadExistingValues(String componentName) {
try {
Configuration cfg = cfgAdmin.getConfiguration(componentName, null);
Map<String, ConfigProperty> map = properties.get(componentName);
Dictionary<String, Object> props = cfg.getProperties();
if (props != null) {
Enumeration<String> it = props.keys();
while (it.hasMoreElements()) {
String name = it.nextElement();
ConfigProperty p = map.get(name);
if (p != null) {
map.put(name, ConfigProperty.setProperty(p, (String) props.get(name)));
}
}
}
} catch (IOException e) {
log.error("Unable to get configuration for " + componentName, e);
}
}
示例6: execute
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
@Override
public Object execute() throws Exception {
if (schedulerManager.getSchedulerNames().contains(schedulerName)) {
throw new IllegalArgumentException("Scheduler with that name already exists");
}
Configuration configuration = configurationAdmin.createFactoryConfiguration(VolatileSchedulerProvider.CONFIG_FACTORY_NAME, "?");
Dictionary<String, Object> dict = new Hashtable<>();
dict.put(VolatileSchedulerProvider.PROPERTY_NAME, schedulerName);
dict.put(VolatileSchedulerProvider.PROPERTY_THREADS, threads);
dict.put(VolatileSchedulerProvider.PROPERTY_PRIORITY, priority);
configuration.update(dict);
return configuration.getPid();
}
示例7: execute
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
@Override
public Object execute() throws Exception {
if (schedulerManager.getScheduler(schedulerName) == null) {
throw new IllegalArgumentException("Scheduler with that name doesn't exists");
}
for (Configuration configuration : configurationAdmin.listConfigurations(VolatileSchedulerProvider.CONFIG_FACTORY_NAME)) {
String name = (String)configuration.getProperties().get(VolatileSchedulerProvider.PROPERTY_NAME);
if (name.equalsIgnoreCase(schedulerName)) {
configuration.delete();
return null;
}
}
throw new IllegalArgumentException("Scheduler configuration not found!");
}
示例8: ranking
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
public void ranking() throws IOException {
Configuration configOnline =
this.admin.getConfiguration( "org.fipro.ds.data.online.OnlineDataService", null);
Dictionary<String, Object> propsOnline = null;
if (configOnline != null && configOnline.getProperties() != null) {
propsOnline = configOnline.getProperties();
} else {
propsOnline = new Hashtable<>();
}
int onlineRanking = 7;
if (configOnline != null && configOnline.getProperties() != null) {
Object rank = configOnline.getProperties().get("service.ranking");
if (rank != null) {
onlineRanking = (Integer)rank;
}
}
// toggle between 3 and 7
onlineRanking = (onlineRanking == 7) ? 3 : 7;
propsOnline.put("service.ranking", onlineRanking);
configOnline.update(propsOnline);
}
示例9: toggle
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
public void toggle() throws IOException {
Configuration config =
this.admin.getConfiguration("org.fipro.ds.configurator.DataRetriever");
Dictionary<String, Object> props = null;
Object target = null;
if (config != null && config.getProperties() != null) {
props = config.getProperties();
target = props.get("DataService.target");
} else {
props = new Hashtable<String, Object>();
}
boolean isOnline = (target == null || target.toString().contains("online"));
// toggle the state
StringBuilder filter = new StringBuilder("(fipro.connectivity=");
filter.append(isOnline ? "offline" : "online").append(")");
props.put("DataService.target", filter.toString());
config.update(props);
}
示例10: start
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
@Override
public void start(BundleContext bundleContext) throws Exception {
_context = bundleContext;
_log.info("start called");
ServiceReference configAdminServiceRef = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
ConfigurationAdmin configAdminService = (ConfigurationAdmin) bundleContext.getService( configAdminServiceRef );
Configuration configuration = configAdminService.createFactoryConfiguration("com.pronoia.controlservice");
Properties props = new Properties();
props.put( "control.name", "FredControlOne" );
configuration.update( (Dictionary)props );
configuration = configAdminService.createFactoryConfiguration( "com.pronoia.controlservice");
props = new Properties();
props.put( "control.name", "FredControlTwo" );
configuration.update( (Dictionary)props );
}
示例11: getProperties
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
/**
* Get properties as a map.
* <p>
* Returns an empty map if configAdmin is null, or the configuration is null, etc.
* </p>
*
* @param pid OSGI configAdmin pid.
* @return map of properties
*/
public Map<String, String> getProperties(final String pid) throws Exception {
final Map<String, String> props = new HashMap<>();
if (configAdmin != null) {
final Configuration c = configAdmin.getConfiguration(pid);
if (c != null) {
final Dictionary<String, Object> dict = c.getProperties();
if (dict != null) {
final Enumeration<String> keys = dict.keys();
while (keys.hasMoreElements()) {
final String key = keys.nextElement();
props.put(key, dict.get(key).toString());
}
}
}
}
return props;
}
示例12: doGet
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String PID;
PID = request.getParameter("pid");
if (PID == null) {
response.sendError(404);
return;
}
Configuration config = getConfig(PID);
if (config == null) {
response.sendError(404);
return;
}
Dictionary props = config.getProperties();
response.setContentType("application/json");
response.setStatus(200);
try (PrintWriter writer = response.getWriter()) {
if (props == null) {
writer.write("{}");
} else {
writer.write(dictionaryToJson(props).toString());
}
writer.flush();
}
}
示例13: getConfig
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
private Configuration getConfig(String pid) throws IOException {
//If bundle's serviceReference is null (e.g., when you only install driver without start),
//use loc, it setup bundle's location forcibly
//String loc = null;
BundleContext ctx = context;
Bundle[] bundles = ctx.getBundles();
for (Bundle bun : bundles) {
if (bun.getSymbolicName().contains(pid)) {
ctx = bun.getBundleContext();
//loc = bun.getLocation();
break;
}
}
ServiceReference configurationAdminReference
= ctx.getServiceReference(ConfigurationAdmin.class.getName());
if (configurationAdminReference != null) {
ConfigurationAdmin configurationAdmin = (ConfigurationAdmin) ctx.getService(configurationAdminReference);
Configuration config = (Configuration) configurationAdmin.getConfiguration(pid);
return config;
}
return null;
}
示例14: configuringBundle
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
public void configuringBundle(BundleContext ctx, HashMap<String, BundleContext> contextBundles) {
if (pid != null && properties != null) {
if(contextBundles.containsKey(pid)) {
ctx = contextBundles.get(pid);
}
ServiceReference configurationAdminReference =
ctx.getServiceReference(ConfigurationAdmin.class.getName());
if (configurationAdminReference != null) {
ConfigurationAdmin configurationAdmin =
(ConfigurationAdmin) ctx.getService(configurationAdminReference);
try {
Configuration config = configurationAdmin.getConfiguration(pid);
config.update(properties);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
}
示例15: config
import org.osgi.service.cm.Configuration; //導入依賴的package包/類
@RequestMapping
public ModelAndView config ()
{
final Map<String, Object> model = new HashMap<> ();
final StorageConfiguration command = new StorageConfiguration ();
try
{
final Configuration cfg = this.configurationAdmin.getConfiguration ( PID_STORAGE_MANAGER, null );
if ( cfg != null && cfg.getProperties () != null )
{
command.setBasePath ( (String)cfg.getProperties ().get ( "basePath" ) );
}
}
catch ( final Exception e )
{
// ignore
}
model.put ( "command", command );
fillData ( model );
return new ModelAndView ( "/config/index", model );
}