1 /* 2 * Copyright (c) 1998-2005 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 package jgroup.util.log; 19 20 import java.net.InetAddress; 21 22 import jgroup.relacs.config.AppConfig; 23 import jgroup.util.Network; 24 25 /** 26 * A replica event to be logged. 27 * 28 * @author Hein Meling 29 */ 30 public class ReplicaEvent 31 extends Event 32 { 33 34 //////////////////////////////////////////////////////////////////////////////////////////// 35 // Constants 36 //////////////////////////////////////////////////////////////////////////////////////////// 37 38 private static final long serialVersionUID = 442667830497627858L; 39 40 /** 41 * Supported replica event types. 42 */ 43 public enum Type implements EventType { 44 Created, Initialized, Leaving, Removed, ForcedRemove, Failed, Shutdown 45 } 46 47 48 //////////////////////////////////////////////////////////////////////////////////////////// 49 // Fields 50 //////////////////////////////////////////////////////////////////////////////////////////// 51 52 /** The group identifier for this ReplicaEvent */ 53 private final int groupId; 54 55 /** The host on which the event takes place or a remote host if it is a created event */ 56 private final InetAddress host; 57 58 /** The AppConfig object associated with this event */ 59 private AppConfig thisApp; 60 61 62 //////////////////////////////////////////////////////////////////////////////////////////// 63 // Constructor 64 //////////////////////////////////////////////////////////////////////////////////////////// 65 66 public ReplicaEvent(EventType type, int groupId) 67 { 68 this(type, groupId, null); 69 } 70 71 public ReplicaEvent(EventType type, int groupId, InetAddress host) 72 { 73 super(type, ""); 74 this.groupId = groupId; 75 if (host == null) 76 this.host = super.eventHost; 77 else 78 this.host = host; 79 } 80 81 82 //////////////////////////////////////////////////////////////////////////////////////////// 83 // Access Methods 84 //////////////////////////////////////////////////////////////////////////////////////////// 85 86 /** 87 * @return Returns the groupId. 88 */ 89 public int getGroupId() 90 { 91 return groupId; 92 } 93 94 /** 95 * @return Returns the <code>AppConfig</code> object associated with 96 * this event. 97 */ 98 public AppConfig getAppConfig() 99 { 100 if (thisApp == null) 101 thisApp = AppConfig.getApplication(this.groupId); 102 return thisApp; 103 } 104 105 /** 106 * @return Returns the location of this event. 107 */ 108 public InetAddress getLocation() 109 { 110 return host; 111 } 112 113 //////////////////////////////////////////////////////////////////////////////////////////// 114 // Methods from Object 115 //////////////////////////////////////////////////////////////////////////////////////////// 116 117 public String toString() 118 { 119 StringBuilder buf = commonToString(true); 120 buf.append(" @ "); 121 if (host != null) 122 buf.append(Network.getMachineName(host.getHostName())); 123 buf.append(" "); 124 buf.append(getAppConfig().getClassData().getShortName()); 125 buf.append(" gid="); 126 buf.append(groupId); 127 return buf.toString(); 128 } 129 130 } // END ReplicaEvent