Search in sources :

Example 1 with Event

use of org.jgroups.Event in project hibernate-orm by hibernate.

the class TestDisconnectHandler method down.

@Override
public Object down(Event evt) {
    switch(evt.getType()) {
        case Event.SET_LOCAL_ADDRESS:
            localAddress = (Address) evt.getArg();
            log.trace("Set address " + localAddress);
            break;
        case Event.CONNECT:
        case Event.CONNECT_WITH_STATE_TRANSFER:
        case Event.CONNECT_USE_FLUSH:
        case Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH:
            log.trace("Connecting on " + localAddress);
            // we need to pass the message from below GMS (let's say regular FD* protocols
            connected.add(getFD());
            break;
        case Event.DISCONNECT:
            log.trace("Disconnecting on " + localAddress);
            connected.remove(getFD());
            // reduce view ack collection timeout to minimum, since we don't want to wait anymore
            GMS gms = (GMS) getProtocolStack().findProtocol(GMS.class);
            gms.setViewAckCollectionTimeout(1);
            for (Protocol other : connected) {
                executor.execute(() -> {
                    log.trace("Suspecting " + localAddress + " on " + other);
                    Event suspectEvent = new Event(Event.SUSPECT, localAddress);
                    other.up(suspectEvent);
                    other.down(suspectEvent);
                });
            }
            break;
    }
    return super.down(evt);
}
Also used : Event(org.jgroups.Event) GMS(org.jgroups.protocols.pbcast.GMS) Protocol(org.jgroups.stack.Protocol)

Example 2 with Event

use of org.jgroups.Event 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 3 with Event

use of org.jgroups.Event 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 4 with Event

use of org.jgroups.Event in project geode by apache.

the class JGroupsMessenger method filterIncomingMessage.

void filterIncomingMessage(DistributionMessage m) {
    switch(m.getDSFID()) {
        case JOIN_RESPONSE:
            JoinResponseMessage jrsp = (JoinResponseMessage) m;
            if (jrsp.getRejectionMessage() == null && services.getConfig().getTransport().isMcastEnabled()) {
                byte[] serializedDigest = jrsp.getMessengerData();
                ByteArrayInputStream bis = new ByteArrayInputStream(serializedDigest);
                DataInputStream dis = new DataInputStream(bis);
                try {
                    Digest digest = new Digest();
                    digest.readFrom(dis);
                    logger.trace("installing JGroups message digest {}", digest);
                    this.myChannel.getProtocolStack().getTopProtocol().down(new Event(Event.MERGE_DIGEST, digest));
                    jrsp.setMessengerData(null);
                } catch (Exception e) {
                    logger.fatal("Unable to read JGroups messaging digest", e);
                }
            }
            break;
        default:
            break;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Digest(org.jgroups.util.Digest) Event(org.jgroups.Event) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) 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)

Example 5 with Event

use of org.jgroups.Event in project geode by apache.

the class JGroupsMessenger method installView.

@Override
public void installView(NetView v) {
    this.view = v;
    if (this.jgAddress.getVmViewId() < 0) {
        this.jgAddress.setVmViewId(this.localAddress.getVmViewId());
    }
    List<JGAddress> mbrs = new ArrayList<>(v.size());
    mbrs.addAll(v.getMembers().stream().map(JGAddress::new).collect(Collectors.toList()));
    ViewId vid = new ViewId(new JGAddress(v.getCoordinator()), v.getViewId());
    View jgv = new View(vid, new ArrayList<>(mbrs));
    logger.trace("installing JGroups view: {}", jgv);
    this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
    addressesWithIoExceptionsProcessed.clear();
    if (encrypt != null) {
        encrypt.installView(v);
    }
    synchronized (scheduledMcastSeqnos) {
        for (DistributedMember mbr : v.getCrashedMembers()) {
            scheduledMcastSeqnos.remove(mbr);
        }
        for (DistributedMember mbr : v.getShutdownMembers()) {
            scheduledMcastSeqnos.remove(mbr);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ViewId(org.jgroups.ViewId) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Event(org.jgroups.Event) NetView(org.apache.geode.distributed.internal.membership.NetView) View(org.jgroups.View)

Aggregations

Event (org.jgroups.Event)14 Message (org.jgroups.Message)7 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)5 NetView (org.apache.geode.distributed.internal.membership.NetView)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)3 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 UUID (org.jgroups.util.UUID)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)2 GemFireConfigException (org.apache.geode.GemFireConfigException)2 GemFireIOException (org.apache.geode.GemFireIOException)2 SystemConnectException (org.apache.geode.SystemConnectException)2