mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-17 08:46:22 +10:00
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-tomcat-profiler/trunk@569 84d0f5b1-2673-498c-a247-62c4ff18d310
51 lines
1.1 KiB
Java
51 lines
1.1 KiB
Java
package com.profiler.interceptor;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
public class InterceptorRegistry {
|
|
|
|
private final static int DEFAULT_MAX = 1024;
|
|
private final int max;
|
|
|
|
private final AtomicInteger id = new AtomicInteger(0);
|
|
private final Interceptor[] index;
|
|
|
|
public static final InterceptorRegistry REGISTRY = new InterceptorRegistry();
|
|
|
|
InterceptorRegistry() {
|
|
this(DEFAULT_MAX);
|
|
}
|
|
|
|
InterceptorRegistry(int max) {
|
|
this.max = max;
|
|
this.index = new Interceptor[max];
|
|
}
|
|
|
|
|
|
int addInterceptor0(Interceptor interceptor) {
|
|
if (interceptor == null) {
|
|
return -1;
|
|
}
|
|
int newId = id.getAndIncrement();
|
|
if (newId > max) {
|
|
throw new IllegalArgumentException("id" + id);
|
|
}
|
|
|
|
this.index[newId] = interceptor;
|
|
return newId;
|
|
}
|
|
|
|
Interceptor getInterceptor0(int key) {
|
|
return index[key];
|
|
}
|
|
|
|
public static int addInterceptor(Interceptor interceptor) {
|
|
return REGISTRY.addInterceptor0(interceptor);
|
|
}
|
|
|
|
public static Interceptor getInterceptor(int key) {
|
|
return REGISTRY.getInterceptor0(key);
|
|
}
|
|
|
|
}
|