001
014
015 package com.liferay.util.transport;
016
017 import com.liferay.portal.kernel.util.StringBundler;
018
019 import java.util.HashMap;
020 import java.util.Map;
021
022
031 public class MulticastClientTool {
032
033 public static void main(String[] args) {
034 try {
035 new MulticastClientTool(args);
036 }
037 catch (Exception e) {
038 e.printStackTrace();
039
040 StringBundler sb = new StringBundler(4);
041
042 sb.append("Usage: java -classpath ");
043 sb.append("commons-logging.jar:util-java.jar ");
044 sb.append("com.liferay.util.transport.MulticastClientTool [-g] ");
045 sb.append("[-s] -h [multicastAddress] -p [port]");
046
047 System.err.println(sb.toString());
048
049 System.exit(1);
050 }
051 }
052
053 private MulticastClientTool(String[] args) throws Exception {
054 Map<String, Object> argsMap = _getArgsMap(args);
055
056 Integer port = (Integer)argsMap.get("port");
057 String host = (String)argsMap.get("host");
058 Boolean gzipData = (Boolean)argsMap.get("gzip");
059 Boolean shortData = (Boolean)argsMap.get("short");
060
061 DatagramHandler handler = new MulticastDatagramHandler(
062 gzipData.booleanValue(), shortData.booleanValue());
063
064 MulticastTransport transport = new MulticastTransport(
065 handler, host, port);
066
067 if (shortData.booleanValue()) {
068 System.out.println("Truncating to 96 bytes.");
069 }
070
071 System.out.println("Started up and waiting...");
072
073 transport.connect();
074
075 synchronized (transport) {
076 transport.wait();
077 }
078 }
079
080 private Map<String, Object> _getArgsMap(String[] args)
081 throws Exception {
082
083 Map<String, Object> argsMap = new HashMap<String, Object>();
084
085 for (int i = 0; i < args.length; i++) {
086 if (args[i].equals("-g")) {
087 argsMap.put("gzip", Boolean.TRUE);
088 }
089 else if (args[i].equals("-s")) {
090 argsMap.put("short", Boolean.TRUE);
091 }
092 else if (args[i].equals("-h")) {
093 argsMap.put("host", args[i + 1]);
094
095 i++;
096 }
097 else if (args[i].equals("-p")) {
098 argsMap.put("port", new Integer(args[i + 1]));
099
100 i++;
101 }
102 }
103
104 if (!argsMap.containsKey("gzip")) {
105 argsMap.put("gzip", Boolean.FALSE);
106 }
107
108 if (!argsMap.containsKey("short")) {
109 argsMap.put("short", Boolean.FALSE);
110 }
111
112 return argsMap;
113 }
114
115 }