jdk/test/sun/management/jdp/ClientConnection.java
author sla
Mon, 07 Apr 2014 08:09:55 +0200
changeset 23723 46b29c0e9656
parent 23010 6dadb192ad81
permissions -rw-r--r--
8039256: Add sun/jvmstat/monitor/MonitoredVm/CR6672135.java to ProblemList.txt Reviewed-by: mgronlun, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21646
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21646
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
21646
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
     4
 *
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
     7
 * published by the Free Software Foundation.
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
     8
 *
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    13
 * accompanied this code).
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    14
 *
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    18
 *
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    21
 * questions.
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    22
 */
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    23
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    24
import java.io.IOException;
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    25
import java.net.InetAddress;
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    26
import java.net.MulticastSocket;
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    27
import java.net.UnknownHostException;
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    28
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    29
public class ClientConnection {
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    30
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    31
    public final String IANA_JDP_ADDRESS = "224.0.23.178";
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    32
    public final String IANA_JDP_PORT = "7095";
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    33
    public final String UNDEFINED_NAME = "TheVMwithNoName";
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    34
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    35
    public final int port;
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    36
    public final InetAddress address;
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    37
    public final int pauseInSeconds;
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    38
    public final String instanceName;
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    39
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    40
    public ClientConnection()
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    41
            throws UnknownHostException {
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    42
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    43
        String discoveryAddress = System.getProperty("com.sun.management.jdp.address", IANA_JDP_ADDRESS);
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    44
        address = InetAddress.getByName(discoveryAddress);
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    45
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    46
        String discoveryPort = System.getProperty("com.sun.management.jdp.port", IANA_JDP_PORT);
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    47
        port = Integer.parseInt(discoveryPort);
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    48
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    49
        String pause = System.getProperty("com.sun.management.jdp.pause", "1");
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    50
        pauseInSeconds = Integer.parseUnsignedInt(pause);
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    51
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    52
        instanceName = System.getProperty("com.sun.management.jdp.name", UNDEFINED_NAME);
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    53
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    54
    }
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    55
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    56
    public MulticastSocket connectWithTimeout(int msTimeOut) throws IOException {
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    57
        MulticastSocket socket = new MulticastSocket(port);
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    58
        socket.joinGroup(address);
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    59
        socket.setSoTimeout(msTimeOut);
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    60
        return socket;
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    61
    }
38f9ba0664de 8014506: Test of Jdp feature
sla
parents:
diff changeset
    62
}