Search in sources :

Example 6 with UUID

use of org.jgroups.util.UUID in project geode by apache.

the class JGroupsMessenger method start.

@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void start() {
    // create the configuration XML string for JGroups
    String properties = this.jgStackConfig;
    long start = System.currentTimeMillis();
    // start the jgroups channel and establish the membership ID
    boolean reconnecting = false;
    try {
        Object oldChannel = services.getConfig().getTransport().getOldDSMembershipInfo();
        if (oldChannel != null) {
            logger.debug("Reusing JGroups channel from previous system", properties);
            myChannel = (JChannel) oldChannel;
            // scrub the old channel
            ViewId vid = new ViewId(new JGAddress(), 0);
            View jgv = new View(vid, new ArrayList<>());
            this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
            UUID logicalAddress = (UUID) myChannel.getAddress();
            if (logicalAddress instanceof JGAddress) {
                ((JGAddress) logicalAddress).setVmViewId(-1);
            }
            reconnecting = true;
        } else {
            logger.debug("JGroups configuration: {}", properties);
            checkForIPv6();
            InputStream is = new ByteArrayInputStream(properties.getBytes("UTF-8"));
            myChannel = new JChannel(is);
        }
    } catch (Exception e) {
        throw new GemFireConfigException("unable to create jgroups channel", e);
    }
    // give the stats to the jchannel statistics recorder
    StatRecorder sr = (StatRecorder) myChannel.getProtocolStack().findProtocol(StatRecorder.class);
    if (sr != null) {
        sr.setServices(services);
    }
    Transport transport = (Transport) myChannel.getProtocolStack().getTransport();
    transport.setMessenger(this);
    nackack2HeaderId = ClassConfigurator.getProtocolId(NAKACK2.class);
    try {
        myChannel.setReceiver(null);
        myChannel.setReceiver(new JGroupsReceiver());
        if (!reconnecting) {
            // apache g***** (whatever we end up calling it)
            myChannel.connect("AG");
        }
    } catch (Exception e) {
        myChannel.close();
        throw new SystemConnectException("unable to create jgroups channel", e);
    }
    if (JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK) {
        JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK = false;
        throw new SystemConnectException("failing for test");
    }
    establishLocalAddress();
    logger.info("JGroups channel {} (took {}ms)", (reconnecting ? "reinitialized" : "created"), System.currentTimeMillis() - start);
}
Also used : JChannel(org.jgroups.JChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) NetView(org.apache.geode.distributed.internal.membership.NetView) View(org.jgroups.View) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) ByteArrayInputStream(java.io.ByteArrayInputStream) GemFireConfigException(org.apache.geode.GemFireConfigException) ViewId(org.jgroups.ViewId) Event(org.jgroups.Event) UUID(org.jgroups.util.UUID) SystemConnectException(org.apache.geode.SystemConnectException)

Example 7 with UUID

use of org.jgroups.util.UUID 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)

Example 8 with UUID

use of org.jgroups.util.UUID in project JGroups by belaban.

the class RELAY2 method deliverLocally.

protected void deliverLocally(SiteAddress dest, SiteAddress sender, Message msg) {
    Address local_dest;
    boolean send_to_coord = false;
    if (dest instanceof SiteUUID) {
        if (dest instanceof SiteMaster) {
            local_dest = pickSiteMaster(sender);
            if (local_dest == null)
                throw new IllegalStateException("site master was null");
            send_to_coord = true;
        } else {
            SiteUUID tmp = (SiteUUID) dest;
            local_dest = new UUID(tmp.getMostSignificantBits(), tmp.getLeastSignificantBits());
        }
    } else
        local_dest = dest;
    if (log.isTraceEnabled())
        log.trace(local_addr + ": delivering message to " + dest + " in local cluster");
    long start = stats ? System.nanoTime() : 0;
    forwardTo(local_dest, dest, sender, msg, send_to_coord);
    if (stats) {
        forward_to_local_mbr_time.add(System.nanoTime() - start);
        forward_to_local_mbr.increment();
    }
}
Also used : UUID(org.jgroups.util.UUID)

Example 9 with UUID

use of org.jgroups.util.UUID in project JGroups by belaban.

the class RELAY2 method handleRelayMessage.

/**
 * Called to handle a message received by the relayer
 */
protected void handleRelayMessage(Relay2Header hdr, Message msg) {
    if (hdr.final_dest != null) {
        Message message = msg;
        Relay2Header header = hdr;
        if (header.type == Relay2Header.DATA && can_forward_local_cluster) {
            SiteUUID site_uuid = (SiteUUID) hdr.final_dest;
            // If configured to do so, we want to load-balance these messages,
            UUID tmp = (UUID) Util.pickRandomElement(members);
            SiteAddress final_dest = new SiteUUID(tmp, site_uuid.getName(), site_uuid.getSite());
            // If we select a different address to handle this message, we handle it here.
            if (!final_dest.equals(hdr.final_dest)) {
                message = copy(msg);
                header = new Relay2Header(Relay2Header.DATA, final_dest, hdr.original_sender);
                message.putHeader(id, header);
            }
        }
        handleMessage(header, message);
    } else {
        Message copy = copy(msg).setDest(null).setSrc(null).putHeader(id, hdr);
        // multicast locally
        down_prot.down(copy);
    // Don't forward: https://issues.jboss.org/browse/JGRP-1519
    // sendToBridges(msg.getSrc(), buf, from_site, site_id);  // forward to all bridges except self and from
    }
}
Also used : UUID(org.jgroups.util.UUID)

Example 10 with UUID

use of org.jgroups.util.UUID in project JGroups by belaban.

the class LazyRemovalCacheTest method testAdd.

public static void testAdd() {
    LazyRemovalCache<UUID, String> cache = new LazyRemovalCache<>();
    UUID uuid = UUID.randomUUID();
    cache.add(uuid, "node-1");
    System.out.println("cache = " + cache);
    assert 1 == cache.size();
    String val = cache.get(uuid);
    assert Objects.equals(val, "node-1");
    cache.remove(uuid);
    System.out.println("cache = " + cache);
}
Also used : UUID(org.jgroups.util.UUID)

Aggregations

UUID (org.jgroups.util.UUID)27 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)5 GMSMember (org.apache.geode.distributed.internal.membership.gms.GMSMember)4 Event (org.jgroups.Event)4 Test (org.junit.Test)4 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 SiteUUID (org.jgroups.protocols.relay.SiteUUID)3 IpAddress (org.jgroups.stack.IpAddress)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NetView (org.apache.geode.distributed.internal.membership.NetView)2 ExtendedUUID (org.jgroups.util.ExtendedUUID)2 FlagsUUID (org.jgroups.util.FlagsUUID)2 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1