Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Features  





2 Code sample  





3 Flexible protocol stack  





4 Building blocks  





5 References  





6 External links  














JGroups






Français
Magyar
Türkçe
 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


JGroups
Developer(s)Bela Ban
Stable release(s)
5.x5.1.6.Final / April 6, 2021; 3 years ago (2021-04-06)[1]
4.x4.2.12.Final / April 1, 2021; 3 years ago (2021-04-01)[1]
Repositorygithub.com/belaban/JGroups
Written inJava
Operating systemCross-platform
Size2.1 MB
Typereliable multicast system
LicenseApache License 2.0
Websitewww.jgroups.org

JGroups is a library for reliable one-to-one or one-to-many communication written in the Java language.

It can be used to create groups of processes whose members send messages to each other. JGroups enables developers to create reliable multipoint (multicast) applications where reliability is a deployment issue. JGroups also relieves the application developer from implementing this logic themselves. This saves significant development time and allows for the application to be deployed in different environments without having to change code.

Features

[edit]

Code sample

[edit]

This code below demonstrates the implementation of a simple command-line IRC client using JGroups:

public class Chat extends ReceiverAdapter {
    private JChannel channel;

    public Chat(String props, String name) {
        channel = new JChannel(props)
            .setName(name)
            .setReceiver(this)
            .connect("ChatCluster");
    }

    public void viewAccepted(View view) {
        System.out.printf("** view: %s\n", view);
    }

    public void receive(Message msg) {
        System.out.printf("from %s: %s\n", msg.getSource(), msg.getObject());
    }

    private void send(String line) {
        try {
            channel.send(new Message(null, line));
        } catch (Exception e) {}
    }

    public void run() throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        while (true) {
            System.out.print("> ");
            System.out.flush();
            send(in.readLine().toLowerCase());
        }
    }

    public void end() throws Exception {
        channel.close();
    }

    public static void start(Chat client) throws Exception {
        try {
            client.run();
        } catch (Exception e) {
        } finally {
            client.end();
        }
    }

    public static void main(String[] args) throws Exception {
        String props = "udp.xml";
        String name;

        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-props")) {
                props = args[++i];
                continue;
            }

            if (args[i].equals("-name")) {
                name = args[++i];
                continue;
            }

            System.out.println("Chat [-props XML config] [-name name]");
            return;
        }

        start(new Chat(props, name));
    }
}

A JChannel is instantiated from an XML configuration (e.g. udp.xml). The channel is the endpoint for joining a cluster.

Next, the receiver is set, which means that two callbacks will be invoked:

Then, the channel joins cluster "ChatCluster". From now, messages can be sent and received, plus a new view (including this member) will be installed in all cluster members (including the newly joined member).

Anything typed in the main loop results in the creation of a message to be sent to all cluster members, including the sender.

Instances of the chat application can be run in the same process, on the same box, on different hosts in the local network, on hosts in different networks, or in the cloud. The code remains the same; only the configuration needs to be changed.

For example, in a local network, IP multicasting might be used. When IP multicasting is disabled, TCP can be used as transport. When run in the cloud, TCP plus a cloud discovery protocol would be used and so on...

Flexible protocol stack

[edit]

The most powerful feature of JGroups is its flexible protocol stack, which allows developers to adapt it to exactly match their application requirements and network characteristics. The benefit of this is that you only pay for what you use. By mixing and matching protocols, various differing application requirements can be satisfied. JGroups comes with a number of protocols (but anyone can write their own), for example

Building blocks

[edit]

Building blocks are classes layered over JGroups channels, which provide higher-level abstractions such as

References

[edit]
  1. ^ a b "Releases · belaban/JGroups". github.com. Retrieved 2021-04-13.
[edit]
Retrieved from "https://en.wikipedia.org/w/index.php?title=JGroups&oldid=1089030098"

Categories: 
Computer networking
Java (programming language) software
Hidden categories: 
Articles with short description
Short description is different from Wikidata
Articles with hatnote templates targeting a nonexistent page
Articles needing additional references from February 2018
All articles needing additional references
Articles with example Java code
 



This page was last edited on 21 May 2022, at 14:12 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki