@Before public void setUp() throws Exception { payload = new byte[333]; Arrays.fill(payload, (byte) 1); m1 = new MemberImpl("localhost", 3333, 1, payload); m2 = new MemberImpl("localhost", 3333, 1); payload = new byte[333]; Arrays.fill(payload, (byte) 2); p1 = new MemberImpl("127.0.0.1", 3333, 1, payload); p2 = new MemberImpl("localhost", 3331, 1, payload); m1.setDomain(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9}); m2.setDomain(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9}); m1.setCommand(new byte[] {1, 2, 4, 5, 6, 7, 8, 9}); m2.setCommand(new byte[] {1, 2, 4, 5, 6, 7, 8, 9}); m1.setUdpPort(udpPort); m2.setUdpPort(m1.getUdpPort()); }
/** Sets the local member properties for broadcasting */ @Override public void setLocalMemberProperties( String listenHost, int listenPort, int securePort, int udpPort) { properties.setProperty("tcpListenHost", listenHost); properties.setProperty("tcpListenPort", String.valueOf(listenPort)); properties.setProperty("udpListenPort", String.valueOf(udpPort)); properties.setProperty("tcpSecurePort", String.valueOf(securePort)); try { if (localMember != null) { localMember.setHostname(listenHost); localMember.setPort(listenPort); } else { localMember = new MemberImpl(listenHost, listenPort, 0); localMember.setUniqueId(UUIDGenerator.randomUUID(true)); localMember.setPayload(getPayload()); localMember.setDomain(getDomain()); } localMember.setSecurePort(securePort); localMember.setUdpPort(udpPort); localMember.getData(true, true); } catch (IOException x) { throw new IllegalArgumentException(x); } }
@Override public void start(int level) throws java.lang.Exception { hasProperty(properties, "mcastPort"); hasProperty(properties, "mcastAddress"); hasProperty(properties, "memberDropTime"); hasProperty(properties, "mcastFrequency"); hasProperty(properties, "tcpListenPort"); hasProperty(properties, "tcpListenHost"); hasProperty(properties, "tcpSecurePort"); hasProperty(properties, "udpListenPort"); if (impl != null) { impl.start(level); return; } String host = getProperties().getProperty("tcpListenHost"); int port = Integer.parseInt(getProperties().getProperty("tcpListenPort")); int securePort = Integer.parseInt(getProperties().getProperty("tcpSecurePort")); int udpPort = Integer.parseInt(getProperties().getProperty("udpListenPort")); if (localMember == null) { localMember = new MemberImpl(host, port, 100); localMember.setUniqueId(UUIDGenerator.randomUUID(true)); } else { localMember.setHostname(host); localMember.setPort(port); localMember.setMemberAliveTime(100); } localMember.setSecurePort(securePort); localMember.setUdpPort(udpPort); if (this.payload != null) localMember.setPayload(payload); if (this.domain != null) localMember.setDomain(domain); localMember.setServiceStartTime(System.currentTimeMillis()); java.net.InetAddress bind = null; if (properties.getProperty("mcastBindAddress") != null) { bind = java.net.InetAddress.getByName(properties.getProperty("mcastBindAddress")); } int ttl = -1; int soTimeout = -1; if (properties.getProperty("mcastTTL") != null) { try { ttl = Integer.parseInt(properties.getProperty("mcastTTL")); } catch (Exception x) { log.error(sm.getString("McastService.parseTTL", properties.getProperty("mcastTTL")), x); } } if (properties.getProperty("mcastSoTimeout") != null) { try { soTimeout = Integer.parseInt(properties.getProperty("mcastSoTimeout")); } catch (Exception x) { log.error( sm.getString("McastService.parseSoTimeout", properties.getProperty("mcastSoTimeout")), x); } } impl = new McastServiceImpl( localMember, Long.parseLong(properties.getProperty("mcastFrequency")), Long.parseLong(properties.getProperty("memberDropTime")), Integer.parseInt(properties.getProperty("mcastPort")), bind, java.net.InetAddress.getByName(properties.getProperty("mcastAddress")), ttl, soTimeout, this, this, Boolean.valueOf(properties.getProperty("localLoopbackDisabled", "false")) .booleanValue()); String value = properties.getProperty("recoveryEnabled", "true"); boolean recEnabled = Boolean.valueOf(value).booleanValue(); impl.setRecoveryEnabled(recEnabled); int recCnt = Integer.parseInt(properties.getProperty("recoveryCounter", "10")); impl.setRecoveryCounter(recCnt); long recSlpTime = Long.parseLong(properties.getProperty("recoverySleepTime", "5000")); impl.setRecoverySleepTime(recSlpTime); impl.start(level); }