use of org.apache.geode.distributed.internal.membership.MemberAttributes in project geode by apache.
the class JGroupsMessenger method establishLocalAddress.
private void establishLocalAddress() {
UUID logicalAddress = (UUID) myChannel.getAddress();
logicalAddress = logicalAddress.copy();
IpAddress ipaddr = (IpAddress) myChannel.down(new Event(Event.GET_PHYSICAL_ADDRESS));
if (ipaddr != null) {
this.jgAddress = new JGAddress(logicalAddress, ipaddr);
} else {
UDP udp = (UDP) myChannel.getProtocolStack().getTransport();
try {
Method getAddress = UDP.class.getDeclaredMethod("getPhysicalAddress");
getAddress.setAccessible(true);
ipaddr = (IpAddress) getAddress.invoke(udp, new Object[0]);
this.jgAddress = new JGAddress(logicalAddress, ipaddr);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
logger.info("Unable to find getPhysicallAddress method in UDP - parsing its address instead");
}
// if (this.jgAddress == null) {
// String addr = udp.getLocalPhysicalAddress();
// int cidx = addr.lastIndexOf(':'); // IPv6 literals might have colons
// String host = addr.substring(0, cidx);
// int jgport = Integer.parseInt(addr.substring(cidx+1, addr.length()));
// try {
// this.jgAddress = new JGAddress(logicalAddress, new IpAddress(InetAddress.getByName(host),
// jgport));
// } catch (UnknownHostException e) {
// myChannel.disconnect();
// throw new SystemConnectException("unable to initialize jgroups address", e);
// }
// }
}
// install the address in the JGroups channel protocols
myChannel.down(new Event(Event.SET_LOCAL_ADDRESS, this.jgAddress));
DistributionConfig config = services.getConfig().getDistributionConfig();
boolean isLocator = (services.getConfig().getTransport().getVmKind() == DistributionManager.LOCATOR_DM_TYPE) || !services.getConfig().getDistributionConfig().getStartLocator().isEmpty();
// establish the DistributedSystem's address
DurableClientAttributes dca = null;
if (config.getDurableClientId() != null) {
dca = new DurableClientAttributes(config.getDurableClientId(), config.getDurableClientTimeout());
}
MemberAttributes attr = new MemberAttributes(-1, /* dcPort - not known at this time */
OSProcess.getId(), services.getConfig().getTransport().getVmKind(), -1, /* view id - not known at this time */
config.getName(), MemberAttributes.parseGroups(config.getRoles(), config.getGroups()), dca);
localAddress = new InternalDistributedMember(jgAddress.getInetAddress(), jgAddress.getPort(), config.getEnableNetworkPartitionDetection(), isLocator, attr);
// add the JGroups logical address to the GMSMember
UUID uuid = this.jgAddress;
GMSMember gmsMember = (GMSMember) localAddress.getNetMember();
gmsMember.setUUID(uuid);
gmsMember.setMemberWeight((byte) (services.getConfig().getMemberWeight() & 0xff));
gmsMember.setNetworkPartitionDetectionEnabled(services.getConfig().getDistributionConfig().getEnableNetworkPartitionDetection());
}
use of org.apache.geode.distributed.internal.membership.MemberAttributes in project geode by apache.
the class GMSMember method setAttributes.
public void setAttributes(MemberAttributes p_attr) {
MemberAttributes attr = p_attr;
if (attr == null) {
attr = MemberAttributes.INVALID;
}
processId = attr.getVmPid();
vmKind = (byte) attr.getVmKind();
directPort = attr.getPort();
vmViewId = attr.getVmViewId();
name = attr.getName();
groups = attr.getGroups();
durableClientAttributes = attr.getDurableClientAttributes();
}
use of org.apache.geode.distributed.internal.membership.MemberAttributes in project geode by apache.
the class GMSMemberJUnitTest method testNoNPEWhenSetAttributesWithNull.
/**
* Makes sure a NPE is not thrown
*/
@Test
public void testNoNPEWhenSetAttributesWithNull() {
GMSMember member = new GMSMember();
member.setAttributes(null);
MemberAttributes attrs = member.getAttributes();
MemberAttributes invalid = MemberAttributes.INVALID;
assertEquals(attrs.getVmKind(), invalid.getVmKind());
assertEquals(attrs.getPort(), invalid.getPort());
assertEquals(attrs.getVmViewId(), invalid.getVmViewId());
assertEquals(attrs.getName(), invalid.getName());
}
use of org.apache.geode.distributed.internal.membership.MemberAttributes in project geode by apache.
the class GMSMemberJUnitTest method testGMSMemberBackwardCompatibility.
/**
* <p>
* GEODE-2875 - adds vmKind to on-wire form of GMSMember.writeEssentialData
* </p>
* <p>
* This must be backward-compatible with Geode 1.0 (Version.GFE_90)
* </p>
*
* @throws Exception
*/
@Test
public void testGMSMemberBackwardCompatibility() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MemberAttributes attributes = new MemberAttributes(10, 20, 1, 2, "member", null, null);
GMSMember member = new GMSMember();
member.setAttributes(attributes);
DataOutput dataOutput = new DataOutputStream(baos);
member.writeEssentialData(dataOutput);
// vmKind should be transmitted to a member with the current version
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
DataInput dataInput = new DataInputStream(bais);
GMSMember newMember = new GMSMember();
newMember.readEssentialData(dataInput);
assertEquals(1, newMember.getVmKind());
// vmKind should not be transmitted to a member with version GFE_90 or earlier
dataOutput = new HeapDataOutputStream(Version.GFE_90);
member.writeEssentialData(dataOutput);
bais = new ByteArrayInputStream(baos.toByteArray());
dataInput = new VersionedDataInputStream(new DataInputStream(bais), Version.GFE_90);
newMember = new GMSMember();
newMember.readEssentialData(dataInput);
assertEquals(0, newMember.getVmKind());
}
Aggregations