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.io.Serializable;
19 import java.util.logging.Level;
20 import java.util.logging.Logger;
21
22 /**
23 * This class is used as ID for storing RetryableCall objects.
24 *
25 * @author smolloy
26 *
27 */
28 public class RetryableCallId implements Comparable<RetryableCallId>, Serializable {
29 /**
30 * Logger for this class
31 */
32 private static final Logger logger = Logger.getLogger(RetryableCallId.class.getName());
33
34 /** Serial UID */
35 private static final long serialVersionUID = -5349395545122185734L;
36
37 /** Name of the class to use for the call. */
38 private String className;
39
40 /** Name of the method to call. */
41 private String methodName;
42
43 /** Unique ID to the stored arguments for the call. */
44 private Long args;
45
46 /**
47 * Constructor.
48 */
49 public RetryableCallId() {
50 }
51
52 /**
53 * @see java.lang.Comparable#compareTo(T)
54 */
55 public int compareTo(final RetryableCallId o) {
56 if (RetryableCallId.logger.isLoggable(Level.FINEST)) {
57 RetryableCallId.logger.entering("RetryableCallId", "compareTo(RetryableCallId=" + o + ")", "start");
58 }
59
60 if (o == null) {
61 if (RetryableCallId.logger.isLoggable(Level.FINEST)) {
62 RetryableCallId.logger.exiting("RetryableCallId", "compareTo(RetryableCallId=null)",
63 "end - return value=" + 1);
64 }
65 return 1;
66 }
67
68 int res = ((className == null) ? "" : className).compareTo((o.getClassName() == null) ? "" : o.getClassName());
69 if (res == 0) {
70 res =
71 ((methodName == null) ? "" : methodName)
72 .compareTo((o.getMethodName() == null) ? "" : o.getMethodName());
73 if (res == 0) {
74 if (args == null) {
75 res = (o.getArgs() == null) ? 0 : -1;
76 } else {
77 res = args.compareTo(o.getArgs());
78 }
79 }
80 }
81
82 if (RetryableCallId.logger.isLoggable(Level.FINEST)) {
83 RetryableCallId.logger.exiting("RetryableCallId", "compareTo(RetryableCallId=" + o + ")",
84 "end - return value=" + res);
85 }
86 return res;
87 }
88
89 /**
90 * @see java.lang.Object#equals(java.lang.Object)
91 */
92 @Override
93 public boolean equals(final Object obj) {
94 if (RetryableCallId.logger.isLoggable(Level.FINEST)) {
95 RetryableCallId.logger.entering("RetryableCallId", "equals(Object=" + obj + ")", "start");
96 }
97
98 final boolean returnboolean = (obj instanceof RetryableCallId && compareTo((RetryableCallId) obj) == 0);
99
100 if (RetryableCallId.logger.isLoggable(Level.FINEST)) {
101 RetryableCallId.logger.exiting("RetryableCallId", "equals(Object=" + obj + ")", "end - return value="
102 + returnboolean);
103 }
104 return returnboolean;
105 }
106
107 /**
108 * @return Returns the args.
109 */
110 public Long getArgs() {
111 return args;
112 }
113
114 /**
115 * @return Returns the className.
116 */
117 public String getClassName() {
118 return className;
119 }
120
121 /**
122 * @return Returns the methodName.
123 */
124 public String getMethodName() {
125 return methodName;
126 }
127
128 /**
129 * @see java.lang.Object#hashCode()
130 */
131 @Override
132 public int hashCode() {
133 return (className == null ? 0 : className.hashCode()) + (methodName == null ? 0 : methodName.hashCode())
134 + (args == null ? 0 : args.hashCode());
135 }
136
137 /**
138 * @param args
139 * The args to set.
140 */
141 public void setArgs(final Long args) {
142 this.args = args;
143 }
144
145 /**
146 * @param className
147 * The className to set.
148 */
149 public void setClassName(final String className) {
150 this.className = className;
151 }
152
153 /**
154 * @param methodName
155 * The methodName to set.
156 */
157 public void setMethodName(final String methodName) {
158 this.methodName = methodName;
159 }
160
161 /**
162 * @see java.long.Object#toString()
163 */
164 @Override
165 public String toString() {
166 return "RetryableCallId(Class: " + className + ", Method: " + methodName + ", Args: " + args + ")";
167 }
168 }