| MulticastClientTool.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.util.transport;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 /**
29 * <a href="MulticastClientTool.java.html"><b><i>View Source</i></b></a>
30 *
31 * <p>
32 * A client that listens for multicast messages at a designated port. You may
33 * use this to for potential multicast issues when tuning distributed caches.
34 * </p>
35 *
36 * @author Michael C. Han
37 * @author Raymond Augé
38 */
39 public class MulticastClientTool {
40
41 public static void main(String[] args) {
42 try {
43 new MulticastClientTool(args);
44 }
45 catch (Exception e) {
46 e.printStackTrace();
47
48 StringBuilder sb = new StringBuilder();
49
50 sb.append("Usage: java -classpath ");
51 sb.append("commons-logging.jar:util-java.jar ");
52 sb.append("com.liferay.util.transport.MulticastClientTool [-g] ");
53 sb.append("[-s] -h [multicastAddress] -p [port]");
54
55 System.err.println(sb.toString());
56
57 System.exit(1);
58 }
59 }
60
61 private MulticastClientTool(String[] args) throws Exception {
62 Map<String, Object> argsMap = _getArgsMap(args);
63
64 Integer port = (Integer)argsMap.get("port");
65 String host = (String)argsMap.get("host");
66 Boolean gzipData = (Boolean)argsMap.get("gzip");
67 Boolean shortData = (Boolean)argsMap.get("short");
68
69 DatagramHandler handler = new MulticastDatagramHandler(
70 gzipData.booleanValue(), shortData.booleanValue());
71
72 MulticastTransport transport = new MulticastTransport(
73 handler, host, port);
74
75 if (shortData.booleanValue()) {
76 System.out.println("Truncating to 96 bytes.");
77 }
78
79 System.out.println("Started up and waiting...");
80
81 transport.connect();
82
83 synchronized (transport) {
84 transport.wait();
85 }
86 }
87
88 private Map<String, Object> _getArgsMap(String[] args)
89 throws Exception {
90
91 Map<String, Object> argsMap = new HashMap<String, Object>();
92
93 for (int i = 0; i < args.length; i++) {
94 if (args[i].equals("-g")) {
95 argsMap.put("gzip", Boolean.TRUE);
96 }
97 else if (args[i].equals("-s")) {
98 argsMap.put("short", Boolean.TRUE);
99 }
100 else if (args[i].equals("-h")) {
101 argsMap.put("host", args[i + 1]);
102
103 i++;
104 }
105 else if (args[i].equals("-p")) {
106 argsMap.put("port", new Integer(args[i + 1]));
107
108 i++;
109 }
110 }
111
112 if (!argsMap.containsKey("gzip")) {
113 argsMap.put("gzip", Boolean.FALSE);
114 }
115
116 if (!argsMap.containsKey("short")) {
117 argsMap.put("short", Boolean.FALSE);
118 }
119
120 return argsMap;
121 }
122
123 }