Java Code Examples for net.sf.cglib.reflect.FastClass#newInstance()
The following examples show how to use
net.sf.cglib.reflect.FastClass#newInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CGlibInvoker.java From TakinRPC with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Override public Object invoke(RemotingProtocol msg) throws Exception { Stopwatch watch = Stopwatch.createStarted(); Object[] args = msg.getArgs(); Class<?> implClass = GuiceDI.getInstance(ServiceInfosHolder.class).getImplClass(msg.getDefineClass(), msg.getImplClass()); if (implClass == null) { throw new NoImplClassException(msg.getDefineClass().getName()); } logger.info(implClass.getName()); // Tcc tcc = GuiceDI.getInstance(TccProvider.class).getCompensable(msg.getDefineClass()); // logger.info(JSON.toJSONString(tcc)); try { FastClass fastClazz = FastClass.create(implClass); // fast class反射调用 String mkey = String.format("%s_%s", implClass.getSimpleName(), msg.getMethod()); Tuple<Object, FastMethod> classmethod = map.get(mkey); if (classmethod == null) { Object target = fastClazz.newInstance(); FastMethod method = fastClazz.getMethod(msg.getMethod(), msg.getmParamsTypes()); if (method != null) { map.put(mkey, new Tuple<Object, FastMethod>(target, method)); } } Object obj = classmethod.value.invoke(classmethod.key, args); logger.info(String.format("cglib invoke use:%s", watch.toString())); return obj; } catch (Exception e) { throw e; } }
Example 2
Source File: BytecodeProviderImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public ReflectionOptimizer getReflectionOptimizer( Class clazz, String[] getterNames, String[] setterNames, Class[] types) { FastClass fastClass; BulkBean bulkBean; try { fastClass = FastClass.create( clazz ); bulkBean = BulkBean.create( clazz, getterNames, setterNames, types ); if ( !clazz.isInterface() && !Modifier.isAbstract( clazz.getModifiers() ) ) { if ( fastClass == null ) { bulkBean = null; } else { //test out the optimizer: Object instance = fastClass.newInstance(); bulkBean.setPropertyValues( instance, bulkBean.getPropertyValues( instance ) ); } } } catch( Throwable t ) { fastClass = null; bulkBean = null; String message = "reflection optimizer disabled for: " + clazz.getName() + " [" + StringHelper.unqualify( t.getClass().getName() ) + ": " + t.getMessage(); if (t instanceof BulkBeanException ) { int index = ( (BulkBeanException) t ).getIndex(); if (index >= 0) { message += " (property " + setterNames[index] + ")"; } } log.debug( message ); } if ( fastClass != null && bulkBean != null ) { return new ReflectionOptimizerImpl( new InstantiationOptimizerAdapter( fastClass ), new AccessOptimizerAdapter( bulkBean, clazz ) ); } else { return null; } }