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>IncarnationId</code> class wraps a value of the relacs daemon type 
27   *  "incarnation id" in an object. An incarnation id uniquely identifies 
28   *  different JVM incarnations. An object of type <code>IncarnationId</code> 
29   *  contains a single field whose type is int. 
30   *
31   *  @author Alberto Montresor
32   *  @since  Jgroup 1.2
33   */
34  public final class IncarnationId
35  {
36    
37    ////////////////////////////////////////////////////////////////////////////////////////////
38    // Constants
39    ////////////////////////////////////////////////////////////////////////////////////////////
40  
41    /** Size of this object in bytes */
42    public static final int SIZE = 4;
43  
44  
45    ////////////////////////////////////////////////////////////////////////////////////////////
46    // Fields
47    ////////////////////////////////////////////////////////////////////////////////////////////
48    
49    /** Wrapped value */
50    private int value;
51  
52    ////////////////////////////////////////////////////////////////////////////////////////////
53    // Constructor
54    ////////////////////////////////////////////////////////////////////////////////////////////
55    
56    /**
57     *  Creates a <CODE>IncarnationId</CODE> object containing the specified
58     *  value.
59     */
60    public IncarnationId(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    ////////////////////////////////////////////////////////////////////////////////////////////
80    // Marshaling / unmarshaling methods
81    ////////////////////////////////////////////////////////////////////////////////////////////
82    
83    /**
84     *  Marshals the specified incarnation id to an outgoing message.
85     */
86    public static void marshal(ObjectOutput msg, int value)
87      throws IOException
88    {
89      msg.writeInt(value);
90    }
91    
92    /**
93     *  Unmarshals an incarnation id from an incoming message.
94     */
95    public static int unmarshal(ObjectInput msg)
96      throws IOException
97    {
98      return msg.readInt();
99    }
100 
101 } // END IncarnationId