KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > tribe > messages > FragmentedMessage


1 /**
2  * Tribe: Group communication library.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: tribe@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.tribe.messages;
26
27 /**
28  * This class defines a FragmentedMessage to be used as a facility to send a
29  * large message in smaller chunks if the underlying network is not capable of
30  * fragmentation.
31  *
32  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
33  * @version 1.0
34  */

35 public class FragmentedMessage extends ByteMessage
36 {
37
38   private String JavaDoc messageId;
39   private int size;
40   private int fragmentId;
41
42   /**
43    * Creates a new <code>FragmentedMessage</code> object
44    *
45    * @param messageSize the overall message size
46    */

47   public FragmentedMessage(int messageSize)
48   {
49     super(null);
50     this.messageId = toString(); // Dirty hack here
51
this.size = messageSize;
52     this.fragmentId = 0;
53   }
54
55   /**
56    * Return the fragment data
57    *
58    * @return byte array containing the fragment data
59    */

60   public byte[] getFragmentData()
61   {
62     return getContent();
63   }
64
65   /**
66    * Get the identifier of this fragment
67    *
68    * @return fragment number
69    */

70   public int getFragmentId()
71   {
72     return fragmentId;
73   }
74
75   /**
76    * Return the message identifier
77    *
78    * @return message identifier
79    */

80   public String JavaDoc getMessageId()
81   {
82     return messageId;
83   }
84
85   /**
86    * Get the total message size (for all fragments)
87    *
88    * @return overall message size
89    */

90   public int getMessageSize()
91   {
92     return size;
93   }
94
95   /**
96    * Sets the next fragment in the message
97    *
98    * @param fragmentId fragment number
99    * @param buf fragment data
100    */

101   public void setFragment(int fragmentId, byte[] buf)
102   {
103     this.fragmentId = fragmentId;
104     setContent(buf);
105   }
106
107 }
Popular Tags