KickJava   Java API By Example, From Geeks To Geeks.

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


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 IPChannelDestinationChunk}
40  */

41 public class IPChannelDestinationChunkImpl extends AbstractChunk
42     implements
43       IPChannelDestinationChunk,
44       Externalizable JavaDoc
45 {
46
47   InetAddress JavaDoc ipChannelDestinationAddr;
48   int ipChannelDestinationPort;
49
50   // ---------------------------------------------------------------------------
51
// Implementation of IPChannelChunk interface
52
// ---------------------------------------------------------------------------
53

54   /**
55    * @see IPChannelDestinationChunk#getChannelDestinationAddr()
56    */

57   public InetAddress JavaDoc getChannelDestinationAddr()
58   {
59     return ipChannelDestinationAddr;
60   }
61
62   /**
63    * @see IPChannelDestinationChunk#setChannelDestinationAddr(InetAddress)
64    */

65   public void setChannelDestinationAddr(InetAddress JavaDoc addr)
66   {
67     ipChannelDestinationAddr = addr;
68   }
69
70   /**
71    * @see IPChannelDestinationChunk#getChannelDestinationPort()
72    */

73   public int getChannelDestinationPort()
74   {
75     return ipChannelDestinationPort;
76   }
77
78   /**
79    * @see IPChannelDestinationChunk#setChannelDestinationPort(int)
80    */

81   public void setChannelDestinationPort(int port)
82   {
83     ipChannelDestinationPort = 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     ipChannelDestinationAddr = null;
104   }
105
106   /**
107    * @see Chunk#transfertState(Chunk)
108    */

109   public void transfertState(Chunk newInstance)
110   {
111     IPChannelDestinationChunk chunk = (IPChannelDestinationChunk) newInstance;
112     chunk.setChannelDestinationAddr(getChannelDestinationAddr());
113     chunk.setChannelDestinationPort(getChannelDestinationPort());
114   }
115
116   // ---------------------------------------------------------------------------
117
// Overriden methods
118
// ---------------------------------------------------------------------------
119

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

123   public String JavaDoc toString()
124   {
125     return "IPChannelDestinationChunkImpl(ipChannelDestinationAddress="
126         + ipChannelDestinationAddr + ", ipChannelDestinationPort="
127         + ipChannelDestinationPort + ")";
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     ipChannelDestinationPort = in.readInt();
141     byte[] addr = Util.readExternalByteArray(in);
142     ipChannelDestinationAddr = 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(ipChannelDestinationPort);
151     Util.writeExternalByteArray(out, ipChannelDestinationAddr.getAddress());
152   }
153 }
Popular Tags