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.core.multicast.AckListener;
27  import jgroup.core.multicast.ChainIdentifier;
28  import jgroup.relacs.types.Flag;
29  import jgroup.relacs.types.MemberIdImpl;
30  import jgroup.util.OutMessage;
31  
32  /**
33   *  This class represents a local message exchanged between members and 
34   *  the daemon.  It is used by members to multicast a message.
35   *
36   *  @author Alberto Montresor
37   *  @since  Jgroup 1.2
38   */
39  public final class MulticastRequest
40    extends Event
41  {
42  
43    ////////////////////////////////////////////////////////////////////////////////////////////
44    // Fields
45    ////////////////////////////////////////////////////////////////////////////////////////////
46  
47    private static final long serialVersionUID = 6936202150321190893L;
48  
49    /** Message codified as message payload */
50    private OutMessage payload;
51    
52    /** True if the payload contains a single object */
53    private boolean isObject;
54    
55    /** Identifier of the sender */
56    private MemberId sender;
57    
58    /** Ack listener to be notified */
59    private AckListener ackListener;
60  
61    /** The chain identifier for this multicast message (may be null) */
62    private ChainIdentifier chainId;
63  
64  
65    ////////////////////////////////////////////////////////////////////////////////////////////
66    // Constructors
67    ////////////////////////////////////////////////////////////////////////////////////////////
68  
69    /**
70     *  Default constructor for externalization.
71     */
72    public MulticastRequest() { }
73  
74  
75    /**
76     *  Creates a <CODE>MulticastRequest</CODE> event.
77     * 
78     *  @param gid group identifier
79     *  @param isObject true if the message contains a single message
80     *  @param payload the payload of the message
81     *  @param sender sender identifier
82     *  @param ackListener  ack listener
83     *  @param chainId the chain identifier
84     */
85    public MulticastRequest(int gid, boolean isObject, OutMessage payload,
86        MemberId sender, AckListener ackListener, ChainIdentifier chId)
87    {
88      super(MULTICAST_REQUEST, gid);
89      this.payload = payload;
90      this.isObject = isObject;
91      this.sender = sender;
92      this.ackListener = ackListener;
93      this.chainId = chId;
94    }
95  
96  
97    ////////////////////////////////////////////////////////////////////////////////////////////
98    // Accessor methods
99    ////////////////////////////////////////////////////////////////////////////////////////////
100 
101   /**
102    * 
103    */
104   public OutMessage getPayload()
105   {
106     return payload;
107   }
108   
109   /**
110    * 
111    */
112   public boolean isObject()
113   {
114     return isObject;
115   }
116 
117   /**
118    * 
119    */
120   public MemberId getSender()
121   {
122     return sender;
123   }
124 
125   /**
126    * 
127    */
128   public AckListener getAckListener()
129   {
130     return ackListener;
131   }
132 
133   /**
134    * 
135    */
136   public ChainIdentifier getChainId()
137   {
138     return chainId;
139   }
140 
141 
142   ////////////////////////////////////////////////////////////////////////////////////////////
143   // Object methods
144   ////////////////////////////////////////////////////////////////////////////////////////////
145 
146   public String toString()
147   {
148     StringBuilder buf = new StringBuilder();
149     buf.append("[");
150     buf.append(super.toString());
151     buf.append(", sender=");
152     buf.append(sender);
153     buf.append(", isObj=");
154     buf.append(isObject);
155     buf.append(", ackListener=");
156     buf.append(ackListener);
157     buf.append(", payload=");
158     buf.append(payload);
159     if (chainId != null) {
160       buf.append(", chainId=");
161       buf.append(chainId);
162     }
163     return buf.toString();    
164   }
165 
166 
167   ////////////////////////////////////////////////////////////////////////////////////////////
168   // Methods from Externalizable
169   ////////////////////////////////////////////////////////////////////////////////////////////
170 
171   /**
172    *  Restores the content of this object from the marshalled data contained
173    *  in the specified input stream.
174    * 
175    *  @param in the stream to be read
176    */
177   public void readExternal(ObjectInput in)
178     throws IOException, ClassNotFoundException
179   {
180     super.readExternal(in);
181     sender = new MemberIdImpl();
182     sender.readExternal(in);
183     isObject = Flag.unmarshal(in);
184     ackListener = (AckListener) in.readObject();
185     payload = (OutMessage) in.readObject();
186     chainId = (ChainIdentifier) in.readObject();
187   }
188   
189   /**
190    *  Marshals the content of this object to the specified output stream.
191    * 
192    *  @param out the stream to be written
193    */
194   public void writeExternal(ObjectOutput out)
195     throws IOException
196   {
197     super.writeExternal(out);
198     sender.writeExternal(out);
199     Flag.marshal(out, isObject);
200     out.writeObject(ackListener);
201     out.writeObject(payload);
202     out.writeObject(chainId);
203   }
204 
205 } // END MulticastRequest
206