org.jgroups.util.Util.objectToByteBuffer()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(260)

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

Util.objectToByteBuffer介绍

[英]Serializes/Streams an object into a byte buffer. The object has to implement interface Serializable or Externalizable or Streamable.
[中]将对象序列化/流式传输到字节缓冲区。对象必须实现可序列化、可外部化或可流化的接口。

代码示例

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

  1. public ConfigChange(String attr_name, Object val) throws Exception {
  2. this.attr_name=attr_name;
  3. this.attr_value=Util.objectToByteBuffer(val);
  4. }

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

  1. public ConfigChange(String attr_name, Object val) throws Exception {
  2. this.attr_name=attr_name;
  3. this.attr_value=Util.objectToByteBuffer(val);
  4. }

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

  1. public static void writeObject(Object obj,DataOutput out) throws Exception {
  2. if(obj instanceof Streamable) {
  3. out.writeInt(-1);
  4. writeGenericStreamable((Streamable)obj,out);
  5. }
  6. else {
  7. byte[] buf=objectToByteBuffer(obj);
  8. out.writeInt(buf.length);
  9. out.write(buf,0,buf.length);
  10. }
  11. }

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

  1. void sendDiscoveryRequest() {
  2. DiscoveryRequest req;
  3. byte[] buf;
  4. DatagramPacket packet;
  5. req = new DiscoveryRequest(local_addr, local_port);
  6. System.out.println("--> " + req);
  7. try {
  8. buf = Util.objectToByteBuffer(req);
  9. packet = new DatagramPacket(buf, buf.length, mcast_addr, mcast_port);
  10. mcast_sock.send(packet);
  11. } catch (Exception ex) {
  12. System.err.println("McastDiscovery.sendDiscoveryRequest(): " + ex);
  13. }
  14. }

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

  1. public void writeTo(DataOutput out) throws Exception {
  2. out.writeByte(type.ordinal());
  3. // We can't use Util.writeObject since it's size is limited to 2^15-1
  4. try {
  5. if (object instanceof Streamable) {
  6. out.writeShort(-1);
  7. Util.writeGenericStreamable((Streamable)object, out);
  8. }
  9. else {
  10. byte[] bytes = Util.objectToByteBuffer(object);
  11. out.writeInt(bytes.length);
  12. out.write(bytes);
  13. }
  14. }
  15. catch (IOException e) {
  16. throw e;
  17. }
  18. catch (Exception e) {
  19. throw new IOException("Exception encountered while serializing execution request", e);
  20. }
  21. out.writeLong(request);
  22. }

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

  1. public void run() {
  2. while (running) {
  3. buf = new byte[16000];
  4. mcast_packet = new DatagramPacket(buf, buf.length);
  5. try {
  6. mcast_sock.receive(mcast_packet);
  7. req = (DiscoveryRequest) Util.objectFromByteBuffer(mcast_packet.getData());
  8. System.out.println("<-- " + req);
  9. // send response back to req.sender_addr
  10. rsp = new DiscoveryResponse(new InetSocketAddress(local_addr, local_port), req.sender_addr.getAddress());
  11. buf = Util.objectToByteBuffer(rsp);
  12. rsp_packet = new DatagramPacket(buf, buf.length, req.sender_addr);
  13. sock.send(rsp_packet);
  14. } catch (Exception ex) {
  15. System.err.println("McastReceiver.run(): " + ex + ", rsp_packet=" +
  16. rsp_packet.getSocketAddress() + ", length=" + rsp_packet.getLength() + " bytes");
  17. ex.printStackTrace();
  18. }
  19. }
  20. }
  21. }

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

  1. /**
  2. * Takes an object and uses Java serialization to generate the byte[] buffer which is set in the
  3. * message. Parameter 'obj' has to be serializable (e.g. implementing Serializable,
  4. * Externalizable or Streamable, or be a basic type (e.g. Integer, Short etc)).
  5. */
  6. public Message setObject(Object obj) {
  7. if(obj == null) return this;
  8. if(obj instanceof byte[])
  9. return setBuffer((byte[])obj);
  10. if(obj instanceof Buffer)
  11. return setBuffer((Buffer)obj);
  12. try {
  13. return setBuffer(Util.objectToByteBuffer(obj));
  14. }
  15. catch(Exception ex) {
  16. throw new IllegalArgumentException(ex);
  17. }
  18. }

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

  1. public byte[] getState() {
  2. try {
  3. return Util.objectToByteBuffer(history);
  4. }
  5. catch(Exception e) {
  6. return null;
  7. }
  8. }

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

  1. public static long sizeOf(Object inst) {
  2. byte[] data;
  3. try {
  4. data=Util.objectToByteBuffer(inst);
  5. return data.length;
  6. }
  7. catch(Exception ex) {
  8. return -1;
  9. }
  10. }

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

  1. public ConfigChange(String attr_name, Object val) throws Exception {
  2. this.attr_name=attr_name;
  3. this.attr_value=Util.objectToByteBuffer(val);
  4. }

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

  1. public byte[] getState() { // return the copy previously saved by saveState()
  2. try {
  3. return Util.objectToByteBuffer(copy);
  4. }
  5. catch(Throwable ex) {
  6. ex.printStackTrace();
  7. return null;
  8. }
  9. }

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

  1. public byte[] getState() {
  2. byte[] retval=null;
  3. if(state == null) return null;
  4. synchronized(state) {
  5. try {
  6. retval=Util.objectToByteBuffer(state);
  7. }
  8. catch(Exception e) {
  9. e.printStackTrace();
  10. }
  11. }
  12. return retval;
  13. }

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

  1. public byte[] getState() {
  2. try {
  3. return Util.objectToByteBuffer(stocks.clone());
  4. }
  5. catch(Exception ex) {
  6. ex.printStackTrace();
  7. return null;
  8. }
  9. }

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

  1. /** Return a copy of the current cache (tree) */
  2. public byte[] getState() {
  3. try {
  4. return Util.objectToByteBuffer(root.clone());
  5. }
  6. catch(Throwable ex) {
  7. if(log.isErrorEnabled()) log.error("exception returning cache: " + ex);
  8. return null;
  9. }
  10. }

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

  1. public byte[] getState()
  2. {
  3. Vector copy = (Vector)getContents().clone();
  4. try
  5. {
  6. return Util.objectToByteBuffer(copy);
  7. }
  8. catch (Throwable ex)
  9. {
  10. logger.error("DistributedQueue.getState(): exception marshalling state.", ex);
  11. return null;
  12. }
  13. }

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

  1. /** Return a copy of the tree */
  2. public byte[] getState() {
  3. Object copy=root != null? root.copy() : null;
  4. try {
  5. return Util.objectToByteBuffer(copy);
  6. }
  7. catch(Throwable ex) {
  8. if(log.isErrorEnabled()) log.error("exception marshalling state: " + ex);
  9. return null;
  10. }
  11. }

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

  1. public static void writeObject(Object obj, DataOutputStream out) throws Exception {
  2. if(obj == null || !(obj instanceof Streamable)) {
  3. byte[] buf=objectToByteBuffer(obj);
  4. out.writeShort(buf.length);
  5. out.write(buf, 0, buf.length);
  6. }
  7. else {
  8. out.writeShort(-1);
  9. writeGenericStreamable((Streamable)obj, out);
  10. }
  11. }

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

  1. public static long sizeOf(String classname) {
  2. Object inst;
  3. byte[] data;
  4. try {
  5. inst=Util.loadClass(classname, null).newInstance();
  6. data=Util.objectToByteBuffer(inst);
  7. return data.length;
  8. }
  9. catch(Exception ex) {
  10. return -1;
  11. }
  12. }

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

  1. public static void writeObject(Object obj,DataOutput out) throws Exception {
  2. if(obj instanceof Streamable) {
  3. out.writeInt(-1);
  4. writeGenericStreamable((Streamable)obj,out);
  5. }
  6. else {
  7. byte[] buf=objectToByteBuffer(obj);
  8. out.writeInt(buf.length);
  9. out.write(buf,0,buf.length);
  10. }
  11. }

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

  1. private void sendServiceState() throws Exception {
  2. byte[] data=Util.objectToByteBuffer(new HashSet<String>(services.keySet()));
  3. sendServiceMessage(ServiceInfo.LIST_SERVICES_RSP, null, channel.getLocalAddress(), true, data);
  4. }

相关文章

Util类方法