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.mss;
20  
21  import java.io.Externalizable;
22  import java.io.IOException;
23  import java.io.ObjectInput;
24  import java.io.ObjectOutput;
25  
26  import jgroup.core.EndPoint;
27  import jgroup.relacs.types.EndPointImpl;
28  import jgroup.relacs.types.MessageId;
29  
30  /**
31   *  The <code>FCEntry</code> class.
32   * 
33   *  @author Salvatore Cammarata
34   *  @since Jgroup 1.2
35   */
36  public final class FCEntry 
37  implements Externalizable
38  {
39  
40    ////////////////////////////////////////////////////////////////////////////////////////////
41    // Constants
42    ////////////////////////////////////////////////////////////////////////////////////////////
43  
44    /** Size of this object in bytes */
45    public static final int SIZE = EndPointImpl.SIZE + MessageId.SIZE;
46  
47  
48    ////////////////////////////////////////////////////////////////////////////////////////////
49    // Fields
50    ////////////////////////////////////////////////////////////////////////////////////////////
51  
52    /**
53     *  The host endpoint with which we associate the last message
54     *  received value below.
55     */
56    EndPoint key;
57  
58    /**
59     *  The last message received from the host above.
60     */
61    int lastMsgRcvd;
62  
63  
64    ////////////////////////////////////////////////////////////////////////////////////////////
65    // Constructors
66    ////////////////////////////////////////////////////////////////////////////////////////////
67  
68    /**
69     *  Default constructor for externalization. 
70     */
71    public FCEntry()
72    {
73    }
74  
75    /**
76     *  
77     */
78    FCEntry(EndPoint key, int lastMsgRcvd)
79    {
80      this.key = key;
81      this.lastMsgRcvd = lastMsgRcvd;
82    }
83  
84  
85    /**
86     *  Create a new <code>FCEntry</code> for the specified host, and
87     *  initialize it with the last message delivered within the hosts
88     *  cluster window.
89     *
90     *  @param host
91     *    The <code>MssHost</code> to associate with this flow control
92     *    entry.
93     */
94    FCEntry(MssHost host)
95    {
96      key = host.getEndPoint();
97      lastMsgRcvd = host.getMsgFlow().clusterWindow.getLastMsgDelivered();
98    }
99  
100 
101   ////////////////////////////////////////////////////////////////////////////////////////////
102   // Methods for Externalization
103   ////////////////////////////////////////////////////////////////////////////////////////////
104 
105   /**
106    *  Restores the content of this object from the marshalled data contained
107    *  in the specified input stream.
108    * 
109    *  @param in the stream to be read
110    */
111   public void readExternal(ObjectInput in) 
112     throws IOException, ClassNotFoundException
113   {
114     key = new EndPointImpl();
115     key.readExternal(in);
116     lastMsgRcvd = MessageId.unmarshal(in);
117   }   
118 
119   /**
120    *  Marshals the content of this object to the specified output stream.
121    * 
122    *  @param out the stream to be written
123    */
124   public void writeExternal(ObjectOutput out)
125     throws IOException
126   {
127     key.writeExternal(out);
128     MessageId.marshal(out, lastMsgRcvd);
129   }
130 
131   ////////////////////////////////////////////////////////////////////////////////////////////
132   // Methods from Object
133   ////////////////////////////////////////////////////////////////////////////////////////////
134 
135   /**
136    *  Returns a string representation of this object
137    */
138   public String toString() 
139   {
140     StringBuilder buf = new StringBuilder(" FC: ");
141     buf.append(key);
142     buf.append(lastMsgRcvd);
143     return buf.toString();
144   } 
145 
146 }