Skip to content

Instantly share code, notes, and snippets.

@ohumbel
Last active October 24, 2019 04:55
Show Gist options
  • Save ohumbel/9d03d42f22390b8c4e5c56f1a016c9b2 to your computer and use it in GitHub Desktop.
Save ohumbel/9d03d42f22390b8c4e5c56f1a016c9b2 to your computer and use it in GitHub Desktop.
JGroups connect to default channel
package st.extreme;
import org.jgroups.JChannel;
public class JGroups {
public static void main(String[] args) throws Exception {
try (JChannel channel = new JChannel()) {
channel.connect("testChannel");
System.out.println("Connected to a default test channel");
channel.disconnect();
}
}
}
@ohumbel
Copy link
Author

ohumbel commented Oct 24, 2019

Compile with

javac -cp C:/Users/ohumbel/Downloads/jgroups-4.1.6.Final.jar JGroups.java

and then execute it on Windows (runs happily on Linux):

C:\Users\ohumbel\Downloads>java -cp .;jgroups-4.1.6.Final.jar st.extreme.JGroups
Exception in thread "main" java.net.BindException: Cannot assign requested address: Cannot bind
        at java.net.TwoStacksPlainDatagramSocketImpl.bind0(Native Method)
        at java.net.TwoStacksPlainDatagramSocketImpl.bind0(TwoStacksPlainDatagramSocketImpl.java:107)
        at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:93)
        at java.net.TwoStacksPlainDatagramSocketImpl.bind(TwoStacksPlainDatagramSocketImpl.java:97)
        at java.net.DatagramSocket.bind(DatagramSocket.java:392)
        at java.net.MulticastSocket.<init>(MulticastSocket.java:172)
        at org.jgroups.util.DefaultSocketFactory.createMulticastSocket(DefaultSocketFactory.java:92)
        at org.jgroups.stack.DiagnosticsHandler.startUDP(DiagnosticsHandler.java:180)
        at org.jgroups.stack.DiagnosticsHandler.start(DiagnosticsHandler.java:122)
        at org.jgroups.protocols.TP.startDiagnostics(TP.java:1031)
        at org.jgroups.protocols.TP.start(TP.java:938)
        at org.jgroups.protocols.UDP.start(UDP.java:295)
        at org.jgroups.stack.ProtocolStack.startStack(ProtocolStack.java:888)
        at org.jgroups.JChannel.startStack(JChannel.java:980)
        at org.jgroups.JChannel._preConnect(JChannel.java:844)
        at org.jgroups.JChannel.connect(JChannel.java:349)
        at org.jgroups.JChannel.connect(JChannel.java:343)
        at st.extreme.JGroups.main(JGroups.java:8)

Tested with AdoptOpenJDK 8:

C:\Users\ohumbel\Downloads>java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.232-b09, mixed mode)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment