Skip to content

Commit

Permalink
0.4.0
Browse files Browse the repository at this point in the history
- Remove haystack nodes when editing server.
- Add Connecting status
  • Loading branch information
a-hansen authored Dec 17, 2020
2 parents 6d119b7 + d91363e commit e06a78b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.DS_Store
.key
nodes.json
nodes.json.bak
*.bak

# Gradle
.gradle
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'java-library'
mainClassName = 'org.dsa.iot.haystack.Main'
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '0.3.0'
version = '0.4.0'

repositories {
mavenLocal()
Expand Down
2 changes: 1 addition & 1 deletion dslink.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dslink-java-haystack",
"version": "0.2.13",
"version": "0.4.0",
"description": "An implementation dslink of a haystack protocol consumer",
"license": "Apache",
"author": {
Expand Down
36 changes: 22 additions & 14 deletions src/main/java/org/dsa/iot/haystack/Haystack.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public Haystack(final Node node) {
this.subs = new ConcurrentHashMap<>();
this.navHelper = new NavHelper(this);
Utils.getStatusNode(node);
Utils.initCommon(this, node);
this.conn = new ConnectionHelper(this, new Handler<Void>() {
@Override
public void handle(Void event) {
Expand Down Expand Up @@ -143,21 +144,29 @@ public void editConnection(String url,
int readTimeout,
boolean enabled) {
LOGGER.info("Edit Server url={} user={} enabled={}", url, user, enabled);
if (!enabled) {
stop();
Utils.getStatusNode(node).setValue(new Value("Disabled"));
List<String> list = new ArrayList<>(node.getChildren().keySet());
for (String name : list) {
Node tmp = node.getChild(name, false);
if (tmp.getAction() != null) {
continue;
}
if (tmp.getRoConfig("navId") != null) {
node.removeChild(name, false);
node.setRoConfig("lu", new Value(0));
stop();
List<String> list = new ArrayList<>(node.getChildren().keySet());
for (String name : list) {
Node tmp = node.getChild(name, false);
if (tmp == null) {
tmp = node.getChild(name, true);
}
if (tmp == null) {
continue;
}
if (tmp.getAction() != null) {
continue;
}
if (tmp.getRoConfig("navId") != null) {
if (node.removeChild(name, false) == null) {
node.removeChild(name, true);
}
}
}
if (!enabled) {
Utils.getStatusNode(node).setValue(new Value("Disabled"));
} else {
node.setRoConfig("lu", new Value(0));
conn.editConnection(url, user, pass, connTimeout, readTimeout);
setupPoll(pollRate);
}
Expand Down Expand Up @@ -215,8 +224,7 @@ public static void init(Node superRoot) {
for (Node child : children.values()) {
if (child.getAction() == null && !"sys".equals(child.getName())) {
child.clearChildren();
Haystack haystack = new Haystack(child);
Utils.initCommon(haystack, child);
new Haystack(child);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public void handle(ActionResult event) {
builder.setConfig("read timeout", vReadTimeout);
Node node = builder.build();

Haystack haystack = new Haystack(node);
Utils.initCommon(haystack, node);
new Haystack(node);
LOGGER.info("Added server name={} url={} user={}", name, url, user);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public Connector(Handler<HClient> onConnected) {
@Override
public void run() {
try {
if (!haystack.isEnabled()) {
close();
return;
}
statusNode.setValue(new Value("Connecting"));
String pass = "";
if (password != null) {
pass = String.valueOf(password);
Expand Down Expand Up @@ -236,6 +241,8 @@ public void run() {
cause != null ? cause.getMessage() : "");
if (haystack.isEnabled()) {
statusNode.setValue(new Value(err));
} else {
close();
}
LOGGER.warn(err);
}
Expand Down

0 comments on commit e06a78b

Please sign in to comment.