4
* Copyright Ericsson AB 2004-2010. All Rights Reserved.
6
* The contents of this file are subject to the Erlang Public License,
7
* Version 1.1, (the "License"); you may not use this file except in
8
* compliance with the License. You should have received a copy of the
9
* Erlang Public License along with this software. If not, it can be
10
* retrieved online at http://www.erlang.org/.
12
* Software distributed under the License is distributed on an "AS IS"
13
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
* the License for the specific language governing rights and limitations
20
import com.ericsson.otp.erlang.*;
22
public class NodeStatusHandler extends OtpNodeStatus {
24
Implements java side of test cases in jinterface_SUITE.erl
26
Test OtpNode.registerStatusHandler(...) and class OtpNodeStatus.
29
private static final boolean dbg = true;
30
private static final int recTime = 2000;
32
private static String erlNode = null;
33
private static String cookie = null;
34
private static OtpMbox mbox = null;
36
private static final int status_handler_localStatus = 1;
37
private static final int status_handler_remoteStatus = 2;
38
private static final int status_handler_connAttempt = 3;
40
public static void main(String argv[]) {
46
OtpNode javaNode = new OtpNode("javanode", cookie);
47
mbox = javaNode.createMbox();
50
dbg("EXCEPTION when creating javanode: " + e);
55
OtpNode node1 = new OtpNode("javanode1", cookie);
56
node1.registerStatusHandler(new NodeStatusHandler());
58
switch (Integer.parseInt(argv[2])) {
60
case status_handler_localStatus:
61
dbg("java running test case \"status_handler_localStatus\"");
63
Thread.sleep(200); // Give 'nodeup' message a chance
69
case status_handler_remoteStatus:
70
dbg("java running test case \"status_handler_remoteStatus\"");
72
OtpNode node2 = new OtpNode("javanode2", cookie);
73
node2.ping(node1.node(),2000);
78
case status_handler_connAttempt:
79
dbg("java running test case \"status_handler_connAttempt\"");
81
OtpNode node3 = new OtpNode("javanode3","othercookie");
82
node3.ping(node1.node(),2000);
83
node1.ping(node3.node(),2000);
88
OtpErlangObject o = mbox.receive(recTime);
89
if (o == null) System.exit(2);
90
if (! ((OtpErlangAtom)o).atomValue().equals("done"))
95
dbg("EXCEPTION: " + e);
103
public void remoteStatus(String node, boolean up, Object info) {
105
dbg("Got remoteStatus: " + node + " " + up + " " + info);
106
OtpErlangObject[] msgArray = new OtpErlangObject[4];
107
msgArray[0] = new OtpErlangAtom("remoteStatus");
108
msgArray[1] = new OtpErlangString(node);
109
msgArray[2] = new OtpErlangBoolean(up);
110
msgArray[3] = mbox.self();
111
OtpErlangTuple msg = new OtpErlangTuple(msgArray);
112
mbox.send("erl_status_server", erlNode, msg);
115
catch (Exception e) {
116
dbg("EXCEPTION in remoteStatus: " + e + "\nArgs: " +
117
node + " " + up + " " + info);
123
public void localStatus(String node, boolean up, Object info) {
125
dbg("Got localStatus: " + node + " " + up + " " + info);
126
OtpErlangObject[] msgArray = new OtpErlangObject[4];
127
msgArray[0] = new OtpErlangAtom("localStatus");
128
msgArray[1] = new OtpErlangString(node);
129
msgArray[2] = new OtpErlangBoolean(up);
130
msgArray[3] = mbox.self();
131
OtpErlangTuple msg = new OtpErlangTuple(msgArray);
132
mbox.send("erl_status_server", erlNode, msg);
135
catch (Exception e) {
136
dbg("EXCEPTION in localStatus: " + e + "\nArgs: " +
137
node + " " + up + " " + info);
144
public void connAttempt(String node, boolean incoming, Object info) {
146
dbg("Got connAttempt: " + node + " " + incoming + " " + info);
147
OtpErlangObject[] msgArray = new OtpErlangObject[4];
148
msgArray[0] = new OtpErlangAtom("connAttempt");
149
msgArray[1] = new OtpErlangString(node);
150
msgArray[2] = new OtpErlangBoolean(incoming);
151
msgArray[3] = mbox.self();
152
OtpErlangTuple msg = new OtpErlangTuple(msgArray);
153
mbox.send("erl_status_server", erlNode, msg);
156
catch (Exception e) {
157
dbg("EXCEPTION in connAttempt: " + e + "\nArgs: " +
158
node + " " + incoming + " " + info);
164
private static void dbg(String str) {
165
if (dbg) System.out.println(str);