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.homematic.internal.communicator.server;
15 import java.io.IOException;
17 import org.openhab.binding.homematic.internal.HomematicBindingConstants;
18 import org.openhab.binding.homematic.internal.common.HomematicConfig;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Server implementation for receiving messages via BIN-RPC from a Homematic gateway.
25 * @author Gerhard Riegler - Initial contribution
27 public class BinRpcServer implements RpcServer {
28 private final Logger logger = LoggerFactory.getLogger(BinRpcServer.class);
30 private Thread networkServiceThread;
31 private BinRpcNetworkService networkService;
32 private final HomematicConfig config;
33 private final RpcEventListener listener;
34 private final String id;
36 public BinRpcServer(RpcEventListener listener, HomematicConfig config, String id) {
37 this.listener = listener;
43 public void start() throws IOException {
44 logger.debug("Initializing BIN-RPC server at port {}", config.getBinCallbackPort());
46 networkService = new BinRpcNetworkService(listener, config);
47 networkServiceThread = new Thread(networkService);
49 .setName("OH-binding-" + HomematicBindingConstants.THING_TYPE_BRIDGE + ":" + id + "-rpcServer");
50 networkServiceThread.start();
54 public void shutdown() {
55 if (networkService != null) {
56 logger.debug("Stopping BIN-RPC server");
58 if (networkServiceThread != null) {
59 networkServiceThread.interrupt();
61 } catch (Exception e) {
62 logger.error("{}", e.getMessage(), e);
64 networkService.shutdown();
65 networkService = null;