コード例 #1
0
ファイル: FORK.java プロジェクト: xiongrl/JGroups
 protected void getStateFrom(
     JChannel channel, Protocol prot, String stack, String ch, DataOutputStream out)
     throws Exception {
   ByteArrayDataOutputStream output = new ByteArrayDataOutputStream(1024);
   OutputStreamAdapter out_ad = new OutputStreamAdapter(output);
   Event evt = new Event(Event.STATE_TRANSFER_OUTPUTSTREAM, out_ad);
   if (channel != null) channel.up(evt);
   else prot.up(evt);
   int len = output.position();
   if (len > 0) {
     Bits.writeString(stack, out);
     Bits.writeString(ch, out);
     out.writeInt(len);
     out.write(output.buffer(), 0, len);
     log.trace("%s: fetched %d bytes from %s:%s", local_addr, len, stack, ch);
   }
 }
コード例 #2
0
ファイル: UtilTest.java プロジェクト: Sk464036801/JGroups
  public static void testWriteAndReadStreamableArray() throws Exception {
    Message[] msgs = {
      new Message(null, "hello world").setFlag(Message.Flag.OOB, Message.Flag.NO_RELIABILITY),
      new Message(Util.createRandomAddress("dest"), "bela ban"),
      new Message(
              Util.createRandomAddress("dest"),
              Util.createRandomAddress("src"),
              "hello world again")
          .setTransientFlag(Message.TransientFlag.DONT_LOOPBACK)
    };

    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(256);
    Util.write(msgs, out);

    ByteArrayDataInputStream in = new ByteArrayDataInputStream(out.buffer(), 0, out.position());
    Message[] tmp = Util.read(Message.class, in);
    for (int i = 0; i < msgs.length; i++) {
      if (msgs[i].dest() == null) assert tmp[i].dest() == null;
      else assert (msgs[i].dest().equals(tmp[i].dest()));
      assert msgs[i].getLength() == tmp[i].getLength();
      assert msgs[i].getObject().equals(tmp[i].getObject());
    }
  }