Package javassist.util.proxy

Examples of javassist.util.proxy.ProxyFactory$UniqueName


    }
  }

  private static Counter getCounter(final Accumulator<Map<String, Long>> accum, final String group,
                                    final String counterName) {
    ProxyFactory factory = new ProxyFactory();
    Class<Counter> superType = Counter.class;
    Class[] types = new Class[0];
    Object[] args = new Object[0];
    if (superType.isInterface()) {
      factory.setInterfaces(new Class[] { superType });
    } else {
      types = new Class[] { String.class, String.class };
      args = new Object[] { group, counterName };
      factory.setSuperclass(superType);
    }

    final Set<String> handledMethods = ImmutableSet.of("getDisplayName", "getName",
        "getValue", "increment", "setValue", "setDisplayName");
    factory.setFilter(new MethodFilter() {
      @Override
      public boolean isHandled(Method m) {
        return handledMethods.contains(m.getName());
      }
    });
    MethodHandler handler = new MethodHandler() {
      @Override
      public Object invoke(Object arg0, Method m, Method arg2, Object[] args) throws Throwable {
        String name = m.getName();
        if ("increment".equals(name)) {
          accum.add(ImmutableMap.of(group + ":" + counterName, (Long) args[0]));
          return null;
        } else if ("getDisplayName".equals(name)) {
          return counterName;
        } else if ("getName".equals(name)) {
          return counterName;
        } else if ("setDisplayName".equals(name)) {
          // No-op
          return null;
        } else if ("setValue".equals(name)) {
          throw new UnsupportedOperationException("Cannot set counter values in Spark, only increment them");
        } else if ("getValue".equals(name)) {
          throw new UnsupportedOperationException("Cannot read counters during Spark execution");
        } else {
          throw new IllegalStateException("Unhandled method " + name);
        }
      }
    };
    try {
      Object newInstance = factory.create(types, args, handler);
      return (Counter) newInstance;
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
View Full Code Here


   * Note: The intention of this is to provide the bare essentials that are
   * required to make the {@linkplain MemPipeline} work. It lacks even the basic
   * things that can proved some support for unit testing pipeline.
   */
  private static TaskInputOutputContext<?, ?, ?, ?> getInMemoryContext(final Configuration conf) {
    ProxyFactory factory = new ProxyFactory();
    Class<TaskInputOutputContext> superType = TaskInputOutputContext.class;
    Class[] types = new Class[0];
    Object[] args = new Object[0];
    final TaskAttemptID taskAttemptId = new TaskAttemptID();
    if (superType.isInterface()) {
      factory.setInterfaces(new Class[] { superType });
    } else {
      types = new Class[] { Configuration.class, TaskAttemptID.class, RecordWriter.class, OutputCommitter.class,
          StatusReporter.class };
      args = new Object[] { conf, taskAttemptId, null, null, null };
      factory.setSuperclass(superType);
    }

    final Set<String> handledMethods = ImmutableSet.of("getConfiguration", "getCounter",
                                                  "progress", "getTaskAttemptID");
    factory.setFilter(new MethodFilter() {
      @Override
      public boolean isHandled(Method m) {
        return handledMethods.contains(m.getName());
      }
    });
    MethodHandler handler = new MethodHandler() {
      @Override
      public Object invoke(Object arg0, Method m, Method arg2, Object[] args) throws Throwable {
        String name = m.getName();
        if ("getConfiguration".equals(name)) {
          return conf;
        } else if ("progress".equals(name)) {
          // no-op
          return null;
        } else if ("getTaskAttemptID".equals(name)) {
          return taskAttemptId;
        } else if ("getCounter".equals(name)){ // getCounter
          if (args.length == 1) {
            return MemPipeline.getCounters().findCounter((Enum<?>) args[0]);
          } else {
            return MemPipeline.getCounters().findCounter((String) args[0], (String) args[1]);
          }
        } else {
          throw new IllegalStateException("Unhandled method " + name);
        }
      }
    };
    try {
      Object newInstance = factory.create(types, args, handler);
      return (TaskInputOutputContext<?, ?, ?, ?>) newInstance;
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
View Full Code Here

              getIdentifierMethod,
              setIdentifierMethod,
              componentIdType,
              session
      );
      ProxyFactory factory = new ProxyFactory();
      factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
      factory.setInterfaces( interfaces );
      factory.setFilter( FINALIZE_FILTER );
      Class cl = factory.createClass();
      final HibernateProxy proxy = ( HibernateProxy ) cl.newInstance();
      ( ( ProxyObject ) proxy ).setHandler( instance );
      instance.constructed = true;
      return proxy;
    }
View Full Code Here

      Class persistentClass,
          Class[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
      ProxyFactory factory = new ProxyFactory();
      factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
      factory.setInterfaces( interfaces );
      factory.setFilter( FINALIZE_FILTER );
      return factory.createClass();
    }
    catch ( Throwable t ) {
      LoggerFactory.getLogger( BasicLazyInitializer.class ).error(
          "Javassist Enhancement failed: "
          + persistentClass.getName(), t
View Full Code Here

          setIdentifierMethod,
          componentIdType,
          session,
          ReflectHelper.overridesEquals(persistentClass)
      );
      ProxyFactory factory = new ProxyFactory();
      factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
      factory.setInterfaces( interfaces );
      factory.setFilter( FINALIZE_FILTER );
      Class cl = factory.createClass();
      final HibernateProxy proxy = ( HibernateProxy ) cl.newInstance();
      ( ( Proxy ) proxy ).setHandler( instance );
      instance.constructed = true;
      return proxy;
    }
View Full Code Here

      Class persistentClass,
      Class[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
      ProxyFactory factory = new ProxyFactory();
      factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
      factory.setInterfaces( interfaces );
      factory.setFilter( FINALIZE_FILTER );
      return factory.createClass();
    }
    catch ( Throwable t ) {
      LOG.error(LOG.javassistEnhancementFailed(persistentClass.getName()), t);
      throw new HibernateException(LOG.javassistEnhancementFailed(persistentClass.getName()), t);
    }
View Full Code Here

              getIdentifierMethod,
              setIdentifierMethod,
              componentIdType,
              session
      );
      ProxyFactory factory = new ProxyFactory();
      factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
      factory.setInterfaces( interfaces );
      factory.setFilter( FINALIZE_FILTER );
      Class cl = factory.createClass();
      final HibernateProxy proxy = ( HibernateProxy ) cl.newInstance();
      ( ( ProxyObject ) proxy ).setHandler( instance );
      instance.constructed = true;
      return proxy;
    }
