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.arm;
20  
21  import java.io.IOException;
22  import java.io.ObjectInput;
23  import java.io.ObjectOutput;
24  import java.rmi.RemoteException;
25  
26  import jgroup.core.View;
27  import jgroup.core.arm.ARMEvent;
28  import jgroup.core.arm.DistributionScheme;
29  import jgroup.core.arm.UnknownGroupException;
30  import jgroup.relacs.types.ViewImpl;
31  
32  /**
33   *  Event to notify the replication manager of a view change that has
34   *  occured in object group assigned to the system by the replication
35   *  manager.
36   *
37   *  @author Hein Meling
38   *  @since Jgroup 1.2
39   */
40  final class ViewChangeEvent
41    implements ARMEvent
42  {
43  
44    private static final long serialVersionUID = 7943725380815810998L;
45  
46  
47    ////////////////////////////////////////////////////////////////////////////////////////////
48    // Fields
49    ////////////////////////////////////////////////////////////////////////////////////////////
50  
51    /** The view associated with this event */
52    private View view;
53  
54  
55    ////////////////////////////////////////////////////////////////////////////////////////////
56    // Constructors
57    ////////////////////////////////////////////////////////////////////////////////////////////
58  
59    /**
60     *  Default constructor for externalization.
61     */
62    public ViewChangeEvent() { }
63  
64  
65    /**
66     *  Construct a new <code>ViewChangeEvent</code> instance.
67     */
68    ViewChangeEvent(View view)
69    {
70      this.view = view;
71    }
72  
73  
74    ////////////////////////////////////////////////////////////////////////////////////////////
75    // ARMEvent interface methods
76    ////////////////////////////////////////////////////////////////////////////////////////////
77  
78    /**
79     *  The event handling is performed by the event object itself, at the
80     *  (replication manager) receiver side. <p>
81     *
82     *  The handler method is invoked by the replication manager; it
83     *  enables the recovery layer of the group communication stack to
84     *  notify the replication manager of view change events that occured
85     *  within its group.
86     *
87     *  @exception RemoteException
88     *    Raised if the remote operation failed.
89     *  @exception UnknownGroupException
90     *    Raised of the group identifier of the view associated with this
91     *    event was not known to the replication manager.
92     *  @exception NullPointerException
93     *    Thrown if this method is invoked at sender side (recovery
94     *    layer); that is before view has been marshalled and then
95     *    unmarshalled again.  The unmarshal process will initialize the
96     *    object so that this method can be invoked.
97     */
98    public void handle(DistributionScheme distScheme)
99      throws Exception
100   {
101     distScheme.viewChangeEvent(view);
102   }
103 
104 
105   /* (non-Javadoc)
106    * @see jgroup.core.arm.ARMEvent#getGroupId()
107    */
108   public int getGroupId()
109   {
110     return view.getGid();
111   }
112 
113 
114   /* (non-Javadoc)
115    * @see jgroup.core.arm.ARMEvent#getObject()
116    */
117   public Object getObject()
118   {
119     return view;
120   }
121 
122 
123   public String toString()
124   {
125     return "ViewChangeEvent: " + view;
126   }
127 
128 
129   ////////////////////////////////////////////////////////////////////////////////////////////
130   // Methods from the Externalizable interface (as required by the ARMEvent interface)
131   ////////////////////////////////////////////////////////////////////////////////////////////
132 
133   /**
134    *  Restores the content of this object from the marshalled data
135    *  contained in the specified input stream.
136    *
137    *  @param in
138    *    The stream to be read from.
139    *  @exception IOException
140    *    Thrown if there was problems unmarshalling the input stream.
141    *  @exception ClassNotFoundException
142    *    Thrown if the local classloader cannot find a class marshalled
143    *    in the stream.
144    */
145   public void readExternal(ObjectInput in)
146     throws IOException, ClassNotFoundException
147   {
148     view = new ViewImpl();
149     view.readExternal(in);
150   }
151 
152 
153   /**
154    *  Marshals the content of this object to the specified output
155    *  stream.
156    * 
157    *  @param out
158    *    The stream to write this object into.
159    *  @exception IOException
160    *    Thrown if there was problems unmarshalling the input stream.
161    */
162   public void writeExternal(ObjectOutput out)
163     throws IOException
164   {
165     view.writeExternal(out);
166   }
167 
168 } // END ViewChangeEvent