org.jgroups.Message.readFrom()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中org.jgroups.Message.readFrom()方法的一些代码示例,展示了Message.readFrom()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.readFrom()方法的具体详情如下:
包路径:org.jgroups.Message
类名称:Message
方法名:readFrom

Message.readFrom介绍

[英]Reads the message's contents from an input stream, but skips the buffer and instead returns the position (offset) at which the buffer starts
[中]从输入流读取消息内容,但跳过缓冲区,而是返回缓冲区开始的位置(偏移量)

代码示例

代码示例来源:origin: wildfly/wildfly

protected static final Message readMessage(DataInput in) throws Exception {
  short ver=in.readShort();
  byte flags=in.readByte();
  // final boolean multicast=(flags & (byte)2) == (byte)2;
  Message msg=new Message(false); // don't create headers, readFrom() will do this
  msg.readFrom(in);
  return msg;
}

代码示例来源:origin: wildfly/wildfly

public static Message readMessage(DataInput instream) throws Exception {
  Message msg=new Message(false); // don't create headers, readFrom() will do this
  msg.readFrom(instream);
  return msg;
}

代码示例来源:origin: wildfly/wildfly

public static Message byteBufferToMessage(byte[] buffer,int offset,int length) throws Exception {
  DataInput in=new ByteArrayDataInputStream(buffer,offset,length);
  if(!in.readBoolean())
    return null;
  Message msg=new Message(false); // don't create headers, readFrom() will do this
  msg.readFrom(in);
  return msg;
}

代码示例来源:origin: wildfly/wildfly

public void run() {
  // System.out.printf("[%s] reading from sock, conn: %s\n", Thread.currentThread().getName(), this);
  try {
    int len=in.readInt();
    if(buffer == null || buffer.length < len)
      buffer=new byte[len];
    in.readFully(buffer, 0, len);
    ByteArrayDataInputStream input=new ByteArrayDataInputStream(buffer, 0, len);
    Message msg=new Message(false);
    msg.readFrom(input);
    thread_pool.execute(() -> up_prot.up(msg));
  }
  catch(IOException io_ex) {
    runner.stop();
    throw new RuntimeException(io_ex);
  }
  catch(Exception ex) {
    if(sock.isClosed())
      runner.stop();
    throw new RuntimeException(ex);
  }
}

代码示例来源:origin: wildfly/wildfly

protected static Message readMessage(byte[] buf, int offset, int length) throws Exception {
  ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf, offset, length);
  short ver=in.readShort();
  byte flags=in.readByte();
  // final boolean multicast=(flags & (byte)2) == (byte)2;
  Message msg=new Message(false); // don't create headers, readFrom() will do this
  msg.readFrom(in);
  return msg;
}

代码示例来源:origin: wildfly/wildfly

public static List<Message> readMessageList(DataInput in, short transport_id) throws Exception {
  List<Message> list=new LinkedList<>();
  Address dest=Util.readAddress(in);
  Address src=Util.readAddress(in);
  // AsciiString cluster_name=Bits.readAsciiString(in); // not used here
  short length=in.readShort();
  byte[] cluster_name=length >= 0? new byte[length] : null;
  if(cluster_name != null)
    in.readFully(cluster_name, 0, cluster_name.length);
  int len=in.readInt();
  for(int i=0; i < len; i++) {
    Message msg=new Message(false);
    msg.readFrom(in);
    msg.setDest(dest);
    if(msg.getSrc() == null)
      msg.setSrc(src);
    // Now add a TpHeader back on, was not marshalled. Every message references the *same* TpHeader, saving memory !
    msg.putHeader(transport_id, new TpHeader(cluster_name));
    list.add(msg);
  }
  return list;
}

代码示例来源:origin: wildfly/wildfly

public void run() {
  final byte[]    receive_buf=new byte[65535];
  DatagramPacket  packet=new DatagramPacket(receive_buf, receive_buf.length);
  DataInput       inp;
  while(sock != null && receiver != null && Thread.currentThread().equals(receiver)) {
    packet.setData(receive_buf, 0, receive_buf.length);
    try {
      sock.receive(packet);
      inp=new ByteArrayDataInputStream(packet.getData(), packet.getOffset(), packet.getLength());
      Message msg=new Message();
      msg.readFrom(inp);
      up(msg);
    }
    catch(SocketException socketEx) {
      break;
    }
    catch(Throwable ex) {
      log.error(Util.getMessage("FailedReceivingPacketFrom"), packet.getSocketAddress(), ex);
    }
  }
  if(log.isTraceEnabled())
    log.trace("receiver thread terminated");
}

代码示例来源:origin: wildfly/wildfly

public void run() {
  final byte[]   receive_buf=new byte[65535];
  DatagramPacket packet=new DatagramPacket(receive_buf, receive_buf.length);
  while(mcast_sock != null && receiver != null && Thread.currentThread().equals(receiver)) {
    packet.setData(receive_buf, 0, receive_buf.length);
    try {
      mcast_sock.receive(packet);
      DataInput inp=new ByteArrayDataInputStream(packet.getData(), packet.getOffset(), packet.getLength());
      Message msg=new Message();
      msg.readFrom(inp);
      if(!Objects.equals(local_addr,msg.getSrc())) // discard discovery request from self
        up(msg);
    }
    catch(SocketException socketEx) {
      break;
    }
    catch(Throwable ex) {
      log.error(Util.getMessage("FailedReceivingPacketFrom"), packet.getSocketAddress(), ex);
    }
  }
  log.debug("receiver thread terminated");
}

