Mercurial > hg > Members > tatsuki > Alice
view src/alice/topology/node/StartTopologyNode.java @ 258:7f7b3506bff9
client can get connection list setkey(_CLIST);
author | sugi |
---|---|
date | Sat, 13 Jul 2013 20:55:32 +0900 |
parents | 75150396681c |
children | c0712e0b0a24 |
line wrap: on
line source
package alice.topology.node; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.UnknownHostException; import java.util.Enumeration; import alice.codesegment.CodeSegment; import alice.datasegment.DataSegment; import alice.topology.HostMessage; public class StartTopologyNode extends CodeSegment { private TopologyNodeConfig conf; private CodeSegment startCS; public StartTopologyNode(TopologyNodeConfig conf, CodeSegment startCS) { this.conf = conf; this.startCS = startCS; } @Override public void run() { DataSegment.connect("manager", "", conf.managerHostName, conf.managerPort); String localHostName = null; try { localHostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { e.printStackTrace(); } HostMessage host = new HostMessage(localHostName, conf.localPort); ods.put("manager", "host", host); IncomingAbstractHostName cs = new IncomingAbstractHostName(); cs.absName.setKey("local", "host"); IncomingReverseKey cs2 = new IncomingReverseKey(); cs2.reverseKey.setKey("local", "reverseKey"); cs2.reverseCount.setKey("local", "reverseCount"); ods.put("local", "reverseCount", 0); ConfigurationFinish cs3 = new ConfigurationFinish(startCS); cs3.reverseCount.setKey("local", "reverseCount"); cs3.configNodeNum.setKey("local", "configNodeNum"); } @SuppressWarnings("unused") private String getIPAddress() throws SocketException { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while(interfaces.hasMoreElements()){ NetworkInterface network = interfaces.nextElement(); Enumeration<InetAddress> addresses = network.getInetAddresses(); while(addresses.hasMoreElements()){ String address = addresses.nextElement().getHostAddress(); if(!"127.0.0.1".equals(address) && !"0.0.0.0".equals(address)){ return address; } } } return "127.0.0.1"; } }