//when(cluster.getSocketAddress((short) 1)).thenReturn(ADDRESS);
JChannel jchannel = new JChannel();
jchannel.setDiscardOwnMessages(true);
ControlChannel control = new ControlChannel(jchannel);
control.setDiscardOwnMessages(true);
jchannel.setReceiver(new ReceiverAdapter() {
@Override
public void receive(Message msg) {
log.info("received: {} headers: {} content: {}", new Object[]{msg, msg.getHeaders(), msg.getObject()});
}
});
control.setReceiver(new ReceiverAdapter() {
@Override
public void receive(Message msg) {
log.info("CONTROL received: {} headers: {} content: {}", new Object[]{msg, msg.getHeaders(), msg.getObject()});
}
@Override
public void viewAccepted(View newView) {
log.info("CONTROL: view: {}", newView);
synchronized (lock) {
clustered = newView.size() > 1;
lock.notifyAll();
}
}
@Override
public void getState(OutputStream output) throws Exception {
log.info("CONTROL: getState()");
}
@Override
public void setState(InputStream input) throws Exception {
log.info("CONTROL: setState()");
}
});
log.info("connecting...");
jchannel.connect("test_cluster");
log.info("connecetd");
synchronized (lock) {
while (!clustered)
lock.wait();
}
log.info("sending data message1");
jchannel.send(message("message1"));
log.info("sending control cmessage1");
control.send(message("cmessage1"));
log.info("sending data message2");
jchannel.send(message("message2"));
log.info("sending control cmessage2");
control.send(message("cmessage2"));
// Thread.sleep(10000);
// jchannel.close();
}