use of org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent in project kura by eclipse.
the class ModemMonitorServiceImpl method handleEvent.
@Override
public void handleEvent(Event event) {
s_logger.debug("handleEvent - topic: {}", event.getTopic());
String topic = event.getTopic();
if (topic.equals(NetworkConfigurationChangeEvent.NETWORK_EVENT_CONFIG_CHANGE_TOPIC)) {
NetworkConfigurationChangeEvent netConfigChangedEvent = (NetworkConfigurationChangeEvent) event;
String[] propNames = netConfigChangedEvent.getPropertyNames();
if (propNames != null && propNames.length > 0) {
Map<String, Object> props = new HashMap<String, Object>();
for (String propName : propNames) {
Object prop = netConfigChangedEvent.getProperty(propName);
if (prop != null) {
props.put(propName, prop);
}
}
try {
final NetworkConfiguration newNetworkConfig = new NetworkConfiguration(props);
ExecutorService ex = Executors.newSingleThreadExecutor();
ex.submit(new Runnable() {
@Override
public void run() {
processNetworkConfigurationChangeEvent(newNetworkConfig);
}
});
} catch (Exception e) {
s_logger.error("Failed to handle the NetworkConfigurationChangeEvent - {}", e);
}
}
} else if (topic.equals(ModemAddedEvent.MODEM_EVENT_ADDED_TOPIC)) {
ModemAddedEvent modemAddedEvent = (ModemAddedEvent) event;
final ModemDevice modemDevice = modemAddedEvent.getModemDevice();
if (this.m_serviceActivated) {
ExecutorService ex = Executors.newSingleThreadExecutor();
ex.submit(new Runnable() {
@Override
public void run() {
trackModem(modemDevice);
}
});
}
} else if (topic.equals(ModemRemovedEvent.MODEM_EVENT_REMOVED_TOPIC)) {
ModemRemovedEvent modemRemovedEvent = (ModemRemovedEvent) event;
String usbPort = (String) modemRemovedEvent.getProperty(UsbDeviceEvent.USB_EVENT_USB_PORT_PROPERTY);
this.m_modems.remove(usbPort);
}
}
use of org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent in project kura by eclipse.
the class WifiMonitorServiceImpl method handleEvent.
@Override
public void handleEvent(Event event) {
s_logger.debug("handleEvent - topic: {}", event.getTopic());
String topic = event.getTopic();
if (topic.equals(NetworkConfigurationChangeEvent.NETWORK_EVENT_CONFIG_CHANGE_TOPIC)) {
s_logger.debug("handleEvent - received network change event");
NetworkConfigurationChangeEvent netConfigChangedEvent = (NetworkConfigurationChangeEvent) event;
String[] propNames = netConfigChangedEvent.getPropertyNames();
if (propNames != null && propNames.length > 0) {
Map<String, Object> props = new HashMap<String, Object>();
for (String propName : propNames) {
Object prop = netConfigChangedEvent.getProperty(propName);
if (prop != null) {
props.put(propName, prop);
}
}
try {
this.m_newNetConfiguration = new NetworkConfiguration(props);
// Initialize the monitor thread if needed
if (monitorTask == null) {
initializeMonitoredInterfaces(this.m_newNetConfiguration);
} else {
monitorNotify();
}
} catch (Exception e) {
s_logger.warn("Error during WiFi Monitor handle event", e);
}
}
}
}
use of org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent in project kura by eclipse.
the class DnsMonitorServiceImpl method handleEvent.
@Override
public void handleEvent(Event event) {
s_logger.debug("handleEvent - topic: {}", event.getTopic());
String topic = event.getTopic();
if (topic.equals(NetworkConfigurationChangeEvent.NETWORK_EVENT_CONFIG_CHANGE_TOPIC)) {
NetworkConfigurationChangeEvent netConfigChangedEvent = (NetworkConfigurationChangeEvent) event;
String[] propNames = netConfigChangedEvent.getPropertyNames();
if (propNames != null && propNames.length > 0) {
Map<String, Object> props = new HashMap<String, Object>();
for (String propName : propNames) {
Object prop = netConfigChangedEvent.getProperty(propName);
if (prop != null) {
props.put(propName, prop);
}
}
try {
this.m_networkConfiguration = new NetworkConfiguration(props);
} catch (Exception e) {
e.printStackTrace();
}
}
updateDnsResolverConfig();
updateDnsProxyConfig();
} else if (topic.equals(NetworkStatusChangeEvent.NETWORK_EVENT_STATUS_CHANGE_TOPIC)) {
updateDnsResolverConfig();
updateDnsProxyConfig();
}
}
use of org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent in project kura by eclipse.
the class EthernetMonitorServiceImpl method handleEvent.
// On a network config change event, verify the change was for ethernet and add a new ethernet config
@Override
public void handleEvent(Event event) {
String topic = event.getTopic();
s_logger.debug("handleEvent - topic: {}", topic);
if (topic.equals(NetworkConfigurationChangeEvent.NETWORK_EVENT_CONFIG_CHANGE_TOPIC)) {
NetworkConfigurationChangeEvent netConfigChangedEvent = (NetworkConfigurationChangeEvent) event;
String[] propNames = netConfigChangedEvent.getPropertyNames();
if (propNames != null && propNames.length > 0) {
Map<String, Object> props = new HashMap<String, Object>();
for (String propName : propNames) {
Object prop = netConfigChangedEvent.getProperty(propName);
if (prop != null) {
props.put(propName, prop);
} else {
}
}
try {
NetworkConfiguration newNetworkConfig = new NetworkConfiguration(props);
if (newNetworkConfig != null) {
for (NetInterfaceConfig<? extends NetInterfaceAddressConfig> netInterfaceConfig : newNetworkConfig.getNetInterfaceConfigs()) {
if (netInterfaceConfig instanceof EthernetInterfaceConfigImpl) {
s_logger.debug("Adding new ethernet config for {}", netInterfaceConfig.getName());
EthernetInterfaceConfigImpl newEthernetConfig = (EthernetInterfaceConfigImpl) netInterfaceConfig;
this.m_newNetworkConfiguration.put(netInterfaceConfig.getName(), newEthernetConfig);
if (isEthernetEnabled(newEthernetConfig)) {
startMonitor(netInterfaceConfig.getName());
}
}
}
}
} catch (Exception e) {
s_logger.warn("Error during Ethernet Monitor handle event", e);
}
}
}
}
use of org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent in project kura by eclipse.
the class NetworkConfigurationServiceImpl method updated.
public synchronized void updated(Map<String, Object> properties) {
// skip the first config
if (this.m_firstConfig) {
s_logger.debug("Ignoring first configuration");
this.m_firstConfig = false;
return;
}
try {
if (properties != null) {
s_logger.debug("new properties - updating");
s_logger.debug("modified.interface.names: {}", properties.get("modified.interface.names"));
// dynamically insert the type properties..
Map<String, Object> modifiedProps = new HashMap<String, Object>();
modifiedProps.putAll(properties);
String interfaces = (String) properties.get("net.interfaces");
StringTokenizer st = new StringTokenizer(interfaces, ",");
while (st.hasMoreTokens()) {
String interfaceName = st.nextToken();
StringBuilder sb = new StringBuilder();
sb.append("net.interface.").append(interfaceName).append(".type");
NetInterfaceType type = LinuxNetworkUtil.getType(interfaceName);
if (type == NetInterfaceType.UNKNOWN) {
if (interfaceName.matches(UNCONFIGURED_MODEM_REGEX)) {
// If the interface name is in a form such as "1-3.4" (USB address), assume it is a modem
type = NetInterfaceType.MODEM;
} else {
SupportedSerialModemInfo serialModemInfo = SupportedSerialModemsInfo.getModem();
if (serialModemInfo != null && serialModemInfo.getModemName().equals(interfaceName)) {
type = NetInterfaceType.MODEM;
}
}
}
modifiedProps.put(sb.toString(), type.toString());
}
NetworkConfiguration networkConfig = new NetworkConfiguration(modifiedProps);
for (NetworkConfigurationVisitor visitor : this.m_writeVisitors) {
networkConfig.accept(visitor);
}
// raise the event because there was a change
this.m_eventAdmin.postEvent(new NetworkConfigurationChangeEvent(modifiedProps));
} else {
s_logger.debug("properties are null");
}
} catch (Exception e) {
// TODO - would still want an event if partially successful?
s_logger.error("Error updating the configuration", e);
}
}
Aggregations