1 21 22 package org.objectweb.jonas.webapp.jonasadmin.joramplatform; 23 24 import java.util.Calendar ; 25 import java.util.Hashtable ; 26 import java.util.Set ; 27 import java.util.StringTokenizer ; 28 29 import javax.management.MalformedObjectNameException ; 30 import javax.management.ObjectName ; 31 import javax.servlet.http.HttpServletRequest ; 32 33 import org.apache.struts.action.ActionForward; 34 import org.apache.struts.action.ActionMapping; 35 import org.objectweb.jonas.jmx.JonasManagementRepr; 36 import org.objectweb.jonas.jmx.JonasObjectName; 37 import org.objectweb.jonas.jmx.JoramObjectName; 38 import org.objectweb.jonas.webapp.jonasadmin.JonasAdminJmx; 39 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction; 40 41 44 public abstract class EditJoramBaseAction extends JonasBaseAction { 45 46 ObjectName ejbServiceObjectName = null; 47 48 55 protected ActionForward treatError(Throwable pThrowable, ActionMapping pMapping, HttpServletRequest pRequest) { 56 String throwableClassName = pThrowable.getClass().getName(); 57 Throwable t = null; 58 if (throwableClassName.equals("javax.management.InstanceNotFoundException")) { 59 t = new Throwable ("No MBeans found for the Joram platform. Try to refresh!", pThrowable); 60 } else if (throwableClassName.equals("javax.management.MalformedObjectNameException")) { 61 t = new Throwable ("This is not a valid name for a Joram MBean (" + pThrowable.getMessage() + ")", pThrowable); 62 } 63 addGlobalError(t); 64 saveErrors(pRequest, m_Errors); 65 return (pMapping.findForward("Global Error")); 66 } 67 68 75 public ItemDestination getDestinationItem(String joramAdminDestination) throws MalformedObjectNameException { 76 ItemDestination destinationItem = new ItemDestination(); 77 ObjectName destinationON = null; 78 StringTokenizer st = new StringTokenizer (joramAdminDestination, ","); 79 String type = null; 80 String name = null; 81 String id = null; 82 String serverId = null; 83 while (st.hasMoreTokens()) { 84 String couple = st.nextToken().trim(); 86 int index = couple.indexOf("="); 87 String key = couple.substring(0, index); 88 String value = couple.substring(index+1, couple.length()); 89 if (key.equals("type")) { 90 type = value; 91 destinationItem.setType(type); 92 } 93 if (key.equals("name")) { 94 name = value; 95 destinationItem.setName(name); 96 } 97 if (key.equals("id")) { 98 id = value; 99 destinationItem.setId(id); 100 int indexBefore = id.indexOf("#"); 101 int indexAfter = id.indexOf(".", indexBefore); 102 serverId = id.substring(indexBefore + 1, indexAfter); 103 destinationItem.setServerId(serverId); 104 } 105 if (name != null && type != null) { 106 if (type.equals("topic")) { 107 destinationON = JoramObjectName.joramTopic(name); 108 } else if (type.equals("queue")) { 109 destinationON = JoramObjectName.joramQueue(name); 110 } 111 if (JonasAdminJmx.hasMBeanName(destinationON)) { 112 boolean deps = hasDeps(name); 113 destinationItem.setOn(destinationON); 114 destinationItem.setUsed(deps); 115 } 116 } 117 } 118 return destinationItem; 119 } 120 121 128 protected ItemUser getUserItem(String joramAdminUser) throws MalformedObjectNameException { 129 ItemUser userItem = new ItemUser(); 130 joramAdminUser.trim(); 131 int indextBeforeName = joramAdminUser.indexOf("["); 132 int indexAfterName = joramAdminUser.indexOf("]", indextBeforeName); 133 String name = joramAdminUser.substring(indextBeforeName + 1, indexAfterName); 134 if (!name.equals("root")) { 135 userItem.setName(name); 136 int indexBeforeId = joramAdminUser.indexOf(":", indexAfterName); 137 String idString = joramAdminUser.substring(indexBeforeId + 1, joramAdminUser.length()); 138 userItem.setId(idString); 139 name = name.concat("["); 140 name = name.concat(idString); 141 name = name.concat("]"); 142 ObjectName on = JoramObjectName.joramUser(name); 143 if (JonasAdminJmx.hasMBeanName(on)) { 144 userItem.setOn(on); 145 } 146 } 147 return userItem; 148 } 149 150 public void printDestination(ItemDestination dest) { 151 System.out.println("Destination:"); 152 System.out.println("- name " + dest.getName()); 153 System.out.println("- type " + dest.getType()); 154 System.out.println("- id " + dest.getId()); 155 System.out.println("- servrId " + dest.getServerId()); 156 System.out.println("- on " + dest.getOn()); 157 } 158 159 void printUser(ItemUser user) { 160 System.out.println("User:"); 161 System.out.println("- name " + user.getName()); 162 System.out.println("- id " + user.getId()); 163 System.out.println("- on " + user.getOn()); 164 } 165 protected void initRefs() { 166 String [] asParam = new String [1]; 167 String [] asSignature = new String [1]; 168 asSignature[0] = "java.lang.String"; 169 ejbServiceObjectName = JonasObjectName.ejbService(); 170 if (!JonasManagementRepr.isRegistered(ejbServiceObjectName)) { 171 ejbServiceObjectName = null; 172 } 173 } 174 175 protected boolean hasDeps(String pDestName) { 176 boolean ret = false; 177 String [] asParam = new String [1]; 178 String [] asSignature = new String [1]; 179 if (ejbServiceObjectName != null) { 180 asParam[0] = pDestName; 181 asSignature[0] = "java.lang.String"; 182 Set deps = (Set ) JonasManagementRepr.invoke( 183 ejbServiceObjectName, "getJmsDestinationDependence", 184 asParam, asSignature); 185 if (!deps.isEmpty()) { 186 ret = true; 187 } 188 } 189 return ret; 190 } 191 192 198 protected String currentServerId(String id) { 199 String serverId = null; 200 int indexBefore = id.indexOf("#"); 201 int indexAfter = id.indexOf(".", indexBefore); 202 serverId = id.substring(indexBefore + 1, indexAfter); 203 return serverId; 204 } 205 206 protected void populateDestination(ObjectName destOn, DestinationForm oForm) { 207 oForm.setName(getStringAttribute(destOn, "AdminName")); 208 oForm.setDmq(getStringAttribute(destOn, "DMQ")); 209 oForm.setId(getStringAttribute(destOn, "Name")); 210 oForm.setType(getStringAttribute(destOn, "Type")); 211 oForm.setFreelyReadable(getBooleanAttribute(destOn, "FreelyReadable")); 212 oForm.setFreelyWriteable(getBooleanAttribute(destOn, "FreelyWriteable")); 213 oForm.setReaderList(null); oForm.setWriterList(null); } 216 217 protected void getStatistics(ObjectName destOn, MonitoringDestForm oMonitForm, DestinationForm oForm) { 218 Hashtable stats = (Hashtable ) JonasManagementRepr.getAttribute(destOn, "Statistic"); 219 Calendar cal = Calendar.getInstance(); 220 Long creationDateVale = (Long ) stats.get("creationDate"); 221 cal.setTimeInMillis(creationDateVale.longValue()); 222 oForm.setCreationDate(cal.getTime().toString()); 223 Long value = (Long ) stats.get("nbMsgsReceiveSinceCreation"); 224 oMonitForm.setNbMsgsReceiveSinceCreation(value.longValue()); 225 value = (Long ) stats.get("nbMsgsSendToDMQSinceCreation"); 226 oMonitForm.setNbMsgsSendToDMQSinceCreation(value.longValue()); 227 value = (Long ) stats.get("nbMsgsDeliverSinceCreation"); 228 oMonitForm.setNbMsgsDeliverSinceCreation(value.longValue()); 229 oMonitForm.setName(getStringAttribute(destOn, "AdminName")); 230 oMonitForm.setType(getStringAttribute(destOn, "Type")); 231 } 232 } 233 | Popular Tags |