]> git.basschouten.com Git - openhab-addons.git/blob
3781a533774a555fba6e82fc4d8d46c6d6b046b8
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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
19 /**
20  * This state is active when the connection failed. A grace period is enforced to prevent fast cycling through the
21  * states.
22  *
23  * @author Fabian Wolter - Initial Contribution
24  */
25 @NonNullByDefault
26 public class ConnectionStateGracePeriodBeforeReconnect extends AbstractConnectionState {
27     private static final int RECONNECT_GRACE_PERIOD_SEC = 5;
28
29     public ConnectionStateGracePeriodBeforeReconnect(ConnectionStateMachine context) {
30         super(context);
31     }
32
33     @Override
34     public void startWorking() {
35         closeSocketChannel();
36
37         addTimer(getScheduler().schedule(() -> nextState(ConnectionStateConnecting::new), RECONNECT_GRACE_PERIOD_SEC,
38                 TimeUnit.SECONDS));
39     }
40
41     @Override
42     public void onPckMessageReceived(String data) {
43         // nothing
44     }
45 }