Question

I have an issue with JGroups where after building my project, running it produces this error:

Caused by: java.lang.ClassNotFoundException: org.jgroups.ReceiverAdapter

My class looks something like this -

import org.jgroups.ReceiverAdapter;
import org.jgroups.Channel;
import org.jgroups.JChannel;

public class MyClass extends ReceiverAdapter implements MyInterface {

    Channel channel;
    String state = "state";

    public MyClass() {
        super();
        start();
    }

    public void start() {
        try {
            channel = new JChannel();
            channel.setReceiver(this);
            channel.connect("ServerCluster");
            channel.getState(null, 0);
            System.out.println("Connected to cluster");
        } catch (Exception e) {
            System.out.println("Failed to connect to cluster");
        }
    }

    public void getState(OutputStream output) throws Exception {
        System.out.println("get response");
    }

    public void setState(InputStream input) throws Exception {
        System.out.println("set test");
    }
}

Running the project from IntelliJ produces no errors, but does not produce the desired prints from getState() and setState() either. I tried creating a brand new project in the Eclipse IDE, but the same is happening there too. Connecting has been working fine, states is a new addition to my project.

Running java MyClass from the command line fires the error seen at the start of this question. The JGroups jar seems to be added to the classpath properly as org.jgroups.Channel and org.jgroups.Channel (among others) are being found.

There is a SimpleChat program provided by the JGroup devs, but when I created a new project for this I encountered the same problem.

Edit

So it turns out I have to explicitly set the classpath when running from the CLI. But still, when running the code it seems like the getState() and setState() methods are never called as there are no print statements. SimpleChat doesn't print received state... like it is meant to.

Does anyone have a solution?

Best.

Was it helpful?

Solution

So, I on the JChannel I was using RpcDispatcher and it seems I can't use the dispatcher and the getState() and setState() methods on the same channel. Simple solution: create a second channel. Seems my knowledge on the fundamentals of JGroups is lacking!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top