代码示例来源:origin: wildfly/wildfly

protected void handleSingleMessage(DataInput in, boolean multicast) {
  try {
    Message msg=new Message(false); // don't create headers, readFrom() will do this
    msg.readFrom(in);
    if(!multicast && unicastDestMismatch(msg.getDest()))
      return;
    boolean oob=msg.isFlagSet(Message.Flag.OOB), internal=msg.isFlagSet(Message.Flag.INTERNAL);
    msg_processing_policy.process(msg, oob, internal);
  }
  catch(Throwable t) {
    log.error(String.format(Util.getMessage("IncomingMsgFailure"), local_addr), t);
  }
}

代码示例来源:origin: wildfly/wildfly

for(int i=0; i < len; i++) {
  Message msg=new Message(false);
  msg.readFrom(in);
  msg.setDest(dest);
  if(msg.getSrc() == null)

代码示例来源:origin: wildfly/wildfly

DataInput in=new ByteArrayDataInputStream(buf);
Message assembled_msg=new Message(false);
assembled_msg.readFrom(in);

代码示例来源:origin: org.jboss.eap/wildfly-client-all

public static Message readMessage(DataInput instream) throws Exception {
  Message msg=new Message(false); // don't create headers, readFrom() will do this
  msg.readFrom(instream);
  return msg;
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

protected static final Message readMessage(DataInput in) throws Exception {
  short ver=in.readShort();
  byte flags=in.readByte();
  // final boolean multicast=(flags & (byte)2) == (byte)2;
  Message msg=new Message(false); // don't create headers, readFrom() will do this
  msg.readFrom(in);
  return msg;
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

public static Message byteBufferToMessage(byte[] buffer,int offset,int length) throws Exception {
  DataInput in=new ByteArrayDataInputStream(buffer,offset,length);
  if(!in.readBoolean())
    return null;
  Message msg=new Message(false); // don't create headers, readFrom() will do this
  msg.readFrom(in);
  return msg;
}

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

private Message readMessage(DataInputStream instream, Address dest, Address sender, boolean multicast) throws Exception {
  Message msg=new Message(false); // don't create headers, readFrom() will do this
  msg.readFrom(instream);
  postUnmarshalling(msg, dest, sender, multicast); // allows for optimization by subclass
  return msg;
}

代码示例来源:origin: org.jgroups.kubernetes/common

public void handlePingRequest(InputStream stream) throws Exception {
  DataInputStream dataInput = new DataInputStream(stream);
  Message msg = new Message();
  msg.readFrom(dataInput);
  try {
    sendUp(msg);
  } catch (Exception e) {
    log.error("Error processing GET_MBRS_REQ.", e);
  }
}

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

private List<Message> readMessageList(DataInputStream instream, Address dest, boolean multicast) throws Exception {
  List<Message> list=new LinkedList<Message>();
  int           len;
  Message       msg;
  Address       src;
  len=instream.readInt();
  src=Util.readAddress(instream);
  for(int i=0; i < len; i++) {
    msg=new Message(false); // don't create headers, readFrom() will do this
    msg.readFrom(instream);
    postUnmarshallingList(msg, dest, multicast);
    msg.setSrc(src);
    list.add(msg);
  }
  return list;
}

代码示例来源:origin: org.projectodd.openshift.ping/openshift-ping-common

public void handlePingRequest(InputStream stream) throws Exception {
  DataInputStream dataInput = new DataInputStream(stream);
  Message msg = new Message();
  msg.readFrom(dataInput);
  try {
    up(new Event(Event.MSG, msg));
  } catch (Exception e) {
    log.error("Error processing GET_MBRS_REQ.", e);
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

protected static Message readMessage(byte[] buf, int offset, int length) throws Exception {
  ByteArrayDataInputStream in=new ByteArrayDataInputStream(buf, offset, length);
  short ver=in.readShort();
  byte flags=in.readByte();
  // final boolean multicast=(flags & (byte)2) == (byte)2;
  Message msg=new Message(false); // don't create headers, readFrom() will do this
  msg.readFrom(in);
  return msg;
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

protected void handleSingleMessage(DataInput in, boolean multicast) {
  try {
    Message msg=new Message(false); // don't create headers, readFrom() will do this
    msg.readFrom(in);
    if(!multicast && unicastDestMismatch(msg.getDest()))
      return;
    boolean oob=msg.isFlagSet(Message.Flag.OOB), internal=msg.isFlagSet(Message.Flag.INTERNAL);
    msg_processing_policy.process(msg, oob, internal);
  }
  catch(Throwable t) {
    log.error(String.format(Util.getMessage("IncomingMsgFailure"), local_addr), t);
  }
}

相关文章