File: MerlinMXBean.java

package info (click to toggle)
openjdk-11 11.0.4%2B11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (457 lines) | stat: -rw-r--r-- 15,693 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/*
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

import java.util.Arrays;
import javax.management.openmbean.ArrayType;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeDataView;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;

public interface MerlinMXBean {

    int PInt = 59;
    SimpleType PIntType = SimpleType.INTEGER;
    int getPInt();
    void setPInt(int x);
    int opPInt(int x, int y);

    long PLong = Long.MAX_VALUE;
    SimpleType PLongType = SimpleType.LONG;
    long getPLong();
    void setPLong(long x);
    long opPLong(long x, long y);

    short PShort = 55;
    SimpleType PShortType = SimpleType.SHORT;
    short getPShort();
    void setPShort(short x);
    short opPShort(short x, short y);

    byte PByte = 13;
    SimpleType PByteType = SimpleType.BYTE;
    byte getPByte();
    void setPByte(byte x);
    byte opPByte(byte x, byte y);

    char PChar = 'x';
    SimpleType PCharType = SimpleType.CHARACTER;
    char getPChar();
    void setPChar(char x);
    char opPChar(char x, char y);

    float PFloat = 1.3f;
    SimpleType PFloatType = SimpleType.FLOAT;
    float getPFloat();
    void setPFloat(float x);
    float opPFloat(float x, float y);

    double PDouble = Double.MAX_VALUE;
    SimpleType PDoubleType = SimpleType.DOUBLE;
    double getPDouble();
    void setPDouble(double x);
    double opPDouble(double x, double y);

    boolean PBoolean = true;
    SimpleType PBooleanType = SimpleType.BOOLEAN;
    boolean getPBoolean();
    void setPBoolean(boolean x);
    boolean opPBoolean(boolean x, boolean y);

    Integer WInteger = new Integer(59);
    SimpleType WIntegerType = SimpleType.INTEGER;
    Integer getWInteger();
    void setWInteger(Integer x);
    Integer opWInteger(Integer x, Integer y);

    Long WLong = new Long(Long.MAX_VALUE);
    SimpleType WLongType = SimpleType.LONG;
    Long getWLong();
    void setWLong(Long x);
    Long opWLong(Long x, Long y);

    Short WShort = new Short(Short.MAX_VALUE);
    SimpleType WShortType = SimpleType.SHORT;
    Short getWShort();
    void setWShort(Short x);
    Short opWShort(Short x, Short y);

    Byte WByte = new Byte(Byte.MAX_VALUE);
    SimpleType WByteType = SimpleType.BYTE;
    Byte getWByte();
    void setWByte(Byte x);
    Byte opWByte(Byte x, Byte y);

    Character WCharacter = new Character('x');
    SimpleType WCharacterType = SimpleType.CHARACTER;
    Character getWCharacter();
    void setWCharacter(Character x);
    Character opWCharacter(Character x, Character y);

    Float WFloat = new Float(1.3f);
    SimpleType WFloatType = SimpleType.FLOAT;
    Float getWFloat();
    void setWFloat(Float x);
    Float opWFloat(Float x, Float y);

    Double WDouble = new Double(Double.MAX_VALUE);
    SimpleType WDoubleType = SimpleType.DOUBLE;
    Double getWDouble();
    void setWDouble(Double x);
    Double opWDouble(Double x, Double y);

    Boolean WBoolean = Boolean.TRUE;
    SimpleType WBooleanType = SimpleType.BOOLEAN;
    Boolean getWBoolean();
    void setWBoolean(Boolean x);
    Boolean opWBoolean(Boolean x, Boolean y);

    int[] PIntA = {2, 3, 5, 7, 11, 13};
    ArrayType PIntAType = ArrayTypeMaker.make(SimpleType.INTEGER, true);
    int[] getPIntA();
    void setPIntA(int[] x);
    int[] opPIntA(int[] x, int[] y);

    int[][] PInt2D = {{1, 2}, {3, 4}};
    ArrayType PInt2DType = ArrayTypeMaker.make(1, PIntAType);
    int[][] getPInt2D();
    void setPInt2D(int[][] x);
    int[][] opPInt2D(int[][] x, int[][] y);

    Integer[] WIntA = {new Integer(3), new Integer(5)};
    ArrayType WIntAType = ArrayTypeMaker.make(1, SimpleType.INTEGER);
    Integer[] getWIntA();
    void setWIntA(Integer[] x);
    Integer[] opWIntA(Integer[] x, Integer[] y);

    Integer[][] WInt2D = {{new Integer(3)}, {new Integer(5)}};
    ArrayType WInt2DType = ArrayTypeMaker.make(2, SimpleType.INTEGER);
    Integer[][] getWInt2D();
    void setWInt2D(Integer[][] x);
    Integer[][] opWInt2D(Integer[][] x, Integer[][] y);

    String XString = "yo!";
    SimpleType XStringType = SimpleType.STRING;
    String getXString();
    void setXString(String x);
    String opXString(String x, String y);

    String[] XStringA = {"hello", "world"};
    ArrayType XStringAType = ArrayTypeMaker.make(1, SimpleType.STRING);
    String[] getXStringA();
    void setXStringA(String[] x);
    String[] opXStringA(String[] x, String[] y);

    int[] NoInts = {};
    ArrayType NoIntsType = ArrayTypeMaker.make(SimpleType.INTEGER, true);
    int[] getNoInts();
    void setNoInts(int[] x);
    int[] opNoInts(int[] x, int[] y);

    GetSetBean GetSet = GetSetBean.make(5, "x", new String[] {"a", "b"});
    CompositeType GetSetType =
        CompositeTypeMaker.make(GetSetBean.class.getName(),
                                GetSetBean.class.getName(),
                                new String[] {"int", "string", "stringArray"},
                                new String[] {"int", "string", "stringArray"},
                                new OpenType[] {
                                    SimpleType.INTEGER,
                                    SimpleType.STRING,
                                    ArrayTypeMaker.make(1, SimpleType.STRING),
                                });
    GetSetBean getGetSet();
    void setGetSet(GetSetBean bean);
    GetSetBean opGetSet(GetSetBean x, GetSetBean y);

    GetterInterface Interface = new GetterInterface() {
        public boolean isWhatsit() {
            return true;
        }

        public int[] getInts() {
            return new int[] {1};
        }

        public String[] getStrings() {
            return new String[] {"x"};
        }

        public GetSetBean getGetSet() {
            return GetSetBean.make(3, "a", new String[] {"b"});
        }

        public boolean equals(Object o) {
            if (!(o instanceof GetterInterface))
                return false;
            GetterInterface i = (GetterInterface) o;
            return isWhatsit() == i.isWhatsit() &&
                   Arrays.equals(getInts(), i.getInts()) &&
                   Arrays.equals(getStrings(), i.getStrings()) &&
                   getGetSet().equals(i.getGetSet());
        }
     };
     CompositeType InterfaceType =
        CompositeTypeMaker.make(GetterInterface.class.getName(),
                                GetterInterface.class.getName(),
                                new String[] {
                                    "ints", "getSet", "strings", "whatsit",
                                },
                                new String[] {
                                    "ints", "getSet", "strings", "whatsit",
                                },
                                new OpenType[] {
                                    ArrayTypeMaker.make(SimpleType.INTEGER, true),
                                    GetSetType,
                                    ArrayTypeMaker.make(1, SimpleType.STRING),
                                    SimpleType.BOOLEAN,
                                });
     GetterInterface getInterface();
     void setInterface(GetterInterface i);
     GetterInterface opInterface(GetterInterface x, GetterInterface y);

    /* Testing that we can use a public no-arg constructor plus a setter
     * for every getter to reconstruct this object.  Note that the
     * constructor-guessing logic is no longer valid for this class,
     * so if we can reconstruct it it must be because of the setters.
     */
    public static class GetSetBean {
        public GetSetBean() {
            this(0, null, null);
        }

        private GetSetBean(int Int, String string, String[] stringArray) {
            this.Int = Int;
            this.string = string;
            this.stringArray = stringArray;
        }

        public static GetSetBean
                make(int Int, String string, String[] stringArray) {
            GetSetBean b = new GetSetBean(Int, string, stringArray);
            return b;
        }

        public int getInt() {
            return Int;
        }

        public String getString() {
            return this.string;
        }

        public String[] getStringArray() {
            return this.stringArray;
        }

        public void setInt(int x) {
            this.Int = x;
        }

        public void setString(String string) {
            this.string = string;
        }

        public void setStringArray(String[] stringArray) {
            this.stringArray = stringArray;
        }

        public boolean equals(Object o) {
            if (!(o instanceof GetSetBean))
                return false;
            GetSetBean b = (GetSetBean) o;
            return (b.Int == Int &&
                    b.string.equals(string) &&
                    Arrays.equals(b.stringArray, stringArray));
        }

        String string;
        String[] stringArray;
        int Int;
    }

    public static interface GetterInterface {
        public String[] getStrings();
        public int[] getInts();
        public boolean isWhatsit();
        public GetSetBean getGetSet();

        // We uselessly mention the public methods inherited from Object because
        // they should not prevent the interface from being translatable.
        // We could consider encoding the result of hashCode() and toString()
        // on the original object that implements this interface into the
        // generated CompositeData and referencing that in the proxy, but
        // that seems ambitious for now.  Doing it only if hashCode() and/or
        // toString() are mentioned in the interface is a possibility but
        // a rather abstruse one.
        public boolean equals(Object o);
        public int hashCode();
        public String toString();
    }

    public static class ArrayTypeMaker {
        static ArrayType make(int dims, OpenType baseType) {
            try {
                return new ArrayType(dims, baseType);
            } catch (OpenDataException e) {
                throw new Error(e);
            }
        }

        static ArrayType make(SimpleType baseType, boolean primitiveArray) {
            try {
                return new ArrayType(baseType, primitiveArray);
            } catch (OpenDataException e) {
                throw new Error(e);
            }
        }
    }

    public static class CompositeTypeMaker {
        static CompositeType make(String className,
                                  String description,
                                  String[] itemNames,
                                  String[] itemDescriptions,
                                  OpenType[] itemTypes) {
            try {
                return new CompositeType(className,
                                         description,
                                         itemNames,
                                         itemDescriptions,
                                         itemTypes);
            } catch (OpenDataException e) {
                throw new Error(e);
            }
        }
    }

    public static interface GraphMXBean {
        public NodeMXBean[] getNodes();
    }

    public static class Graph implements GraphMXBean {
        public Graph(Node... nodes) {
            for (Node node : nodes)
                node.setGraph(this);
            this.nodes = nodes;
        }

        public NodeMXBean[] getNodes() {
            return nodes;
        }

        private final Node[] nodes;
    }

    public static interface NodeMXBean {
        public String getName();
        public GraphMXBean getGraph();
    }

    public static class Node implements NodeMXBean {
        public Node(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public GraphMXBean getGraph() {
            return graph;
        }

        public void setGraph(Graph graph) {
            this.graph = graph;
        }

        private final String name;
        private Graph graph;
    }

    SimpleType GraphType = SimpleType.OBJECTNAME;
    GraphMXBean getGraph();
    void setGraph(GraphMXBean g);
    GraphMXBean opGraph(GraphMXBean x, GraphMXBean y);
    String GraphObjectName = "test:type=GraphMXBean";
    String NodeAObjectName = "test:type=NodeMXBean,name=a";
    String NodeBObjectName = "test:type=NodeMXBean,name=b";
    Node NodeA = new Node("a");
    Node NodeB = new Node("b");
    GraphMXBean Graph = new Graph(NodeA, NodeB);

    public static class ExoticCompositeData implements CompositeDataView {
        private ExoticCompositeData(String whatsit) {
            this.whatsit = whatsit;
        }

        public static ExoticCompositeData from(CompositeData cd) {
            String whatsit = (String) cd.get("whatsit");
            if (!whatsit.startsWith("!"))
                throw new IllegalArgumentException(whatsit);
            return new ExoticCompositeData(whatsit.substring(1));
        }

        public CompositeData toCompositeData(CompositeType ct) {
            try {
                return new CompositeDataSupport(ct, new String[] {"whatsit"},
                                                new String[] {"!" + whatsit});
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        public String getWhatsit() {
            return whatsit;
        }

        public boolean equals(Object o) {
            return ((o instanceof ExoticCompositeData) &&
                    ((ExoticCompositeData) o).whatsit.equals(whatsit));
        }

        private final String whatsit;

        public static final CompositeType type;
        static {
            try {
                type =
                    new CompositeType(ExoticCompositeData.class.getName(),
                                      ExoticCompositeData.class.getName(),
                                      new String[] {"whatsit"},
                                      new String[] {"whatsit"},
                                      new OpenType[] {SimpleType.STRING});
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    CompositeType ExoticType = ExoticCompositeData.type;
    ExoticCompositeData getExotic();
    void setExotic(ExoticCompositeData ecd);
    ExoticCompositeData opExotic(ExoticCompositeData ecd1,
                                 ExoticCompositeData ecd2);
    ExoticCompositeData Exotic = new ExoticCompositeData("foo");
}