use of org.apache.edgent.function.Supplier in project plc4x by apache.
the class PlcConnectionAdapter method newSupplier.
Supplier<PlcReadResponse> newSupplier(PlcReadRequest readRequest) {
return new Supplier<PlcReadResponse>() {
private static final long serialVersionUID = 1L;
@Override
public PlcReadResponse get() {
PlcConnection connection = null;
try {
connection = getConnection();
LocalDateTime start = LocalDateTime.now();
PlcReadResponse plcReadResponse = readRequest.execute().get();
LocalDateTime end = LocalDateTime.now();
if (logger.isTraceEnabled()) {
long diff = ChronoUnit.MILLIS.between(start, end);
logger.trace("Processed request in " + diff + "ms");
}
return plcReadResponse;
} catch (Exception e) {
logger.error("reading from plc device {} {} failed", connection, readRequest, e);
return null;
}
}
};
}
Aggregations