org.jgroups.Event Java Examples

The following examples show how to use org.jgroups.Event. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerTestBase.java    From openshift-ping with Apache License 2.0 6 votes vote down vote up
@Test @Ignore
public void testResponse() throws Exception {
    Address local_addr = pinger.getLocalAddress();
    PhysicalAddress physical_addr = (PhysicalAddress) pinger
            .down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
    PingData data = createPingData(local_addr, physical_addr);
    final PingHeader hdr = getPingHeader(data);
    Message msg = new Message(null).setFlag(Message.Flag.DONT_BUNDLE)
            .putHeader(pinger.getId(), hdr).setBuffer(streamableToBuffer(data));
    URL url = new URL("http://localhost:8888");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
    conn.addRequestProperty(Server.CLUSTER_NAME, TestBase.CLUSTER_NAME);
    conn.setDoOutput(true);
    conn.setRequestMethod("POST");

    DataOutputStream out = new DataOutputStream(conn.getOutputStream());
    msg.writeTo(out);
    out.flush();

    Assert.assertEquals(200, conn.getResponseCode());
}
 
Example #2
Source File: OpenshiftPing.java    From openshift-ping with Apache License 2.0 6 votes vote down vote up
@Override
protected void sendMcastDiscoveryRequest(Message msg) {
    final List<InetSocketAddress> hosts = readAll();
    final PhysicalAddress physical_addr = (PhysicalAddress) down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
    if (!(physical_addr instanceof IpAddress)) {
        log.error("Unable to send PING requests: physical_addr is not an IpAddress.");
        return;
    }
    // XXX: is it better to force this to be defined?
    // assume symmetry
    final int port = ((IpAddress) physical_addr).getPort();
    for (InetSocketAddress host: hosts) {
        // JGroups messages cannot be reused - https://github.com/belaban/workshop/blob/master/slides/admin.adoc#problem-9-reusing-a-message-the-sebastian-problem
        Message msgToHost = msg.copy();
        msgToHost.dest(new IpAddress(host.getAddress(), port));
        sendDown(down_prot, msgToHost);
    }
}
 
Example #3
Source File: ELECTION.java    From jgroups-raft with Apache License 2.0 6 votes vote down vote up
public Object down(Event evt) {
    switch(evt.getType()) {
        case Event.CONNECT:
        case Event.CONNECT_USE_FLUSH:
        case Event.CONNECT_WITH_STATE_TRANSFER:
        case Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH:
            Object retval=down_prot.down(evt); // connect first
            startElectionTimer();
            return retval;
        case Event.DISCONNECT:
            changeRole(Role.Follower);
            stopElectionTimer();
            break;
        case Event.SET_LOCAL_ADDRESS:
            local_addr=evt.getArg();
            break;
    }
    return down_prot.down(evt);
}
 
Example #4
Source File: OpenshiftPing.java    From openshift-ping with Apache License 2.0 5 votes vote down vote up
public OpenshiftPing(String systemEnvPrefix) {
    super();
    _systemEnvPrefix = trimToNull(systemEnvPrefix);
    try {
        if(CompatibilityUtils.isJGroups4()) {
            sendDownMethod = Protocol.class.getMethod("down", Message.class);
        } else {
            sendDownMethod = Protocol.class.getMethod("down", Event.class);
        }
    } catch (Exception e) {
        throw new CompatibilityException("Could not find suitable 'up' method.", e);
    }
}
 
Example #5
Source File: OpenshiftPing.java    From openshift-ping with Apache License 2.0 5 votes vote down vote up
public Object down(Event evt) {
    switch (evt.getType()) {
    case Event.CONNECT:
    case Event.CONNECT_WITH_STATE_TRANSFER:
    case Event.CONNECT_USE_FLUSH:
    case Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH:
        clusterName = (String) evt.getArg();
        break;
    }
    return super.down(evt);
}
 
Example #6
Source File: OpenshiftPing.java    From openshift-ping with Apache License 2.0 5 votes vote down vote up
private void sendDown(Object obj, Message msg) {
    try {
        if(CompatibilityUtils.isJGroups4()) {
            sendDownMethod.invoke(obj, msg);
        } else {
            sendDownMethod.invoke(obj, new Event(1, msg));
        }
    } catch (Exception e) {
        throw new CompatibilityException("Could not invoke 'down' method.", e);
    }
}
 
Example #7
Source File: NO_DUPES.java    From jgroups-raft with Apache License 2.0 5 votes vote down vote up
public Object down(Event evt) {
    switch(evt.getType()) {
        case Event.VIEW_CHANGE:
            view=evt.getArg();
            break;
    }
    return down_prot.down(evt);
}
 
Example #8
Source File: TopologyInfo.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Get route to be used as the identifier for sticky session. Return null if I am not able to find the appropriate route (or in case of local mode)
 */
public String getRouteName(Cache cache, Object key) {
    if (cache.getCacheConfiguration().clustering().cacheMode().isClustered() && isGeneratedNodeName) {
        logger.warn("Clustered configuration used, but node name is not properly set. Make sure to start server with jboss.node.name property identifying cluster node");
    }

    if (isGeneratedNodeName) {
        return null;
    }

    // Impl based on Wildfly sticky session algorithm for generating routes ( org.wildfly.clustering.web.infinispan.session.InfinispanRouteLocator )
    Address address = getOwnerAddress(cache, key);

    // Local mode
    if (address == null ||  (address == LocalModeAddress.INSTANCE)) {
        return myNodeName;
    }

    org.jgroups.Address jgroupsAddress = toJGroupsAddress(address);
    String name = NameCache.get(jgroupsAddress);

    // If no logical name exists, create one using physical address
    if (name == null) {

        Transport transport = cache.getCacheManager().getTransport();
        JChannel jgroupsChannel = ((JGroupsTransport) transport).getChannel();

        IpAddress ipAddress = (IpAddress) jgroupsChannel.down(new Event(Event.GET_PHYSICAL_ADDRESS, jgroupsAddress));
        // 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);
        name = String.format("%s:%s", socketAddress.getHostString(), socketAddress.getPort());

        logger.debugf("Address not found in NameCache. Fallback to %s", name);
    }

    return name;
}
 
Example #9
Source File: KUBE_PING.java    From jgroups-kubernetes with Apache License 2.0 4 votes vote down vote up
private PhysicalAddress getCurrentPhysicalAddress(Address addr) {
    return (PhysicalAddress)down(new Event(Event.GET_PHYSICAL_ADDRESS, addr));
}
 
Example #10
Source File: UniTimeClusterDiscovery.java    From unitime with Apache License 2.0 4 votes vote down vote up
protected void writeOwnInformation() {
    PhysicalAddress physical_addr=(PhysicalAddress)down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
    update(new PingData(local_addr, is_server, UUID.get(local_addr), physical_addr).coord(is_coord));
}