Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

removed InterceptorMetadataRegistry - will leave caching/reading of i…

…nterceptor metadata to client

git-svn-id: http://svn.jboss.org/repos/jbossas/projects/interceptors/trunk@107156 84be2c1e-ba19-0410-b317-a758671a6fc1
  • Loading branch information...
commit afbce0ba91f24cb32cdc208ed8e54ab503d923f4 1 parent ddb2ec3
@mbogoevici authored
View
5 jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/DirectClassInterceptorInstantiator.java
@@ -17,7 +17,6 @@
package org.jboss.interceptor.proxy;
-import org.jboss.interceptor.registry.InterceptorMetadataRegistry;
import org.jboss.interceptor.spi.instance.InterceptorInstantiator;
import org.jboss.interceptor.spi.metadata.ClassMetadata;
@@ -26,11 +25,9 @@
*/
public class DirectClassInterceptorInstantiator implements InterceptorInstantiator<ClassMetadata<?>, Object>
{
- private InterceptorMetadataRegistry interceptorMetadataRegistry;
- public DirectClassInterceptorInstantiator(InterceptorMetadataRegistry interceptorMetadataRegistry)
+ public DirectClassInterceptorInstantiator()
{
- this.interceptorMetadataRegistry = interceptorMetadataRegistry;
}
public Object createFor(ClassMetadata<?> clazz)
View
18 jboss-interceptor/src/main/java/org/jboss/interceptor/registry/InterceptorMetadataRegistry.java
@@ -1,18 +0,0 @@
-package org.jboss.interceptor.registry;
-
-import org.jboss.interceptor.spi.metadata.ClassMetadata;
-import org.jboss.interceptor.spi.metadata.InterceptorMetadata;
-
-
-/**
- * Acts as a repository of
- *
- * @author Marius Bogoevici
- */
-public interface InterceptorMetadataRegistry
-{
- InterceptorMetadata getInterceptorClassMetadata(ClassMetadata<?> interceptorClass);
-
- InterceptorMetadata getInterceptorClassMetadata(ClassMetadata<?> interceptorClass, boolean isInterceptorTargetClass);
-
-}
View
123 jboss-interceptor/src/main/java/org/jboss/interceptor/registry/SimpleInterceptorMetadataRegistry.java
@@ -1,123 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
- * contributors by the @authors tag. See the copyright.txt in the
- * distribution for a full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.interceptor.registry;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import org.jboss.interceptor.reader.InterceptorMetadataUtils;
-import org.jboss.interceptor.spi.metadata.ClassMetadata;
-import org.jboss.interceptor.spi.metadata.InterceptorMetadata;
-
-
-/**
- * @author <a href="mailto:mariusb@redhat.com">Marius Bogoevici</a>
- */
-public class SimpleInterceptorMetadataRegistry implements InterceptorMetadataRegistry
-{
- private final Map<Key, InterceptorMetadata> interceptorClassMetadataMap = new ConcurrentHashMap<Key, InterceptorMetadata>();
-
- private final Lock lock = new ReentrantLock();
-
- public InterceptorMetadata getInterceptorClassMetadata(ClassMetadata interceptorClass)
- {
- return this.getInterceptorClassMetadata(interceptorClass, false);
- }
-
- public InterceptorMetadata getInterceptorClassMetadata(ClassMetadata interceptorClass, boolean isInterceptorTargetClass)
- {
- Key key = new Key(interceptorClass, isInterceptorTargetClass);
- if (!interceptorClassMetadataMap.containsKey(key))
- {
- try
- {
- lock.lock();
- //verify that metadata hasn't been added while waiting for the lock
- if (!interceptorClassMetadataMap.containsKey(key))
- {
- if (isInterceptorTargetClass)
- interceptorClassMetadataMap.put(key, InterceptorMetadataUtils.readMetadataForTargetClass(interceptorClass));
- else
- interceptorClassMetadataMap.put(key, InterceptorMetadataUtils.readMetadataForInterceptorClass(interceptorClass));
- }
- }
- finally
- {
- lock.unlock();
- }
- }
-
- return interceptorClassMetadataMap.get(key);
-
- }
-
- public void cleanup()
- {
- this.interceptorClassMetadataMap.clear();
- }
-
- public static final class Key
- {
- private String className;
-
- private boolean isInterceptorTargetClass;
-
- private Key(ClassMetadata clazz, boolean interceptorTargetClass)
- {
- this.className = clazz.getClassName();
- isInterceptorTargetClass = interceptorTargetClass;
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (this == o)
- {
- return true;
- }
- if (o == null || getClass() != o.getClass())
- {
- return false;
- }
-
- Key key = (Key) o;
-
- if (isInterceptorTargetClass != key.isInterceptorTargetClass)
- {
- return false;
- }
- if (className != null ? !className.equals(key.className) : key.className != null)
- {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode()
- {
- int result = className != null ? className.hashCode() : 0;
- result = 31 * result + (isInterceptorTargetClass ? 1 : 0);
- return result;
- }
- }
-
-}
View
22 jboss-interceptor/src/test/java/org/jboss/interceptors/metadata/InterceptorClassMetadataTestCase.java
@@ -20,14 +20,12 @@
import java.util.List;
-import org.jboss.interceptor.registry.InterceptorMetadataRegistry;
-import org.jboss.interceptor.registry.SimpleInterceptorMetadataRegistry;
+import org.jboss.interceptor.reader.InterceptorMetadataUtils;
import org.jboss.interceptor.reader.ReflectiveClassMetadata;
import org.jboss.interceptor.spi.metadata.InterceptorMetadata;
import org.jboss.interceptor.spi.metadata.MethodMetadata;
import org.jboss.interceptor.spi.model.InterceptionType;
import org.jboss.interceptor.util.InterceptorMetadataException;
-import org.junit.Before;
import org.junit.Test;
/**
@@ -36,18 +34,10 @@
public class InterceptorClassMetadataTestCase
{
- InterceptorMetadataRegistry interceptorMetadataRegistry;
-
- @Before
- public void setUp()
- {
- interceptorMetadataRegistry = new SimpleInterceptorMetadataRegistry();
- }
-
@Test
public void testInterceptorWithAllMethods()
{
- InterceptorMetadata interceptorClassMetadata = interceptorMetadataRegistry.getInterceptorClassMetadata(ReflectiveClassMetadata.of(InterceptorWithAllMethods.class));
+ InterceptorMetadata interceptorClassMetadata = InterceptorMetadataUtils.readMetadataForInterceptorClass(ReflectiveClassMetadata.of(InterceptorWithAllMethods.class));
List<MethodMetadata> postConstructMethods = interceptorClassMetadata.getInterceptorMethods(InterceptionType.POST_CONSTRUCT);
assertEquals(true, postConstructMethods.size() == 1);
@@ -74,7 +64,7 @@ public void testInterceptorWithAllMethods()
@Test
public void testInterceptorWithSomeMethods()
{
- InterceptorMetadata interceptorClassMetadata = interceptorMetadataRegistry.getInterceptorClassMetadata(ReflectiveClassMetadata.of(InterceptorWithSomeMethods.class));
+ InterceptorMetadata interceptorClassMetadata = InterceptorMetadataUtils.readMetadataForInterceptorClass(ReflectiveClassMetadata.of(InterceptorWithSomeMethods.class));
List<MethodMetadata> postConstructMethods = interceptorClassMetadata.getInterceptorMethods(InterceptionType.POST_CONSTRUCT);
assertEquals(true, postConstructMethods.size() == 0);
@@ -99,7 +89,7 @@ public void testInterceptorWithSomeMethods()
@Test
public void testSimpleInheritance()
{
- InterceptorMetadata interceptorClassMetadata = interceptorMetadataRegistry.getInterceptorClassMetadata(ReflectiveClassMetadata.of(SimpleInheritanceChildInterceptor.class));
+ InterceptorMetadata interceptorClassMetadata = InterceptorMetadataUtils.readMetadataForInterceptorClass(ReflectiveClassMetadata.of(SimpleInheritanceChildInterceptor.class));
List<MethodMetadata> postConstructMethods = interceptorClassMetadata.getInterceptorMethods(InterceptionType.POST_CONSTRUCT);
assertEquals(1, postConstructMethods.size());
@@ -123,7 +113,7 @@ public void testSimpleInheritance()
@Test
public void testInheritanceWithAndWithoutOverriding()
{
- InterceptorMetadata interceptorClassMetadata = interceptorMetadataRegistry.getInterceptorClassMetadata(ReflectiveClassMetadata.of(OverrideChildInterceptor.class));
+ InterceptorMetadata interceptorClassMetadata = InterceptorMetadataUtils.readMetadataForInterceptorClass(ReflectiveClassMetadata.of(OverrideChildInterceptor.class));
List<MethodMetadata> postConstructMethods = interceptorClassMetadata.getInterceptorMethods(InterceptionType.POST_CONSTRUCT);
assertEquals(true, postConstructMethods.size() == 1);
@@ -149,7 +139,7 @@ public void testInheritanceWithAndWithoutOverriding()
@Test(expected = InterceptorMetadataException.class)
public void testDuplicateAnnotations()
{
- InterceptorMetadata interceptorClassMetadata = interceptorMetadataRegistry.getInterceptorClassMetadata(ReflectiveClassMetadata.of(InterceptorWithDuplicateAnnotations.class));
+ InterceptorMetadata interceptorClassMetadata = InterceptorMetadataUtils.readMetadataForInterceptorClass(ReflectiveClassMetadata.of(InterceptorWithDuplicateAnnotations.class));
}
View
10 jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTestCase.java
@@ -32,9 +32,8 @@
import org.jboss.interceptor.proxy.DirectClassInterceptorInstantiator;
import org.jboss.interceptor.proxy.InterceptorProxyCreatorImpl;
import org.jboss.interceptor.proxy.javassist.CompositeHandler;
+import org.jboss.interceptor.reader.InterceptorMetadataUtils;
import org.jboss.interceptor.reader.ReflectiveClassMetadata;
-import org.jboss.interceptor.registry.InterceptorMetadataRegistry;
-import org.jboss.interceptor.registry.SimpleInterceptorMetadataRegistry;
import org.jboss.interceptor.spi.metadata.ClassMetadata;
import org.jboss.interceptor.spi.metadata.InterceptorMetadata;
import org.jboss.interceptor.spi.model.InterceptionModel;
@@ -100,13 +99,10 @@
private DirectClassInterceptorInstantiator interceptionHandlerFactory;
- private InterceptorMetadataRegistry interceptorMetadataRegistry;
-
@Before
public void setUp()
{
- interceptorMetadataRegistry = new SimpleInterceptorMetadataRegistry();
- interceptionHandlerFactory = new DirectClassInterceptorInstantiator(interceptorMetadataRegistry);
+ interceptionHandlerFactory = new DirectClassInterceptorInstantiator();
}
public void resetLogAndSetupClassesForMethod() throws Exception
@@ -464,7 +460,7 @@ private String iterateAndDisplay(Object[] logValues)
private <T> T proxifyInstance(T instance, Class<? extends T> targetClass)
{
InterceptorProxyCreatorImpl ipc = new InterceptorProxyCreatorImpl(interceptionHandlerFactory, interceptionModelRegistry.get(targetClass));
- InterceptorMetadata classMetadata = interceptorMetadataRegistry.getInterceptorClassMetadata(ReflectiveClassMetadata.of(targetClass), true);
+ InterceptorMetadata classMetadata = InterceptorMetadataUtils.readMetadataForTargetClass(ReflectiveClassMetadata.of(targetClass));
ClassMetadata<? extends T> targetClassMetadata = ReflectiveClassMetadata.of(targetClass);
MethodHandler methodHandler = ipc.createMethodHandler(instance, targetClassMetadata, classMetadata);
Class<? extends T> proxyClassWithHandler = InterceptionUtils.createProxyClassWithHandler(targetClassMetadata, methodHandler);
View
10 jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/SubclassingInterceptionTestCase.java
@@ -29,9 +29,8 @@
import org.jboss.interceptor.proxy.DirectClassInterceptorInstantiator;
import org.jboss.interceptor.proxy.InterceptorProxyCreatorImpl;
import org.jboss.interceptor.proxy.javassist.CompositeHandler;
+import org.jboss.interceptor.reader.InterceptorMetadataUtils;
import org.jboss.interceptor.reader.ReflectiveClassMetadata;
-import org.jboss.interceptor.registry.InterceptorMetadataRegistry;
-import org.jboss.interceptor.registry.SimpleInterceptorMetadataRegistry;
import org.jboss.interceptor.spi.metadata.ClassMetadata;
import org.jboss.interceptor.spi.model.InterceptionModel;
import org.jboss.interceptor.util.InterceptionUtils;
@@ -96,13 +95,10 @@
private DirectClassInterceptorInstantiator interceptionHandlerFactory;
- private InterceptorMetadataRegistry interceptorMetadataRegistry;
-
@Before
public void setUp()
{
- interceptorMetadataRegistry = new SimpleInterceptorMetadataRegistry();
- interceptionHandlerFactory = new DirectClassInterceptorInstantiator(interceptorMetadataRegistry);
+ interceptionHandlerFactory = new DirectClassInterceptorInstantiator();
}
public void resetLogAndSetupClassesForMethod() throws Exception
@@ -449,7 +445,7 @@ private String iterateAndDisplay(Object[] logValues)
{
InterceptionModel<ClassMetadata<?>, ClassMetadata> classMetadataInterceptionModel = interceptionModelRegistry.get(targetClass);
InterceptorProxyCreatorImpl ipc = new InterceptorProxyCreatorImpl(interceptionHandlerFactory, classMetadataInterceptionModel);
- return ipc.createProxyFromClass(ReflectiveClassMetadata.of((Class<? extends T>) targetClass), new Class<?>[]{String.class}, args, interceptorMetadataRegistry.getInterceptorClassMetadata(ReflectiveClassMetadata.of((Class<? extends T>) targetClass), true));
+ return ipc.createProxyFromClass(ReflectiveClassMetadata.of((Class<? extends T>) targetClass), new Class<?>[]{String.class}, args, InterceptorMetadataUtils.readMetadataForTargetClass(ReflectiveClassMetadata.of((Class<? extends T>) targetClass)));
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.