360
|
1 package alice.datasegment;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.net.InetAddress;
|
|
5 import java.net.NetworkInterface;
|
|
6 import java.net.StandardProtocolFamily;
|
|
7 import java.net.StandardSocketOptions;
|
|
8 import java.nio.channels.DatagramChannel;
|
|
9 import org.apache.log4j.Logger;
|
|
10
|
|
11 import alice.codesegment.CodeSegment;
|
|
12 import alice.daemon.Connection;
|
|
13
|
|
14 public class MulticastDataSegmentManager extends DataSegmentManager {
|
|
15 Connection connection;
|
|
16 Logger logger;
|
|
17
|
|
18 public MulticastDataSegmentManager(final String MCASTADDR, final int port, final String nis) {
|
|
19 logger = Logger.getLogger("multicast");
|
|
20 connection = new Connection();
|
|
21 DatagramChannel dc = createDatagramChannel(MCASTADDR, port, nis);
|
|
22
|
|
23 }
|
|
24
|
|
25 private DatagramChannel createDatagramChannel(String MCASTADDR, int port, String nis) {
|
|
26 DatagramChannel dc = null;
|
|
27 NetworkInterface ni;
|
|
28 try {
|
|
29 ni = NetworkInterface.getByName(nis);
|
|
30 if (ni==null) {
|
|
31 System.err.println("Can't open network interface "+nis);
|
|
32 throw new IOException();
|
|
33 }
|
|
34 if (!ni.supportsMulticast()) {
|
|
35 System.err.println("Network interface does not support multicast"+nis);
|
|
36 throw new IOException();
|
|
37 }
|
|
38
|
|
39 dc = DatagramChannel.open(StandardProtocolFamily.INET);
|
|
40 dc.setOption(StandardSocketOptions.SO_REUSEADDR, true);
|
|
41 dc.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni);
|
|
42 InetAddress group = InetAddress.getByName(MCASTADDR);
|
|
43 dc.join(group, ni);
|
|
44 } catch (Exception e) {
|
|
45 e.printStackTrace();
|
|
46 }
|
|
47 return dc;
|
|
48 }
|
|
49
|
|
50 @Override
|
|
51 public void put(String key, Object val) {
|
|
52
|
|
53 }
|
|
54
|
|
55 @Override
|
|
56 public void update(String key, Object val) {
|
|
57
|
|
58 }
|
|
59
|
|
60 @Override
|
|
61 public void take(Receiver receiver, CodeSegment cs) {}
|
|
62 @Override
|
|
63 public void peek(Receiver receiver, CodeSegment cs) {}
|
|
64
|
|
65 @Override
|
|
66 public void quickPut(String key, Object val) {
|
|
67
|
|
68 }
|
|
69
|
|
70 @Override
|
|
71 public void quickUpdate(String key, Object val) {
|
|
72
|
|
73 }
|
|
74
|
|
75 @Override
|
|
76 public void quickPeek(Receiver receiver, CodeSegment cs) {}
|
|
77 @Override
|
|
78 public void quickTake(Receiver receiver, CodeSegment cs) {}
|
|
79
|
|
80 @Override
|
|
81 public void remove(String key) {
|
|
82
|
|
83 }
|
|
84
|
|
85 @Override
|
|
86 public void shutdown() {
|
|
87
|
|
88 }
|
|
89
|
|
90 @Override
|
|
91 public void close() {
|
|
92
|
|
93 }
|
|
94
|
|
95 @Override
|
|
96 public void finish() {
|
|
97
|
|
98 }
|
|
99
|
|
100 @Override
|
|
101 public void ping(String returnKey) {}
|
|
102
|
|
103 @Override
|
|
104 public void response(String returnKey) {}
|
|
105
|
|
106 }
|