1 21 22 package org.jacorb.notification.filter; 23 24 import java.lang.reflect.InvocationHandler ; 25 import java.lang.reflect.Method ; 26 import java.util.Date ; 27 28 32 public abstract class AbstractFilterUsageDecorator 33 { 34 private final Date created_ = new Date (); 35 36 protected final FilterInvocationHandler invocationHandler_; 37 38 protected class FilterInvocationHandler implements InvocationHandler 39 { 40 private long lastUsage_; 41 42 private final Object delegate_; 43 44 private long matchCount_ = 0; 45 46 private long matchStructuredCount_ = 0; 47 48 private long matchTypedCount_ = 0; 49 50 public FilterInvocationHandler(Object delegate) 51 { 52 delegate_ = delegate; 53 } 54 55 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable 56 { 57 updateUsage(method); 58 59 return method.invoke(delegate_, args); 60 } 61 62 63 private void updateUsage(Method method) 64 { 65 lastUsage_ = System.currentTimeMillis(); 66 67 if (method.getName().equals("match")) 69 { 70 ++matchCount_; 71 } 72 else if (method.getName().equals("match_structured")) 73 { 74 ++matchStructuredCount_; 75 } 76 else if (method.getName().equals("match_typed")) 77 { 78 ++matchTypedCount_; 79 } 80 } 81 82 public long getLastUsage() 83 { 84 return lastUsage_; 85 } 86 } 87 88 91 public AbstractFilterUsageDecorator(Object delegate) 92 { 93 super(); 94 95 invocationHandler_ = new FilterInvocationHandler(delegate); 96 } 97 98 public Date getLastUsage() 99 { 100 return new Date (invocationHandler_.getLastUsage()); 101 } 102 103 public Date getCreationDate() 104 { 105 return created_; 106 } 107 } 108 | Popular Tags |