List of usage examples for java.lang.reflect Proxy newProxyInstance
private static Object newProxyInstance(Class<?> caller, Constructor<?> cons, InvocationHandler h)
From source file:com.alibaba.wasp.ipc.ProtobufRpcEngine.java
@Override public VersionedProtocol getProxy(Class<? extends VersionedProtocol> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, SocketFactory factory, int rpcTimeout) throws IOException { final Invoker invoker = new Invoker(protocol, addr, conf, factory, rpcTimeout); return (VersionedProtocol) Proxy.newProxyInstance(protocol.getClassLoader(), new Class[] { protocol }, invoker);// w w w .j a v a 2s. co m }
From source file:com.taobao.common.tedis.atomic.TedisSingle.java
public TedisSingle(ServerProperties prop) { this.prop = prop; this.pool_size = prop.pool_size; this.tedis = (RedisCommands) Proxy.newProxyInstance(RedisCommands.class.getClassLoader(), new Class[] { RedisCommands.class }, new TedisInvocationHandler()); for (int i = 0; i < pool_size; i++) { Tedis[] _tedises = new Tedis[prop.servers.length]; for (int j = 0; j < prop.servers.length; j++) { Tedis _tedis = new Tedis(prop.servers[j].addr, prop.servers[j].port, prop.timeout); if (null != prop.password && !"".equals(prop.password)) { _tedis.auth(prop.password); } else { _tedis.ping();// www. j a v a 2s . c om } _tedises[j] = _tedis; } BatchThread thread = new BatchThread(i, _tedises); threadPool.add(thread); thread.start(); } }
From source file:org.apache.tajo.rpc.NettyAsyncRpcProxy.java
public Object getProxy() { return Proxy.newProxyInstance(protocol.getClassLoader(), new Class[] { protocol }, new Invoker(getChannel())); }
From source file:org.gradle.model.internal.manage.state.ManagedModelElement.java
public T createInstance() { Class<T> concreteType = type.getConcreteClass(); Object instance = Proxy.newProxyInstance(concreteType.getClassLoader(), new Class<?>[] { concreteType, ManagedInstance.class }, new ManagedModelElementInvocationHandler()); @SuppressWarnings("unchecked") T typedInstance = (T) instance;/*w w w .j av a 2 s . c o m*/ return typedInstance; }
From source file:org.softdays.mandy.config.TransactionAwareDestination.java
@Override public Connection getConnection() throws SQLException { return (Connection) Proxy.newProxyInstance(ConnectionProxy.class.getClassLoader(), new Class[] { ConnectionProxy.class }, new TransactionAwareInvocationHandler(this.dataSource)); }
From source file:my.school.spring.beans.ProfilingBeanPostProcessor.java
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { Class beanClazz = profilingClasses.get(beanName); if (beanClazz != null) { Object proxyInstance = Proxy.newProxyInstance(beanClazz.getClassLoader(), beanClazz.getInterfaces(), (Object proxy, Method method, Object[] args) -> { LOG.info("Call for {}::{}", proxy.getClass().getName(), method.getName()); Object ret;/*ww w . j a va 2s . c o m*/ if (profilingController.isEnabled()) { long startTime = System.nanoTime(); ret = method.invoke(bean, args); long endTime = System.nanoTime(); LOG.info("PROF:8150F577C514: {}", endTime - startTime); } else { ret = method.invoke(bean, args); } ret.getClass().getName(); return ret; }); LOG.info("Creating a PROXY for {}: {} over target of class {} (Defined as: {})", beanName, proxyInstance.getClass().getName(), bean.getClass().getName(), beanClazz.getName()); return proxyInstance; } return bean; }
From source file:org.apache.hadoop.hbase.monitoring.TaskMonitor.java
public synchronized MonitoredTask createStatus(String description) { MonitoredTask stat = new MonitoredTaskImpl(); stat.setDescription(description);/* w w w . java2 s.co m*/ MonitoredTask proxy = (MonitoredTask) Proxy.newProxyInstance(stat.getClass().getClassLoader(), new Class<?>[] { MonitoredTask.class }, new PassthroughInvocationHandler<MonitoredTask>(stat)); TaskAndWeakRefPair pair = new TaskAndWeakRefPair(stat, proxy); tasks.add(pair); return proxy; }
From source file:org.zenoss.zep.dao.impl.EventIndexQueueDaoImpl.java
public EventIndexQueueDaoImpl(DataSource ds, boolean isArchive, EventDaoHelper daoHelper, DatabaseCompatibility databaseCompatibility) { this.template = (SimpleJdbcOperations) Proxy.newProxyInstance(SimpleJdbcOperations.class.getClassLoader(), new Class<?>[] { SimpleJdbcOperations.class }, new SimpleJdbcTemplateProxy(ds)); this.isArchive = isArchive; if (isArchive) { this.tableName = EventConstants.TABLE_EVENT_ARCHIVE; } else {/*w w w. j av a 2 s . c om*/ this.tableName = EventConstants.TABLE_EVENT_SUMMARY; } this.queueTableName = this.tableName + "_index_queue"; this.uuidConverter = databaseCompatibility.getUUIDConverter(); this.timestampConverter = databaseCompatibility.getTimestampConverter(); this.rowMapper = new EventSummaryRowMapper(daoHelper, databaseCompatibility); }
From source file:io.syndesis.runtime.Recordings.java
static public <T> T recorder(Object object, Class<T> as) { if (as.isInterface()) { // If it's just an interface, use standard java reflect proxying return as.cast(Proxy.newProxyInstance(as.getClassLoader(), new Class[] { as }, new RecordingInvocationHandler(object))); }//from w w w. jav a 2s . c om // If it's a class then use gclib to implement a subclass to implement proxying RecordingInvocationHandler ih = new RecordingInvocationHandler(object); Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(as); enhancer.setInterfaces(new Class[] { RecordingProxy.class }); enhancer.setCallback(new org.springframework.cglib.proxy.InvocationHandler() { @Override public Object invoke(Object o, Method method, Object[] objects) throws Throwable { return ih.invoke(o, method, objects); } }); return as.cast(enhancer.create()); }
From source file:com.mtgi.analytics.sql.BehaviorTrackingDataSource.java
@Override public Connection getConnection() throws SQLException { Connection target = getTargetDataSource().getConnection(); return (Connection) Proxy.newProxyInstance(BehaviorTrackingDataSource.class.getClassLoader(), PROXY_TYPE, new ConnectionHandler(target)); }