cascading.util.Util.invokeInstanceMethod()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中cascading.util.Util.invokeInstanceMethod()方法的一些代码示例,展示了Util.invokeInstanceMethod()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.invokeInstanceMethod()方法的具体详情如下:
包路径:cascading.util.Util
类名称:Util
方法名:invokeInstanceMethod

Util.invokeInstanceMethod介绍

暂无

代码示例

代码示例来源:origin: cwensel/cascading

  1. public void writeDOT( String filename )
  2. {
  3. Util.invokeInstanceMethod( graph, "writeDOT", new Object[]{filename}, new Class[]{String.class} );
  4. }
  5. }

代码示例来源:origin: cwensel/cascading

  1. public static Object invokeInstanceMethodSafe( Object target, String methodName, Object[] parameters, Class[] parameterTypes )
  2. {
  3. try
  4. {
  5. return invokeInstanceMethod( target, methodName, parameters, parameterTypes );
  6. }
  7. catch( Exception exception )
  8. {
  9. return null;
  10. }
  11. }

代码示例来源:origin: cwensel/cascading

  1. public static <C> C copyConfiguration( C parent )
  2. {
  3. if( parent == null )
  4. throw new IllegalArgumentException( "parent may not be null" );
  5. if( !( parent instanceof Configuration ) )
  6. throw new IllegalArgumentException( "parent must be of type Configuration" );
  7. Configuration conf = (Configuration) parent;
  8. // see https://github.com/Cascading/cascading/pull/21
  9. // The JobConf(JobConf) constructor causes derived JobConfs to share Credentials. We want to avoid this, in
  10. // case those Credentials are mutated later on down the road (which they will be, during job submission, in
  11. // separate threads!). Using the JobConf(Configuration) constructor avoids Credentials-sharing.
  12. Configuration configurationCopy = new Configuration( conf );
  13. Configuration copiedConf = callCopyConstructor( parent.getClass(), configurationCopy );
  14. if( Util.hasInstanceMethod( parent, "getCredentials", null ) )
  15. {
  16. Object result = invokeInstanceMethod( parent, "getCredentials", null, null );
  17. Object credentials = invokeInstanceMethod( copiedConf, "getCredentials", null, null );
  18. invokeInstanceMethod( credentials, "addAll", new Object[]{result}, new Class[]{credentials.getClass()} );
  19. }
  20. return (C) copiedConf;
  21. }

代码示例来源:origin: cascading/cascading-hadoop2-io

  1. public static <C> C copyConfiguration( C parent )
  2. {
  3. if( parent == null )
  4. throw new IllegalArgumentException( "parent may not be null" );
  5. if( !( parent instanceof Configuration ) )
  6. throw new IllegalArgumentException( "parent must be of type Configuration" );
  7. Configuration conf = (Configuration) parent;
  8. // see https://github.com/Cascading/cascading/pull/21
  9. // The JobConf(JobConf) constructor causes derived JobConfs to share Credentials. We want to avoid this, in
  10. // case those Credentials are mutated later on down the road (which they will be, during job submission, in
  11. // separate threads!). Using the JobConf(Configuration) constructor avoids Credentials-sharing.
  12. Configuration configurationCopy = new Configuration( conf );
  13. Configuration copiedConf = callCopyConstructor( parent.getClass(), configurationCopy );
  14. if( Util.hasInstanceMethod( parent, "getCredentials", null ) )
  15. {
  16. Object result = invokeInstanceMethod( parent, "getCredentials", null, null );
  17. Object credentials = invokeInstanceMethod( copiedConf, "getCredentials", null, null );
  18. invokeInstanceMethod( credentials, "addAll", new Object[]{result}, new Class[]{credentials.getClass()} );
  19. }
  20. return (C) copiedConf;
  21. }

代码示例来源:origin: cwensel/cascading

  1. public static String setLog4jLevel( String logger, String level )
  2. {
  3. // removing logj4 dependency
  4. // org.apache.log4j.Logger.getLogger( logger[ 0 ] ).setLevel( org.apache.log4j.Level.toLevel( logger[ 1 ] ) );
  5. Object loggerObject = Util.invokeStaticMethod( "org.apache.log4j.Logger", "getLogger",
  6. new Object[]{logger}, new Class[]{String.class} );
  7. Object levelObject = null;
  8. if( level != null )
  9. levelObject = Util.invokeStaticMethod( "org.apache.log4j.Level", "toLevel",
  10. new Object[]{level}, new Class[]{String.class} );
  11. Object oldLevel = Util.invokeInstanceMethod( loggerObject, "getLevel",
  12. new Object[]{}, new Class[]{} );
  13. Util.invokeInstanceMethod( loggerObject, "setLevel",
  14. new Object[]{levelObject}, new Class[]{Util.loadClass( "org.apache.log4j.Level" )} );
  15. if( oldLevel == null )
  16. return null;
  17. return oldLevel.toString();
  18. }

代码示例来源:origin: cwensel/cascading

  1. @Test
  2. public void testSetLogLevel()
  3. {
  4. Configuration jobConf = new Configuration();
  5. jobConf.set( "log4j.logger", "cascading=DEBUG" );
  6. HadoopUtil.initLog4j( jobConf );
  7. Object loggerObject = Util.invokeStaticMethod( "org.apache.log4j.Logger", "getLogger",
  8. new Object[]{"cascading"}, new Class[]{String.class} );
  9. Object levelObject = Util.invokeStaticMethod( "org.apache.log4j.Level", "toLevel",
  10. new Object[]{"DEBUG"}, new Class[]{String.class} );
  11. Object returnedLevel = Util.invokeInstanceMethod( loggerObject, "getLevel",
  12. new Object[]{}, new Class[]{} );
  13. assertEquals( levelObject, returnedLevel );
  14. }
  15. }

代码示例来源:origin: cascading/cascading-hadoop2-common

  1. @Test
  2. public void testSetLogLevel()
  3. {
  4. Configuration jobConf = new Configuration();
  5. jobConf.set( "log4j.logger", "cascading=DEBUG" );
  6. HadoopUtil.initLog4j( jobConf );
  7. Object loggerObject = Util.invokeStaticMethod( "org.apache.log4j.Logger", "getLogger",
  8. new Object[]{"cascading"}, new Class[]{String.class} );
  9. Object levelObject = Util.invokeStaticMethod( "org.apache.log4j.Level", "toLevel",
  10. new Object[]{"DEBUG"}, new Class[]{String.class} );
  11. Object returnedLevel = Util.invokeInstanceMethod( loggerObject, "getLevel",
  12. new Object[]{}, new Class[]{} );
  13. assertEquals( levelObject, returnedLevel );
  14. }
  15. }

相关文章