1 23 24 package com.sun.enterprise.cli.commands; 25 26 import com.sun.enterprise.cli.framework.*; 27 import java.util.HashMap ; 28 import javax.management.MBeanServerConnection ; 29 import javax.management.ObjectName ; 30 import java.util.Map ; 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 34 35 38 39 public class DisplayErrorDistributionCommand extends S1ASCommand 40 { 41 45 public void runCommand() throws CommandException, CommandValidationException 46 { 47 if (!validateOptions()) 48 throw new CommandValidationException("Validation is false"); 49 50 MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 52 getUser(), getPassword()); 53 final String objectName = getObjectName(); 54 final String operationName = getOperationName(); 55 final long timeStamp = new Long ((String )getOperands().get(0)).longValue(); 56 57 try 58 { 59 Object [] params = new Object []{timeStamp, "SEVERE"}; 61 String [] types = getTypesInfo(); 62 Map returnMap = (Map ) mbsc.invoke(new ObjectName (objectName), 63 operationName, params, types); 64 Map errorsMap = handleErrorDistribution(returnMap, 65 new HashMap (), true); 66 67 params = new Object []{timeStamp, "WARNING"}; 69 returnMap = (Map ) mbsc.invoke(new ObjectName (objectName), 70 operationName, params, types); 71 errorsMap = handleErrorDistribution(returnMap, errorsMap, false); 72 73 displayErrorDistribution(errorsMap); 75 } 76 catch(Exception e) 77 { 78 displayExceptionMessage(e); 79 } 80 81 CLILogger.getInstance().printDetailMessage(getLocalizedString( 82 "CommandSuccessful", 83 new Object [] {name})); 84 } 85 86 87 private Map handleErrorDistribution(Map errorMap, Map resultMap, boolean isSevere) 88 { 89 java.util.Set <String > keySet = errorMap.keySet(); 90 for (String module : keySet) { 91 Integer count = (Integer ) errorMap.get(module); 92 if (count > 0) 93 { 94 if (isSevere) 95 { 96 int[] errorCounts = new int[]{count,0}; 97 resultMap.put(module, errorCounts); 98 } 99 else 100 { 101 if (resultMap.containsKey(module)) 102 { 103 int[] errorCounts = (int[])resultMap.get(module); 104 errorCounts[1] = count; 105 resultMap.put(module, errorCounts); 106 } 107 else 108 { 109 int[] errorCounts = new int[]{0, count}; 110 resultMap.put(module, errorCounts); 111 } 112 } 113 } 114 } 115 return resultMap; 116 } 117 118 119 private void displayErrorDistribution(Map errorsMap) 120 { 121 if (errorsMap.size() > 0) 122 { 123 String sTitle = String.format("%1$-9s %2$-14s %3$-40s", 125 getLocalizedString("Severity"), 126 getLocalizedString("Warning"), 127 getLocalizedString("ModuleID")); 128 129 CLILogger.getInstance().printDetailMessage(sTitle); 130 131 CLILogger.getInstance().printDetailMessage("---------------------------------------------------------"); 132 133 } 134 else 135 { 136 CLILogger.getInstance().printMessage(getLocalizedString("NoElementsToList")); 137 return; 138 } 139 java.util.Set <String > keySet = errorsMap.keySet(); 140 for (String module : keySet) 141 { 142 int[] errorCounts = (int[]) errorsMap.get(module); 143 final String sErrorRecord = String.format(" %1$-8s %2$-8s %3$-40s", 144 errorCounts[0], errorCounts[1], module); 145 CLILogger.getInstance().printMessage(sErrorRecord); 146 } 147 } 148 } 149 | Popular Tags |