使用ForkChannel调用MembershipListener#viewAccepted时,RpcDispatcher#callRemoteMethods不起作用。
我试图将应用程序中使用的JGroups版本从2升级到4.1.0.Final。 该应用程序使用MuxRpcDispatcher,因为它使用多个RpcDispatchers。 mux软件包在版本4中已弃用,我们正在尝试使用替代的fork-stack。 但是,当您在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");
在viewAccept中调用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)
是否有避免冻结的方法?
答案 0 :(得分:0)
您应该从不阻塞在回调中,例如client.Properties.SourceAddress = "COMPANYNAME";
client.SourceAddress.Ton = JamaaTech.Smpp.Net.Lib.TypeOfNumber.Alphanumeric;
client.SourceAddress.Npi=JamaaTech.Smpp.Net.Lib.NumberingPlanIndicator.Unknown;
!如果绝对必须调用RPC,则可以异步(mode = {viewAccepted()
)或带外(GET_NONE
)调用它。
您也可以在单独的线程中执行此操作。
有关详细信息,请参见[1]。 干杯,
[1] http://www.jgroups.org/manual4/index.html#ReceiverAdapter
答案 1 :(得分:0)
您犯的错误是您在JChannel上注册了一个视图侦听器,但在ForkChannel上却注册了不是。
这意味着在ForkChannel尚未查看时调用了viewAccepted()
回调,因此调用该方法将立即返回,因为此时尚未记录任何成员身份。
我在该行中添加了注释,并添加了dispatcher1.setMembershipListener(),现在,示例代码可以正常工作了。 干杯,
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");
}
}