1 24 25 package benchmark.ring; 26 27 import java.io.Externalizable ; 28 import java.io.IOException ; 29 import java.io.ObjectInput ; 30 import java.io.ObjectOutput ; 31 import java.net.InetAddress ; 32 33 import org.objectweb.dream.channel.IPChannelDestinationChunk; 34 import org.objectweb.dream.message.AbstractNonExtensibleMessage; 35 import org.objectweb.dream.message.Message; 36 import org.objectweb.dream.util.Util; 37 38 41 public class PayLoadMessage extends AbstractNonExtensibleMessage 42 implements 43 PayLoadChunk, 44 IPChannelDestinationChunk, 45 Externalizable 46 { 47 48 private byte[] payLoad = null; 49 private transient InetAddress destinationAddr; 50 private transient int destinationPort; 51 52 55 public void setPayLoadSize(int nbByte) 56 { 57 payLoad = new byte[nbByte]; 58 } 59 60 63 public int getPayLoadSize() 64 { 65 if (payLoad == null) 66 { 67 return 0; 68 } 69 return payLoad.length; 70 } 71 72 75 public InetAddress getChannelDestinationAddr() 76 { 77 return destinationAddr; 78 } 79 80 83 public int getChannelDestinationPort() 84 { 85 return destinationPort; 86 } 87 88 91 public void setChannelDestinationAddr(InetAddress addr) 92 { 93 destinationAddr = addr; 94 } 95 96 99 public void setChannelDestinationPort(int port) 100 { 101 this.destinationPort = port; 102 } 103 104 107 public void transfertChunkStates(Message newInstance) 108 { 109 PayLoadChunk chunk = (PayLoadChunk) newInstance 110 .getChunk(PayLoadChunk.DEFAULT_NAME); 111 chunk.setPayLoadSize(getPayLoadSize()); 112 } 113 114 117 public void recycle() 118 { 119 payLoad = null; 120 } 121 122 125 public void readExternal(ObjectInput in) throws IOException , 126 ClassNotFoundException 127 { 128 payLoad = Util.readExternalByteArray(in); 129 } 130 131 134 public void writeExternal(ObjectOutput out) throws IOException 135 { 136 Util.writeExternalByteArray(out, payLoad); 137 } 138 } | Popular Tags |