1 /*
2 * Copyright (c) 1998-2002 The Jgroup Team.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 *
17 */
18
19 package jgroup.relacs.types;
20
21 import java.io.IOException;
22 import java.io.ObjectInput;
23 import java.io.ObjectOutput;
24
25 /**
26 * The <code>GroupIndex</code> class wraps a value of the relacs daemon
27 * type "group index" in an object. A group index is used to uniquely
28 * identify members of a group through their index in the current view.
29 *
30 * @author Alberto Montresor
31 * @since Jgroup 1.2
32 */
33 public final class GroupIndex
34 {
35
36 ////////////////////////////////////////////////////////////////////////////////////////////
37 // Constants
38 ////////////////////////////////////////////////////////////////////////////////////////////
39
40 /** Size of this object in bytes */
41 public static final int SIZE = 2;
42
43
44 ////////////////////////////////////////////////////////////////////////////////////////////
45 // Fields
46 ////////////////////////////////////////////////////////////////////////////////////////////
47
48 /** Wrapped value */
49 private int value;
50
51
52 ////////////////////////////////////////////////////////////////////////////////////////////
53 // Constructor
54 ////////////////////////////////////////////////////////////////////////////////////////////
55
56 /**
57 * Creates a <CODE>GroupIndex</CODE> object containing the specified
58 * value.
59 */
60 public GroupIndex(int value)
61 {
62 this.value = value;
63 }
64
65
66 ////////////////////////////////////////////////////////////////////////////////////////////
67 // Accessor method
68 ////////////////////////////////////////////////////////////////////////////////////////////
69
70 /**
71 * Returned the wrapped value.
72 */
73 public int getValue()
74 {
75 return value;
76 }
77
78 ////////////////////////////////////////////////////////////////////////////////////////////
79 // Marshaling / unmarshaling methods
80 ////////////////////////////////////////////////////////////////////////////////////////////
81
82 /**
83 * Marshals the specified group index to an outgoing message.
84 */
85 public static void marshal(ObjectOutput msg, int value)
86 throws IOException
87 {
88 msg.writeShort(value);
89 }
90
91 /**
92 * Unmarshals a group index from an incoming message.
93 */
94 public static int unmarshal(ObjectInput msg)
95 throws IOException
96 {
97 return msg.readShort();
98 }
99
100 } // END GroupIndex