annotate src/main/java/alice/datasegment/MulticastDataSegmentManager.java @ 360:6cf08aebfc31 multicast

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