001/* 002 * Copyright (c) 2015 Maxim Yunusov 003 * Licensed under the Apache License, Version 2.0 (the "License"); 004 * you may not use this file except in compliance with the License. 005 * You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software 010 * distributed under the License is distributed on an "AS IS" BASIS, 011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 * See the License for the specific language governing permissions and 013 * limitations under the License. 014 */ 015 016package org.maxur.perfmodel.backend.service; 017 018import org.aopalliance.intercept.ConstructorInterceptor; 019import org.aopalliance.intercept.MethodInterceptor; 020import org.glassfish.hk2.api.Filter; 021import org.glassfish.hk2.api.InterceptionService; 022import org.glassfish.hk2.utilities.BuilderHelper; 023import org.jvnet.hk2.annotations.Service; 024 025import java.lang.reflect.Constructor; 026import java.lang.reflect.Method; 027import java.util.Collections; 028import java.util.List; 029 030/** 031 * @author myunusov 032 * @version 1.0 033 * @since <pre>02.09.2015</pre> 034 */ 035@Service 036public class HK2InterceptionService implements InterceptionService { 037 038 private static final MethodInterceptor METHOD_INTERCEPTOR = new BenchmarkMethodInterceptor(); 039 040 private static final List<MethodInterceptor> METHOD_LIST = Collections.singletonList(METHOD_INTERCEPTOR); 041 042 public Filter getDescriptorFilter() { 043 return BuilderHelper.allFilter(); 044 } 045 046 @Override 047 public List<ConstructorInterceptor> getConstructorInterceptors(Constructor<?> constructor) { 048 return null; 049 } 050 051 @Override 052 public List<MethodInterceptor> getMethodInterceptors(Method method) { 053 if (method.isAnnotationPresent(Benchmark.class)) { 054 return METHOD_LIST; 055 } 056 return null; 057 } 058 059 060} 061