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.View;
26  import jgroup.relacs.types.GroupIndex;
27  import jgroup.relacs.types.ViewImpl;
28  
29  /**
30   *  The <code>InstallEvent</code> class represents a local message 
31   *  exchanged between members and the daemon; it is used by a daemon 
32   *  to notify members about a view to be installed.
33   *
34   *  @author Alberto Montresor
35   *  @since  Jgroup 1.2
36   */
37  public final class InstallEvent
38    extends Event
39  {
40  
41    ////////////////////////////////////////////////////////////////////////////////////////////
42    // Fields
43    ////////////////////////////////////////////////////////////////////////////////////////////
44  
45    private static final long serialVersionUID = -8820607837570501729L;
46  
47    /** View to be installed */
48    private View view;
49    
50    /**
51     *  Position index of the local host in the array 
52     *  containing the hosts of the current view.
53     */
54    private int hostIndex;
55    
56    /**
57     *  Position index of the member that generated this
58     *  event in the array containing the members of the current view.
59     */
60    private int memberIndex;
61  
62  
63    ////////////////////////////////////////////////////////////////////////////////////////////
64    // Constructors
65    ////////////////////////////////////////////////////////////////////////////////////////////
66  
67    /**
68     *  Default constructor for externalization.
69     */
70    public InstallEvent()
71    {
72    }
73  
74    /**
75     *  Constructs a new view to be installed.
76     */
77    public InstallEvent(int gid, View view, int hostIndex, int memberIndex)
78    {
79      super(INSTALL_EVENT, gid);
80      this.view = view;
81      this.hostIndex = hostIndex;
82      this.memberIndex = memberIndex;
83    }
84  
85    ////////////////////////////////////////////////////////////////////////////////////////////
86    // Methods
87    ////////////////////////////////////////////////////////////////////////////////////////////
88  
89    /**
90     *  Returns the position index of the local host in the array 
91     *  containing the hosts of the current view.
92     */
93    public int getHostIndex()
94    {
95      return hostIndex;
96    }
97  
98    /**
99     *  Returns the position index of the member that generated this
100    *  event in the array containing the members of the current view.
101    */
102   public int getMemberIndex()
103   {
104     return memberIndex;
105   }
106   
107   /**
108    *  Returns the view to be installed
109    */
110   public View getView()
111   {
112     return view;
113   }
114   
115   ////////////////////////////////////////////////////////////////////////////////////////////
116   //  Methods from Externalizable
117   ////////////////////////////////////////////////////////////////////////////////////////////
118   
119   /**
120    *  Restores the content of this object from the marshalled data contained
121    *  in the specified input stream.
122    * 
123    *  @param in the stream to be read
124    */
125   public void readExternal(ObjectInput in)
126     throws IOException, ClassNotFoundException
127   {
128     super.readExternal(in);
129     memberIndex = GroupIndex.unmarshal(in);
130     hostIndex = GroupIndex.unmarshal(in);
131     view = new ViewImpl();
132     view.readExternal(in);
133   }
134   
135   /**
136    *  Marshals the content of this object to the specified output stream.
137    * 
138    *  @param out the stream to be written
139    */
140   public void writeExternal(ObjectOutput out)
141     throws IOException
142   {
143     super.writeExternal(out);
144     GroupIndex.marshal(out, memberIndex);
145     GroupIndex.marshal(out, hostIndex);
146     view.writeExternal(out);
147   }
148 
149 } // END InstallEvent