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