JGroups:在远程节点上无限调用Callable的调用方法,即使使用RPCDispatcher的callRemoteMethod方法调用它一次

时间:2015-04-23 09:15:51

标签: jgroups

我使用jgroups库创建了一个包含2个节点(Node1和Node2)的集群。群集成功形成。但是在调用从Node1到Node2的可调用时,它在Node2中执行无限次,在Node1中执行一次。

使用的Jgroups版本是3.6.1.Final

使用的协议配置文件是

<?xml version="1.0" encoding="UTF-8"?>
   <config xmlns="urn:org:jgroups"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:org:jgroups       http://www.jgroups.org/schema/JGroups-3.0.xsd">
    <TCP bind_port="7951"
         bind_addr="192.XXX.XXX.1"
         loopback="true"
         recv_buf_size="${tcp.recv_buf_size:20M}"
         send_buf_size="${tcp.send_buf_size:640K}"
         discard_incompatible_packets="true"
         max_bundle_size="64K"
         max_bundle_timeout="30"
         enable_bundling="true"
         use_send_queues="true"
         sock_conn_timeout="3000"

         timer_type="new"
         timer.min_threads="4"
         timer.max_threads="10"
         timer.keep_alive_time="3000"
         timer.queue_max_size="500"

         thread_pool.enabled="true"
         thread_pool.min_threads="10"
         thread_pool.max_threads="80"
         thread_pool.keep_alive_time="5000"
         thread_pool.queue_enabled="false"
         thread_pool.queue_max_size="100"
         thread_pool.rejection_policy="discard"

         oob_thread_pool.enabled="true"
         oob_thread_pool.min_threads="1"
         oob_thread_pool.max_threads="8"
         oob_thread_pool.keep_alive_time="5000"
         oob_thread_pool.queue_enabled="false"
         oob_thread_pool.queue_max_size="100"
         oob_thread_pool.rejection_policy="discard"/>

    <TCPPING timeout="3000"
             initial_hosts="192.XXX.XXX.1[7951],192.XXX.XXX.2[7950]"

             port_range="1"
             num_initial_members="2"/>
    <MERGE2  min_interval="10000"
             max_interval="30000"/>
    <FD_SOCK/>
    <FD timeout="3000" max_tries="3" />
    <VERIFY_SUSPECT timeout="1500"  />
    <BARRIER />
    <pbcast.NAKACK use_mcast_xmit="false"
                   exponential_backoff="5000"
                   discard_delivered_msgs="false"/>
    <UNICAST />
    <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
                   max_bytes="4M"/>
    <pbcast.GMS print_local_addr="true" join_timeout="3000"

                view_bundling="true"/>
    <UFC max_credits="2M"
         min_threshold="0.4"/>
    <MFC max_credits="2M"
         min_threshold="0.4"/>
    <FRAG2 frag_size="60K"  />
<!--     <pbcast.STATE_TRANSFER/> -->
   </config>

使用以下代码创建通道并调用callRemoteMethod方法。

    public void initialize(String protocolFileName) throws Exception
{

    File file = new File("." + File.separator + "config" + File.separator + protocolFileName); 
    System.out.println(file.getAbsolutePath()); 
    InputStream inputStream = new FileInputStream(file); 

    this.jChannel = new JChannel(inputStream); 
    this.jChannel.setName("DEFAULT_CHANNEL"); 

   this.rpcDispatcher = new RpcDispatcher(jChannel, null, new MembershipListener(), new TestClass()); 
    this.requestOptions = new RequestOptions(ResponseMode.GET_NONE, -1) .setTransientFlags(org.jgroups.Message.TransientFlag.DONT_LOOPBACK); 
}

public void start() throws Exception {
    this.jChannel.connect("DEFAULT_CHANNEL"); 
    // this.jChannel.getState(null, 10000); 

    System.out.println("Channel Started"); 
}

public <T> T send(String remoteNodeIP, int Port) throws Exception { 
    final MethodCall call = new MethodCall(TestClass.class.getMethod("execute", Integer.class)); 
    System.out.println("Inside send method " + InetAddress.getLocalHost().getHostAddress()); 

    call.setArgs(1); 

    return rpcDispatcher.callRemoteMethod(new IpAddress(remoteNodeIP, Port), call, this.requestOptions); 
}

将一个TestClass注册到调度程序,其执行方法作为调度程序的callRemoteMethod的methodCall参数给出。

public class TestClass {
    /**
    Method which will be invoked on the remote node
    @param a
    @return
    */
    public String execute(Integer a) { 
        System.out.println("Value :" + a); 
        return "hello"; 
    }
}

使用输入调用send方法为(192.XXX.XXX.2,7950)

请帮我解决此问题。

1 个答案:

答案 0 :(得分:0)

callRemoteMethod期望UUID类型的地址。我给出的Address实例是IPAddress类型。将其更改为UUID解决了这个问题。