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 package org.archive.hcc.client;
27
28 import java.net.InetAddress;
29 import java.net.InetSocketAddress;
30 import java.util.logging.Level;
31 import java.util.logging.Logger;
32
33 /***
34 * This class manages singleton instances of the ClusterControllerClient. Within
35 * a jvm there will be one instance of ClusterControllerClient for each jmx
36 * socket address (assuming that a ClusterControllerBean is running on that
37 * local or remote socket).
38 *
39 * @author Daniel Bernstein (dbernstein@archive.org)
40 *
41 */
42 public class ClusterControllerClientManager {
43 private static Logger log = Logger
44 .getLogger(ClusterControllerClientManager.class.getName());
45
46 private static ClusterControllerClient defaultClient;
47
48 /***
49 * Returns this singleton instance of the default cluster controller client.
50 * The host and jmx port can be set in the following command line options.
51 * -Dorg.archive.hcc.client.host={your host}
52 * -Dorg.archive.hcc.client.jmxPort={your port}
53 *
54 * If you do not specify these values on the command line, the client will
55 * connect to the local jmx server on port 8849.
56 *
57 * @return
58 */
59 public static ClusterControllerClient getDefaultClient() {
60 try {
61 if (defaultClient == null) {
62 String host = System.getProperty(
63 "org.archive.hcc.client.host",
64 InetAddress.getLocalHost().getHostName());
65
66 int jmxPort = Integer.parseInt(System.getProperty(
67 "org.archive.hcc.client.jmxPort",
68 "8849"));
69 InetSocketAddress address = new InetSocketAddress(host, jmxPort);
70 defaultClient = new ClusterControllerClientImpl(address);
71 }
72
73 return defaultClient;
74 } catch (Exception e) {
75 e.printStackTrace();
76 if (log.isLoggable(Level.SEVERE)) {
77 log.severe(": " + e.getMessage());
78 }
79
80 throw new RuntimeException(e);
81 }
82 }
83
84 /***
85 * Removes the manager's reference to the default client for use with unit
86 * tests.
87 */
88 public static void resetDefaultClient() {
89 defaultClient = null;
90 }
91
92 }