/* ----------------------------------- Private Methods ------------------------------------- */ protected Object invokeCallback(int type, Object arg) { switch (type) { case Event.MSG: receiver.receive((Message) arg); break; case Event.VIEW_CHANGE: receiver.viewAccepted((View) arg); break; case Event.SUSPECT: receiver.suspect((Address) arg); break; case Event.GET_APPLSTATE: byte[] tmp_state = null; if (receiver != null) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); try { receiver.getState(output); tmp_state = output.toByteArray(); } catch (Exception e) { throw new RuntimeException(local_addr + ": failed getting state from application", e); } } return new StateTransferInfo(null, 0L, tmp_state); case Event.BLOCK: receiver.block(); return true; case Event.UNBLOCK: receiver.unblock(); } return null; }
byte[] messageToBuffer(Message msg) throws Exception { ObjectOutputStream out; // BufferedOutputStream bos; out_stream.reset(); // bos=new BufferedOutputStream(out_stream); out_stream.write(Version.version_id, 0, Version.version_id.length); // write the version // bos.write(Version.version_id, 0, Version.version_id.length); // write the version out = new ObjectOutputStream(out_stream); // out=new ObjectOutputStream(bos); msg.writeExternal(out); out.flush(); // needed if out buffers its output to out_stream return out_stream.toByteArray(); }