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.events;
20  
21  import java.io.IOException;
22  import java.io.ObjectInput;
23  import java.io.ObjectOutput;
24  
25  import jgroup.core.MemberId;
26  import jgroup.relacs.types.MemberIdImpl;
27  
28  
29  
30  /**
31   *  The <code>PrepareAck</code> class represents a local message
32   *  exchanged between members and the daemon; it is used by local
33   *  members to notify the daemon that it has notified its membership
34   *  listener(s) that a new view is to be installed.
35   *
36   *  @author Alberto Montresor
37   *  @author Hein Meling
38   *  @since  Jgroup 0.1
39   */
40  public final class PrepareAck
41    extends Event
42  {
43  
44    ////////////////////////////////////////////////////////////////////////////////////////////
45    // Fields
46    ////////////////////////////////////////////////////////////////////////////////////////////
47  
48    private static final long serialVersionUID = 6671374717319612210L;
49  
50    /** Local member identifier */
51    private MemberId memberId;
52  
53  
54    ////////////////////////////////////////////////////////////////////////////////////////////
55    // Constructors
56    ////////////////////////////////////////////////////////////////////////////////////////////
57  
58    /**
59     *  Default constructor for externalization.
60     */
61    public PrepareAck() {}
62  
63    /**
64     *  Creates a <code>PrepareAck</code> object for the specified group
65     *  identifier.
66     */
67    public PrepareAck(int gid, MemberId member)
68    {
69      super(PREPARE_ACK, gid);
70      this.memberId = member;
71    }
72  
73  
74    ////////////////////////////////////////////////////////////////////////////////////////////
75    // Methods
76    ////////////////////////////////////////////////////////////////////////////////////////////
77  
78    /**
79     *  Returns the member identifier for the member acknowledging
80     *  the prepare event.
81     */
82    public MemberId getMemberId()
83    {
84      return memberId;
85    }
86  
87  
88    ////////////////////////////////////////////////////////////////////////////////////////////
89    // Methods from Externalizable
90    ////////////////////////////////////////////////////////////////////////////////////////////
91    
92    /**
93     *  Restores the content of this object from the marshalled data contained
94     *  in the specified input stream.
95     * 
96     *  @param in the stream to be read
97     */
98    public void readExternal(ObjectInput in)
99      throws IOException, ClassNotFoundException
100   {
101     super.readExternal(in);
102     memberId = new MemberIdImpl();
103     memberId.readExternal(in);
104   }
105   
106   /**
107    *  Marshals the content of this object to the specified output stream.
108    * 
109    *  @param out the stream to be written
110    */
111   public void writeExternal(ObjectOutput out)
112     throws IOException
113   {
114     super.writeExternal(out);
115     memberId.writeExternal(out);
116   }
117 
118 
119   ////////////////////////////////////////////////////////////////////////////////////////////
120   // Methods from Object
121   ////////////////////////////////////////////////////////////////////////////////////////////
122 
123   public String toString()
124   {
125     StringBuilder buf = new StringBuilder();
126     buf.append(super.toString());
127     buf.append("[PrepareAck: memberId=");
128     buf.append(memberId);
129     buf.append("]");
130     return buf.toString();
131   }
132 
133 } // END PrepareAck