1 package org.rpi.songcast;
2
3 import java.net.InetAddress;
4
5 import org.apache.log4j.Logger;
6
7 public class OHZManager {
8
9 private Logger log = Logger.getLogger(this.getClass());
10
11 private int mcastPort = 51970;
12
13 private InetAddress mcastAddr = null;
14
15 private String zoneID = "";
16
17 private Thread tReceiver =null;
18
19 private Thread tSender = null;
20
21 private UDPReceiver udpReceiver = null;
22 private UDPSender udpSender = null;
23
24 public OHZManager(String uri, String zoneID) {
25 try {
26 int lastColon = uri.lastIndexOf(":");
27 int lastSlash = uri.lastIndexOf("/");
28 String host = uri.substring(lastSlash + 1, lastColon);
29 String sPort = uri.substring(lastColon + 1);
30 mcastAddr = InetAddress.getByName(host);
31 mcastPort = Integer.parseInt(sPort);
32 this.zoneID = zoneID;
33 } catch (Exception e) {
34 log.error(e);
35 }
36
37 }
38
39 public void start() {
40
41 udpReceiver = new UDPReceiver(mcastPort, mcastAddr, zoneID);
42 tReceiver = new Thread(udpReceiver, "McastReceiver");
43
44
45 tReceiver.start();
46
47 while(!udpReceiver.isConnected())
48 {
49 try {
50 Thread.sleep(500);
51 } catch (InterruptedException e) {
52 }
53 }
54
55
56 udpSender = new UDPSender(mcastPort, mcastAddr, zoneID);
57 tSender = new Thread(udpSender, "McastRepeater");
58 tSender.start();
59 OHZJoin join = new OHZJoin(zoneID);
60 udpSender.put(join.data);
61 }
62
63
64 public void stop()
65 {
66 udpSender.disconnect();
67 udpReceiver.disconnect();
68 tReceiver = null;
69 tSender = null;
70 }
71
72 }