Mercurial > hg > Database > Alice
view src/main/java/alice/datasegment/MulticastDataSegmentManager.java @ 361:60eee1fb0fd3 multicast
create sender with udp
author | sugi |
---|---|
date | Thu, 15 May 2014 18:29:30 +0900 |
parents | 6cf08aebfc31 |
children | 1494d44392a2 |
line wrap: on
line source
package alice.datasegment; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.NetworkInterface; import java.net.SocketAddress; import java.net.StandardProtocolFamily; import java.net.StandardSocketOptions; import java.nio.channels.DatagramChannel; import org.apache.log4j.Logger; import alice.codesegment.CodeSegment; import alice.daemon.IncomingUdpConnection; import alice.daemon.MulticastConnection; import alice.daemon.OutboundTcpConnection; public class MulticastDataSegmentManager extends DataSegmentManager { MulticastConnection sender; Logger logger; public MulticastDataSegmentManager(final String MCASTADDR, final int port, final String nis) { logger = Logger.getLogger("multicast"); InetAddress mAddr; try { mAddr = InetAddress.getByName(MCASTADDR); DatagramChannel dcr = createDatagramChannel(mAddr, port, nis); dcr.bind(new InetSocketAddress(port)); SocketAddress sAddrr = new InetSocketAddress(mAddr,port); MulticastConnection receiver = new MulticastConnection(dcr, sAddrr); new IncomingUdpConnection(receiver).start(); DatagramChannel dcs = createDatagramChannel(mAddr, port, nis); SocketAddress sAddrs = new InetSocketAddress(mAddr,port); sender = new MulticastConnection(dcs, sAddrs); new OutboundTcpConnection(sender).start(); // OutboundUdpConnection sender } catch (Exception e) { e.printStackTrace(); } } private DatagramChannel createDatagramChannel(InetAddress group, int port, String nis) { DatagramChannel dc = null; NetworkInterface ni; try { ni = NetworkInterface.getByName(nis); if (ni==null) { System.err.println("Can't open network interface "+nis); throw new IOException(); } if (!ni.supportsMulticast()) { System.err.println("Network interface does not support multicast"+nis); throw new IOException(); } dc = DatagramChannel.open(StandardProtocolFamily.INET); dc.setOption(StandardSocketOptions.SO_REUSEADDR, true); dc.setOption(StandardSocketOptions.IP_MULTICAST_IF, ni); dc.join(group, ni); } catch (Exception e) { e.printStackTrace(); } return dc; } @Override public void put(String key, Object val) { } @Override public void update(String key, Object val) { } @Override public void take(Receiver receiver, CodeSegment cs) {} @Override public void peek(Receiver receiver, CodeSegment cs) {} @Override public void quickPut(String key, Object val) { } @Override public void quickUpdate(String key, Object val) { } @Override public void quickPeek(Receiver receiver, CodeSegment cs) {} @Override public void quickTake(Receiver receiver, CodeSegment cs) {} @Override public void remove(String key) { } @Override public void shutdown() { } @Override public void close() { } @Override public void finish() { } @Override public void ping(String returnKey) {} @Override public void response(String returnKey) {} }