KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > benchmark > ring > PayLoadChunkImpl


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
32 import org.objectweb.dream.message.AbstractChunk;
33 import org.objectweb.dream.message.Chunk;
34 import org.objectweb.dream.message.ChunkType;
35 import org.objectweb.dream.util.Util;
36
37 /**
38  * {@link PayLoadChunk }implementation.
39  */

40 public class PayLoadChunkImpl extends AbstractChunk
41     implements
42       PayLoadChunk,
43       Externalizable JavaDoc
44 {
45
46   private byte[] payLoad = null;
47
48   /**
49    * @see PayLoadChunk#setPayLoadSize(int)
50    */

51   public void setPayLoadSize(int nbByte)
52   {
53     payLoad = new byte[nbByte];
54   }
55
56   /**
57    * @see PayLoadChunk#getPayLoadSize()
58    */

59   public int getPayLoadSize()
60   {
61     if (payLoad == null)
62     {
63       return 0;
64     }
65     return payLoad.length;
66   }
67
68   /**
69    * @see Chunk#getType()
70    */

71   public ChunkType getType()
72   {
73     return TYPE;
74   }
75
76   /**
77    * @see Chunk#transfertState(Chunk)
78    */

79   public void transfertState(Chunk newInstance)
80   {
81     ((PayLoadChunk) newInstance).setPayLoadSize(getPayLoadSize());
82   }
83
84   /**
85    * @see Chunk#recycle()
86    */

87   public void recycle()
88   {
89     payLoad = null;
90   }
91
92   /**
93    * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
94    */

95   public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc,
96       ClassNotFoundException JavaDoc
97   {
98     payLoad = Util.readExternalByteArray(in);
99   }
100
101   /**
102    * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
103    */

104   public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
105   {
106     Util.writeExternalByteArray(out, payLoad);
107   }
108
109 }
Popular Tags