View Full Code Here

      Class persistentClass,
          Class[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
      ProxyFactory factory = new ProxyFactory();
      factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
      factory.setInterfaces( interfaces );
      factory.setFilter( FINALIZE_FILTER );
      return factory.createClass();
    }
    catch ( Throwable t ) {
      LoggerFactory.getLogger( BasicLazyInitializer.class ).error(
          "Javassist Enhancement failed: "
          + persistentClass.getName(), t
View Full Code Here

              getIdentifierMethod,
              setIdentifierMethod,
              componentIdType,
              session
      );
      ProxyFactory factory = new ProxyFactory();
      factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
      factory.setInterfaces( interfaces );
      factory.setFilter( FINALIZE_FILTER );
      Class cl = factory.createClass();
      final HibernateProxy proxy = ( HibernateProxy ) cl.newInstance();
      ( ( ProxyObject ) proxy ).setHandler( instance );
      instance.constructed = true;
      return proxy;
    }
View Full Code Here

      Class persistentClass,
          Class[] interfaces) throws HibernateException {
    // note: interfaces is assumed to already contain HibernateProxy.class

    try {
      ProxyFactory factory = new ProxyFactory();
      factory.setSuperclass( interfaces.length == 1 ? persistentClass : null );
      factory.setInterfaces( interfaces );
      factory.setFilter( FINALIZE_FILTER );
      return factory.createClass();
    }
    catch ( Throwable t ) {
      LogFactory.getLog( BasicLazyInitializer.class ).error(
          "Javassist Enhancement failed: "
          + persistentClass.getName(), t
View Full Code Here

TOP

Related Classes of javassist.util.proxy.ProxyFactory$UniqueName

Copyright © 2018 www.massapicom. 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.