1

我有一个 JGroups 问题,在构建我的项目后,运行它会产生这个错误:

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

我的课看起来像这样 -

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");
    }
}

从 IntelliJ 运行项目不会产生任何错误,但也不会产生所需的getState()打印setState()。我尝试在 Eclipse IDE 中创建一个全新的项目,但那里也发生了同样的事情。连接一直工作正常,状态是我项目的新成员。

java MyClass从命令行运行会触发在此问题开头看到的错误。JGroups jar 似乎已正确添加到类路径中,org.jgroups.Channel并且org.jgroups.Channel(除其他外)正在被发现。

JGroup 开发人员提供了一个SimpleChat程序,但是当我为此创建一个新项目时,我遇到了同样的问题。

编辑

所以事实证明,当从 CLI 运行时,我必须显式设置类路径。但是,在运行代码时,似乎永远不会调用getState()andsetState()方法,因为没有打印语句。SimpleChat不会received state...像预期的那样打印。

有没有人有办法解决吗?

最好的。

4

1 回答 1

1

所以,我在 JChannel 上使用的是 RpcDispatcher,看来我不能在同一个频道上使用调度程序getState()和方法。setState()简单的解决方案:创建第二个频道。似乎我缺乏对 JGroups 基础知识的了解!

于 2013-12-10T13:00:43.890 回答