]> git.basschouten.com Git - openhab-addons.git/blob
0e506196ea92086104b096661a2be9d4cc42e28c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lcn.internal.connection;
14
15 import java.util.concurrent.TimeUnit;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * This state is active when the connection failed. A grace period is enforced to prevent fast cycling through the
22  * states.
23  *
24  * @author Fabian Wolter - Initial Contribution
25  */
26 @NonNullByDefault
27 public class ConnectionStateGracePeriodBeforeReconnect extends AbstractConnectionState {
28     private static final int RECONNECT_GRACE_PERIOD_SEC = 5;
29
30     public ConnectionStateGracePeriodBeforeReconnect(ConnectionStateMachine context) {
31         super(context);
32     }
33
34     @Override
35     public void startWorking() {
36         closeSocketChannel();
37
38         addTimer(getScheduler().schedule(() -> nextState(ConnectionStateConnecting::new), RECONNECT_GRACE_PERIOD_SEC,
39                 TimeUnit.SECONDS));
40     }
41
42     @Override
43     public void onPckMessageReceived(String data) {
44         // nothing
45     }
46
47     @Override
48     public void handleConnectionFailed(@Nullable Throwable e) {
49         // nothing
50     }
51 }