View Javadoc

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>GroupId</code> class wraps a value of the relacs daemon type 
27   *  "group id" in an object. A group id uniquely identifies groups. 
28   *
29   *  @author Alberto Montresor
30   *  @since  Jgroup 1.2
31   */
32  public final class GroupId
33  {
34    
35    ////////////////////////////////////////////////////////////////////////////////////////////
36    // Constants
37    ////////////////////////////////////////////////////////////////////////////////////////////
38  
39    /** Size of this object in bytes */
40    public static final int SIZE = 4;
41  
42  
43    ////////////////////////////////////////////////////////////////////////////////////////////
44    // Fields
45    ////////////////////////////////////////////////////////////////////////////////////////////
46    
47    /** Wrapped value */
48    private int value;
49  
50  
51    ////////////////////////////////////////////////////////////////////////////////////////////
52    // Constructor
53    ////////////////////////////////////////////////////////////////////////////////////////////
54    
55    /**
56     *  Creates a <CODE>GroupId</CODE> object containing the specified
57     *  value.
58     */
59    public GroupId(int value)
60    {
61      this.value = value;
62    }
63    
64    
65    ////////////////////////////////////////////////////////////////////////////////////////////
66    // Accessor method
67    ////////////////////////////////////////////////////////////////////////////////////////////
68    
69    /**
70     *  Returned the wrapped value.
71     */
72    public int getValue()
73    {
74      return value;
75    }
76    
77    ////////////////////////////////////////////////////////////////////////////////////////////
78    // Marshaling / unmarshaling methods
79    ////////////////////////////////////////////////////////////////////////////////////////////
80    
81    /**
82     *  Marshals the specified group id to an outgoing message.
83     */
84    public static void marshal(ObjectOutput msg, int value)
85      throws IOException
86    {
87      msg.writeInt(value);
88    }
89    
90    /**
91     *  Unmarshals a group id from an incoming message.
92     */
93    public static int unmarshal(ObjectInput msg)
94      throws IOException
95    {
96      return msg.readInt();
97    }
98  
99  } // END GroupId