2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.nibeheatpump.internal;
15 import java.util.concurrent.Future;
16 import java.util.concurrent.TimeUnit;
17 import java.util.concurrent.TimeoutException;
18 import java.util.concurrent.locks.Condition;
19 import java.util.concurrent.locks.Lock;
20 import java.util.concurrent.locks.ReentrantLock;
22 import org.openhab.binding.nibeheatpump.internal.message.NibeHeatPumpMessage;
25 * The {@link NibeHeatPumpCommandResult} implements a very simple {@link Future} for {@link NibeHeatPumpMessage}s.
28 * @author Pauli Anttila - Initial contribution
30 public class NibeHeatPumpCommandResult implements Future<NibeHeatPumpMessage> {
32 private final Lock lock = new ReentrantLock();
33 private final Condition condition = lock.newCondition();
35 private NibeHeatPumpMessage result = null;
36 private boolean done = false;
39 public boolean cancel(boolean mayInterruptIfRunning) {
44 public boolean isCancelled() {
49 public boolean isDone() {
59 public NibeHeatPumpMessage get() throws InterruptedException {
72 public NibeHeatPumpMessage get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
76 final boolean timedOut = !condition.await(timeout, unit);
78 throw new TimeoutException("waiting timed out");
87 public void set(final NibeHeatPumpMessage result) {
92 condition.signalAll();