在使用ForkChannel时调用MembershipListener#viewAccepted时,RpcDispatcher#callRemoteMethods不起作用。
我正在尝试将我的应用程序中使用的JGroups版本从2升级到4.1.0。应用程序使用MuxRpcDispatcher,因为它使用多个RpcDispatchers。mux包在版本4中已被弃用,我们正在尝试使用替代的分支堆栈。但是,当您在viewAccepted中执行RpcDispatcher时,处理会冻结。
在使用ForkChannel时调用MembershipListener#viewAccepted时,RpcDispatcher#callRemoteMethods不起作用。
channel = new JChannel();
channel.setReceiver(this);
if (channel.getProtocolStack().findProtocol(FORK.class) == null) {
channel.getProtocolStack().addProtocol(new FORK());
}
forkChannel = new ForkChannel(channel, "fork", "fork");
dispatcher1 = new RpcDispatcher(forkChannel, new Boe1());
channel.connect("test");
forkChannel.connect("test");在viewAccepted中调用RpcDispatcher。处理在此调用时停止。
@Override
public void viewAccepted(final View new_view) {
LOGGER.info("viewAccepted:start");
try {
final MethodCall call = new MethodCall(Boe1.class.getMethod("boeee"));
final RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, 0, true, null);
dispatcher1.callRemoteMethods(null, call, options);
} catch (final Exception e) {
e.printStackTrace();
}
LOGGER.info("viewAccepted:end");
}下面是一个处于停止状态的线程转储。
"jgroups-10,test,IM9072-10017" #22 prio=5 os_prio=0 tid=0x000000002b4b5800 nid=0x2cf8 waiting on condition [0x000000002c84d000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000071b24ccd0> (a java.util.concurrent.CompletableFuture$Signaller)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.CompletableFuture$Signaller.block(CompletableFuture.java:1693)
at java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3323)
at java.util.concurrent.CompletableFuture.waitingGet(CompletableFuture.java:1729)
at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
at org.jgroups.blocks.GroupRequest.access$7(GroupRequest.java:1)
at org.jgroups.blocks.GroupRequest$$Lambda$135/1688803174.call(Unknown Source)
at org.jgroups.blocks.GroupRequest.doAndComplete(GroupRequest.java:274)
at org.jgroups.blocks.GroupRequest.waitForCompletion(GroupRequest.java:254)
at org.jgroups.blocks.GroupRequest.waitForCompletion(GroupRequest.java:1)
at org.jgroups.blocks.Request.execute(Request.java:52)
at org.jgroups.blocks.MessageDispatcher.cast(MessageDispatcher.java:319)
at org.jgroups.blocks.MessageDispatcher.castMessage(MessageDispatcher.java:251)
at org.jgroups.blocks.RpcDispatcher.callRemoteMethods(RpcDispatcher.java:96)
at ppp.network.JChannelRunner.viewAccepted(JChannelRunner.java:79)
at org.jgroups.JChannel.invokeCallback(JChannel.java:917)
at org.jgroups.JChannel.up(JChannel.java:759)
at org.jgroups.stack.ProtocolStack.up(ProtocolStack.java:908)
at org.jgroups.protocols.FORK.up(FORK.java:131)有没有办法避免冻结?
发布于 2019-06-18 14:29:48
你不应该在回调中阻塞,比如viewAccepted()!如果一定要调用RPC,那么可以异步调用(mode=GET_NONE)或带外调用(OOB)。您也可以在单独的线程中执行此操作。
详情请参见1。干杯,
1
发布于 2019-06-24 21:40:01
您所犯的错误是您在JChannel上注册了一个视图侦听器,而不是在ForkChannel上。
这意味着viewAccepted()回调是在ForkChannel还没有视图时调用的,因此调用该方法将立即返回,因为此时还没有记录成员资格。
我对该行进行了注释,并添加了Dispatcher1.setMembership line (),现在,示例代码可以工作了。干杯,
public class JChannelRunner extends ReceiverAdapter implements Closeable {
public static class Boe1 {
public void boeee() {System.out.println("boe-1");}
}
private final static Logger LOGGER = Logger.getLogger(JChannelRunner.class.getName());
JChannel channel;
ForkChannel forkChannel;
RpcDispatcher dispatcher1;
protected void start() throws Exception {
channel = new JChannel();
// channel.setReceiver(this);
if (channel.getProtocolStack().findProtocol(FORK.class) == null) {
channel.getProtocolStack().addProtocol(new FORK());
}
forkChannel = new ForkChannel(channel, "fork", "fork");
dispatcher1 = new RpcDispatcher(forkChannel, new Boe1());
dispatcher1.setMembershipListener(this);
channel.connect("test");
forkChannel.connect("test");
}
public JChannelRunner() throws Exception {}
public static void main(final String[] args) throws IOException, Exception {
try (JChannelRunner runner = new JChannelRunner()) {
runner.start();
Thread.sleep(60 * 1000);
}
}
@Override
public void close() throws IOException {
Util.close(dispatcher1, forkChannel, channel);
}
@Override
public void viewAccepted(final View new_view) {
LOGGER.info("viewAccepted:start");
try {
final MethodCall call = new MethodCall(Boe1.class.getMethod("boeee"));
final RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, 0, true, null);
dispatcher1.callRemoteMethods(null, call, options);
} catch (final Exception e) {
e.printStackTrace();
}
LOGGER.info("viewAccepted:end");
}
}https://stackoverflow.com/questions/56624951
复制相似问题