use of org.jgroups.stack.IpAddress in project wildfly by wildfly.
the class ChannelNodeFactory method createNode.
@Override
public Node createNode(Address key) {
return this.nodes.computeIfAbsent(key, (Address address) -> {
IpAddress ipAddress = (IpAddress) this.channel.down(new Event(Event.GET_PHYSICAL_ADDRESS, address));
// Physical address might be null if node is no longer a member of the cluster
InetSocketAddress socketAddress = (ipAddress != null) ? new InetSocketAddress(ipAddress.getIpAddress(), ipAddress.getPort()) : new InetSocketAddress(0);
String name = this.channel.getName(address);
if (name == null) {
// If no logical name exists, create one using physical address
name = String.format("%s:%s", socketAddress.getHostString(), socketAddress.getPort());
}
return new AddressableNode(address, name, socketAddress);
});
}
use of org.jgroups.stack.IpAddress 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.jgroups.stack.IpAddress in project JGroups by belaban.
the class Util method parseCommaDelimitedHosts.
/**
* Input is "daddy[8880],sindhu[8880],camille[5555]. Returns a list of IpAddresses
*/
public static List<PhysicalAddress> parseCommaDelimitedHosts(String hosts, int port_range) throws UnknownHostException {
StringTokenizer tok = hosts != null ? new StringTokenizer(hosts, ",") : null;
String t;
IpAddress addr;
Set<PhysicalAddress> retval = new HashSet<>();
while (tok != null && tok.hasMoreTokens()) {
t = tok.nextToken().trim();
String host = t.substring(0, t.indexOf('['));
host = host.trim();
int port = Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']')));
for (int i = port; i <= port + port_range; i++) {
addr = new IpAddress(host, i);
retval.add(addr);
}
}
return new LinkedList<>(retval);
}
use of org.jgroups.stack.IpAddress in project JGroups by belaban.
the class AUTHTest method testFixedMembershipTokenIPv6.
public void testFixedMembershipTokenIPv6() throws Exception {
FixedMembershipToken tok = new FixedMembershipToken();
tok.setMemberList("fe80::aa20:66ff:fe11:d346,2a02:120b:2c45:1b70:aa20:66ff:fe11:d346/7500,2a02:120b:2c45:1b70:f474:e6ca:3038:6b5f/7500");
assert tok.isInMembersList(new IpAddress("2a02:120b:2c45:1b70:f474:e6ca:3038:6b5f", 7500));
}
use of org.jgroups.stack.IpAddress in project JGroups by belaban.
the class DNS_PINGTest method test_valid_dns_response.
@Test
public void test_valid_dns_response() throws Exception {
// given
DNSDiscoveryTester dns_discovery_tester = new DNSDiscoveryTester(2, PORT_START, 500, TimeUnit.SECONDS).add("test", DNSResolver.DNSRecordType.A, new IpAddress(InetAddress.getLoopbackAddress(), PORT_START)).add("test", DNSResolver.DNSRecordType.A, new IpAddress(InetAddress.getLoopbackAddress(), PORT_START + 1));
// when
boolean was_view_received = dns_discovery_tester.runTestAndCheckIfViewWasReceived("test", "A");
// then
Assert.assertTrue(was_view_received);
}
Aggregations