1 16 17 package org.springframework.web.context.support; 18 19 import org.springframework.context.ApplicationEvent; 20 21 37 public class RequestHandledEvent extends ApplicationEvent { 38 39 40 private String sessionId; 41 42 43 private String userName; 44 45 46 private final long processingTimeMillis; 47 48 49 private Throwable failureCause; 50 51 52 60 public RequestHandledEvent(Object source, String sessionId, String userName, long processingTimeMillis) { 61 super(source); 62 this.sessionId = sessionId; 63 this.userName = userName; 64 this.processingTimeMillis = processingTimeMillis; 65 } 66 67 76 public RequestHandledEvent( 77 Object source, String sessionId, String userName, long processingTimeMillis, Throwable failureCause) { 78 79 this(source, sessionId, userName, processingTimeMillis); 80 this.failureCause = failureCause; 81 } 82 83 84 87 public long getProcessingTimeMillis() { 88 return processingTimeMillis; 89 } 90 91 94 public String getSessionId() { 95 return sessionId; 96 } 97 98 103 public String getUserName() { 104 return userName; 105 } 106 107 110 public boolean wasFailure() { 111 return (this.failureCause != null); 112 } 113 114 117 public Throwable getFailureCause() { 118 return failureCause; 119 } 120 121 122 126 public String getShortDescription() { 127 StringBuffer sb = new StringBuffer (); 128 sb.append("session=[").append(this.sessionId).append("]; "); 129 sb.append("user=[").append(this.userName).append("]; "); 130 return sb.toString(); 131 } 132 133 137 public String getDescription() { 138 StringBuffer sb = new StringBuffer (); 139 sb.append("session=[").append(this.sessionId).append("]; "); 140 sb.append("user=[").append(this.userName).append("]; "); 141 sb.append("time=[").append(this.processingTimeMillis).append("ms]; "); 142 sb.append("status=["); 143 if (!wasFailure()) { 144 sb.append("OK"); 145 } 146 else { 147 sb.append("failed: ").append(this.failureCause); 148 } 149 sb.append(']'); 150 return sb.toString(); 151 } 152 153 public String toString() { 154 return ("RequestHandledEvent: " + getDescription()); 155 } 156 157 } 158 | Popular Tags |