public void setPort(int p) { IpAddress i = new IpAddress(ipAddr.getIpAddress(), p); i.setFlags(ipAddr.getFlags()); i.setVmKind(ipAddr.getVmKind()); i.setDirectPort(ipAddr.getDirectPort()); i.setProcessId(ipAddr.getProcessId()); i.setRoles(ipAddr.getRoles()); i.setDurableClientAttributes(ipAddr.getDurableClientAttributes()); i.setVersionOrdinal(ipAddr.getVersionOrdinal()); this.ipAddr = i; } }
/** * For Externalizable * * @see java.io.Externalizable */ public void writeExternal(ObjectOutput out) throws IOException { if (ipAddr == null) throw new InternalGemFireError(LocalizedStrings.JGroupMember_ATTEMPT_TO_EXTERNALIZE_NULL_IP_ADDRESS.toLocalizedString()); // ipAddr.writeExternal(out); // do it the way we like byte[] address = ipAddr.getIpAddress().getAddress(); out.writeInt(address.length); // IPv6 compatible out.write(address); out.writeInt(ipAddr.getPort()); out.write(ipAddr.getFlags()); Version.writeOrdinal(out, ipAddr.getVersionOrdinal(), true); byte bytes[] = new MemberAttributes(ipAddr.getDirectPort(), ipAddr.getProcessId(), ipAddr.getVmKind(), ipAddr.getBirthViewId(), ipAddr.getName(), ipAddr.getRoles(), (DurableClientAttributes)ipAddr.getDurableClientAttributes()).toByteArray(); if (bytes == null) out.writeInt(0); else { out.writeInt(bytes.length); out.write(bytes); } }
private String memberName(Address m) { if (!(m instanceof IpAddress)) return m.toString(); IpAddress im = (IpAddress)m; StringBuffer sb = new StringBuffer(); sb.append(im.toString()); int port = im.getDirectPort(); if (port > 0) { sb.append('/'); sb.append(port); } return sb.toString(); }
/** * Create a CacheMember referring to the current host (as defined by * the given string). * * @param i the hostname, must be for the current host * @param p the membership listening port * @param splitBrainEnabled whether the member has network partition detection enabled * @param canBeCoordinator whether the member can be group coordinator */ public JGroupMember(InetAddress i, int p, boolean splitBrainEnabled, boolean canBeCoordinator) { ipAddr = new IpAddress(i, p); ipAddr.splitBrainEnabled(splitBrainEnabled); ipAddr.shouldntBeCoordinator(!canBeCoordinator); }
/** * Print addresses in host_ip:port form to bypass DNS */ private String _addrToString(Object addr) { return ( addr == null ? "<null>" : ((addr instanceof com.gemstone.org.jgroups.stack.IpAddress) ? (((com.gemstone.org.jgroups.stack.IpAddress)addr).getIpAddress( ).getHostAddress() + ':' + ((com.gemstone.org.jgroups.stack.IpAddress)addr).getPort()) : addr.toString()) ); }
public void testAddressEquality() throws Exception { IpAddress addr1 = new IpAddress(InetAddress.getLocalHost(), 1234); IpAddress addr2 = new IpAddress(addr1.getIpAddress(), addr1.getPort()); if (!addr1.equals(addr2)) { fail("expected addresses to be equal"); } addr2.setBirthViewId(4); if (!addr1.equals(addr2)) { fail("expected addresses to be equal"); } addr1.setBirthViewId(0); int comparison = addr1.compareTo(addr2); if (comparison >= 0) { fail("expected addresses to be unequal but compareTo returned " + comparison); } }
/** * Create a CacheMember referring to the current host (as defined by * the given string). * * @param i the hostname, must be for the current host * @param p the membership listening port */ public JGroupMember(String i, int p) { ipAddr = new IpAddress(i, p); // ipAddr.splitBrainEnabled(false); // ipAddr.cantBeCoordinator(false); }
public static void insertGemFireAttributes(IpAddress addr, Object obj) { MemberAttributes attr = (MemberAttributes)obj; addr.setProcessId(attr.getVmPid()); addr.setVmKind(attr.getVmKind()); addr.setDirectPort(attr.getPort()); addr.setBirthViewId(attr.getVmViewId()); addr.setName(attr.getName()); addr.setRoles(attr.getGroups()); addr.setDurableClientAttributes(attr.getDurableClientAttributes()); addr.setSize(-1); addr.setSize(addr.size(Version.CURRENT_ORDINAL)); }
public void beHealthy() { // GemStoneAddition srv_sock_handler.beSick = false; // synchronized(srv_sock_handler.sicknessGuard) { // srv_sock_handler.sicknessGuard.notifyAll(); // } // try to start up with the same address/port srv_sock=Util.createServerSocket(srv_sock_addr.getIpAddress(), srv_sock_addr.getPort(), 65535); if (srv_sock_addr.getPort() != srv_sock.getLocalPort()) { // oops - couldn't get the same port. Things won't work if we don't tell others about it sendIHaveSockMessage(null, local_addr, srv_sock_addr); } srv_sock_addr=new IpAddress(srv_sock_bind_addr, srv_sock.getLocalPort()); startServerSocket(); }
public IpAddress call() throws Exception { log.getLogWriter().info(ExternalStrings.SUSPECTING_MEMBER_WHICH_DIDNT_ACK, new Object[]{failedAddress.toString()}); if (sockAddress == null) { if (log.getLogWriter().fineEnabled()) { log.getLogWriter().fine("unable to find ping address for " + failedAddress + " - using direct port to verify if it's there"); } // fdSock can't perform the verification because it has no FD_SOCK // address for the member // If we can connect to the member's cache socket, then we know its machine is // up. It may be dead and its socket port reused, but we know there isn't a // network partition going on. sockAddress = new IpAddress(failedAddress.getIpAddress(), failedAddress.getDirectPort()); if (sockAddress.getPort() != 0 && fdSock.checkSuspect(failedAddress, sockAddress, ExternalStrings.MEMBER_DID_NOT_ACKNOWLEDGE_VIEW.toLocalizedString(), false, false)) { if (log.getLogWriter().infoEnabled()) { log.getLogWriter().info(ExternalStrings.ABLE_TO_CONNECT_TO_DC_PORT, new Object[]{failedAddress, sockAddress.getPort()}); } return failedAddress;//now we remove below using feature } } else if (fdSock.checkSuspect(failedAddress, sockAddress, ExternalStrings.MEMBER_DID_NOT_ACKNOWLEDGE_VIEW.toLocalizedString(), true, false)) { if (log.getLogWriter().infoEnabled()) { log.getLogWriter().info(ExternalStrings.ABLE_TO_CONNECT_TO_FD_PORT, new Object[]{failedAddress, sockAddress.getPort()}); } return failedAddress;//now we remove below using feature } return null; } }
final GossipClient client2 = new GossipClient(new IpAddress(InetAddress.getLocalHost(), port1), 500); Vector<IpAddress> members = client2.getMembers("mygroup1", new IpAddress(InetAddress.getLocalHost(), port1), true, 5000); Assert.assertEquals(2, members.size()); int port = ipAddr.getPort(); String hostname = ipAddr.getIpAddress().getHostAddress(); int pid = ipAddr.getProcessId(); Assert.assertTrue(" " + ipAddr, port == port0 || port == port1); Assert.assertTrue(" " + ipAddr, hostname.equals(InetAddress.getLocalHost().getHostAddress()));
MemberAttributes.DEFAULT.getVmPid(), MemberAttributes.DEFAULT.getVmKind(), myAddr.getBirthViewId(), MemberAttributes.DEFAULT.getName(), MemberAttributes.DEFAULT.getGroups(), MemberAttributes.DEFAULT.getDurableClientAttributes()); directChannel.getConduit().setVmViewID(myAddr.getBirthViewId()); myMemberId = new InternalDistributedMember(myAddr.getIpAddress(), myAddr.getPort(), myAddr.splitBrainEnabled(), myAddr.preferredForCoordinator(), MemberAttributes.DEFAULT);
new IpAddress("localhost", 1), new IpAddress("localhost", 2), new IpAddress("localhost", 3), new IpAddress("localhost", 4), new IpAddress("localhost", 5), new IpAddress("localhost", 6)}; int i = 0; members[i].setVmKind(DistributionManager.LOCATOR_DM_TYPE); members[i++].shouldntBeCoordinator(false); members[i].setVmKind(DistributionManager.LOCATOR_DM_TYPE); members[i++].shouldntBeCoordinator(false); members[i].setVmKind(DistributionManager.NORMAL_DM_TYPE); members[i++].shouldntBeCoordinator(true); members[i].setVmKind(DistributionManager.ADMIN_ONLY_DM_TYPE); members[i++].shouldntBeCoordinator(true); members[i].setVmKind(DistributionManager.ADMIN_ONLY_DM_TYPE); members[i++].shouldntBeCoordinator(true); members[i].setVmKind(DistributionManager.NORMAL_DM_TYPE); members[i++].shouldntBeCoordinator(true); assertTrue(!leader.preferredForCoordinator()); IpAddress joiningMember = new IpAddress("localhost", 7); joiningMember.setVmKind(DistributionManager.NORMAL_DM_TYPE); joiningMember.shouldntBeCoordinator(true);
while (it.hasNext()) { entry = (IpAddress)it.next(); entry.setBirthViewId(0); if(entry.getIpAddress() == null || entry.getPort() == 0) { if(log.isTraceEnabled()) log.trace("GET_REQ --> " + entry.getIpAddress() + ':' + entry.getPort()); entry.getIpAddress(), entry.getPort(), log.getLogWriter(), this.timeout, timeoutTask, false); if (entry.getVersionOrdinal() <= JGroupsVersion.CURRENT_ORDINAL) { serverOrdinal = entry.getVersionOrdinal(); gossipVersion = JChannel.getGfFunctions().getGossipVersionForOrdinal(serverOrdinal);
log.trace("GEMFIRE_VERSION --> " + entry.getIpAddress() + ':' + +entry.getPort()); entry.getIpAddress(), entry.getPort(), log.getLogWriter(), 2 * this.timeout, timeoutTask, false); if (entry.getVersionOrdinal() <= JGroupsVersion.CURRENT_ORDINAL) { serverOrdinal = entry.getVersionOrdinal(); gossipVersion = JChannel.getGfFunctions().getGossipVersionForOrdinal(serverOrdinal); entry.setVersionOrdinal((short)versionOrdinal.intValue());
if (iaddr.getBirthViewId() >= 0 && this.stack.gfPeerFunctions.isShunnedMemberNoSync(iaddr)) { log.getLogWriter().info( ExternalStrings. COORDGMSIMPL_REJECTING_0_DUE_TO_REUSED_IDENTITY, hdr.mbr); for (Iterator it=members.getMembers().iterator(); it.hasNext(); ) { IpAddress addr = (IpAddress)it.next(); if (addr.equals(hdr.mbr)) { if (addr.getUniqueID() != hmbr.getUniqueID()) { log.getLogWriter().info( ExternalStrings. COORDGMSIMPL_REJECTING_0_DUE_TO_REUSED_IDENTITY, hdr.mbr); ((IpAddress)local_addr).splitBrainEnabled(this.splitBrainDetectionEnabled); ((IpAddress)local_addr).setMemberWeight(this.memberWeight); log.getLogWriter().fine("This member of the distributed system will only be a coordinator if there are no locators available"); ((IpAddress)local_addr).shouldntBeCoordinator(true); Event newaddr = new Event(Event.SET_LOCAL_ADDRESS, this.local_addr);
while (it.hasNext()) { entry = (IpAddress)it.next(); if(entry.getIpAddress() == null || entry.getPort() == 0) { log.trace("REGISTER_REQ --> " + entry.getIpAddress() + ':' + entry.getPort()); entry.getIpAddress(), entry.getPort(), log.getLogWriter(), 2 * this.timeout, timeoutTask, false); if (entry.getVersionOrdinal() <= JGroupsVersion.CURRENT_ORDINAL) { serverOrdinal = entry.getVersionOrdinal(); gossipVersion = JChannel.getGfFunctions().getGossipVersionForOrdinal(serverOrdinal);
/** GemStoneAddition - return the weight of the given IDs */ public static int getWeight(Collection ids, Address leader) { int weight = 0; for (Iterator<IpAddress> it=ids.iterator(); it.hasNext(); ) { IpAddress addr = it.next(); int thisWeight = addr.getMemberWeight(); if (addr.getVmKind() == 10 /* NORMAL_DM_KIND */) { thisWeight += 10; if (leader != null && addr.equals(leader)) { thisWeight += 5; } } else if (addr.preferredForCoordinator()) { thisWeight += 3; } weight += thisWeight; } return weight; }
public final InetAddress getIpAddress() { return ipAddr.getIpAddress(); }
len=packet.getLength(); data=packet.getData(); sender=new IpAddress(sender_addr, sender_port); ((IpAddress)sender).setBirthViewId(-1); ((IpAddress)sender).setProcessId(0); stack.gfPeerFunctions.incUcastReadBytes(len);