{"id":13470631,"url":"https://github.com/belaban/JGroups","last_synced_at":"2025-03-26T11:32:57.243Z","repository":{"id":1167330,"uuid":"1059430","full_name":"belaban/JGroups","owner":"belaban","description":"The JGroups project","archived":false,"fork":false,"pushed_at":"2024-10-29T12:28:35.000Z","size":63135,"stargazers_count":1027,"open_issues_count":1,"forks_count":477,"subscribers_count":93,"default_branch":"master","last_synced_at":"2024-10-29T15:05:19.423Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.jgroups.org","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/belaban.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2010-11-07T15:51:28.000Z","updated_at":"2024-10-28T12:27:16.000Z","dependencies_parsed_at":"2023-07-07T12:16:47.058Z","dependency_job_id":"a1dcc0fc-fb71-4a23-903d-4bcaab7cdfec","html_url":"https://github.com/belaban/JGroups","commit_stats":{"total_commits":19245,"total_committers":134,"mean_commits":"143.61940298507463","dds":0.5278773707456482,"last_synced_commit":"3db42989ede9a97e2f86f2df460773789008eed3"},"previous_names":[],"tags_count":320,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belaban%2FJGroups","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belaban%2FJGroups/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belaban%2FJGroups/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belaban%2FJGroups/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/belaban","download_url":"https://codeload.github.com/belaban/JGroups/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222138883,"owners_count":16937422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T16:00:32.954Z","updated_at":"2025-03-26T11:32:57.236Z","avatar_url":"https://github.com/belaban.png","language":"Java","funding_links":[],"categories":["Java","Projects","进程间通信"],"sub_categories":[],"readme":"\n\n\n= JGroups\n:author: Bela Ban \u003cbelaban@gmail.com\u003e\n:toc2:\n:toclevels: 3\n:icons:\n:homepage: http://www.jgroups.org\n:source-highlighter: pygments\n\n== Overview\nlink:$$http:///jgroups.org$$[JGroups] is a clustering library, allowing members to exchange messages.\n\nIt provides the following functionality:\n\n* Joining a given cluster (becoming a member)\n* (Once joined), sending messages to other members\n* Getting a list of the members in the same cluster\n* Registering callbacks that are invoked when\n** a message is received\n** a member joins\n** a member leaves\n* Leaving a cluster\n\n\n== Sample code\n\nThe code below shows how to send messages to all cluster members. Open two or more shells and run the demo with\ndifferent arguments (names of the members), e.g. `node1`, `node2` etc.\n\n[source,java]\n----\npublic class Demo {\n    protected JChannel ch;\n\n    protected void start(String name) throws Exception {\n        ch=new JChannel(\"udp.xml\").name(name)\n          .setReceiver(new MyReceiver(name))\n          .connect(\"demo-cluster\");\n        int counter=1;\n        for(;;) {\n            ch.send(null, \"msg-\" + counter++);\n            Util.sleep(3000);\n        }\n    }\n\n    protected static class MyReceiver implements Receiver {\n        protected final String name;\n\n        protected MyReceiver(String name) {\n            this.name=name;\n        }\n\n        public void receive(Message msg) {\n            System.out.printf(\"-- [%s] msg from %s: %s\\n\", name, msg.src(), msg.getObject());\n        }\n\n        public void viewAccepted(View v) {\n            System.out.printf(\"-- [%s] new view: %s\\n\", name, v);\n        }\n    }\n\n    public static void main(String[] args) throws Exception {\n        new Demo().start(args[0]);\n    }\n}\n----\n\n`JChannel` is the handle to interact with JGroups. In `start()`, a new `JChannel` is created with configuration\n`udp.xml` (see \u003c\u003cConfiguration\u003e\u003e), which needs to be found on the classpath. Alternatively, a fully qualified\npathname can be given, e.g. `/Users/bela/tcp.xml`.\n\nThe receiver is set to an instance of `MyReceiver`, which implements two callbacks: `viewAccepted()`, invoked when a\nmember joins or leaves, and `receive()`, invoked when a message is received.\n\nFinally, cluster `\"demo-cluster\"` is joined via `JChannel.connect()`. When this call returns, a member can start\nsending and receiving messages.\n\nThe main loop sends a message to all cluster members (including itself) at a given interval.\n\nThe output of running 3 members `A`, `B` and `C` might look like this:\n\n[listing]\n....\n-------------------------------------------------------------------\nGMS: address=C, cluster=demo-cluster, physical address=192.168.1.106:59093\n-------------------------------------------------------------------\n-- [C] new view: [A|6] (3) [A, B, C]\n-- [C] message from C: msg-1\n-- [C] message from A: msg-15\n-- [C] message from B: msg-5\n-- [C] message from C: msg-2\n-- [C] message from A: msg-16\n....\n\n\n[[Configuration]]\n== Configuration\nA `JChannel` is created from an XML configuration (but can also be created programmatically, see the manual for\ndetails). The configuration contains a list of _protocols_. `JChannel.send(Message msg)` sends a message down the\nstack, passing each protocol, and the _transport protocol_ (at the bottom) sends the message.\n\nAt the receiver, the transport protocol reads the message and passes it up the stack to the `JChannel`, which\ndelivers it to the application (the `receive(Message msg)` callback).\n\nA configuration might look as follows:\n\n[source,xml]\n----\n\u003cconfig xmlns=\"urn:org:jgroups\"\n        xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n        xsi:schemaLocation=\"urn:org:jgroups http://www.jgroups.org/schema/jgroups.xsd\"\u003e\n    \u003cUDP\n         mcast_port=\"${jgroups.udp.mcast_port:45588}\"\n         thread_pool.max_threads=\"200\" /\u003e\n    \u003cPING /\u003e\n    \u003cMERGE3 max_interval=\"30000\"\n            min_interval=\"10000\"/\u003e\n    \u003cFD_SOCK2/\u003e\n    \u003cFD_ALL3/\u003e\n    \u003cVERIFY_SUSPECT2 timeout=\"1500\"  /\u003e\n    \u003cpbcast.NAKACK2 xmit_interval=\"500\"/\u003e\n    \u003cUNICAST3 xmit_interval=\"500\" /\u003e\n    \u003cpbcast.STABLE desired_avg_gossip=\"50000\"\n                   max_bytes=\"4M\"/\u003e\n    \u003cpbcast.GMS print_local_addr=\"true\" join_timeout=\"1000\"/\u003e\n    \u003cUFC max_credits=\"4M\"\n         min_threshold=\"0.4\"/\u003e\n    \u003cMFC max_credits=\"4M\"\n         min_threshold=\"0.4\"/\u003e\n    \u003cFRAG2 frag_size=\"60K\"  /\u003e\n\u003c/config\u003e\n----\n\nIt essentially contains the list of protocols. In the example above, `UDP` is the transport protocol and\n`FRAG2` is the top protocol. Protocols have attributes, which govern the working of a protocol, e.g.\n`xmit_interval` in `UNICAST3`, which is the retransmission interval (in milliseconds) of messages, until\nthey're acknowledged.\n\nThe list of protocols defines the _quality of service_ of a given stack, ie. reliable retransmisson, FIFO or\ntotal ordering and so on.\n\nJGroups ships with multiple sample configurations, e.g. `tcp.xml`, which uses TCP instead of UDP as transport\nprotocol. Consult the manual (link below) for more details.\n\n== Links\n* Web site: link:$$http://jgroups.org$$[http://www.jgroups.org]\n* Manual: link:$$http://www.jgroups.org/ug.html$$[http://www.jgroups.org/ug.html]\n* JIRA: link:$$https://issues.redhat.com/projects/JGRP$$[https://issues.redhat.com/projects/JGRP]\n* Forum: link:$$https://groups.google.com/g/jgroups-dev$$[https://groups.google.com/g/jgroups-dev]\n\n\n\nBela Ban, Dec 2022\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbelaban%2FJGroups","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbelaban%2FJGroups","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbelaban%2FJGroups/lists"}