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