1 17 18 package org.objectweb.jac.wrappers; 19 20 import org.aopalliance.intercept.ConstructorInvocation; 21 import org.aopalliance.intercept.MethodInvocation; 22 import org.objectweb.jac.core.AspectComponent; 23 import org.objectweb.jac.core.Interaction; 24 import org.objectweb.jac.core.Wrapper; 25 26 55 56 public class LimiterWrapper extends Wrapper { 57 58 59 protected int max; 60 61 protected int min; 62 63 protected int counter = 0; 64 65 71 public LimiterWrapper(AspectComponent ac, int min, int max) { 72 super(ac); 73 this.min = min; 74 this.max = max; 75 } 76 77 82 public int getMax() { 83 return max; 84 } 85 86 91 public void setMax(int max) { 92 this.max = max; 93 } 94 95 100 public int getCounter() { 101 return counter; 102 } 103 104 120 121 public Object inc(Interaction interaction) { 122 counter++; 123 return proceed(interaction); 124 } 125 126 141 142 public Object dec(Interaction interaction) { 143 counter--; 144 return proceed(interaction); 145 } 146 147 161 162 public Object testMax(Interaction interaction) 163 throws LimiterException { 164 if(counter >= max) { 165 throw new LimiterException("counter reached its maximum count"); 166 } 167 return proceed(interaction); 168 } 169 170 184 185 public Object testMin(Interaction interaction) 186 throws LimiterException { 187 if(counter <= min) { 188 throw new LimiterException("counter reached its minimum count"); 189 } 190 return proceed(interaction); 191 } 192 193 196 public Object invoke(MethodInvocation invocation) throws Throwable { 197 return null; 199 } 200 201 204 public Object construct(ConstructorInvocation invocation) throws Throwable { 205 return null; 207 } 208 209 } 210 | Popular Tags |