Skip to content

Commit 84e609e

Browse files
committed
Some codes for hello lora tutorial.
1 parent 4b3bded commit 84e609e

File tree

45 files changed

+502
-414
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+502
-414
lines changed

client/concentrator/src/main/java/com/thefirstlineofcode/sand/client/concentrator/Concentrator.java

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class Concentrator extends Actuator implements IConcentrator {
7878
private static final long DEFAULT_VALUE_OF_DEFAULT_LAN_EXECUTION_TIMEOUT = 1000 * 10;
7979
private static final int DEFAULT_LAN_EXECUTION_TIMEOUT_CHECK_INTERVAL = 500;
8080

81-
private static final int DEFAULT_NODE_ADDITION_TIMEOUT = 1000 * 60 * 5;
81+
private static final long DEFAULT_ADD_NODE_TIMEOUT = 1000 * 60 * 5;
8282

8383
private static final int DEFAULT_ACK_REQUIRED_LAN_NOTIFICATIONS_POOL_SIZE = 512;
8484

@@ -100,6 +100,7 @@ public class Concentrator extends Actuator implements IConcentrator {
100100
protected Map<Integer, LanNode> nodes;
101101
protected Map<String, LanNode> confirmingNodes;
102102
protected Object nodesLock;
103+
protected long addNodeTimeout;
103104

104105
protected Map<String, IThingModelDescriptor> lanThingModelDescriptors = new HashMap<>();
105106

@@ -127,7 +128,7 @@ public class Concentrator extends Actuator implements IConcentrator {
127128
protected IFollowProcessor followProcessor;
128129

129130
protected QoS defaultDataQoS;
130-
protected Map<Class<?>, QoS> datumTypeToQoSs;
131+
protected Map<Class<?>, QoS> dataTypeToQoSs;
131132

132133
public Concentrator(IChatServices chatServices) {
133134
super(chatServices);
@@ -145,6 +146,8 @@ public Concentrator(IChatServices chatServices) {
145146
confirmingNodes = new LinkedHashMap<>();
146147
nodesLock = new Object();
147148

149+
addNodeTimeout = DEFAULT_ADD_NODE_TIMEOUT;
150+
148151
lanRouting = false;
149152

150153
ackRequiredLanNotificationsPoolSize = DEFAULT_ACK_REQUIRED_LAN_NOTIFICATIONS_POOL_SIZE;
@@ -160,7 +163,7 @@ public Concentrator(IChatServices chatServices) {
160163
lanReportPreprocessors = new ArrayList<>();
161164

162165
defaultDataQoS = QoS.AT_MOST_ONCE;
163-
datumTypeToQoSs = new HashMap<>();
166+
dataTypeToQoSs = new HashMap<>();
164167

165168
INotificationService notificationService = chatServices.createApi(INotificationService.class);
166169
notifier = notificationService.getNotifier();
@@ -240,7 +243,7 @@ public void registerLanThingModel(IThingModelDescriptor modelDescriptor) {
240243
}
241244

242245
for (Entry<Protocol, Class<?>> entry : modelDescriptor.getSupportedData().entrySet()) {
243-
registerLanDatum(entry.getValue());
246+
registerLanData(entry.getValue());
244247
}
245248

246249
if (logger.isInfoEnabled())
@@ -267,10 +270,10 @@ protected void registerLanFollowedEvent(Protocol protocol, Class<?> eventType) {
267270
ObxFactory.getInstance().registerLanFollowedEvent(eventType);
268271
}
269272

270-
protected void registerLanDatum(Class<?> datumType) {
271-
ObxFactory.getInstance().registerLanDatum(datumType);
273+
protected void registerLanData(Class<?> dataType) {
274+
ObxFactory.getInstance().registerLanData(dataType);
272275

273-
reporter.registerSupportedDatum(datumType);
276+
reporter.registerSupportedData(dataType);
274277
}
275278

276279
@Override
@@ -502,7 +505,7 @@ protected void processLanReport(LanReport lanReport) {
502505
ackRequiredLanReportsPool.put(traceId, null);
503506
}
504507

505-
QoS qos = getDatumQoS(lanReport.getData().getClass());
508+
QoS qos = getDataQoS(lanReport.getData().getClass());
506509
if (qos == null)
507510
qos = defaultDataQoS;
508511

@@ -754,10 +757,10 @@ public void requestServerToAddNode(String thingId, String registrationCode, int
754757

755758
if (nodes.size() > (MAX_LAN_SIZE - 1)) {
756759
if (logger.isErrorEnabled()) {
757-
logger.error("Node size overflow.");
760+
logger.error("Nodes size overflow.");
758761
}
759762

760-
processNodeAdditionError(AddNodeError.SIZE_OVERFLOW, node);
763+
processAddNodeError(AddNodeError.SIZE_OVERFLOW, node);
761764

762765
return;
763766
}
@@ -768,7 +771,7 @@ public void requestServerToAddNode(String thingId, String registrationCode, int
768771
logger.error("Reduplicate thing ID: {}.", node.getThingId());
769772
}
770773

771-
processNodeAdditionError(AddNodeError.REDUPLICATE_THING_ID, node);
774+
processAddNodeError(AddNodeError.REDUPLICATE_THING_ID, node);
772775
return;
773776
}
774777

@@ -777,7 +780,7 @@ public void requestServerToAddNode(String thingId, String registrationCode, int
777780
logger.error("Reduplicate thing address: {}.", node.getAddress());
778781
}
779782

780-
processNodeAdditionError(AddNodeError.REDUPLICATE_THING_ADDRESS, node);
783+
processAddNodeError(AddNodeError.REDUPLICATE_THING_ADDRESS, node);
781784
return;
782785
}
783786

@@ -786,24 +789,24 @@ public void requestServerToAddNode(String thingId, String registrationCode, int
786789
logger.error("Reduplicate thing LAN ID: {}.", node.getLanId());
787790
}
788791

789-
processNodeAdditionError(AddNodeError.REDUPLICATE_LAN_ID, node);
792+
processAddNodeError(AddNodeError.REDUPLICATE_LAN_ID, node);
790793
return;
791794
}
792795
}
793796

794-
chatServices.getTaskService().execute(new NodeAdditionTask(node));
797+
chatServices.getTaskService().execute(new AddNodeTask(node));
795798

796799
if (logger.isInfoEnabled()) {
797-
logger.info("Node addition request for node which's thingID is '{}' and address is '{}' has sent.",
800+
logger.info("Add node request for node which's thingID is '{}' and address is '{}' has sent.",
798801
thingId, address);
799802
}
800803
}
801804
}
802805

803-
private class NodeAdditionTask implements ITask<Iq> {
806+
private class AddNodeTask implements ITask<Iq> {
804807
private LanNode node;
805808

806-
public NodeAdditionTask(LanNode node) {
809+
public AddNodeTask(LanNode node) {
807810
this.node = node;
808811
}
809812

@@ -817,13 +820,13 @@ public void trigger(IUnidirectionalStream<Iq> stream) {
817820
addNode.setAddress(node.getAddress());
818821

819822
Iq iq = new Iq(Iq.Type.SET, addNode);
820-
stream.send(iq, DEFAULT_NODE_ADDITION_TIMEOUT);
823+
stream.send(iq, addNodeTimeout);
821824

822825
synchronized (nodesLock) {
823826
confirmingNodes.put(iq.getId(), node);
824827
}
825828
}
826-
829+
827830
@Override
828831
public void processResponse(IUnidirectionalStream<Iq> stream, Iq iq) {
829832
NodeAdded nodeAdded = iq.getObject();
@@ -834,7 +837,7 @@ public void processResponse(IUnidirectionalStream<Iq> stream, Iq iq) {
834837
logger.error("Confirming node which's thing ID is '{}' not found.", nodeAdded.getNodeThingId());
835838
}
836839

837-
processNodeAdditionError(IConcentrator.AddNodeError.ADDED_NODE_NOT_FOUND, node);
840+
processAddNodeError(IConcentrator.AddNodeError.ADDED_NODE_NOT_FOUND, node);
838841
return;
839842
}
840843

@@ -847,7 +850,7 @@ public void processResponse(IUnidirectionalStream<Iq> stream, Iq iq) {
847850
getThingName(), confirmingNode.getThingId(), nodeAdded.getNodeThingId(), nodeAdded.getConcentratorThingName());
848851
}
849852

850-
processNodeAdditionError(IConcentrator.AddNodeError.BAD_NODE_ADDITION_RESPONSE, node);
853+
processAddNodeError(IConcentrator.AddNodeError.BAD_NODE_ADDITION_RESPONSE, node);
851854
return;
852855
}
853856

@@ -856,7 +859,7 @@ public void processResponse(IUnidirectionalStream<Iq> stream, Iq iq) {
856859
logger.error("Bad node addition response. The server changed LAN ID of node to {}.", nodeAdded.getLanId());
857860
}
858861

859-
processNodeAdditionError(IConcentrator.AddNodeError.SERVER_CHANGED_LAN_ID, node);
862+
processAddNodeError(IConcentrator.AddNodeError.SERVER_CHANGED_LAN_ID, node);
860863
return;
861864
}
862865

@@ -888,15 +891,15 @@ public boolean processError(IUnidirectionalStream<Iq> stream, StanzaError error)
888891
}
889892

890893
if (ItemNotFound.DEFINED_CONDITION.equals(error.getDefinedCondition())) {
891-
processNodeAdditionError(IConcentrator.AddNodeError.NO_SUCH_CONCENTRATOR, node);
894+
processAddNodeError(IConcentrator.AddNodeError.NO_SUCH_CONCENTRATOR, node);
892895
} else if (ServiceUnavailable.DEFINED_CONDITION.equals(error.getDefinedCondition())) {
893-
processNodeAdditionError(IConcentrator.AddNodeError.NOT_CONCENTRATOR, node);
896+
processAddNodeError(IConcentrator.AddNodeError.NOT_CONCENTRATOR, node);
894897
} else if (Conflict.DEFINED_CONDITION.equals(error.getDefinedCondition())) {
895-
processNodeAdditionError(IConcentrator.AddNodeError.REDUPLICATE_NODE_OR_LAN_ID, node);
898+
processAddNodeError(IConcentrator.AddNodeError.REDUPLICATE_NODE_OR_LAN_ID, node);
896899
} else if (NotAcceptable.DEFINED_CONDITION.equals(error.getDefinedCondition())) {
897-
processNodeAdditionError(IConcentrator.AddNodeError.NOT_UNREGISTERED_THING, node);
900+
processAddNodeError(IConcentrator.AddNodeError.NOT_UNREGISTERED_THING, node);
898901
} else {
899-
processNodeAdditionError(IConcentrator.AddNodeError.UNKNOWN_ERROR, node);
902+
processAddNodeError(IConcentrator.AddNodeError.UNKNOWN_ERROR, node);
900903
}
901904
} finally {
902905
synchronized (nodesLock) {
@@ -915,7 +918,7 @@ public boolean processTimeout(IUnidirectionalStream<Iq> stream, Iq iq) {
915918

916919
nodes.remove(node.getLanId());
917920

918-
processNodeAdditionError(IConcentrator.AddNodeError.REMOTE_SERVER_TIMEOUT, node);
921+
processAddNodeError(IConcentrator.AddNodeError.REMOTE_SERVER_TIMEOUT, node);
919922

920923
return true;
921924
}
@@ -934,7 +937,7 @@ public void removeNode(int lanId) {
934937
}
935938
}
936939

937-
private void processNodeAdditionError(IConcentrator.AddNodeError error, LanNode node) {
940+
private void processAddNodeError(IConcentrator.AddNodeError error, LanNode node) {
938941
for (IConcentrator.Listener listener : listeners) {
939942
listener.occurred(error, node);
940943
}
@@ -1108,20 +1111,20 @@ public String getThingName() {
11081111
}
11091112

11101113
@Override
1111-
public boolean isLanDatumSupported(String model, Protocol protocol) {
1114+
public boolean isLanDataSupported(String model, Protocol protocol) {
11121115
if (!lanThingModelDescriptors.containsKey(model))
11131116
throw new IllegalArgumentException(String.format("Unsupported model: '%s'", model));
11141117

11151118
return lanThingModelDescriptors.get(model).getSupportedData().containsKey(protocol);
11161119
}
11171120

11181121
@Override
1119-
public Class<?> getLanDatumType(String model, Protocol protocol) {
1122+
public Class<?> getLanDataType(String model, Protocol protocol) {
11201123
if (!lanThingModelDescriptors.containsKey(model))
11211124
throw new IllegalArgumentException(String.format("Unsupported model: '%s'", model));
11221125

11231126
if (!lanThingModelDescriptors.get(model).getSupportedData().containsKey(protocol)) {
1124-
throw new IllegalArgumentException(String.format("Unsupported datum which's protocol is '%s' for thing which's model is '%s'.", protocol, model));
1127+
throw new IllegalArgumentException(String.format("Unsupported data which's protocol is '%s' for thing which's model is '%s'.", protocol, model));
11251128
}
11261129

11271130
return lanThingModelDescriptors.get(model).getSupportedData().get(protocol);
@@ -1176,11 +1179,11 @@ public Class<?> getLanEventType(String model, Protocol protocol) {
11761179
}
11771180

11781181
@Override
1179-
public boolean isLanDatumSupported(String model, Class<?> datumType) {
1182+
public boolean isLanDataSupported(String model, Class<?> dataType) {
11801183
if (!lanThingModelDescriptors.containsKey(model))
11811184
throw new IllegalArgumentException(String.format("Unsupported model: '%s'", model));
11821185

1183-
return lanThingModelDescriptors.get(model).getSupportedData().containsValue(datumType);
1186+
return lanThingModelDescriptors.get(model).getSupportedData().containsValue(dataType);
11841187
}
11851188

11861189
@Override
@@ -1564,12 +1567,22 @@ public QoS getDefaultDataQoS() {
15641567
}
15651568

15661569
@Override
1567-
public void setDatumQoS(Class<?> datumType, QoS qos) {
1568-
datumTypeToQoSs.put(datumType, qos);
1570+
public void setDataQoS(Class<?> dataType, QoS qos) {
1571+
dataTypeToQoSs.put(dataType, qos);
1572+
}
1573+
1574+
@Override
1575+
public QoS getDataQoS(Class<?> dataType) {
1576+
return dataTypeToQoSs.get(dataType);
1577+
}
1578+
1579+
@Override
1580+
public void setAddNodeTimeout(long addNodeTimeout) {
1581+
this.addNodeTimeout = addNodeTimeout;
15691582
}
15701583

15711584
@Override
1572-
public QoS getDatumQoS(Class<?> datumType) {
1573-
return datumTypeToQoSs.get(datumType);
1585+
public long getAddNodeTimeout() {
1586+
return addNodeTimeout;
15741587
}
15751588
}

client/concentrator/src/main/java/com/thefirstlineofcode/sand/client/concentrator/IConcentrator.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public enum AddNodeError {
3636
void addCommunicator(CommunicationNet net, ICommunicator<?, ?, byte[]> communicator);
3737
ICommunicator<?, ?, byte[]> getCommunicator(CommunicationNet communicationNet);
3838
int getBestSuitedNewLanId();
39+
void setAddNodeTimeout(long addNodeTimeout);
40+
long getAddNodeTimeout();
3941
void requestServerToAddNode(String thingId, String registrationCode, int lanId, IAddress address);
4042
void removeNode(int lanId) throws NodeNotFoundException;
4143
void cleanNodes();
@@ -62,9 +64,9 @@ public enum AddNodeError {
6264
boolean isLanEventFollowed(String model, Protocol protocol);
6365
boolean isLanEventFollowed(String model, Class<?> eventType);
6466
Class<?> getLanEventType(String model, Protocol protocol);
65-
boolean isLanDatumSupported(String model, Protocol protocol);
66-
boolean isLanDatumSupported(String model, Class<?> datumType);
67-
Class<?> getLanDatumType(String model, Protocol protocol);
67+
boolean isLanDataSupported(String model, Protocol protocol);
68+
boolean isLanDataSupported(String model, Class<?> dataType);
69+
Class<?> getLanDataType(String model, Protocol protocol);
6870
void enableLanRouting();
6971
void disableLanRouting();
7072
boolean isLanRoutingEnabled();
@@ -81,8 +83,8 @@ public enum AddNodeError {
8183
long getNotificationRexTimeout();
8284
void setDefaultDataQoS(QoS qos);
8385
QoS getDefaultDataQoS();
84-
void setDatumQoS(Class<?> datumType, QoS qos);
85-
QoS getDatumQoS(Class<?> datumType);
86+
void setDataQoS(Class<?> dataType, QoS qos);
87+
QoS getDataQoS(Class<?> dataType);
8688

8789
public interface Listener {
8890
void nodeAdded(int lanId, LanNode node);

client/edge/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
<packaging>jar</packaging>
1919

2020
<dependencies>
21-
<dependency>
22-
<groupId>com.thefirstlineofcode.chalk</groupId>
23-
<artifactId>chalk-logger</artifactId>
24-
</dependency>
2521
<dependency>
2622
<groupId>com.thefirstlineofcode.sand.client</groupId>
2723
<artifactId>sand-client-ibtr</artifactId>

0 commit comments

Comments
 (0)