Examples of MethodProxy


Examples of com.firefly.utils.ReflectUtils.MethodProxy

  }
 
  @Test
  public void testProxyMethod() throws NoSuchMethodException, SecurityException, Throwable {
    Foo foo = new Foo();
    MethodProxy proxy = ReflectUtils.getMethodProxy(Foo.class.getMethod("setProperty", String.class, boolean.class));
    Assert.assertThat(proxy.invoke(foo, "proxy foo", true), nullValue());
    Assert.assertThat(foo.getName(), is("proxy foo"));
    Assert.assertThat(foo.isFailure(), is(true));
   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "name"));
    Assert.assertThat((String)proxy.invoke(foo), is("proxy foo"));
   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "failure"));
    Assert.assertThat((Boolean)proxy.invoke(foo), is(true));
   
    proxy = ReflectUtils.getMethodProxy(ReflectUtils.getSetterMethod(Foo.class, "price"));
    Assert.assertThat(proxy.invoke(foo, 35.5), nullValue());
    Assert.assertThat(foo.getPrice(), is(35.5));
   
    MethodProxyFactoryUsingJavaCompiler proxyUsingJavaCompiler = MethodProxyFactoryUsingJavaCompiler.INSTANCE;
    Foo foo2 = new Foo();
    MethodProxy proxy2 = proxyUsingJavaCompiler.getMethodProxy(Foo.class.getMethod("setProperty", String.class, boolean.class));
    Assert.assertThat(proxy2.invoke(foo2, "proxy foo", true), nullValue());
    Assert.assertThat(foo2.getName(), is("proxy foo"));
    Assert.assertThat(foo2.isFailure(), is(true));
   
    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "name"));
    Assert.assertThat((String)proxy2.invoke(foo2), is("proxy foo"));
   
   
    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "failure"));
    Assert.assertThat((Boolean)proxy2.invoke(foo2), is(true));
   
    proxy2 = proxyUsingJavaCompiler.getMethodProxy(ReflectUtils.getSetterMethod(Foo.class, "price"));
    Assert.assertThat(proxy2.invoke(foo2, 35.5), nullValue());
    Assert.assertThat(foo2.getPrice(), is(35.5));
  }
View Full Code Here

Examples of com.firefly.utils.ReflectUtils.MethodProxy

  }
 
  public static void main7(String[] args) throws Throwable {
    Foo foo = new Foo();
    MethodProxyFactoryUsingJavaCompiler proxy = MethodProxyFactoryUsingJavaCompiler.INSTANCE;
    MethodProxy setPriceProxy = proxy.getMethodProxy(ReflectUtils.getSetterMethod(Foo.class, "price"));
    setPriceProxy.invoke(foo, 3.3);
   
    MethodProxy getPriceProxy = proxy.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "price"));
    System.out.println(getPriceProxy.invoke(foo));
   
    MethodProxy getPriceProxy2 = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "price"));
    System.out.println(getPriceProxy2.invoke(foo));
   
    int times = 1000 * 1000 * 1000;
    long start = System.currentTimeMillis();
    for (int i = 0; i < times; i++) {
      getPriceProxy.invoke(foo);
    }
    long end = System.currentTimeMillis();
    System.out.println("java compiler -> " + (end - start));
   
    start = System.currentTimeMillis();
    for (int i = 0; i < times; i++) {
      getPriceProxy.invoke(foo);
    }
    end = System.currentTimeMillis();
    System.out.println("java compiler -> " + (end - start));
   
    start = System.currentTimeMillis();
    for (int i = 0; i < times; i++) {
      getPriceProxy2.invoke(foo);
    }
    end = System.currentTimeMillis();
    System.out.println("javassist -> " + (end - start));
   
    start = System.currentTimeMillis();
    for (int i = 0; i < times; i++) {
      getPriceProxy2.invoke(foo);
    }
    end = System.currentTimeMillis();
    System.out.println("javassist -> " + (end - start));
  }
View Full Code Here

