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.gm.RemoteDispatcher;
27  import jgroup.relacs.types.MemberIdImpl;
28  
29  /**
30   *  The <code>JoinRequest</code> class represents a local message
31   *  exchange between members and the daemon; it is used by the member to
32   *  notify the daemon of a join request from the specified member.
33   *
34   *  @author Alberto Montresor
35   *  @since Jgroup 1.2
36   */
37  public final class JoinRequest
38    extends Event
39  {
40  
41    ////////////////////////////////////////////////////////////////////////////////////////////
42    // Fields
43    ////////////////////////////////////////////////////////////////////////////////////////////
44  
45    private static final long serialVersionUID = -749635009327118327L;
46  
47    /** Local member identifier */
48    private MemberId memberId;
49  
50    /** Reference to the member */
51    private RemoteDispatcher dispatcher;
52  
53  
54    ////////////////////////////////////////////////////////////////////////////////////////////
55    // Constructors
56    ////////////////////////////////////////////////////////////////////////////////////////////
57  
58    /**
59     *  Default constructor for externalization.
60     */
61    public JoinRequest()
62    {
63    }
64  
65    /**
66     *  Creates a new <code>JoinRequest</code> event for the specified
67     *  <code>memberId</code> to join group <code>gid</code>.
68     */
69    public JoinRequest(int gid, MemberId memberId, RemoteDispatcher dispatcher)
70    {
71      super(JOIN_REQUEST, gid);
72      this.memberId = memberId;
73      this.dispatcher = dispatcher;
74    }
75  
76    ////////////////////////////////////////////////////////////////////////////////////////////
77    // Methods
78    ////////////////////////////////////////////////////////////////////////////////////////////
79    
80    /**
81     * 
82     */
83    public MemberId getMemberId()
84    {
85      return memberId;
86    }
87  
88    /**
89     * 
90     */
91    public RemoteDispatcher getDispatcher()
92    {
93      return dispatcher;
94    }
95  
96  
97    ////////////////////////////////////////////////////////////////////////////////////////////
98    //  Methods from Externalizable
99    ////////////////////////////////////////////////////////////////////////////////////////////
100   
101   /**
102    *  Restores the content of this object from the marshalled data contained
103    *  in the specified input stream.
104    * 
105    *  @param in the stream to be read
106    */
107   public void readExternal(ObjectInput in)
108     throws IOException, ClassNotFoundException
109   {
110     super.readExternal(in);
111     memberId = new MemberIdImpl();
112     memberId.readExternal(in);
113     dispatcher = (RemoteDispatcher) in.readObject();
114   }
115   
116   /**
117    *  Marshals the content of this object to the specified output stream.
118    * 
119    *  @param out the stream to be written
120    */
121   public void writeExternal(ObjectOutput out)
122     throws IOException
123   {
124     super.writeExternal(out);
125     memberId.writeExternal(out);
126     out.writeObject(dispatcher);
127   }
128 
129 
130   ////////////////////////////////////////////////////////////////////////////////////////////
131   // Methods from Object
132   ////////////////////////////////////////////////////////////////////////////////////////////
133 
134   /**
135    *  Returns a string representation of the object.
136    */
137   public String toString()
138   {
139     StringBuilder buf = new StringBuilder();
140     buf.append(super.toString());
141     buf.append("[JoinRequest:");
142     buf.append(" memberId=");
143     buf.append(memberId);
144     buf.append(" remoteDispatcher=");
145     buf.append(dispatcher);
146     buf.append("]");
147     return buf.toString();
148   }
149 
150 } // END JoinRequest