List of usage examples for java.lang.reflect Proxy newProxyInstance
private static Object newProxyInstance(Class<?> caller, Constructor<?> cons, InvocationHandler h)
From source file:org.zenoss.zep.dao.impl.ConfigDaoImpl.java
public ConfigDaoImpl(DataSource ds, PartitionConfig partitionConfig) { this.template = (SimpleJdbcOperations) Proxy.newProxyInstance(SimpleJdbcOperations.class.getClassLoader(), new Class<?>[] { SimpleJdbcOperations.class }, new SimpleJdbcTemplateProxy(ds)); this.maxEventArchivePurgeIntervalDays = calculateMaximumDays( partitionConfig.getConfig(TABLE_EVENT_ARCHIVE)); logger.info("Maximum archive days: {}", maxEventArchivePurgeIntervalDays); }
From source file:com.mtgi.analytics.sql.BehaviorTrackingDataSource.java
@Override public Connection getConnection(String username, String password) throws SQLException { Connection target = getTargetDataSource().getConnection(username, password); return (Connection) Proxy.newProxyInstance(BehaviorTrackingDataSource.class.getClassLoader(), PROXY_TYPE, new ConnectionHandler(target)); }
From source file:net.sourceforge.pmd.lang.java.ParserTstUtil.java
public static <E> List<E> getOrderedNodes(Class<E> clazz, String javaCode) { Collector<E> coll = new Collector<>(clazz, new ArrayList<E>()); LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(JavaLanguageModule.NAME) .getDefaultVersion().getLanguageVersionHandler(); ASTCompilationUnit cu = (ASTCompilationUnit) languageVersionHandler .getParser(languageVersionHandler.getDefaultParserOptions()) .parse(null, new StringReader(javaCode)); JavaParserVisitor jpv = (JavaParserVisitor) Proxy.newProxyInstance(JavaParserVisitor.class.getClassLoader(), new Class[] { JavaParserVisitor.class }, coll); jpv.visit(cu, null);//w w w .ja va 2s .c o m new QualifiedNameResolver().initializeWith(ParserTstUtil.class.getClassLoader(), cu); new SymbolFacade().initializeWith(cu); new DataFlowFacade().initializeWith(languageVersionHandler.getDataFlowHandler(), cu); return (List<E>) coll.getCollection(); }
From source file:com.hubspot.utils.circuitbreaker.CircuitBreakerWrapper.java
/** * Wraps the supplied object toWrap in a CircuitBreaker conforming to the supplied CircuitBreakerPolicy. */// w w w.j a va2s .c o m public <T, W extends T> T wrap(W toWrap, Class<T> interfaceToProxy, CircuitBreakerPolicy policy) throws CircuitBreakerWrappingException { sanityCheck(toWrap, interfaceToProxy, policy); // walk the chain of interfaces implemented by T and check for their blacklisted methods Stack<Class<?>> implementedInterfaces = new Stack<Class<?>>(); implementedInterfaces.addAll(Arrays.asList(interfaceToProxy.getInterfaces())); implementedInterfaces.add(interfaceToProxy); Map<Method, Class[]> blacklist = new HashMap(); while (!implementedInterfaces.isEmpty()) { Class<?> implementedInterface = implementedInterfaces.pop(); for (Method m : implementedInterface.getDeclaredMethods()) { // check that the blacklisted method throws CircuitBreakerException if (m.isAnnotationPresent(CircuitBreakerExceptionBlacklist.class)) { if (!ArrayUtils.contains(m.getExceptionTypes(), CircuitBreakerException.class)) { throw new CircuitBreakerWrappingException( "Wrapped methods must throw CircuitBreakerException"); } CircuitBreakerExceptionBlacklist a = (CircuitBreakerExceptionBlacklist) m .getAnnotation(CircuitBreakerExceptionBlacklist.class); blacklist.put(m, a.blacklist()); } } implementedInterfaces.addAll(Arrays.asList(implementedInterface.getInterfaces())); } Class<?>[] interfaces = new Class<?>[] { interfaceToProxy }; InvocationHandler handler = new CircuitBreakerInvocationHandler(toWrap, blacklist, policy); T newProxyInstance = (T) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces, handler); return newProxyInstance; }
From source file:org.apache.hadoop.yarn.ipc.ProtoOverHadoopRpcEngine.java
@Override @SuppressWarnings("unchecked") public <T> ProtocolProxy<T> getProxy(Class<T> protocol, long clientVersion, InetSocketAddress addr, UserGroupInformation ticket, Configuration conf, SocketFactory factory, int rpcTimeout) throws IOException { return new ProtocolProxy<T>(protocol, (T) Proxy.newProxyInstance(protocol.getClassLoader(), new Class[] { protocol }, new Invoker(protocol, addr, ticket, conf, factory, rpcTimeout)), false); }
From source file:jp.primecloud.auto.ui.mock.MockBeanContext.java
protected ApplicationContext createMockContext() { InvocationHandler handler = new InvocationHandler() { @Override/*from ww w . ja va2 s .c o m*/ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("getBean".equals(method.getName())) { return getBean((String) args[0]); } else if ("getBeansOfType".equals(method.getName())) { return getBeansOfType((Class<?>) args[0]); } throw new UnsupportedOperationException(method.getName()); } }; ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class<?>[] interfaces = new Class<?>[] { ApplicationContext.class }; return (ApplicationContext) Proxy.newProxyInstance(loader, interfaces, handler); }
From source file:org.kuali.rice.core.api.resourceloader.LazyResourceFactoryBean.java
public void afterPropertiesSet() throws Exception { if (ArrayUtils.isEmpty(getProxyInterfaces())) { setProxyInterfaces(detectProxyInterfaces()); if (ArrayUtils.isEmpty(getProxyInterfaces())) { throw new FactoryBeanNotInitializedException("Failed to initialize factory bean because " + "proxyInterfaces were not injected or could not be derived from object type."); }/*from w w w . ja v a 2 s. c o m*/ } this.proxyObject = Proxy.newProxyInstance(getClass().getClassLoader(), getProxyInterfaces(), new LazyInvocationHandler()); }
From source file:org.apache.hadoop.hbase.monitoring.TaskMonitor.java
public synchronized MonitoredRPCHandler createRPCStatus(String description) { MonitoredRPCHandler stat = new MonitoredRPCHandlerImpl(); stat.setDescription(description);//w w w. j av a2 s .c o m MonitoredRPCHandler proxy = (MonitoredRPCHandler) Proxy.newProxyInstance(stat.getClass().getClassLoader(), new Class<?>[] { MonitoredRPCHandler.class }, new PassthroughInvocationHandler<MonitoredRPCHandler>(stat)); TaskAndWeakRefPair pair = new TaskAndWeakRefPair(stat, proxy); tasks.add(pair); return proxy; }
From source file:org.apache.hadoop.hive.metastore.RetryingHMSHandler.java
public static IHMSHandler getProxy(HiveConf hiveConf, IHMSHandler baseHandler, boolean local) throws MetaException { RetryingHMSHandler handler = new RetryingHMSHandler(hiveConf, baseHandler, local); return (IHMSHandler) Proxy.newProxyInstance(RetryingHMSHandler.class.getClassLoader(), new Class[] { IHMSHandler.class }, handler); }
From source file:com.comstar.mars.env.EnvMapperFactoryBean.java
/** * {@inheritDoc}//w ww . j av a 2 s . co m */ @SuppressWarnings("unchecked") public T getObject() throws Exception { installEnv(); return (T) Proxy.newProxyInstance(EnvMapperFactoryBean.class.getClassLoader(), new Class<?>[] { mapperInterface }, new MapperProxy()); }