1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.plus.annotation;
15
16 import java.lang.reflect.Method;
17 import java.lang.reflect.Modifier;
18
19 import org.eclipse.jetty.util.log.Log;
20 import org.eclipse.jetty.util.log.Logger;
21
22
23
24
25
26
27 public class PreDestroyCallback extends LifeCycleCallback
28 {
29 private static final Logger LOG = Log.getLogger(PreDestroyCallback.class);
30
31
32
33
34
35
36
37
38
39
40 public void validate(Class<?> clazz, Method method)
41 {
42
43 if (method.getExceptionTypes().length > 0)
44 throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot not throw a checked exception");
45
46 if (!method.getReturnType().equals(Void.TYPE))
47 throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot not have a return type");
48
49 if (Modifier.isStatic(method.getModifiers()))
50 throw new IllegalArgumentException(clazz.getName()+"."+method.getName()+ " cannot be static");
51
52 }
53
54
55 public void callback(Object instance)
56 {
57 try
58 {
59 super.callback(instance);
60 }
61 catch (Exception e)
62 {
63 LOG.warn("Ignoring exception thrown on preDestroy call to "+getTargetClass()+"."+getTarget().getName(), e);
64 }
65 }
66
67 public boolean equals(Object o)
68 {
69 if (super.equals(o) && (o instanceof PreDestroyCallback))
70 return true;
71 return false;
72 }
73 }