KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > benchmark > ring > PayLoadMessage


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):
23  */

24
25 package benchmark.ring;
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.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 /**
39  * Non extensible message implementation of a message containning a PayLoadChunk
40  */

41 public class PayLoadMessage extends AbstractNonExtensibleMessage
42     implements
43       PayLoadChunk,
44       IPChannelDestinationChunk,
45       Externalizable JavaDoc
46 {
47
48   private byte[] payLoad = null;
49   private transient InetAddress JavaDoc destinationAddr;
50   private transient int destinationPort;
51
52   /**
53    * @see PayLoadChunk#setPayLoadSize(int)
54    */

55   public void setPayLoadSize(int nbByte)
56   {
57     payLoad = new byte[nbByte];
58   }
59
60   /**
61    * @see PayLoadChunk#getPayLoadSize()
62    */

63   public int getPayLoadSize()
64   {
65     if (payLoad == null)
66     {
67       return 0;
68     }
69     return payLoad.length;
70   }
71
72   /**
73    * @see IPChannelDestinationChunk#getChannelDestinationAddr()
74    */

75   public InetAddress JavaDoc getChannelDestinationAddr()
76   {
77     return destinationAddr;
78   }
79
80   /**
81    * @see IPChannelDestinationChunk#getChannelDestinationPort()
82    */

83   public int getChannelDestinationPort()
84   {
85     return destinationPort;
86   }
87
88   /**
89    * @see IPChannelDestinationChunk#setChannelDestinationAddr(InetAddress)
90    */

91   public void setChannelDestinationAddr(InetAddress JavaDoc addr)
92   {
93     destinationAddr = addr;
94   }
95
96   /**
97    * @see IPChannelDestinationChunk#setChannelDestinationPort(int)
98    */

99   public void setChannelDestinationPort(int port)
100   {
101     this.destinationPort = port;
102   }
103
104   /**
105    * @see Message#transfertChunkStates(Message)
106    */

107   public void transfertChunkStates(Message newInstance)
108   {
109     PayLoadChunk chunk = (PayLoadChunk) newInstance
110         .getChunk(PayLoadChunk.DEFAULT_NAME);
111     chunk.setPayLoadSize(getPayLoadSize());
112   }
113
114   /**
115    * @see Message#recycle()
116    */

117   public void recycle()
118   {
119     payLoad = null;
120   }
121
122   /**
123    * @see Externalizable#readExternal(ObjectInput)
124    */

125   public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc,
126       ClassNotFoundException JavaDoc
127   {
128     payLoad = Util.readExternalByteArray(in);
129   }
130
131   /**
132    * @see Externalizable#writeExternal(ObjectOutput)
133    */

134   public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
135   {
136     Util.writeExternalByteArray(out, payLoad);
137   }
138 }
Popular Tags