1 /** 2 * Copyright 2005 Steve Molloy 3 * 4 * This file is part of OV4J. 5 * 6 * OV4J is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as 7 * published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 8 * 9 * OV4J is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License along with OV4J; if not, write to the Free Software 13 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 * 15 */ 16 package org.ov4j.retry; 17 18 import java.lang.reflect.Method; 19 import java.util.Arrays; 20 import java.util.logging.Level; 21 import java.util.logging.Logger; 22 23 /** 24 * This class holds information about the result of a retried call. 25 * 26 * @author smolloy 27 * 28 */ 29 public class RetryableCallResult { 30 /** 31 * Logger for this class 32 */ 33 private static final Logger logger = Logger.getLogger(RetryableCallResult.class.getName()); 34 35 /** Name of the class used for the call. */ 36 private String className; 37 38 /** Method called. */ 39 private Method method; 40 41 /** Arguments used. */ 42 private Object[] args; 43 44 /** Result of the call. */ 45 private Object result; 46 47 /** Number of times the call was retried. */ 48 private int numRetries; 49 50 /** 51 * Constructor. 52 * 53 * @param call 54 * The call which was retried. 55 * @param result 56 * The result of the call. 57 */ 58 public RetryableCallResult(final RetryableCall call, final Object result, final Object... args) { 59 className = call.getClassName(); 60 method = call.getMethod(); 61 numRetries = call.getNumRetries(); 62 if (args == null) { 63 this.args = null; 64 } else { 65 this.args = new Object[args.length]; 66 System.arraycopy(args, 0, this.args, 0, args.length); 67 } 68 this.result = result; 69 } 70 71 /** 72 * @return Returns the args. 73 */ 74 public Object[] getArgs() { 75 if (RetryableCallResult.logger.isLoggable(Level.FINEST)) { 76 RetryableCallResult.logger.entering("RetryableCallResult", "getArgs()", "start"); 77 } 78 79 if (args == null) { 80 if (RetryableCallResult.logger.isLoggable(Level.FINEST)) { 81 RetryableCallResult.logger.exiting("RetryableCallResult", "getArgs()", "end - return value=" + null); 82 } 83 return null; 84 } 85 final Object[] a = new Object[args.length]; 86 System.arraycopy(args, 0, a, 0, a.length); 87 88 if (RetryableCallResult.logger.isLoggable(Level.FINEST)) { 89 RetryableCallResult.logger.exiting("RetryableCallResult", "getArgs()", "end - return value=" 90 + Arrays.toString(a)); 91 } 92 return a; 93 } 94 95 /** 96 * @return Returns the className. 97 */ 98 public String getClassName() { 99 return className; 100 } 101 102 /** 103 * @return Returns the method. 104 */ 105 public Method getMethod() { 106 return method; 107 } 108 109 /** 110 * @return Returns the numRetries. 111 */ 112 public int getNumRetries() { 113 return numRetries; 114 } 115 116 /** 117 * @return Returns the result. 118 */ 119 public Object getResult() { 120 return result; 121 } 122 123 /** 124 * @param args 125 * The args to set. 126 */ 127 public void setArgs(final Object[] args) { 128 if (RetryableCallResult.logger.isLoggable(Level.FINEST)) { 129 RetryableCallResult.logger.entering("RetryableCallResult", "setArgs(Object[]=" + Arrays.toString(args) 130 + ")", "start"); 131 } 132 133 if (args == null) { 134 this.args = null; 135 } else { 136 this.args = new Object[args.length]; 137 System.arraycopy(args, 0, this.args, 0, args.length); 138 } 139 140 if (RetryableCallResult.logger.isLoggable(Level.FINEST)) { 141 RetryableCallResult.logger.exiting("RetryableCallResult", 142 "setArgs(Object[]=" + Arrays.toString(args) + ")", "end"); 143 } 144 } 145 146 /** 147 * @param className 148 * The className to set. 149 */ 150 public void setClassName(final String className) { 151 this.className = className; 152 } 153 154 /** 155 * @param method 156 * The method to set. 157 */ 158 public void setMethod(final Method method) { 159 this.method = method; 160 } 161 162 /** 163 * @param numRetries 164 * The numRetries to set. 165 */ 166 public void setNumRetries(final int numRetries) { 167 this.numRetries = numRetries; 168 } 169 170 /** 171 * @param result 172 * The result to set. 173 */ 174 public void setResult(final Object result) { 175 this.result = result; 176 } 177 178 /** 179 * @see java.lang.Object#toString() 180 */ 181 @Override 182 public String toString() { 183 final StringBuffer sb = new StringBuffer("RetryableCallResult(Class: ").append(className); 184 sb.append(", Method: ").append(method.getName()).append(", Args: ["); 185 if (args == null) { 186 sb.append("null"); 187 } else { 188 sb.append(args[0] == null ? "null" : args[0].toString()); 189 for (int i = 1; i < args.length; i++) { 190 sb.append(", ").append(args[i] == null ? "null" : args[i].toString()); 191 } 192 } 193 sb.append("], Result: ").append(result == null ? "null" : result.toString()); 194 sb.append(", NumRetries: ").append(numRetries).append(")"); 195 return sb.toString(); 196 } 197 }