Examples of com.firefly.utils.ReflectUtils.MethodProxy

    System.out.println(ReflectUtils.getArrayProxy(obj.getClass()).get(obj, index));
  }
 
  public static void main2(String[] args) throws Throwable {
    Foo foo = new Foo();
    MethodProxy proxy = ReflectUtils.getMethodProxy(ReflectUtils.getGetterMethod(Foo.class, "failure"));
    System.out.println(proxy.invoke(foo));
   
    Field field = Foo.class.getField("num2");
    System.out.println(field.getType());
    System.out.println(field.getName());
    Field info = Foo.class.getField("info");
View Full Code Here

Examples of com.firefly.utils.ReflectUtils.MethodProxy

    int times = 1000 * 1000 * 1000;
   
    Foo foo = new Foo();
    Method method = Foo.class.getMethod("setProperty", String.class, boolean.class);
    method.setAccessible(true);
    MethodProxy proxy = ReflectUtils.getMethodProxy(method);
   
    long start = System.currentTimeMillis();
    for (int i = 0; i < times; i++) {
      proxy.invoke(foo, "method b", true);
    }
    long end = System.currentTimeMillis();
    System.out.println(foo.getName() + " invoke: " + (end - start) + "ms");
   
    start = System.currentTimeMillis();
    for (int i = 0; i < times; i++) {
      proxy.invoke(foo, "method b", true);
    }
    end = System.currentTimeMillis();
    System.out.println(foo.getName() + " invoke: " + (end - start) + "ms");
   
    start = System.currentTimeMillis();
View Full Code Here

Examples of com.firefly.utils.ReflectUtils.MethodProxy

   
  }
 
  @Override
  public MethodProxy getMethodProxy(Method method) throws Throwable {
    MethodProxy ret = methodCache.get(method);
    if(ret != null)
      return ret;
   
    synchronized(methodCache) {
      ret = methodCache.get(method);
View Full Code Here

Examples of net.sf.cglib.proxy.MethodProxy

        sortedOperationInfos = new OperationInfo[FastClass.create(serviceEndpointClass).getMaxIndex() + 1];
        String encodingStyle = "";
        for (int i = 0; i < operationInfos.length; i++) {
            OperationInfo operationInfo = operationInfos[i];
            Signature signature = operationInfo.getSignature();
            MethodProxy methodProxy = MethodProxy.find(serviceEndpointClass, signature);
            if (methodProxy == null) {
                throw new RuntimeException("No method proxy for operationInfo " + signature);
            }
            int index = methodProxy.getSuperIndex();
            sortedOperationInfos[index] = operationInfo;
            if (operationInfo.getOperationDesc().getUse() == Use.ENCODED) {
                encodingStyle = org.apache.axis.Constants.URI_SOAP11_ENC;
            }
        }
View Full Code Here

Examples of net.sf.cglib.proxy.MethodProxy

        return null;
    }

    private static int getSuperIndex(Class proxyType, Method method) {
        Signature signature = new Signature(method.getName(), Type.getReturnType(method), Type.getArgumentTypes(method));
        MethodProxy methodProxy = MethodProxy.find(proxyType, signature);
        if (methodProxy != null) {
            return methodProxy.getSuperIndex();
        }
        return -1;
    }
View Full Code Here

Examples of net.sf.cglib.proxy.MethodProxy

    void initialize() {
        String encodingStyle = "";
        for (int i = 0; i < operationInfos.length; i++) {
            OperationInfo operationInfo = operationInfos[i];
            Signature signature = operationInfo.getSignature();
            MethodProxy methodProxy = MethodProxy.find(serviceEndpointClass, signature);
            if (methodProxy == null) {
                throw new RuntimeException("No method proxy for operationInfo " + signature);
            }
            int index = methodProxy.getSuperIndex();
            sortedOperationInfos[index] = operationInfo;
            if (operationInfo.getOperationDesc().getUse() == Use.ENCODED) {
                encodingStyle = org.apache.axis.Constants.URI_SOAP11_ENC;
            }
        }
View Full Code Here

Examples of net.sf.cglib.proxy.MethodProxy

        return new KernelOperationInvoker(kernel, method);
    }

    private static int getSuperIndex(Class proxyType, Method method) {
        Signature signature = new Signature(method.getName(), Type.getReturnType(method), Type.getArgumentTypes(method));
        MethodProxy methodProxy = MethodProxy.find(proxyType, signature);
        if (methodProxy != null) {
            return methodProxy.getSuperIndex();
        }
        return -1;
    }
View Full Code Here

Examples of net.sf.cglib.proxy.MethodProxy

        return new KernelOperationInvoker(kernel, method);
    }

    private static int getSuperIndex(Class proxyType, Method method) {
        Signature signature = new Signature(method.getName(), Type.getReturnType(method), Type.getArgumentTypes(method));
        MethodProxy methodProxy = MethodProxy.find(proxyType, signature);
        if (methodProxy != null) {
            return methodProxy.getSuperIndex();
        }
        return -1;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.