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

[epsonprojector] Update epsonprojector binding for OH3 #9021

Merged
merged 17 commits into from
Dec 4, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class EpsonProjectorDevice {
private ScheduledExecutorService scheduler = null;
private EpsonProjectorConnector connection;
private ExpiringCache<Integer> cachedLampHours = new ExpiringCache<>(Duration.ofMinutes(LAMP_REFRESH_WAIT_MINUTES),
() -> queryLamp());
this::queryLamp);
private boolean connected = false;
private boolean ready = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.binding.epsonprojector.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* Exception for Epson projector errors.
Expand All @@ -28,7 +29,7 @@ public EpsonProjectorException(String message) {
super(message);
}

public EpsonProjectorException(String message, Throwable cause) {
public EpsonProjectorException(@Nullable String message, Throwable cause) {
super(message, cause);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void connect() throws EpsonProjectorException {
this.out = out;
}
} catch (PortInUseException | UnsupportedCommOperationException | IOException e) {
throw new EpsonProjectorException(e);
throw new EpsonProjectorException(e.getMessage(), e);
mlobstein marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -98,7 +98,7 @@ public void disconnect() throws EpsonProjectorException {
try {
out.close();
} catch (IOException e) {
logger.debug("Error occurred when closing serial out stream", e);
logger.debug("Error occurred when closing serial out stream: {}", e.getMessage());
}
this.out = null;
}
Expand All @@ -107,7 +107,7 @@ public void disconnect() throws EpsonProjectorException {
try {
in.close();
} catch (IOException e) {
logger.debug("Error occurred when closing serial in stream", e);
logger.debug("Error occurred when closing serial in stream: {}", e.getMessage());
}
this.in = null;
}
Expand Down Expand Up @@ -152,25 +152,20 @@ public String sendMessage(String data, int timeout) throws EpsonProjectorExcepti
return "";
}
} catch (IOException e) {
logger.debug("IO error occurred...reconnect and resend once", e);
logger.debug("IO error occurred...reconnect and resend once: {}", e.getMessage());
disconnect();
connect();

try {
return sendMmsg(data, timeout);
} catch (IOException e1) {
throw new EpsonProjectorException(e);
throw new EpsonProjectorException(e.getMessage(), e);
}
}
}

@Override
public void serialEvent(SerialPortEvent arg0) {
try {
logger.trace("RXTX library CPU load workaround, sleep forever");
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
}
}

private String sendMmsg(String data, int timeout) throws IOException, EpsonProjectorException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are you handling the case where multiple message are sent at the same time from multiple threads? Are you already preventing this from happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is called by sendQuery() which is a synchronized method... Is that sufficient?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sufficient, but it would be safer if you did the synchronization in this class instead. It looks safe enough as is though, so you don't have to change it.

Expand Down Expand Up @@ -201,7 +196,7 @@ private String sendMmsg(String data, int timeout) throws IOException, EpsonProje
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new EpsonProjectorException(e);
throw new EpsonProjectorException(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void connect() throws EpsonProjectorException {
in = socket.getInputStream();
out = socket.getOutputStream();
} catch (IOException e) {
throw new EpsonProjectorException(e);
throw new EpsonProjectorException(e.getMessage(), e);
}
}

Expand All @@ -69,7 +69,7 @@ public void disconnect() throws EpsonProjectorException {
try {
out.close();
} catch (IOException e) {
logger.debug("Error occurred when closing tcp out stream", e);
logger.debug("Error occurred when closing tcp out stream: {}", e.getMessage());
}
}

Expand All @@ -79,7 +79,7 @@ public void disconnect() throws EpsonProjectorException {
try {
in.close();
} catch (IOException e) {
logger.debug("Error occurred when closing tcp in stream", e);
logger.debug("Error occurred when closing tcp in stream: {}", e.getMessage());
}
}

Expand All @@ -89,7 +89,7 @@ public void disconnect() throws EpsonProjectorException {
try {
socket.close();
} catch (IOException e) {
logger.debug("Error occurred when closing tcp socket", e);
logger.debug("Error occurred when closing tcp socket: {}", e.getMessage());
}
}

Expand Down Expand Up @@ -131,14 +131,14 @@ public String sendMessage(String data, int timeout) throws EpsonProjectorExcepti
return "";
}
} catch (IOException e) {
logger.debug("IO error occurred...reconnect and resend once", e);
logger.debug("IO error occurred...reconnect and resend once: {}", e.getMessage());
disconnect();
connect();

try {
return sendMmsg(data, timeout);
} catch (IOException e1) {
throw new EpsonProjectorException(e);
throw new EpsonProjectorException(e.getMessage(), e);
}
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ private String sendMmsg(String data, int timeout) throws IOException, EpsonProje
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new EpsonProjectorException(e);
throw new EpsonProjectorException(e.getMessage(), e);
}
}

Expand Down