]> git.basschouten.com Git - openhab-addons.git/blob
dedbe08de784ff719b582a2375bf78fa57a653ce
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.paradoxalarm.internal.communication;
14
15 import org.openhab.binding.paradoxalarm.internal.communication.messages.IPPacket;
16
17 /**
18  * The {@link Request}. Abstract request class. Used to be derived for the particular types of requests to Paradox.
19  *
20  * @author Konstantin Polihronov - Initial contribution
21  */
22 public abstract class Request implements IRequest {
23
24     private IPPacket packet;
25     private long timestamp;
26     private RequestType type;
27     private IResponseReceiver receiver;
28
29     public Request(RequestType type, IPPacket packet, IResponseReceiver receiver) {
30         this.packet = packet;
31         this.type = type;
32         this.receiver = receiver;
33     }
34
35     @Override
36     public IPPacket getRequestPacket() {
37         return packet;
38     }
39
40     @Override
41     public void setTimeStamp() {
42         timestamp = System.currentTimeMillis();
43     }
44
45     @Override
46     public boolean isTimeStampExpired(long tresholdInMillis) {
47         return System.currentTimeMillis() - timestamp >= tresholdInMillis;
48     }
49
50     @Override
51     public RequestType getType() {
52         return type;
53     }
54
55     @Override
56     public String toString() {
57         return "Request [packet=" + packet + ", timestamp=" + timestamp + ", type=" + type + "]";
58     }
59
60     @Override
61     public IResponseReceiver getResponseReceiver() {
62         return receiver;
63     }
64 }