]> git.basschouten.com Git - openhab-addons.git/blob
5733463b92d4c7c6c1b13afde0f7f0a17e67c3e7
[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.lifx.internal;
14
15 import java.net.InetSocketAddress;
16 import java.nio.channels.SelectionKey;
17 import java.nio.channels.Selector;
18 import java.util.function.Supplier;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.lifx.internal.fields.MACAddress;
23
24 /**
25  * The {@link LifxSelectorContext} stores the context that is used for broadcast and unicast communications with a
26  * light using a {@link Selector}.
27  *
28  * @author Wouter Born - Initial contribution
29  */
30 @NonNullByDefault
31 public class LifxSelectorContext {
32
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;
41
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);
45     }
46
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;
53         this.logId = logId;
54         this.host = host;
55         this.macAddress = macAddress;
56         this.broadcastKey = broadcastKey;
57         this.unicastKey = unicastKey;
58     }
59
60     public Selector getSelector() {
61         return selector;
62     }
63
64     public long getSourceId() {
65         return sourceId;
66     }
67
68     public Supplier<Integer> getSequenceNumberSupplier() {
69         return sequenceNumberSupplier;
70     }
71
72     public String getLogId() {
73         return logId;
74     }
75
76     public @Nullable InetSocketAddress getHost() {
77         return host;
78     }
79
80     public @Nullable MACAddress getMACAddress() {
81         return macAddress;
82     }
83
84     public @Nullable SelectionKey getBroadcastKey() {
85         return broadcastKey;
86     }
87
88     public @Nullable SelectionKey getUnicastKey() {
89         return unicastKey;
90     }
91
92     public void setHost(@Nullable InetSocketAddress host) {
93         this.host = host;
94     }
95
96     public void setMACAddress(@Nullable MACAddress macAddress) {
97         this.macAddress = macAddress;
98     }
99
100     public void setBroadcastKey(@Nullable SelectionKey broadcastKey) {
101         this.broadcastKey = broadcastKey;
102     }
103
104     public void setUnicastKey(@Nullable SelectionKey unicastKey) {
105         this.unicastKey = unicastKey;
106     }
107 }