Skip to content

Commit

Permalink
[oceanic] Remove org.apache.common (openhab#15332)
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
  • Loading branch information
lsiepel authored and austvik committed Mar 27, 2024
1 parent 5b69b3f commit 2d9747b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.oceanic.internal.NetworkOceanicBindingConfiguration;
import org.openhab.binding.oceanic.internal.Throttler;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -62,13 +63,12 @@ public void initialize() {
NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class);

try {
socket = new Socket(config.ipAddress, config.portNumber);
if (socket != null) {
socket.setSoTimeout(REQUEST_TIMEOUT);
outputStream = socket.getOutputStream();
inputStream = socket.getInputStream();
updateStatus(ThingStatus.ONLINE);
}
Socket socket = new Socket(config.ipAddress, config.portNumber);
this.socket = socket;
socket.setSoTimeout(REQUEST_TIMEOUT);
outputStream = socket.getOutputStream();
inputStream = socket.getInputStream();
updateStatus(ThingStatus.ONLINE);
} catch (UnknownHostException e) {
logger.error("An exception occurred while resolving host {}:{} : '{}'", config.ipAddress, config.portNumber,
e.getMessage());
Expand All @@ -86,15 +86,15 @@ public void initialize() {
@Override
public void dispose() {
NetworkOceanicBindingConfiguration config = getConfigAs(NetworkOceanicBindingConfiguration.class);

Socket socket = this.socket;
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
logger.error("An exception occurred while disconnecting to host {}:{} : '{}'", config.ipAddress,
config.portNumber, e.getMessage());
} finally {
socket = null;
this.socket = null;
outputStream = null;
inputStream = null;
}
Expand Down Expand Up @@ -186,7 +186,7 @@ public void dispose() {
if (index > 0) {
line = new String(Arrays.copyOf(dataBuffer, index));
logger.debug("Received response '{}'", line);
line = StringUtils.chomp(line);
line = Objects.requireNonNull(StringUtils.chomp(line));
line = line.replace(",", ".");
line = line.trim();
index = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,19 @@ public void initialize() {
} else {
bufferSize = ((BigDecimal) getConfig().get(BUFFER_SIZE)).intValue();
}

ScheduledFuture<?> pollingJob = this.pollingJob;
if (pollingJob == null || pollingJob.isCancelled()) {
pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1,
this.pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 1,
((BigDecimal) getConfig().get(INTERVAL)).intValue(), TimeUnit.SECONDS);
}
}

@Override
public void dispose() {
if (pollingJob != null && !pollingJob.isCancelled()) {
ScheduledFuture<?> pollingJob = this.pollingJob;
if (pollingJob != null) {
pollingJob.cancel(true);
pollingJob = null;
this.pollingJob = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Objects;
import java.util.TooManyListenersException;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.openhab.binding.oceanic.internal.SerialOceanicBindingConfiguration;
import org.openhab.binding.oceanic.internal.Throttler;
import org.openhab.core.io.transport.serial.PortInUseException;
Expand All @@ -33,6 +33,7 @@
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -272,7 +273,8 @@ public void run() {
logger.trace("The resulting line is '{}'",
new String(Arrays.copyOf(dataBuffer, index)));
}
line = StringUtils.chomp(new String(Arrays.copyOf(dataBuffer, index)));
line = Objects.requireNonNull(
StringUtils.chomp(new String(Arrays.copyOf(dataBuffer, index))));
line = line.replace(",", ".");
line = line.trim();
index = 0;
Expand Down

0 comments on commit 2d9747b

Please sign in to comment.