Search in sources :

Example 1 with UDP

use of org.jgroups.protocols.UDP 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());
}
Also used : UDP(org.jgroups.protocols.UDP) MemberAttributes(org.apache.geode.distributed.internal.membership.MemberAttributes) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Event(org.jgroups.Event) IpAddress(org.jgroups.stack.IpAddress) UUID(org.jgroups.util.UUID) DurableClientAttributes(org.apache.geode.distributed.DurableClientAttributes)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 DurableClientAttributes (org.apache.geode.distributed.DurableClientAttributes)1 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 MemberAttributes (org.apache.geode.distributed.internal.membership.MemberAttributes)1 GMSMember (org.apache.geode.distributed.internal.membership.gms.GMSMember)1 Event (org.jgroups.Event)1 UDP (org.jgroups.protocols.UDP)1 IpAddress (org.jgroups.stack.IpAddress)1 UUID (org.jgroups.util.UUID)1