Search in sources :

Example 1 with Supplier

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;
            }
        }
    };
}
Also used : LocalDateTime(java.time.LocalDateTime) PlcReadResponse(org.apache.plc4x.java.api.messages.PlcReadResponse) Supplier(org.apache.edgent.function.Supplier) PlcConnection(org.apache.plc4x.java.api.PlcConnection) PlcException(org.apache.plc4x.java.api.exceptions.PlcException)

Aggregations

LocalDateTime (java.time.LocalDateTime)1 Supplier (org.apache.edgent.function.Supplier)1 PlcConnection (org.apache.plc4x.java.api.PlcConnection)1 PlcException (org.apache.plc4x.java.api.exceptions.PlcException)1 PlcReadResponse (org.apache.plc4x.java.api.messages.PlcReadResponse)1