本文整理汇总了Java中org.apache.flink.util.InstantiationUtil.instantiate方法的典型用法代码示例。如果您正苦于以下问题:Java InstantiationUtil.instantiate方法的具体用法?Java InstantiationUtil.instantiate怎么用?Java InstantiationUtil.instantiate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.util.InstantiationUtil
的用法示例。
在下文中一共展示了InstantiationUtil.instantiate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RecordPairComparator
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
public RecordPairComparator(int[] keyFieldsReference, int[] keyFieldsCandidate, Class<? extends Value>[] keyTypes) {
if (keyFieldsReference.length != keyFieldsCandidate.length || keyFieldsCandidate.length != keyTypes.length) {
throw new IllegalArgumentException(
"The arrays describing the key positions and types must be of the same length.");
}
this.keyFields1 = keyFieldsReference;
this.keyFields2 = keyFieldsCandidate;
// instantiate fields to extract keys into
this.keyHolders1 = new Value[keyTypes.length];
this.keyHolders2 = new Value[keyTypes.length];
for (int i = 0; i < keyTypes.length; i++) {
if (keyTypes[i] == null) {
throw new NullPointerException("Key type " + i + " is null.");
}
this.keyHolders1[i] = InstantiationUtil.instantiate(keyTypes[i], Value.class);
this.keyHolders2[i] = InstantiationUtil.instantiate(keyTypes[i], Value.class);
}
}
示例2: read
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void read(DataInputView in) throws IOException {
super.read(in);
String serializerConfigClassname = in.readUTF();
Class<? extends TypeSerializerConfigSnapshot> serializerConfigSnapshotClass;
try {
serializerConfigSnapshotClass = (Class<? extends TypeSerializerConfigSnapshot>)
Class.forName(serializerConfigClassname, true, userCodeClassLoader);
} catch (ClassNotFoundException e) {
throw new IOException(
"Could not find requested TypeSerializerConfigSnapshot class "
+ serializerConfigClassname + " in classpath.", e);
}
serializerConfigSnapshot = InstantiationUtil.instantiate(serializerConfigSnapshotClass);
serializerConfigSnapshot.setUserCodeClassLoader(userCodeClassLoader);
serializerConfigSnapshot.read(in);
}
示例3: iterator
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
private int index;
@Override
public boolean hasNext() {
return index < classes.size();
}
@Override
public T next() {
return InstantiationUtil.instantiate(classes.get(index++));
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
示例4: getTypeInfoFactory
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
/**
* Returns the type information factory for a type using the factory registry or annotations.
*/
@Internal
public static <OUT> TypeInfoFactory<OUT> getTypeInfoFactory(Type t) {
final Class<?> factoryClass;
if (registeredTypeInfoFactories.containsKey(t)) {
factoryClass = registeredTypeInfoFactories.get(t);
}
else {
if (!isClassType(t) || !typeToClass(t).isAnnotationPresent(TypeInfo.class)) {
return null;
}
final TypeInfo typeInfoAnnotation = typeToClass(t).getAnnotation(TypeInfo.class);
factoryClass = typeInfoAnnotation.value();
// check for valid factory class
if (!TypeInfoFactory.class.isAssignableFrom(factoryClass)) {
throw new InvalidTypesException("TypeInfo annotation does not specify a valid TypeInfoFactory.");
}
}
// instantiate
return (TypeInfoFactory<OUT>) InstantiationUtil.instantiate(factoryClass);
}
示例5: getPairComparatorFactory
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
public <T1, T2> TypePairComparatorFactory<T1, T2> getPairComparatorFactory(ClassLoader cl) {
final String className = this.config.getString(DRIVER_PAIR_COMPARATOR_FACTORY, null);
if (className == null) {
return null;
}
@SuppressWarnings("unchecked")
final Class<TypePairComparatorFactory<T1, T2>> superClass = (Class<TypePairComparatorFactory<T1, T2>>) (Class<?>) TypePairComparatorFactory.class;
try {
final Class<? extends TypePairComparatorFactory<T1, T2>> clazz = Class.forName(className, true, cl).asSubclass(superClass);
return InstantiationUtil.instantiate(clazz, superClass);
}
catch (ClassNotFoundException cnfex) {
throw new RuntimeException("The class '" + className + "', noted in the configuration as " +
"pair comparator factory, could not be found. It is not part of the user code's class loader resources.");
}
catch (ClassCastException ccex) {
throw new CorruptConfigurationException("The class noted in the configuration as the pair comparator factory " +
"is no subclass of TypePairComparatorFactory.");
}
}
示例6: compareSerialized
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
@Override
public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException {
if (tempReference == null) {
tempReference = InstantiationUtil.instantiate(type, CopyableValue.class);
}
reference.read(firstSource);
tempReference.read(secondSource);
int comp = reference.compareTo(tempReference);
return ascendingComparison ? comp : -comp;
}
示例7: getField
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
/**
* Gets the field at the given position from the record. This method checks internally, if this instance of
* the record has previously returned a value for this field. If so, it reuses the object, if not, it
* creates one from the supplied class.
*
* @param <T> The type of the field.
*
* @param fieldNum The logical position of the field.
* @param type The type of the field as a class. This class is used to instantiate a value object, if none had
* previously been instantiated.
* @return The field at the given position, or null, if the field was null.
* @throws IndexOutOfBoundsException Thrown, if the field number is negative or larger or equal to the number of
* fields in this record.
*/
@SuppressWarnings("unchecked")
public <T extends Value> T getField(final int fieldNum, final Class<T> type) {
// range check
if (fieldNum < 0 || fieldNum >= this.numFields) {
throw new IndexOutOfBoundsException(fieldNum + " for range [0.." + (this.numFields - 1) + "]");
}
// get offset and check for null
final int offset = this.offsets[fieldNum];
if (offset == NULL_INDICATOR_OFFSET) {
return null;
}
else if (offset == MODIFIED_INDICATOR_OFFSET) {
// value that has been set is new or modified
return (T) this.writeFields[fieldNum];
}
final int limit = offset + this.lengths[fieldNum];
// get an instance, either from the instance cache or create a new one
final Value oldField = this.readFields[fieldNum];
final T field;
if (oldField != null && oldField.getClass() == type) {
field = (T) oldField;
}
else {
field = InstantiationUtil.instantiate(type, Value.class);
this.readFields[fieldNum] = field;
}
// deserialize
deserialize(field, offset, limit, fieldNum);
return field;
}
示例8: createInstance
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public T createInstance() {
if (typeClass == NullWritable.class) {
return (T) NullWritable.get();
}
return InstantiationUtil.instantiate(typeClass);
}
示例9: prepare
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
@BeforeClass
public static void prepare() throws Exception {
LOG.info("-------------------------------------------------------------------------");
LOG.info(" Starting embedded Elasticsearch node ");
LOG.info("-------------------------------------------------------------------------");
// dynamically load version-specific implementation of the Elasticsearch embedded node environment
Class<?> clazz = Class.forName(
"org.apache.flink.streaming.connectors.elasticsearch.EmbeddedElasticsearchNodeEnvironmentImpl");
embeddedNodeEnv = (EmbeddedElasticsearchNodeEnvironment) InstantiationUtil.instantiate(clazz);
embeddedNodeEnv.start(tempFolder.newFolder(), CLUSTER_NAME);
}
示例10: startClusters
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
protected static void startClusters(boolean secureMode, boolean hideKafkaBehindProxy) throws ClassNotFoundException {
// dynamically load the implementation for the test
Class<?> clazz = Class.forName("org.apache.flink.streaming.connectors.kafka.KafkaTestEnvironmentImpl");
kafkaServer = (KafkaTestEnvironment) InstantiationUtil.instantiate(clazz);
LOG.info("Starting KafkaTestBase.prepare() for Kafka " + kafkaServer.getVersion());
kafkaServer.prepare(kafkaServer.createConfig()
.setKafkaServersNumber(NUMBER_OF_KAFKA_SERVERS)
.setSecureMode(secureMode)
.setHideKafkaBehindProxy(hideKafkaBehindProxy));
standardProps = kafkaServer.getStandardProperties();
brokerConnectionStrings = kafkaServer.getBrokerConnectionString();
if (secureMode) {
if (!kafkaServer.isSecureRunSupported()) {
throw new IllegalStateException(
"Attempting to test in secure mode but secure mode not supported by the KafkaTestEnvironment.");
}
secureProps = kafkaServer.getSecureProperties();
}
// start also a re-usable Flink mini cluster
flink = new LocalFlinkMiniCluster(getFlinkConfiguration(), false);
flink.start();
}
示例11: copy
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
@Override
public void copy(DataInputView source, DataOutputView target) throws IOException {
checkAvroInitialized();
if (this.deepCopyInstance == null) {
this.deepCopyInstance = InstantiationUtil.instantiate(type, Object.class);
}
this.decoder.setIn(source);
this.encoder.setOut(target);
T tmp = this.reader.read(this.deepCopyInstance, this.decoder);
this.writer.write(tmp, this.encoder);
}
示例12: startClusters
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
protected static void startClusters(boolean secureMode) throws ClassNotFoundException {
// dynamically load the implementation for the test
Class<?> clazz = Class.forName("org.apache.flink.streaming.connectors.kafka.KafkaTestEnvironmentImpl");
kafkaServer = (KafkaTestEnvironment) InstantiationUtil.instantiate(clazz);
LOG.info("Starting KafkaTestBase.prepare() for Kafka " + kafkaServer.getVersion());
kafkaServer.prepare(NUMBER_OF_KAFKA_SERVERS, secureMode);
standardProps = kafkaServer.getStandardProperties();
brokerConnectionStrings = kafkaServer.getBrokerConnectionString();
if (secureMode) {
if (!kafkaServer.isSecureRunSupported()) {
throw new IllegalStateException(
"Attempting to test in secure mode but secure mode not supported by the KafkaTestEnvironment.");
}
secureProps = kafkaServer.getSecureProperties();
}
// start also a re-usable Flink mini cluster
flink = new LocalFlinkMiniCluster(getFlinkConfiguration(), false);
flink.start();
flinkPort = flink.getLeaderRPCPort();
}
示例13: compareSerialized
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
@Override
public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException {
if (reference == null) {
reference = InstantiationUtil.instantiate(type, Value.class);
}
if (tempReference == null) {
tempReference = InstantiationUtil.instantiate(type, Value.class);
}
reference.read(firstSource);
tempReference.read(secondSource);
int comp = reference.compareTo(tempReference);
return ascendingComparison ? comp : -comp;
}
示例14: readObject
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
Class<Reducer<KEYIN,VALUEIN,KEYOUT,VALUEOUT>> reducerClass =
(Class<Reducer<KEYIN,VALUEIN,KEYOUT,VALUEOUT>>)in.readObject();
reducer = InstantiationUtil.instantiate(reducerClass);
jobConf = new JobConf();
jobConf.readFields(in);
}
示例15: PackagedProgram
import org.apache.flink.util.InstantiationUtil; //导入方法依赖的package包/类
PackagedProgram(Class<?> entryPointClass, String... args) throws ProgramInvocationException {
this.jarFile = null;
this.args = args == null ? new String[0] : args;
this.extractedTempLibraries = Collections.emptyList();
this.classpaths = Collections.emptyList();
this.userCodeClassLoader = entryPointClass.getClassLoader();
// load the entry point class
this.mainClass = entryPointClass;
// if the entry point is a program, instantiate the class and get the plan
if (Program.class.isAssignableFrom(this.mainClass)) {
Program prg = null;
try {
prg = InstantiationUtil.instantiate(this.mainClass.asSubclass(Program.class), Program.class);
} catch (Exception e) {
// validate that the class has a main method at least.
// the main method possibly instantiates the program properly
if (!hasMainMethod(mainClass)) {
throw new ProgramInvocationException("The given program class implements the " +
Program.class.getName() + " interface, but cannot be instantiated. " +
"It also declares no main(String[]) method as alternative entry point", e);
}
} catch (Throwable t) {
throw new ProgramInvocationException("Error while trying to instantiate program class.", t);
}
this.program = prg;
} else if (hasMainMethod(mainClass)) {
this.program = null;
} else {
throw new ProgramInvocationException("The given program class neither has a main(String[]) method, nor does it implement the " +
Program.class.getName() + " interface.");
}
}