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