Examples of ProxyFactory

Here, Method is java.lang.reflect.Method.

Then, the following method call will be forwarded to MethodHandler mi and prints a message before executing the originally called method bar() in Foo.

The last three lines of the code shown above can be replaced with a call to the helper method create, which generates a proxy class, instantiates it, and sets the method handler of the instance:

To change the method handler during runtime, execute the following code:

If setHandler is never called for a proxy instance then it will employ the default handler which proceeds by invoking the original method. The behaviour of the default handler is identical to the following handler:

A proxy factory caches and reuses proxy classes by default. It is possible to reset this default globally by setting static field {@link ProxyFactory#useCache} to false.Caching may also be configured for a specific factory by calling instance method {@link ProxyFactory#setUseCache(boolean)}. It is strongly recommended that new clients of class ProxyFactory enable caching. Failure to do so may lead to exhaustion of the heap memory area used to store classes.

Caching is automatically disabled for any given proxy factory if deprecated instance method {@link ProxyFactory#setHandler(MethodHandler)} is called. This method wasused to specify a default handler which newly created proxy classes should install when they create their instances. It is only retained to provide backward compatibility with previous releases of javassist. Unfortunately,this legacy behaviour makes caching and reuse of proxy classes impossible. The current programming model expects javassist clients to set the handler of a proxy instance explicitly by calling method {@link Proxy#setHandler(MethodHandler)} as shown in the sample code above. Newclients are strongly recommended to use this model rather than calling {@link ProxyFactory#setHandler(MethodHandler)}.

A proxy object generated by ProxyFactory is serializable if its super class or any of its interfaces implement java.io.Serializable. However, a serialized proxy object may not be compatible with future releases. The serialization support should be used for short-term storage or RMI.

For compatibility with older releases serialization of proxy objects is implemented by adding a writeReplace method to the proxy class. This allows a proxy to be serialized to a conventional {@link java.io.ObjectOutputStream} and deserialized from a corresponding{@link java.io.ObjectInputStream}. However this method suffers from several problems, the most notable one being that it fails to serialize state inherited from the proxy's superclass.

An alternative method of serializing proxy objects is available which fixes these problems. It requires inhibiting generation of the writeReplace method and instead using instances of {@link javassist.util.proxy.ProxyObjectOutputStream} and {@link javassist.util.proxy.ProxyObjectInputStream}(which are subclasses of {@link java.io.ObjectOutputStream} and {@link java.io.ObjectInputStream}) to serialize and deserialize, respectively, the proxy. These streams recognise javassist proxies and ensure that they are serialized and deserialized without the need for the proxy class to implement special methods such as writeReplace. Generation of the writeReplace method can be disabled globally by setting static field {@link ProxyFactory#useWriteReplace} to false. Alternatively, it may beconfigured per factory by calling instance method {@link ProxyFactory#setUseWriteReplace(boolean)}. @see MethodHandler @since 3.1 @author Muga Nishizawa @author Shigeru Chiba @author Andrew Dinn

  • org.apache.commons.proxy.ProxyFactory
    A ProxyFactory can be used to create three different "flavors" of proxy objects.

    Originally, the ProxyFactory class was an interface. However, to allow for future changes to the class without breaking binary or semantic compatibility, it has been changed to a concrete class.

    Note: This class uses Java reflection. For more efficient proxies, try using either {@link org.apache.commons.proxy.factory.cglib.CglibProxyFactory CglibProxyFactory} or{@link org.apache.commons.proxy.factory.javassist.JavassistProxyFactory JavassistProxyFactory} instead.

    @author James Carman @since 1.0
  • org.apache.geronimo.gbean.jmx.ProxyFactory
    @version $Rev: 46019 $ $Date: 2004-09-14 04:56:06 -0500 (Tue, 14 Sep 2004) $
  • org.apache.geronimo.kernel.proxy.ProxyFactory
    @version $Rev: 396405 $ $Date: 2006-04-24 05:53:26 +0200 (Mon, 24 Apr 2006) $
  • org.apache.tuscany.core.invocation.spi.ProxyFactory
  • org.apache.tuscany.sca.core.invocation.ProxyFactory
    Creates proxies that implement Java interfaces and invocation handlers for fronting wires @version $$Rev: 628809 $$ $$Date: 2008-02-18 16:50:37 +0000 (Mon, 18 Feb 2008) $$
  • org.apache.webbeans.proxy.ProxyFactory
  • org.glassfish.admin.amx.core.proxy.ProxyFactory
    @deprecated Factory for {@link AMXProxy} proxies.
  • org.hibernate.proxy.ProxyFactory
    Contract for run-time, proxy-based lazy initialization proxies. @author Gavin King
  • org.hotswap.agent.javassist.util.proxy.ProxyFactory
    re finalize() return !m.getName().equals("finalize"); } }); Class c = f.createClass(); MethodHandler mi = new MethodHandler() { public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Throwable { System.out.println("Name: " + m.getName()); return proceed.invoke(self, args); // execute the original method. } }; Foo foo = (Foo)c.newInstance(); ((Proxy)foo).setHandler(mi);

    Here, Method is java.lang.reflect.Method.

    Then, the following method call will be forwarded to MethodHandler mi and prints a message before executing the originally called method bar() in Foo.

    The last three lines of the code shown above can be replaced with a call to the helper method create, which generates a proxy class, instantiates it, and sets the method handler of the instance:

    To change the method handler during runtime, execute the following code:

    If setHandler is never called for a proxy instance then it will employ the default handler which proceeds by invoking the original method. The behaviour of the default handler is identical to the following handler:

    A proxy factory caches and reuses proxy classes by default. It is possible to reset this default globally by setting static field {@link ProxyFactory#useCache} to false.Caching may also be configured for a specific factory by calling instance method {@link ProxyFactory#setUseCache(boolean)}. It is strongly recommended that new clients of class ProxyFactory enable caching. Failure to do so may lead to exhaustion of the heap memory area used to store classes.

    Caching is automatically disabled for any given proxy factory if deprecated instance method {@link ProxyFactory#setHandler(MethodHandler)} is called. This method wasused to specify a default handler which newly created proxy classes should install when they create their instances. It is only retained to provide backward compatibility with previous releases of javassist. Unfortunately,this legacy behaviour makes caching and reuse of proxy classes impossible. The current programming model expects javassist clients to set the handler of a proxy instance explicitly by calling method {@link Proxy#setHandler(MethodHandler)} as shown in the sample code above. Newclients are strongly recommended to use this model rather than calling {@link ProxyFactory#setHandler(MethodHandler)}.

    A proxy object generated by ProxyFactory is serializable if its super class or any of its interfaces implement java.io.Serializable. However, a serialized proxy object may not be compatible with future releases. The serialization support should be used for short-term storage or RMI.

    For compatibility with older releases serialization of proxy objects is implemented by adding a writeReplace method to the proxy class. This allows a proxy to be serialized to a conventional {@link java.io.ObjectOutputStream} and deserialized from a corresponding{@link java.io.ObjectInputStream}. However this method suffers from several problems, the most notable one being that it fails to serialize state inherited from the proxy's superclass.

    An alternative method of serializing proxy objects is available which fixes these problems. It requires inhibiting generation of the writeReplace method and instead using instances of {@link ProxyObjectOutputStream} and {@link ProxyObjectInputStream}(which are subclasses of {@link java.io.ObjectOutputStream} and {@link java.io.ObjectInputStream}) to serialize and deserialize, respectively, the proxy. These streams recognise javassist proxies and ensure that they are serialized and deserialized without the need for the proxy class to implement special methods such as writeReplace. Generation of the writeReplace method can be disabled globally by setting static field {@link ProxyFactory#useWriteReplace} to false. Alternatively, it may beconfigured per factory by calling instance method {@link ProxyFactory#setUseWriteReplace(boolean)}. @author Muga Nishizawa @author Shigeru Chiba @author Andrew Dinn @see MethodHandler @since 3.1

  • org.jboss.ejb3.ProxyFactory
    Comment @author Bill Burke @version $Revision: 64133 $
  • org.jboss.ejb3.proxy.ProxyFactory
    Contract for a generic EJB3 Proxy Factory @author Bill Burke @author ALR @version $Revision: 80774 $
  • org.jboss.ejb3.proxy.factory.ProxyFactory
    ProxyFactory Contract for a generic Proxy Factory, specifying a simple lifecycle and functions common to all Proxy Factories @author ALR @version $Revision: $
  • org.jboss.ejb3.proxy.impl.factory.ProxyFactory
    ProxyFactory Contract for a generic Proxy Factory, specifying a simple lifecycle and functions common to all Proxy Factories @author ALR @version $Revision: $
  • org.jboss.ejb3.proxy.spi.factory.ProxyFactory
    Defines the contract for a factory capable of creating implementation non-specific proxies. @author Jaikiran Pai @author ALR @version $Revision: $
  • org.jboss.errai.bus.client.framework.ProxyFactory
  • org.jboss.errai.common.client.framework.ProxyFactory
  • org.jboss.forge.furnace.proxy.javassist.util.proxy.ProxyFactory
    re finalize() return !m.getName().equals("finalize"); } }); Class c = f.createClass(); MethodHandler mi = new MethodHandler() { public Object invoke(Object self, Method m, Method proceed, Object[] args) throws Throwable { System.out.println("Name: " + m.getName()); return proceed.invoke(self, args); // execute the original method. } }; Foo foo = (Foo)c.newInstance(); ((Proxy)foo).setHandler(mi);

    Here, Method is java.lang.reflect.Method.

    Then, the following method call will be forwarded to MethodHandler mi and prints a message before executing the originally called method bar() in Foo.

    The last three lines of the code shown above can be replaced with a call to the helper method create, which generates a proxy class, instantiates it, and sets the method handler of the instance:

    To change the method handler during runtime, execute the following code:

    If setHandler is never called for a proxy instance then it will employ the default handler which proceeds by invoking the original method. The behaviour of the default handler is identical to the following handler:

    A proxy factory caches and reuses proxy classes by default. It is possible to reset this default globally by setting static field {@link ProxyFactory#useCache} to false.Caching may also be configured for a specific factory by calling instance method {@link ProxyFactory#setUseCache(boolean)}. It is strongly recommended that new clients of class ProxyFactory enable caching. Failure to do so may lead to exhaustion of the heap memory area used to store classes.

    Caching is automatically disabled for any given proxy factory if deprecated instance method {@link ProxyFactory#setHandler(MethodHandler)} is called. This method wasused to specify a default handler which newly created proxy classes should install when they create their instances. It is only retained to provide backward compatibility with previous releases of org.jboss.forge.furnace.proxy.javassist. Unfortunately,this legacy behaviour makes caching and reuse of proxy classes impossible. The current programming model expects org.jboss.forge.furnace.proxy.javassist clients to set the handler of a proxy instance explicitly by calling method {@link Proxy#setHandler(MethodHandler)} as shown in the sample code above. Newclients are strongly recommended to use this model rather than calling {@link ProxyFactory#setHandler(MethodHandler)}.

    A proxy object generated by ProxyFactory is serializable if its super class or any of its interfaces implement java.io.Serializable. However, a serialized proxy object may not be compatible with future releases. The serialization support should be used for short-term storage or RMI.

    For compatibility with older releases serialization of proxy objects is implemented by adding a writeReplace method to the proxy class. This allows a proxy to be serialized to a conventional {@link java.io.ObjectOutputStream} and deserialized from a corresponding{@link java.io.ObjectInputStream}. However this method suffers from several problems, the most notable one being that it fails to serialize state inherited from the proxy's superclass.

    An alternative method of serializing proxy objects is available which fixes these problems. It requires inhibiting generation of the writeReplace method and instead using instances of {@link org.jboss.forge.furnace.proxy.javassist.util.proxy.ProxyObjectOutputStream} and {@link org.jboss.forge.furnace.proxy.javassist.util.proxy.ProxyObjectInputStream}(which are subclasses of {@link java.io.ObjectOutputStream} and {@link java.io.ObjectInputStream}) to serialize and deserialize, respectively, the proxy. These streams recognise org.jboss.forge.furnace.proxy.javassist proxies and ensure that they are serialized and deserialized without the need for the proxy class to implement special methods such as writeReplace. Generation of the writeReplace method can be disabled globally by setting static field {@link ProxyFactory#useWriteReplace} to false. Alternatively, it may beconfigured per factory by calling instance method {@link ProxyFactory#setUseWriteReplace(boolean)}. @see MethodHandler @since 3.1 @author Muga Nishizawa @author Shigeru Chiba @author Andrew Dinn

  • org.jboss.invocation.proxy.ProxyFactory
    Proxy Factory that generates proxies that delegate all calls to an {@link InvocationHandler}.

    Typical usage looks like:

     ProxyFactory<SimpleClass> proxyFactory = new ProxyFactory<SimpleClass>(SimpleClass.class); SimpleClass instance = proxyFactory.newInstance(new SimpleDispatcher()); 

    This will create a proxy for SimpleClass, and return a new instance that handles invocations using the InvocationDispatcher SimpleDispatcher.

    Invocations on these proxies are very efficient, as no reflection is involved. @author Stuart Douglas @param < T> the superclass type

  • org.jboss.seam.util.ProxyFactory
    ute the original method. } }; f.setFilter(new MethodFilter() { public boolean isHandled(Method m) { // ignore finalize() return !m.getName().equals("finalize"); } }); Class c = f.createClass(); Foo foo = (Foo)c.newInstance(); ((ProxyObject)foo).setHandler(mi);

    Then, the following method call will be forwarded to MethodHandler mi and prints a message before executing the originally called method bar() in Foo.

    The last three lines of the code shown above can be replaced with a call to the helper method create, which generates a proxy class, instantiates it, and sets the method handler of the instance:

    To change the method handler during runtime, execute the following code:

    You can also specify the default method handler:

    The default handler is implicitly attached to an instance of the generated class c2. Calling setHandler on the instance is not necessary unless another method handler must be attached to the instance.

    The following code is an example of method handler. It does not execute anything except invoking the original method:

    A proxy object generated by ProxyFactory is serializable if its super class or interfaces implement a java.io.Serializable. However, a serialized proxy object will not be compatible with future releases. The serialization support should be used for short-term storage or RMI. @see MethodHandler @since 3.1

  • org.springframework.aop.framework.ProxyFactory
    Factory for AOP proxies for programmatic use, rather than via a bean factory. This class provides a simple way of obtaining and configuring AOP proxies in code. @author Rod Johnson @author Juergen Hoeller @author Rob Harrop @since 14.03.2003
  • uk.ac.soton.itinnovation.grid.client.proxy.ProxyFactory

  • Examples of com.alibaba.dubbo.rpc.ProxyFactory

                    .addParameter(MonitorService.MAX_ELAPSED, 3)
                    .addParameter(MonitorService.CONCURRENT, 1)
                    .addParameter(MonitorService.MAX_CONCURRENT, 1);
           
            Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
            ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
            MonitorFactory monitorFactory = ExtensionLoader.getExtensionLoader(MonitorFactory.class).getAdaptiveExtension();

            Exporter<MonitorService> exporter = protocol.export(proxyFactory.getInvoker(monitorService, MonitorService.class, URL.valueOf("dubbo://127.0.0.1:17979/" + MonitorService.class.getName())));
            try {
                Monitor monitor = monitorFactory.getMonitor(URL.valueOf("dubbo://127.0.0.1:17979?interval=10"));
                try {
                    monitor.collect(statistics);
                    int i = 0;
    View Full Code Here

    Examples of com.dinstone.ut.faststub.internal.ProxyFactory

         * @param interceptor
         *            method interceptor to intercept the target method invocation
         * @return stub instance
         */
        public static <T> T createStub(final Class<T> toStub, MethodInterceptor interceptor) {
            ProxyFactory factory = new ProxyFactory();
            return factory.createProxyInstance(toStub, interceptor);
        }
    View Full Code Here

    Examples of com.sun.appserv.management.client.ProxyFactory

            if ((null == clusterName) || "".equals(clusterName)) {
                throw new IllegalArgumentException();
            }
            ObjectName on = null;
            final MBeanServer mbs = getAdminMBeanServer();
            final ProxyFactory proxyFactory = ProxyFactory.getInstance(
                new MBeanServerConnectionSource(mbs));
            final Set proxies = proxyFactory.getDomainRoot().getQueryMgr().
                queryJ2EETypeSet(J2EECluster.J2EE_TYPE);
            final Iterator it = proxies.iterator();
            while (it.hasNext()) {
                J2EECluster cluster = (J2EECluster)it.next();
                if (cluster.getName().equals(clusterName)) {
    View Full Code Here

    Examples of com.thoughtworks.proxy.ProxyFactory

            pico.registerComponentImplementation(DefaultPicoContainerLifecycleTestCase.Four.class);
            pico.registerComponentImplementation(DefaultPicoContainerLifecycleTestCase.Two.class);
            pico.registerComponentImplementation(DefaultPicoContainerLifecycleTestCase.One.class);
            pico.registerComponentImplementation(DefaultPicoContainerLifecycleTestCase.Three.class);

            ProxyFactory proxyFactory = new StandardProxyFactory();
            Startable startable = (Startable) Multicaster.object(pico, true, proxyFactory);
            Startable stoppable = (Startable) Multicaster.object(pico, false, proxyFactory);
            Disposable disposable = (Disposable) Multicaster.object(pico, false, proxyFactory);

            startable.start();
    View Full Code Here

    Examples of com.volantis.shared.net.proxy.ProxyFactory

        protected ProxyManager retrieveProxyManager(XMLPipelineContext context)
                throws HTTPException {

            // use system properties if available otherwise use proxy settings
            // from configuration file.
            ProxyFactory factory = ProxyFactory.getDefaultInstance();
            ProxyManager manager = factory.getSystemProxyManager();
            if (manager == null) {
                // First see if a proxy has been specified.
                String proxyRef = (String) context.getProperty(ProxyManager.class);
                if (proxyRef != null) {
                    // Now look for the referenced proxy in the configuration.
    View Full Code Here

    Examples of dynaop.ProxyFactory

        // The we setup our aop to wrap objects
        Aspects aspects = new Aspects();
        aspects.interceptor(Pointcuts.instancesOf(SecureObject.class),
            Pointcuts.ALL_METHODS, new AccessInterceptor(methodAccessManager));

        ProxyFactory proxyFactory = ProxyFactory.getInstance(aspects);

        System.out.println("Setting our subject to \"We\" with empty principals.");
        Subject subject = new Subject("We");
        Set principals = new HashSet();
        subject.setPrincipals(principals);
        Subject.set(subject);

        // We create an object which has protected methods
        SecureObject object = (SecureObject) proxyFactory.wrap(new SecureObjectImpl("Dont change me!"));
        System.out.print("We try to call setName() on \""+object.getName()+"\" ... ");
        try {
          object.setName("Changed!");
        } catch (Exception e) {
          System.out.println("denied.");
    View Full Code Here

    Examples of javassist.util.proxy.ProxyFactory

      private JavassistDataObjectInstantiator() {
      }

      public <T> T newInstance(Class<T> classToInstantiate) {
        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setSuperclass(classToInstantiate);
        Class newClass = proxyFactory.createClass();
        Object instance;
        try {
          instance = newClass.newInstance();
        } catch (Exception e) {
          throw new MappingException(e);
    View Full Code Here

    Examples of javassist.util.proxy.ProxyFactory

             socket.setEnabledProtocols(protocols);
          if (cipherSuites != null)
             socket.setEnabledCipherSuites(cipherSuites);

          DomainServerSocket handler = new DomainServerSocket(socket);
          ProxyFactory pf = new ProxyFactory();
          pf.setHandler(handler);
          pf.setSuperclass(SSLServerSocket.class);
          Class[] sig = {};
          Object[] args = {};

          SSLServerSocket proxy = null;
          try
          {
             proxy = (SSLServerSocket) pf.create(sig, args);
          }
          catch (Exception e)
          {
             IOException ioe = new IOException("Failed to create SSLServerSocket proxy");
             ioe.initCause(e);
    View Full Code Here

    Examples of javassist.util.proxy.ProxyFactory

             socket.setEnabledProtocols(protocols);
          if( cipherSuites != null )
             socket.setEnabledCipherSuites(cipherSuites);

          DomainServerSocket handler = new DomainServerSocket(socket);
          ProxyFactory pf = new ProxyFactory();
          pf.setHandler(handler);
          pf.setSuperclass(SSLServerSocket.class);
          Class[] sig = {};
          Object[] args = {};

          SSLServerSocket proxy = null;
          try
          {
             proxy = (SSLServerSocket) pf.create(sig, args);
          }
          catch (Exception e)
          {
             IOException ioe = new IOException("Failed to create SSLServerSocket proxy");
             ioe.initCause(e);
    View Full Code Here

    Examples of javassist.util.proxy.ProxyFactory

      @Override
      @SuppressWarnings("unchecked")
      public <G extends GlobalContext<?, ?>> G createGlobalContext(Class<? extends G> globalContextImplType,
          final Class<? extends EntityContext<?, ?>> entityContextImplType, Class<? extends PropertyContext<?, ?>> propertyContextImplType) {

        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setSuperclass( globalContextImplType );
        proxyFactory.setFilter( new EntityMethodFilter() );

        try {
          return (G) proxyFactory.create(
              new Class<?>[] { ConfigurationContext.class },
              new Object[] { this },
              new EntityOrPropertyMethodHandler( entityContextImplType, propertyContextImplType ) );
        }
        catch (Exception e) {
    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.