org.jgroups.tests.bla6 Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including
all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and
Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
package org.jgroups.tests;
import org.jgroups.*;
import org.jgroups.util.Util;
import java.io.*;
import java.util.LinkedList;
import java.util.List;
/**
* @author Bela Ban
* @since x.y
*/
public class bla6 extends ReceiverAdapter {
JChannel channel;
String user_name=System.getProperty("user.name", "n/a");
final List state=new LinkedList<>();
public void viewAccepted(View new_view) {
System.out.println("** view: " + new_view);
}
public void receive(Message msg) {
String line=msg.getSrc() + ": " + msg.getObject();
System.out.println(line);
synchronized(state) {
state.add(line);
}
}
public void getState(OutputStream output) throws Exception {
synchronized(state) {
Util.objectToStream(state, new DataOutputStream(output));
}
}
public void setState(InputStream input) throws Exception {
List list=Util.objectFromStream(new DataInputStream(input));
synchronized(state) {
state.clear();
state.addAll(list);
}
System.out.println("received state (" + list.size() + " messages in chat history):");
list.forEach(System.out::println);
}
private void start() throws Exception {
channel=new JChannel().setReceiver(this);
channel.connect("ChatCluster");
channel.getState(null, 10000);
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 msg=null; // new BytesMessage(null, line);
channel.send(msg);
}
catch(Exception e) {
}
}
}
public static void main(String[] args) throws Exception {
new bla6().start();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy