1 28 29 package com.caucho.jmx; 30 31 import java.lang.reflect.Method; 32 import java.lang.reflect.InvocationTargetException; 33 34 import java.util.TimerTask; 35 36 39 public class JobManager { 40 private static Method _queueAbsolute; 41 private static Method _queueRelative; 42 private static Method _dequeue; 43 private static Method _getCurrentTime; 44 45 private JobManager() {} 46 47 50 public static long getCurrentTime() 51 { 52 try { 53 Long value = (Long) _getCurrentTime.invoke(null, null); 54 55 if (value == null) 56 return 0; 57 else 58 return value.longValue(); 59 } catch (IllegalAccessException e) { 60 throw new RuntimeException(e); 61 } catch (InvocationTargetException e) { 62 throw (RuntimeException) e.getCause(); 63 } 64 } 65 66 69 public static void queueAbsolute(TimerTask job, long time) 70 { 71 try { 72 _queueAbsolute.invoke(null, new Object[] { job, new Long(time) }); 73 } catch (IllegalAccessException e) { 74 throw new RuntimeException(e); 75 } catch (InvocationTargetException e) { 76 throw (RuntimeException) e.getCause(); 77 } 78 } 79 80 83 public static void queueRelative(TimerTask job, long time) 84 { 85 try { 86 _queueRelative.invoke(null, new Object[] { job, new Long(time) }); 87 } catch (IllegalAccessException e) { 88 throw new RuntimeException(e); 89 } catch (InvocationTargetException e) { 90 throw (RuntimeException) e.getCause(); 91 } 92 } 93 94 97 public static void dequeue(TimerTask job) 98 { 99 try { 100 _dequeue.invoke(null, new Object[] { job }); 101 } catch (IllegalAccessException e) { 102 throw new RuntimeException(e); 103 } catch (InvocationTargetException e) { 104 throw (RuntimeException) e.getCause(); 105 } 106 } 107 108 static { 109 try { 110 Class jmx = Class.forName("com.caucho.jmx.Jmx"); 111 112 _queueAbsolute = jmx.getMethod("queueAbsolute", 113 new Class[] { TimerTask.class, 114 long.class }); 115 _queueRelative = jmx.getMethod("queueRelative", 116 new Class[] { TimerTask.class, 117 long.class }); 118 _dequeue = jmx.getMethod("dequeue", new Class[] { TimerTask.class }); 119 120 Class alarm = Class.forName("com.caucho.util.Alarm"); 121 122 _getCurrentTime = alarm.getMethod("getCurrentTime", new Class[] { }); 123 } catch (Throwable e) { 124 e.printStackTrace(); 125 } 126 } 127 } 128 | Popular Tags |