Java Code Examples for org.osgi.service.component.ComponentContext#getProperties()
The following examples show how to use
org.osgi.service.component.ComponentContext#getProperties() .
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: RedisAppender.java From karaf-decanter with Apache License 2.0 | 6 votes |
@Activate public void activate(ComponentContext componentContext) { config = componentContext.getProperties(); String address = getValue(config, ADDRESS_PROPERTY, ADDRESS_DEFAULT); String mode = getValue(config, MODE_PROPERTY, MODE_DEFAULT); String masterAddress = getValue(config, MASTER_ADDRESS_PROPERTY, MASTER_ADDRESS_DEFAULT); String masterName = getValue(config, MASTER_NAME_PROPERTY, MASTER_NAME_DEFAULT); int scanInterval = Integer.parseInt(getValue(config, SCAN_INTERVAL_PROPERTY, SCAN_INTERVAL_DEFAULT)); Config redissonConfig = new Config(); if (mode.equalsIgnoreCase("Single")) { redissonConfig.useSingleServer().setAddress(address); } else if (mode.equalsIgnoreCase("Master_Slave")) { redissonConfig.useMasterSlaveServers().setMasterAddress(masterAddress).addSlaveAddress(address); } else if (mode.equalsIgnoreCase("Sentinel")) { redissonConfig.useSentinelServers().addSentinelAddress(masterName).addSentinelAddress(address); } else if (mode.equalsIgnoreCase("Cluster")) { redissonConfig.useClusterServers().setScanInterval(scanInterval).addNodeAddress(address); } redissonClient = Redisson.create(redissonConfig); }
Example 2
Source File: RestDeviceProvider.java From onos with Apache License 2.0 | 6 votes |
@Modified public void modified(ComponentContext context) { int previousPollFrequency = pollFrequency; if (context != null) { Dictionary<?, ?> properties = context.getProperties(); pollFrequency = Tools.getIntegerProperty(properties, POLL_FREQUENCY, POLL_FREQUENCY_DEFAULT); replyTimeout = Tools.getIntegerProperty(properties, TIMEOUT, TIMEOUT_DEFAULT); log.info("Configured. Poll frequency = {} seconds, reply timeout = {} seconds ", pollFrequency, replyTimeout); } // Re-schedule only if frequency has changed if (!scheduledTask.isCancelled() && (previousPollFrequency != pollFrequency)) { log.info("Re-scheduling port statistics task with frequency {} seconds", pollFrequency); scheduledTask.cancel(true); scheduledTask = schedulePolling(); } }
Example 3
Source File: JmsCollector.java From karaf-decanter with Apache License 2.0 | 6 votes |
@Activate public void activate(ComponentContext componentContext) throws Exception { properties = componentContext.getProperties(); username = getProperty(properties, "username", null); password = getProperty(properties, "password", null); destinationName = getProperty(properties, "destination.name", "decanter"); destinationType = getProperty(properties, "destination.type", "queue"); dispatcherTopic = getProperty(properties, EventConstants.EVENT_TOPIC, "decanter/collect/jms/decanter"); connection = createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = createDestination(session); MessageConsumer consumer = session.createConsumer(destination); consumer.setMessageListener(new DecanterMessageListener(dispatcher, unmarshaller)); connection.start(); }
Example 4
Source File: DefaultK8sNodeHandler.java From onos with Apache License 2.0 | 6 votes |
/** * Extracts properties from the component configuration context. * * @param context the component context */ private void readComponentConfiguration(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); Integer ovsdbPortConfigured = Tools.getIntegerProperty(properties, OVSDB_PORT); if (ovsdbPortConfigured == null) { ovsdbPortNum = OVSDB_PORT_NUM_DEFAULT; log.info("OVSDB port is NOT configured, default value is {}", ovsdbPortNum); } else { ovsdbPortNum = ovsdbPortConfigured; log.info("Configured. OVSDB port is {}", ovsdbPortNum); } Boolean autoRecoveryConfigured = getBooleanProperty(properties, AUTO_RECOVERY); if (autoRecoveryConfigured == null) { autoRecovery = AUTO_RECOVERY_DEFAULT; log.info("Auto recovery flag is NOT " + "configured, default value is {}", autoRecovery); } else { autoRecovery = autoRecoveryConfigured; log.info("Configured. Auto recovery flag is {}", autoRecovery); } }
Example 5
Source File: GroupManager.java From onos with Apache License 2.0 | 6 votes |
/** * Extracts properties from the component configuration context. * * @param context the component context */ private void readComponentConfiguration(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); Boolean flag; flag = Tools.isPropertyEnabled(properties, GM_PURGE_ON_DISCONNECTION); if (flag == null) { log.info("PurgeOnDisconnection is not configured, " + "using current value of {}", purgeOnDisconnection); } else { purgeOnDisconnection = flag; log.info("Configured. PurgeOnDisconnection is {}", purgeOnDisconnection ? "enabled" : "disabled"); } String s = get(properties, GM_POLL_FREQUENCY); try { fallbackGroupPollFrequency = isNullOrEmpty(s) ? GM_POLL_FREQUENCY_DEFAULT : Integer.parseInt(s); } catch (NumberFormatException e) { fallbackGroupPollFrequency = GM_POLL_FREQUENCY_DEFAULT; } }
Example 6
Source File: DistributedStatisticStore.java From onos with Apache License 2.0 | 6 votes |
@Modified public void modified(ComponentContext context) { Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); int newMessageHandlerThreadPoolSize; try { String s = get(properties, DSS_MESSAGE_HANDLER_THREAD_POOL_SIZE); newMessageHandlerThreadPoolSize = isNullOrEmpty(s) ? messageHandlerThreadPoolSize : Integer.parseInt(s.trim()); } catch (NumberFormatException e) { log.warn(e.getMessage()); newMessageHandlerThreadPoolSize = messageHandlerThreadPoolSize; } // Any change in the following parameters implies thread pool restart if (newMessageHandlerThreadPoolSize != messageHandlerThreadPoolSize) { setMessageHandlerThreadPoolSize(newMessageHandlerThreadPoolSize); restartMessageHandlerThreadPool(); } log.info(FORMAT, messageHandlerThreadPoolSize); }
Example 7
Source File: DistributedFlowStatisticStore.java From onos with Apache License 2.0 | 6 votes |
@Modified public void modified(ComponentContext context) { Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); int newMessageHandlerThreadPoolSize; try { String s = get(properties, DFS_MESSAGE_HANDLER_THREAD_POOL_SIZE); newMessageHandlerThreadPoolSize = isNullOrEmpty(s) ? messageHandlerThreadPoolSize : Integer.parseInt(s.trim()); } catch (NumberFormatException e) { log.warn(e.getMessage()); newMessageHandlerThreadPoolSize = messageHandlerThreadPoolSize; } // Any change in the following parameters implies thread pool restart if (newMessageHandlerThreadPoolSize != messageHandlerThreadPoolSize) { setMessageHandlerThreadPoolSize(newMessageHandlerThreadPoolSize); restartMessageHandlerThreadPool(); } log.info(FORMAT, messageHandlerThreadPoolSize); }
Example 8
Source File: ClusterIpManager.java From onos with Apache License 2.0 | 6 votes |
@Modified protected void modified(ComponentContext context) { log.info("Received configuration change..."); Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); String newIp = get(properties, ALIAS_IP); String newMask = get(properties, ALIAS_MASK); String newAdapter = get(properties, ALIAS_ADAPTER); // Process any changes in the parameters... if (!Objects.equals(newIp, aliasIp) || !Objects.equals(newMask, aliasMask) || !Objects.equals(newAdapter, aliasAdapter)) { synchronized (this) { log.info("Reconfiguring with aliasIp={}, aliasMask={}, aliasAdapter={}, wasLeader={}", newIp, newMask, newAdapter, wasLeader); if (wasLeader) { removeIpAlias(aliasIp, aliasMask, aliasAdapter); addIpAlias(newIp, newMask, newAdapter); } aliasIp = newIp; aliasMask = newMask; aliasAdapter = newAdapter; } } }
Example 9
Source File: FibInstaller.java From onos with Apache License 2.0 | 5 votes |
@Modified protected void modified(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); if (properties == null) { return; } String strRouteToNextHop = Tools.get(properties, "routeToNextHop"); routeToNextHop = Boolean.parseBoolean(strRouteToNextHop); log.info("routeToNextHop set to {}", routeToNextHop); }
Example 10
Source File: FolderObserver.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Activate public void activate(ComponentContext ctx) { Dictionary<String, Object> config = ctx.getProperties(); Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String foldername = keys.nextElement(); if (!StringUtils.isAlphanumeric(foldername)) { // we allow only simple alphanumeric names for model folders - everything else might be other service // properties continue; } String[] fileExts = ((String) config.get(foldername)).split(","); File folder = getFile(foldername); if (folder.exists() && folder.isDirectory()) { folderFileExtMap.put(foldername, fileExts); } else { logger.warn("Directory '{}' does not exist in '{}'. Please check your configuration settings!", foldername, ConfigConstants.getConfigFolder()); } } addModelsToRepo(); super.activate(); }
Example 11
Source File: DhcpManager.java From onos with Apache License 2.0 | 5 votes |
@Modified protected void modified(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); String updatedConfig = Tools.get(properties, ALLOW_HOST_DISCOVERY); if (!Strings.isNullOrEmpty(updatedConfig)) { allowHostDiscovery = Boolean.valueOf(updatedConfig); log.info("Host discovery is set to {}", updatedConfig); } log.info("Modified"); }
Example 12
Source File: NetworkDiagnosticManager.java From onos with Apache License 2.0 | 5 votes |
private void readConfiguration(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); Boolean autoRegisterEnabled = Tools.isPropertyEnabled(properties, AUTO_REGISTER_DEFAULT_DIAGNOSTICS); if (autoRegisterEnabled == null) { log.warn("Auto Register is not configured, " + "using current value of {}", autoRegisterDefaultDiagnostics); } else { autoRegisterDefaultDiagnostics = autoRegisterEnabled; log.info("Configured. Auto Register is {}", autoRegisterDefaultDiagnostics ? "enabled" : "disabled"); } }
Example 13
Source File: OpenstackSwitchingDhcpHandler.java From onos with Apache License 2.0 | 5 votes |
@Modified protected void modified(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); String updatedMac; updatedMac = Tools.get(properties, DHCP_SERVER_MAC); if (!Strings.isNullOrEmpty(updatedMac) && !updatedMac.equals(dhcpServerMac)) { dhcpServerMac = updatedMac; } log.info("Modified"); }
Example 14
Source File: Dhcp6HandlerImpl.java From onos with Apache License 2.0 | 5 votes |
@Modified protected void modified(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); Boolean flag; flag = Tools.isPropertyEnabled(properties, LEARN_ROUTE_FROM_LEASE_QUERY); if (flag != null) { learnRouteFromLeasequery = flag; log.info("Learning routes from DHCP leasequery is {}", learnRouteFromLeasequery ? "enabled" : "disabled"); } }
Example 15
Source File: JdbcCollector.java From karaf-decanter with Apache License 2.0 | 4 votes |
@Activate public void activate(ComponentContext context) throws Exception { properties = context.getProperties(); open(properties); }
Example 16
Source File: NullProviders.java From onos with Apache License 2.0 | 4 votes |
@Modified public void modified(ComponentContext context) { Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); boolean newEnabled; int newDeviceCount, newHostCount, newPacketRate; double newMutationRate; String newTopoShape, newMastership; try { String s = get(properties, ENABLED); newEnabled = isNullOrEmpty(s) ? enabled : Boolean.parseBoolean(s.trim()); newTopoShape = get(properties, TOPO_SHAPE); newMastership = get(properties, MASTERSHIP); s = get(properties, DEVICE_COUNT); newDeviceCount = isNullOrEmpty(s) ? deviceCount : Integer.parseInt(s.trim()); s = get(properties, HOST_COUNT); newHostCount = isNullOrEmpty(s) ? hostCount : Integer.parseInt(s.trim()); s = get(properties, PACKET_RATE); newPacketRate = isNullOrEmpty(s) ? packetRate : Integer.parseInt(s.trim()); s = get(properties, MUTATION_RATE); newMutationRate = isNullOrEmpty(s) ? mutationRate : Double.parseDouble(s.trim()); } catch (NumberFormatException e) { log.warn(e.getMessage()); newEnabled = enabled; newTopoShape = topoShape; newDeviceCount = deviceCount; newHostCount = hostCount; newPacketRate = packetRate; newMutationRate = mutationRate; newMastership = mastership; } // Any change in the following parameters implies hard restart if (newEnabled != enabled || !Objects.equals(newTopoShape, topoShape) || newDeviceCount != deviceCount || newHostCount != hostCount) { enabled = newEnabled; topoShape = newTopoShape; deviceCount = newDeviceCount; hostCount = newHostCount; packetRate = newPacketRate; mutationRate = newMutationRate; restartSimulation(); } // Any change in the following parameters implies just a rate change if (newPacketRate != packetRate || newMutationRate != mutationRate) { packetRate = newPacketRate; mutationRate = newMutationRate; adjustRates(); } // Any change in mastership implies just reassignments. if (!Objects.equals(newMastership, mastership)) { mastership = newMastership; reassignMastership(); } log.info(FORMAT, enabled, topoShape, deviceCount, hostCount, packetRate, mutationRate); }
Example 17
Source File: PacketThrottleManager.java From onos with Apache License 2.0 | 4 votes |
private void checkChangeInPps(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); int newPpsArp, newPpsDhcp, newPpsNs, newPpsNa, newPpsDhcp6Direct; int newPpsDhcp6Indirect, newPpsIcmp, newPpsIcmp6; try { String s = get(properties, PROP_PPS_ARP); newPpsArp = isNullOrEmpty(s) ? ppsArp : Integer.parseInt(s.trim()); s = get(properties, PROP_PPS_DHCP); newPpsDhcp = isNullOrEmpty(s) ? ppsDhcp : Integer.parseInt(s.trim()); s = get(properties, PROP_PPS_NS); newPpsNs = isNullOrEmpty(s) ? ppsNs : Integer.parseInt(s.trim()); s = get(properties, PROP_PPS_NA); newPpsNa = isNullOrEmpty(s) ? ppsNa : Integer.parseInt(s.trim()); s = get(properties, PROP_PPS_DHCP6_DIRECT); newPpsDhcp6Direct = isNullOrEmpty(s) ? ppsDhcp6Direct : Integer.parseInt(s.trim()); s = get(properties, PROP_PPS_DHCP6_INDIRECT); newPpsDhcp6Indirect = isNullOrEmpty(s) ? ppsDhcp6Indirect : Integer.parseInt(s.trim()); s = get(properties, PROP_PPS_ICMP); newPpsIcmp = isNullOrEmpty(s) ? ppsIcmp : Integer.parseInt(s.trim()); s = get(properties, PROP_PPS_ICMP6); newPpsIcmp6 = isNullOrEmpty(s) ? ppsIcmp6 : Integer.parseInt(s.trim()); } catch (NumberFormatException | ClassCastException e) { newPpsArp = PPS_ARP_DEFAULT; newPpsDhcp = PPS_DHCP_DEFAULT; newPpsNs = PPS_NS_DEFAULT; newPpsNa = PPS_NA_DEFAULT; newPpsDhcp6Direct = PPS_DHCP6_DIRECT_DEFAULT; newPpsDhcp6Indirect = PPS_DHCP6_INDIRECT_DEFAULT; newPpsIcmp = PPS_ICMP_DEFAULT; newPpsIcmp6 = PPS_ICMP6_DEFAULT; } if (newPpsArp != ppsArp) { ppsArp = newPpsArp; mapCounterFilter.get(ARP_FILTER).setPps(ppsArp); } if (newPpsDhcp != ppsDhcp) { ppsDhcp = newPpsDhcp; mapCounterFilter.get(DHCP_FILTER).setPps(ppsDhcp); } if (newPpsNs != ppsNs) { ppsNs = newPpsNs; mapCounterFilter.get(NS_FILTER).setPps(ppsNs); } if (newPpsNa != ppsNa) { ppsNa = newPpsNa; mapCounterFilter.get(NA_FILTER).setPps(ppsNa); } if (newPpsDhcp6Direct != ppsDhcp6Direct) { ppsDhcp6Direct = newPpsDhcp6Direct; mapCounterFilter.get(DHCP6_DIRECT_FILTER).setPps(ppsDhcp6Direct); } if (newPpsDhcp6Indirect != ppsDhcp6Indirect) { ppsDhcp6Indirect = newPpsDhcp6Indirect; mapCounterFilter.get(DHCP6_INDIRECT_FILTER).setPps(ppsDhcp6Indirect); } if (newPpsIcmp != ppsIcmp) { ppsIcmp = newPpsIcmp; mapCounterFilter.get(ICMP_FILTER).setPps(ppsIcmp); } if (newPpsIcmp6 != ppsIcmp6) { ppsIcmp6 = newPpsIcmp6; mapCounterFilter.get(ICMP6_FILTER).setPps(ppsIcmp6); } }
Example 18
Source File: KafkaCollector.java From karaf-decanter with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Activate public void activate(ComponentContext componentContext) { properties = componentContext.getProperties(); topic = getValue(properties, "topic", "decanter"); eventAdminTopic = getValue(properties, EventConstants.EVENT_TOPIC, "decanter/collect/kafka/decanter"); messageType = getValue(properties, "message.type", "text"); Properties config = new Properties(); String bootstrapServers = getValue(properties, "bootstrap.servers", "localhost:9092"); config.put("bootstrap.servers", bootstrapServers); String groupId = getValue(properties, "group.id", "decanter"); config.put("group.id", groupId); String enableAutoCommit = getValue(properties, "enable.auto.commit", "true"); config.put("enable.auto.commit", enableAutoCommit); String autoCommitIntervalMs = getValue(properties, "auto.commit.interval.ms", "1000"); config.put("auto.commit.interval.ms", autoCommitIntervalMs); String sessionTimeoutMs = getValue(properties, "session.timeout.ms", "10000"); config.put("session.timeout.ms", sessionTimeoutMs); String keyDeserializer = getValue(properties, "key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); config.put("key.deserializer", keyDeserializer); String valueDeserializer = getValue(properties, "value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); config.put("value.deserializer", valueDeserializer); String securityProtocol = getValue(properties, "security.protocol", null); if (securityProtocol != null) config.put("security.protocol", securityProtocol); String sslTruststoreLocation = getValue(properties, "ssl.truststore.location", null); if (sslTruststoreLocation != null) config.put("ssl.truststore.location", sslTruststoreLocation); String sslTruststorePassword = getValue(properties, "ssl.truststore.password", null); if (sslTruststorePassword != null) config.put("ssl.truststore.password", sslTruststorePassword); String sslKeystoreLocation = getValue(properties, "ssl.keystore.location", null); if (sslKeystoreLocation != null) config.put("ssl.keystore.location", sslKeystoreLocation); String sslKeystorePassword = getValue(properties, "ssl.keystore.password", null); if (sslKeystorePassword != null) config.put("ssl.keystore.password", sslKeystorePassword); String sslKeyPassword = getValue(properties, "ssl.key.password", null); if (sslKeyPassword != null) config.put("ssl.key.password", sslKeyPassword); String sslProvider = getValue(properties, "ssl.provider", null); if (sslProvider != null) config.put("ssl.provider", sslProvider); String sslCipherSuites = getValue(properties, "ssl.cipher.suites", null); if (sslCipherSuites != null) config.put("ssl.cipher.suites", sslCipherSuites); String sslEnabledProtocols = getValue(properties, "ssl.enabled.protocols", null); if (sslEnabledProtocols != null) config.put("ssl.enabled.protocols", sslEnabledProtocols); String sslTruststoreType = getValue(properties, "ssl.truststore.type", null); if (sslTruststoreType != null) config.put("ssl.truststore.type", sslTruststoreType); String sslKeystoreType = getValue(properties, "ssl.keystore.type", null); if (sslKeystoreType != null) config.put("ssl.keystore.type", sslKeystoreType); ClassLoader originClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(null); consumer = new KafkaConsumer<String, String>(config); consumer.subscribe(Arrays.asList(topic)); } finally { Thread.currentThread().setContextClassLoader(originClassLoader); } consuming = true; Executors.newSingleThreadExecutor().execute(this); }
Example 19
Source File: DistributedVirtualFlowRuleStore.java From onos with Apache License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") @Modified public void modified(ComponentContext context) { if (context == null) { logConfig("Default config"); return; } Dictionary properties = context.getProperties(); int newPoolSize; int newBackupPeriod; try { String s = get(properties, MESSAGE_HANDLER_THREAD_POOL_SIZE); newPoolSize = isNullOrEmpty(s) ? messageHandlerThreadPoolSize : Integer.parseInt(s.trim()); s = get(properties, BACKUP_PERIOD_MILLIS); newBackupPeriod = isNullOrEmpty(s) ? backupPeriod : Integer.parseInt(s.trim()); } catch (NumberFormatException | ClassCastException e) { newPoolSize = MESSAGE_HANDLER_THREAD_POOL_SIZE_DEFAULT; newBackupPeriod = BACKUP_PERIOD_MILLIS_DEFAULT; } boolean restartBackupTask = false; if (newBackupPeriod != backupPeriod) { backupPeriod = newBackupPeriod; restartBackupTask = true; } if (restartBackupTask) { log.warn("Currently, backup tasks are not supported."); } if (newPoolSize != messageHandlerThreadPoolSize) { messageHandlerThreadPoolSize = newPoolSize; ExecutorService oldMsgHandler = messageHandlingExecutor; messageHandlingExecutor = Executors.newFixedThreadPool( messageHandlerThreadPoolSize, groupedThreads("onos/store/virtual-flow", "message-handlers", log)); // replace previously registered handlers. registerMessageHandlers(messageHandlingExecutor); oldMsgHandler.shutdown(); } logConfig("Reconfigured"); }
Example 20
Source File: DefaultVirtualFlowRuleProvider.java From onos with Apache License 2.0 | 4 votes |
@Modified protected void modified(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); }