1 24 25 package org.objectweb.dream.channel; 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.message.AbstractChunk; 34 import org.objectweb.dream.message.Chunk; 35 import org.objectweb.dream.message.ChunkType; 36 import org.objectweb.dream.util.Util; 37 38 41 public class IPChannelSourceChunkImpl extends AbstractChunk 42 implements 43 IPChannelSourceChunk, 44 Externalizable 45 { 46 47 InetAddress ipChannelSourceAddr; 48 int ipChannelSourcePort; 49 50 54 57 public InetAddress getChannelSourceAddr() 58 { 59 return ipChannelSourceAddr; 60 } 61 62 65 public void setChannelSourceAddr(InetAddress addr) 66 { 67 ipChannelSourceAddr = addr; 68 } 69 70 73 public int getChannelSourcePort() 74 { 75 return ipChannelSourcePort; 76 } 77 78 81 public void setChannelSourcePort(int port) 82 { 83 ipChannelSourcePort = port; 84 } 85 86 90 93 public ChunkType getType() 94 { 95 return IPChannelDestinationChunk.TYPE; 96 } 97 98 101 public void recycle() 102 { 103 ipChannelSourceAddr = null; 104 } 105 106 109 public void transfertState(Chunk newInstance) 110 { 111 IPChannelSourceChunk chunk = (IPChannelSourceChunk) newInstance; 112 chunk.setChannelSourceAddr(getChannelSourceAddr()); 113 chunk.setChannelSourcePort(getChannelSourcePort()); 114 } 115 116 120 123 public String toString() 124 { 125 return "IPChannelSourceChunkImpl(ipChannelSourceAddress=" 126 + ipChannelSourceAddr + ", ipChannelSourcePort=" + ipChannelSourcePort 127 + ")"; 128 } 129 130 134 137 public void readExternal(ObjectInput in) throws IOException , 138 ClassNotFoundException 139 { 140 ipChannelSourcePort = in.readInt(); 141 byte[] addr = Util.readExternalByteArray(in); 142 ipChannelSourceAddr = InetAddress.getByAddress(addr); 143 } 144 145 148 public void writeExternal(ObjectOutput out) throws IOException 149 { 150 out.writeInt(ipChannelSourcePort); 151 Util.writeExternalByteArray(out, ipChannelSourceAddr.getAddress()); 152 } 153 } | Popular Tags |