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