super.send(msg);
}
@Override
public Object up(Event evt) {
final Receiver dataReceiver = jchannel.getReceiver();
if (receiver != null) {
switch (evt.getType()) {
case Event.MSG:
final Message msg = (Message) evt.getArg();
if (msg.getHeader(MAGIC_HEADER) != null) {
if (!(discardOwnMessages && getAddress() != null && msg.getSrc() != null && getAddress().equals(msg.getSrc())))
receiver.receive(msg);
} else {
if (dataReceiver != null && !(dataDiscardOwnMessages && getAddress() != null && msg.getSrc() != null && getAddress().equals(msg.getSrc())))
dataReceiver.receive(msg);
}
break;
case Event.VIEW_CHANGE:
receiver.viewAccepted((View) evt.getArg());
break;
case Event.SUSPECT:
receiver.suspect((Address) evt.getArg());
break;
case Event.GET_STATE_OK:
final StateTransferResult result = (StateTransferResult) evt.getArg();
final byte[] state = result.getBuffer();
if (state != null) {
final ByteArrayInputStream input = new ByteArrayInputStream(state);
try {
receiver.setState(input);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
break;
case Event.STATE_TRANSFER_INPUTSTREAM:
final InputStream is = (InputStream) evt.getArg();
if (is != null) {
try {
receiver.setState(is);
} catch (Throwable t) {
LOG.error("Error while setting state", t);
throw new RuntimeException("failed calling setState() in state requester", t);
}
}
break;
case Event.GET_APPLSTATE:
byte[] tmpState = null;
if (receiver != null) {
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
try {
receiver.getState(output);
tmpState = output.toByteArray();
} catch (Exception e) {
LOG.error("Error while getting state", e);
throw new RuntimeException(getAddress() + ": failed getting state from application", e);
}
}
return new StateTransferInfo(null, 0L, tmpState);
case Event.BLOCK:
receiver.block();
if (dataReceiver != null)
dataReceiver.block();
return true;
case Event.UNBLOCK:
receiver.unblock();
if (dataReceiver != null)
dataReceiver.unblock();
break;
}
}
return null;