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.lifx.internal;
15 import java.net.InetSocketAddress;
16 import java.nio.channels.SelectionKey;
17 import java.nio.channels.Selector;
18 import java.util.function.Supplier;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.lifx.internal.fields.MACAddress;
25 * The {@link LifxSelectorContext} stores the context that is used for broadcast and unicast communications with a
26 * light using a {@link Selector}.
28 * @author Wouter Born - Initial contribution
31 public class LifxSelectorContext {
33 private final Selector selector;
34 private final long sourceId;
35 private final Supplier<Integer> sequenceNumberSupplier;
36 private final String logId;
37 private @Nullable InetSocketAddress host;
38 private @Nullable MACAddress macAddress;
39 private @Nullable SelectionKey broadcastKey;
40 private @Nullable SelectionKey unicastKey;
42 public LifxSelectorContext(Selector selector, long sourceId, Supplier<Integer> sequenceNumberSupplier, String logId,
43 @Nullable SelectionKey broadcastKey) {
44 this(selector, sourceId, sequenceNumberSupplier, logId, null, null, broadcastKey, null);
47 public LifxSelectorContext(Selector selector, long sourceId, Supplier<Integer> sequenceNumberSupplier, String logId,
48 @Nullable InetSocketAddress host, @Nullable MACAddress macAddress, @Nullable SelectionKey broadcastKey,
49 @Nullable SelectionKey unicastKey) {
50 this.selector = selector;
51 this.sourceId = sourceId;
52 this.sequenceNumberSupplier = sequenceNumberSupplier;
55 this.macAddress = macAddress;
56 this.broadcastKey = broadcastKey;
57 this.unicastKey = unicastKey;
60 public Selector getSelector() {
64 public long getSourceId() {
68 public Supplier<Integer> getSequenceNumberSupplier() {
69 return sequenceNumberSupplier;
72 public String getLogId() {
76 public @Nullable InetSocketAddress getHost() {
80 public @Nullable MACAddress getMACAddress() {
84 public @Nullable SelectionKey getBroadcastKey() {
88 public @Nullable SelectionKey getUnicastKey() {
92 public void setHost(@Nullable InetSocketAddress host) {
96 public void setMACAddress(@Nullable MACAddress macAddress) {
97 this.macAddress = macAddress;
100 public void setBroadcastKey(@Nullable SelectionKey broadcastKey) {
101 this.broadcastKey = broadcastKey;
104 public void setUnicastKey(@Nullable SelectionKey unicastKey) {
105 this.unicastKey = unicastKey;