KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > channel > IPChannelSourceChunkImpl


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact : dream@objectweb.org
20  *
21  * Initial developer(s): Matthieu Leclercq
22  * Contributor(s): Vivien Quema
23  */

24
25 package org.objectweb.dream.channel;
26
27 import java.io.Externalizable JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.ObjectInput JavaDoc;
30 import java.io.ObjectOutput JavaDoc;
31 import java.net.InetAddress JavaDoc;
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 /**
39  * Basic Implementation of {@link IPChannelSourceChunk}
40  */

41 public class IPChannelSourceChunkImpl extends AbstractChunk
42     implements
43       IPChannelSourceChunk,
44       Externalizable JavaDoc
45 {
46
47   InetAddress JavaDoc ipChannelSourceAddr;
48   int ipChannelSourcePort;
49
50   // ---------------------------------------------------------------------------
51
// Implementation of IPChannelChunk interface
52
// ---------------------------------------------------------------------------
53

54   /**
55    * @see IPChannelSourceChunk#getChannelSourceAddr()
56    */

57   public InetAddress JavaDoc getChannelSourceAddr()
58   {
59     return ipChannelSourceAddr;
60   }
61
62   /**
63    * @see IPChannelSourceChunk#setChannelSourceAddr(InetAddress)
64    */

65   public void setChannelSourceAddr(InetAddress JavaDoc addr)
66   {
67     ipChannelSourceAddr = addr;
68   }
69
70   /**
71    * @see IPChannelSourceChunk#getChannelSourcePort()
72    */

73   public int getChannelSourcePort()
74   {
75     return ipChannelSourcePort;
76   }
77
78   /**
79    * @see IPChannelSourceChunk#setChannelSourcePort(int)
80    */

81   public void setChannelSourcePort(int port)
82   {
83     ipChannelSourcePort = port;
84   }
85
86   // ---------------------------------------------------------------------------
87
// Implementation of Chunk interface
88
// ---------------------------------------------------------------------------
89

90   /**
91    * @see Chunk#getType()
92    */

93   public ChunkType getType()
94   {
95     return IPChannelDestinationChunk.TYPE;
96   }
97
98   /**
99    * @see Chunk#recycle()
100    */

101   public void recycle()
102   {
103     ipChannelSourceAddr = null;
104   }
105
106   /**
107    * @see Chunk#transfertState(Chunk)
108    */

109   public void transfertState(Chunk newInstance)
110   {
111     IPChannelSourceChunk chunk = (IPChannelSourceChunk) newInstance;
112     chunk.setChannelSourceAddr(getChannelSourceAddr());
113     chunk.setChannelSourcePort(getChannelSourcePort());
114   }
115
116   // ---------------------------------------------------------------------------
117
// Overriden methods
118
// ---------------------------------------------------------------------------
119

120   /**
121    * @see java.lang.Object#toString()
122    */

123   public String JavaDoc toString()
124   {
125     return "IPChannelSourceChunkImpl(ipChannelSourceAddress="
126         + ipChannelSourceAddr + ", ipChannelSourcePort=" + ipChannelSourcePort
127         + ")";
128   }
129
130   // ---------------------------------------------------------------------------
131
// Implementation of the serialization methods
132
// ---------------------------------------------------------------------------
133

134   /**
135    * @see Externalizable#readExternal(ObjectInput)
136    */

137   public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc,
138       ClassNotFoundException JavaDoc
139   {
140     ipChannelSourcePort = in.readInt();
141     byte[] addr = Util.readExternalByteArray(in);
142     ipChannelSourceAddr = InetAddress.getByAddress(addr);
143   }
144
145   /**
146    * @see Externalizable#writeExternal(ObjectOutput)
147    */

148   public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
149   {
150     out.writeInt(ipChannelSourcePort);
151     Util.writeExternalByteArray(out, ipChannelSourceAddr.getAddress());
152   }
153 }
Popular Tags