List of usage examples for org.springframework.util ReflectionUtils invokeMethod
@Nullable public static Object invokeMethod(Method method, @Nullable Object target)
From source file:org.springframework.cloud.deployer.thin.ThinJarAppWrapper.java
private void close() { if (this.app != null) { try {/*from www .j a v a2 s . c o m*/ Method method = ReflectionUtils.findMethod(this.app.getClass(), "close"); ReflectionUtils.invokeMethod(method, this.app); } catch (Exception e) { this.state = LaunchState.error; logger.error("Cannot undeploy " + resource, e); } finally { reset(); if (this.app != null) { try { ((URLClassLoader) app.getClass().getClassLoader()).close(); this.app = null; } catch (Exception e) { this.state = LaunchState.error; logger.error("Cannot clean up " + resource, e); } finally { this.app = null; System.gc(); } } } } }
From source file:org.springframework.data.hadoop.mapreduce.ExecutionUtils.java
private static void fixHadoopReflectionUtilsLeak() { // org.apache.hadoop.util.ReflectionUtils.clearCache(); ReflectionUtils.invokeMethod(UTILS_CONSTRUCTOR_CACHE, null); }
From source file:org.springframework.data.hadoop.test.support.compat.MiniMRClusterCompat.java
/** * Finds and calls lifecycle stop method for * given cluster via reflection./*from ww w . j a v a 2 s . c o m*/ * * @param mrClusterObject the Cluster Object */ public static void stopCluster(Object mrClusterObject) { Assert.notNull(mrClusterObject, "mrClusterObject must not be null"); log.info("Stopping cluster=" + mrClusterObject); Method method = ReflectionUtils.findMethod(mrClusterObject.getClass(), "stop"); if (method == null) { method = ReflectionUtils.findMethod(mrClusterObject.getClass(), "shutdown"); } if (method != null) { ReflectionUtils.invokeMethod(method, mrClusterObject); } else { log.warn("Can't find stop/shutdown method for cluster=" + mrClusterObject); } }
From source file:org.springframework.data.hadoop.test.support.compat.MiniMRClusterCompat.java
/** * Gets the {@link Configuration} from a cluster. * * @param mrClusterObject the Cluster Object * @return the cluster {@link Configuration} */// ww w . ja v a2s . c om public static Configuration getConfiguration(Object mrClusterObject) { Assert.notNull(mrClusterObject, "mrClusterObject must not be null"); log.info("Getting configuration for cluster=" + mrClusterObject); Method method = ReflectionUtils.findMethod(mrClusterObject.getClass(), "getConfig"); if (method == null) { method = ReflectionUtils.findMethod(mrClusterObject.getClass(), "createJobConf"); } if (method != null) { return (Configuration) ReflectionUtils.invokeMethod(method, mrClusterObject); } else { log.warn("Can't find configuration for cluster=" + mrClusterObject); } return null; }
From source file:org.springframework.data.solr.server.support.SolrServerUtils.java
private static SolrServer cloneHttpSolrServer(SolrServer solrServer, String core) { if (solrServer == null) { return null; }// w w w. j a v a2 s . c o m Method baseUrlGetterMethod = ClassUtils.getMethodIfAvailable(solrServer.getClass(), "getBaseURL"); if (baseUrlGetterMethod == null) { return null; } String baseUrl = (String) ReflectionUtils.invokeMethod(baseUrlGetterMethod, solrServer); String url = appendCoreToBaseUrl(baseUrl, core); try { HttpClient clientToUse = readAndCloneHttpClient(solrServer); if (clientToUse != null) { Constructor<? extends SolrServer> constructor = (Constructor<? extends SolrServer>) ClassUtils .getConstructorIfAvailable(solrServer.getClass(), String.class, HttpClient.class); if (constructor != null) { return (SolrServer) BeanUtils.instantiateClass(constructor, url, clientToUse); } } Constructor<? extends SolrServer> constructor = (Constructor<? extends SolrServer>) ClassUtils .getConstructorIfAvailable(solrServer.getClass(), String.class); return (SolrServer) BeanUtils.instantiateClass(constructor, url); } catch (Exception e) { throw new BeanInstantiationException(solrServer.getClass(), "Cannot create instace of " + solrServer.getClass() + ". ", e); } }
From source file:org.springframework.faces.model.SelectionTrackingActionListener.java
private void trackSelection(UIComponent component) { // Find parent component with a SelectionAware model if it exists UIComponent currentComponent = component; while (currentComponent.getParent() != null && !(currentComponent.getParent() instanceof UIViewRoot)) { UIComponent parent = currentComponent.getParent(); Method valueAccessor = ReflectionUtils.findMethod(parent.getClass(), "getValue"); if (valueAccessor != null) { Object value = ReflectionUtils.invokeMethod(valueAccessor, parent); if (value != null && value instanceof SelectionAware) { ((SelectionAware<?>) value).setCurrentRowSelected(true); if (logger.isDebugEnabled()) { logger.debug("Row selection has been set on the current SelectionAware data model."); }//from w w w. ja v a 2 s .com break; } } currentComponent = currentComponent.getParent(); } }
From source file:org.springframework.flex.core.MessageBrokerFactoryBean.java
private void initThreadLocals() { // allocate static thread local objects // If available, invoke the MessageBroker.createThreadLocalObjects() method: Method createThreadLocalObjMethod = ReflectionUtils.findMethod(MessageBroker.class, "createThreadLocalObjects"); if (createThreadLocalObjMethod != null) { ReflectionUtils.invokeMethod(createThreadLocalObjMethod, null); }//from w ww . j av a2 s . c o m FlexContext.createThreadLocalObjects(); SerializationContext.createThreadLocalObjects(); TypeMarshallingContext.createThreadLocalObjects(); PropertyProxyRegistry.getRegistry(); }
From source file:org.springframework.flex.core.MessageBrokerFactoryBean.java
private void destroyThreadLocals() { // clear static member variables for shutdown MBeanServerLocatorFactory.clear();/* ww w. j a v a 2 s.c o m*/ // If available, invoke the MessageBroker.releaseThreadLocalObjects() method: Method releaseThreadLocalObjMethod = ReflectionUtils.findMethod(MessageBroker.class, "releaseThreadLocalObjects"); if (releaseThreadLocalObjMethod != null) { ReflectionUtils.invokeMethod(releaseThreadLocalObjMethod, null); } FlexContext.releaseThreadLocalObjects(); SerializationContext.releaseThreadLocalObjects(); TypeMarshallingContext.releaseThreadLocalObjects(); }
From source file:org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver.java
@Override public ClassLoader getThrowawayClassLoader() { if (this.getThrowawayClassLoaderMethod != null) { ClassLoader target = (ClassLoader) ReflectionUtils.invokeMethod(this.getThrowawayClassLoaderMethod, this.classLoader); return (target instanceof DecoratingClassLoader ? target : new OverridingClassLoader(this.classLoader, target)); } else {// w w w . j a va 2 s .c o m return new SimpleThrowawayClassLoader(this.classLoader); } }
From source file:org.springframework.jms.connection.JmsResourceHolder.java
public void commitAll() throws JMSException { for (Session session : this.sessions) { try {/* www.j a v a 2 s. co m*/ session.commit(); } catch (TransactionInProgressException ex) { // Ignore -> can only happen in case of a JTA transaction. } catch (javax.jms.IllegalStateException ex) { if (this.connectionFactory != null) { try { Method getDataSourceMethod = this.connectionFactory.getClass().getMethod("getDataSource"); Object ds = ReflectionUtils.invokeMethod(getDataSourceMethod, this.connectionFactory); while (ds != null) { if (TransactionSynchronizationManager.hasResource(ds)) { // IllegalStateException from sharing the underlying JDBC Connection // which typically gets committed first, e.g. with Oracle AQ --> ignore return; } try { // Check for decorated DataSource a la Spring's DelegatingDataSource Method getTargetDataSourceMethod = ds.getClass().getMethod("getTargetDataSource"); ds = ReflectionUtils.invokeMethod(getTargetDataSourceMethod, ds); } catch (NoSuchMethodException nsme) { ds = null; } } } catch (Throwable ex2) { if (logger.isDebugEnabled()) { logger.debug("No working getDataSource method found on ConnectionFactory: " + ex2); } // No working getDataSource method - cannot perform DataSource transaction check } } throw ex; } } }