Re: [jgroups-users] JGroups SimpleChat - not working - Need help

Questions/problems related to using JGroups <[email protected]> Thu, 11 Oct 2018 18:39:27 +0800
Newsgroups gmane.comp.java.javagroups.general
Message-ID <mailman.31705.1539254435.1387.javagroups-users@lists.sourceforge.net>
Hi Bela,

Thank you for your response.

BB: Can you upgrade JGroups to 3.6.16 (latest 3.6.x release)?

Brady: No as of now we haven't upgraded to 3.6.16, I am still using
3.6.10-Final. Will upgrade to 3.6.16 as well.

BB: What do you mean? TCPPING.initial_hosts?

Brady: <TCPPING async_discovery="true"

 initial_hosts="${jgroups.tcpping.initial_hosts:10.1.0.11[7800],10.1.0.4[7800]}"
             port_range="2"/>

BB: Actually, are you using this on Azure? Then UDP:PING won't work as IP
multicasting is not supported on Azure. What's your config?

Brady: Below is the ifconfig details, and the tcp.xml & the java code which
I modified and working fine, the messages are getting replicated now in the
sample one which I have attached.

*IFCONFIG:*

###########################################################################################################

azureuser@POCCluster1:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0d:3a:a1:06:b7
          inet addr:10.1.0.11  Bcast:10.1.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20d:3aff:fea1:6b7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:27668611 errors:0 dropped:2 overruns:0 frame:0
          TX packets:35145324 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:13776216781 (13.7 GB)  TX bytes:6677642951 (6.6 GB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:361589 errors:0 dropped:0 overruns:0 frame:0
          TX packets:361589 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:87320166 (87.3 MB)  TX bytes:87320166 (87.3 MB)


###########################################################################################################

azureuser@POCCluster3:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0d:3a:a0:71:7f
          inet addr:10.1.0.4  Bcast:10.1.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20d:3aff:fea0:717f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:35882350 errors:0 dropped:1 overruns:0 frame:0
          TX packets:38161526 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:17756705340 (17.7 GB)  TX bytes:8124894773 (8.1 GB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:7621310 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7621310 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:1379999399 (1.3 GB)  TX bytes:1379999399 (1.3 GB)

###########################################################################################################

*TCP.XML*
Attached.

*Java Code (renamed as .txt)*:
Attached.

But now when we try to implement in our code we are getting
"java.lang.IllegalStateException: channel is disconnected
        at org.jgroups.JChannel.checkClosedOrNotConnected(JChannel.java:971)
        at org.jgroups.JChannel.send(JChannel.java:427)
        at
com.ncs.beconnect.share.server.service.impl.JGroupsReceiveService.init(JGroupsReceiveService.java:88)"

I am using the same default TCP.xml (the one which I have attached),
however, we would need to have the TCP_NIO2 protocol and it is not working
for this protocol (I mean the sample code which I have attached)

Requesting for your help and suggestion.

Thanks in advance.

Warm Regards,

Brady...

_______________________________________________
javagroups-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/javagroups-users
ClusterTest.txt (text/plain, 2.6 KB)
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package jGroupTest;

import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
import org.jgroups.View;
import org.jgroups.util.Util;

import java.io.*;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.LinkedList;
import org.jgroups.protocols.TCPPING;
import org.jgroups.protocols.TCP_NIO2;
import org.jgroups.protocols.VERIFY_SUSPECT;
import org.jgroups.protocols.pbcast.NAKACK2;
import org.jgroups.stack.IpAddress;
import org.jgroups.stack.ProtocolStack;
import org.jgroups.protocols.pbcast.STABLE;
import org.jgroups.protocols.pbcast.GMS;

/**
 *
 * @author bradya
 */
public class ClusterTest extends ReceiverAdapter {
    JChannel channel;
    String user_name=System.getProperty("user.name", "n/a");

    public void viewAccepted(View new_view) {
        System.out.println("** view: " + new_view);
    }

    @Override
    public void receive(Message msg) {
        System.out.println("Received a message !!!");
        String line=msg.getSrc() + ": " + msg.getObject();
        System.out.println(line);
    }

    private void start() throws Exception {
        System.out.println("Start creating channel");
        
        channel=new JChannel("tcp.xml");
        channel.setReceiver(this);
        channel.connect("ChatCluster");
       
        System.out.println("Done creating channel");
        
        eventLoop();
        channel.close();
    }

    private void eventLoop() {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        while(true) {
            try {
                System.out.print("> "); System.out.flush();
                String line=in.readLine().toLowerCase();
                if(line.startsWith("quit") || line.startsWith("exit")) {
                    break;
                }
                line="[" + user_name + "] " + line;
                Message myMsg = new Message(null, null, line);
                System.out.println("Sending message !!! " + line);
                channel.send(myMsg);
                System.out.println("Sending message done!!! ");
            }
            catch(Exception e) {
                System.out.println("Exception while sending message : " + e.getMessage());
            }
        }
    }


    public static void main(String[] args) throws Exception {
        new ClusterTest().start();
    }
}
tcp.xml (text/xml, 2.4 KB)
<!--
    TCP based stack, with flow control and message bundling. This is usually used when IP
    multicasting cannot be used in a network, e.g. because it is disabled (routers discard multicast).
    Note that TCP.bind_addr and TCPPING.initial_hosts should be set, possibly via system properties, e.g.
    -Djgroups.bind_addr=192.168.5.2 and -Djgroups.tcpping.initial_hosts=192.168.5.2[7800]
    author: Bela Ban
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="urn:org:jgroups"
        xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd">
    <TCP bind_port="7800"
         recv_buf_size="${tcp.recv_buf_size:5M}"
         send_buf_size="${tcp.send_buf_size:5M}"
         max_bundle_size="64K"
         max_bundle_timeout="30"
         use_send_queues="true"
         sock_conn_timeout="300"

         timer_type="new3"
         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="2"
         thread_pool.max_threads="8"
         thread_pool.keep_alive_time="5000"
         thread_pool.queue_enabled="true"
         thread_pool.queue_max_size="10000"
         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 async_discovery="true"
             initial_hosts="${jgroups.tcpping.initial_hosts:10.1.0.11[7800],10.1.0.4[7800]}"
             port_range="2"/>
    <MERGE3  min_interval="10000"
             max_interval="30000"/>
    <FD_SOCK/>
    <FD timeout="3000" max_tries="3" />
    <VERIFY_SUSPECT timeout="1500"  />
    <BARRIER />
    <pbcast.NAKACK2 use_mcast_xmit="false"
                   discard_delivered_msgs="true"/>
    <UNICAST3 />
    <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
                   max_bytes="4M"/>
    <pbcast.GMS print_local_addr="true" join_timeout="2000"
                view_bundling="true"/>
    <MFC max_credits="2M"
         min_threshold="0.4"/>
    <FRAG2 frag_size="60K"  />
    <!--RSVP resend_interval="2000" timeout="10000"/-->
    <pbcast.STATE_TRANSFER/>
</config>