~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/jinterface/test/jinterface_SUITE_data/NodeStatusHandler.java

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * %CopyrightBegin%
 
3
 *
 
4
 * Copyright Ericsson AB 2004-2010. All Rights Reserved.
 
5
 *
 
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/.
 
11
 *
 
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
 
15
 * under the License.
 
16
 *
 
17
 * %CopyrightEnd%
 
18
 */
 
19
 
 
20
import com.ericsson.otp.erlang.*;
 
21
 
 
22
public class NodeStatusHandler extends OtpNodeStatus {
 
23
    /*
 
24
      Implements java side of test cases in jinterface_SUITE.erl
 
25
 
 
26
      Test OtpNode.registerStatusHandler(...) and class OtpNodeStatus.
 
27
     */
 
28
 
 
29
    private static final boolean dbg = true;
 
30
    private static final int recTime = 2000;
 
31
 
 
32
    private static String erlNode = null;
 
33
    private static String cookie = null;
 
34
    private static OtpMbox mbox = null;
 
35
 
 
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;
 
39
 
 
40
    public static void main(String argv[]) {
 
41
 
 
42
        cookie = argv[0];
 
43
        erlNode = argv[1];
 
44
 
 
45
        try {
 
46
          OtpNode javaNode = new OtpNode("javanode", cookie);
 
47
          mbox = javaNode.createMbox();
 
48
        }
 
49
        catch (Exception e) {
 
50
            dbg("EXCEPTION when creating javanode: " + e);
 
51
            System.exit(1);
 
52
        }
 
53
 
 
54
        try {
 
55
            OtpNode node1 = new OtpNode("javanode1", cookie);
 
56
            node1.registerStatusHandler(new NodeStatusHandler());
 
57
 
 
58
            switch (Integer.parseInt(argv[2])) {
 
59
 
 
60
            case status_handler_localStatus:
 
61
                dbg("java running test case \"status_handler_localStatus\"");
 
62
 
 
63
                Thread.sleep(200); // Give 'nodeup' message a chance
 
64
                                   // before closing
 
65
                node1.close();
 
66
                Thread.sleep(500);
 
67
                break;
 
68
 
 
69
            case status_handler_remoteStatus:
 
70
                dbg("java running test case \"status_handler_remoteStatus\"");
 
71
 
 
72
                OtpNode node2 = new OtpNode("javanode2", cookie);
 
73
                node2.ping(node1.node(),2000);
 
74
                node2.close();
 
75
                Thread.sleep(500);
 
76
                break;
 
77
 
 
78
            case status_handler_connAttempt:
 
79
                dbg("java running test case \"status_handler_connAttempt\"");
 
80
 
 
81
                OtpNode node3 = new OtpNode("javanode3","othercookie");
 
82
                node3.ping(node1.node(),2000);
 
83
                node1.ping(node3.node(),2000);
 
84
                break;
 
85
 
 
86
            }
 
87
 
 
88
            OtpErlangObject o = mbox.receive(recTime);
 
89
            if (o == null) System.exit(2);
 
90
            if (! ((OtpErlangAtom)o).atomValue().equals("done"))
 
91
                System.exit(3);
 
92
 
 
93
        }
 
94
        catch (Exception e) {
 
95
            dbg("EXCEPTION: " + e);
 
96
            System.exit(4);
 
97
        }
 
98
 
 
99
    }
 
100
 
 
101
 
 
102
 
 
103
  public void remoteStatus(String node, boolean up, Object info) {
 
104
      try {
 
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);
 
113
 
 
114
      }
 
115
      catch (Exception e) {
 
116
          dbg("EXCEPTION in remoteStatus: " + e + "\nArgs:  " +
 
117
                             node + " " + up + " "  + info);
 
118
          System.exit(5);
 
119
      }
 
120
  }
 
121
 
 
122
 
 
123
  public void localStatus(String node, boolean up, Object info) {
 
124
      try {
 
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);
 
133
 
 
134
      }
 
135
      catch (Exception e) {
 
136
          dbg("EXCEPTION in localStatus: " + e + "\nArgs:  " +
 
137
                             node + " " + up + " "  + info);
 
138
          System.exit(6);
 
139
      }
 
140
  }
 
141
 
 
142
 
 
143
 
 
144
  public void connAttempt(String node, boolean incoming, Object info) {
 
145
      try {
 
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);
 
154
 
 
155
      }
 
156
      catch (Exception e) {
 
157
          dbg("EXCEPTION in connAttempt: " + e + "\nArgs:  " +
 
158
                             node + " " + incoming + " "  + info);
 
159
          System.exit(7);
 
160
      }
 
161
  }
 
162
 
 
163
 
 
164
    private static void dbg(String str) {
 
165
        if (dbg) System.out.println(str);
 
166
    }
 
167
 
 
168
}