Search in sources :

Example 1 with NetworkConfigurationChangeEvent

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);
    }
}
Also used : NetworkConfigurationChangeEvent(org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent) HashMap(java.util.HashMap) ModemAddedEvent(org.eclipse.kura.net.modem.ModemAddedEvent) ModemDevice(org.eclipse.kura.net.modem.ModemDevice) UsbModemDevice(org.eclipse.kura.usb.UsbModemDevice) SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) KuraException(org.eclipse.kura.KuraException) ModemRemovedEvent(org.eclipse.kura.net.modem.ModemRemovedEvent) ExecutorService(java.util.concurrent.ExecutorService) NetworkConfiguration(org.eclipse.kura.core.net.NetworkConfiguration)

Example 2 with NetworkConfigurationChangeEvent

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);
            }
        }
    }
}
Also used : NetworkConfigurationChangeEvent(org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent) HashMap(java.util.HashMap) NetworkConfiguration(org.eclipse.kura.core.net.NetworkConfiguration) KuraException(org.eclipse.kura.KuraException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 3 with NetworkConfigurationChangeEvent

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();
    }
}
Also used : NetworkConfigurationChangeEvent(org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent) HashMap(java.util.HashMap) NetworkConfiguration(org.eclipse.kura.core.net.NetworkConfiguration) KuraException(org.eclipse.kura.KuraException)

Example 4 with NetworkConfigurationChangeEvent

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);
            }
        }
    }
}
Also used : EthernetInterfaceConfigImpl(org.eclipse.kura.core.net.EthernetInterfaceConfigImpl) NetworkConfigurationChangeEvent(org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent) HashMap(java.util.HashMap) NetworkConfiguration(org.eclipse.kura.core.net.NetworkConfiguration) KuraException(org.eclipse.kura.KuraException)

Example 5 with NetworkConfigurationChangeEvent

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);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) NetworkConfigurationChangeEvent(org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent) HashMap(java.util.HashMap) NetInterfaceType(org.eclipse.kura.net.NetInterfaceType) SupportedSerialModemInfo(org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo) NetworkConfiguration(org.eclipse.kura.core.net.NetworkConfiguration) NetworkConfigurationVisitor(org.eclipse.kura.core.net.NetworkConfigurationVisitor) KuraException(org.eclipse.kura.KuraException)

Aggregations

HashMap (java.util.HashMap)5 KuraException (org.eclipse.kura.KuraException)5 NetworkConfiguration (org.eclipse.kura.core.net.NetworkConfiguration)5 NetworkConfigurationChangeEvent (org.eclipse.kura.net.admin.event.NetworkConfigurationChangeEvent)5 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 StringTokenizer (java.util.StringTokenizer)1 ExecutorService (java.util.concurrent.ExecutorService)1 EthernetInterfaceConfigImpl (org.eclipse.kura.core.net.EthernetInterfaceConfigImpl)1 NetworkConfigurationVisitor (org.eclipse.kura.core.net.NetworkConfigurationVisitor)1 SupportedSerialModemInfo (org.eclipse.kura.linux.net.modem.SupportedSerialModemInfo)1 NetInterfaceType (org.eclipse.kura.net.NetInterfaceType)1 ModemAddedEvent (org.eclipse.kura.net.modem.ModemAddedEvent)1 ModemDevice (org.eclipse.kura.net.modem.ModemDevice)1 ModemRemovedEvent (org.eclipse.kura.net.modem.ModemRemovedEvent)1 SerialModemDevice (org.eclipse.kura.net.modem.SerialModemDevice)1 UsbModemDevice (org.eclipse.kura.usb.UsbModemDevice)1