Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pclogo] Remove org.apache.commons.net.util.SubnetUtils #17408

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,21 @@
import static org.openhab.binding.plclogo.internal.PLCLogoBindingConstants.THING_TYPE_DEVICE;

import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.commons.net.util.SubnetUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.DiscoveryService;
import org.openhab.core.model.script.actions.Ping;
import org.openhab.core.net.NetUtil;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.osgi.service.component.annotations.Component;
Expand Down Expand Up @@ -107,44 +101,19 @@

logger.debug("Start scan for LOGO! bridge");

Enumeration<NetworkInterface> devices = null;
try {
devices = NetworkInterface.getNetworkInterfaces();
} catch (SocketException exception) {
logger.warn("LOGO! bridge discovering: {}.", exception.toString());
}

Set<String> addresses = new TreeSet<>();
while ((devices != null) && devices.hasMoreElements()) {
NetworkInterface device = devices.nextElement();
try {
if (!device.isUp() || device.isLoopback()) {
continue;
}
} catch (SocketException exception) {
logger.warn("LOGO! bridge discovering: {}.", exception.toString());
}
for (InterfaceAddress iface : device.getInterfaceAddresses()) {
InetAddress address = iface.getAddress();
if (address instanceof Inet4Address) {
String prefix = String.valueOf(iface.getNetworkPrefixLength());
SubnetUtils utilities = new SubnetUtils(address.getHostAddress() + "/" + prefix);
addresses.addAll(Arrays.asList(utilities.getInfo().getAllAddresses()));
}
}
}
List<InetAddress> addressesToScan = NetUtil.getFullRangeOfAddressesToScan();

Check failure on line 104 in bundles/org.openhab.binding.plclogo/src/main/java/org/openhab/binding/plclogo/internal/discovery/PLCDiscoveryService.java

View workflow job for this annotation

GitHub Actions / Build (Java 17, ubuntu-22.04)

The method getFullRangeOfAddressesToScan() is undefined for the type org.openhab.core.net.NetUtil

ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
for (String address : addresses) {
for (InetAddress address : addressesToScan) {
try {
executor.execute(new Runner(address));
executor.execute(new Runner(address.getHostAddress()));
} catch (RejectedExecutionException exception) {
logger.warn("LOGO! bridge discovering: {}.", exception.toString());
}
}

try {
executor.awaitTermination(CONNECTION_TIMEOUT * addresses.size(), TimeUnit.MILLISECONDS);
executor.awaitTermination(CONNECTION_TIMEOUT * addressesToScan.size(), TimeUnit.MILLISECONDS);
} catch (InterruptedException exception) {
logger.warn("LOGO! bridge discovering: {}.", exception.toString());
}
Expand Down
Loading