本文整理汇总了Java中org.apache.flink.api.common.ExecutionConfig.registerTypeWithKryoSerializer方法的典型用法代码示例。如果您正苦于以下问题:Java ExecutionConfig.registerTypeWithKryoSerializer方法的具体用法?Java ExecutionConfig.registerTypeWithKryoSerializer怎么用?Java ExecutionConfig.registerTypeWithKryoSerializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.api.common.ExecutionConfig
的用法示例。
在下文中一共展示了ExecutionConfig.registerTypeWithKryoSerializer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAvroSerializersIfRequired
import org.apache.flink.api.common.ExecutionConfig; //导入方法依赖的package包/类
@Override
public void addAvroSerializersIfRequired(ExecutionConfig reg, Class<?> type) {
if (org.apache.avro.specific.SpecificRecordBase.class.isAssignableFrom(type) ||
org.apache.avro.generic.GenericData.Record.class.isAssignableFrom(type)) {
// Avro POJOs contain java.util.List which have GenericData.Array as their runtime type
// because Kryo is not able to serialize them properly, we use this serializer for them
reg.registerTypeWithKryoSerializer(GenericData.Array.class, Serializers.SpecificInstanceCollectionSerializerForArrayList.class);
// We register this serializer for users who want to use untyped Avro records (GenericData.Record).
// Kryo is able to serialize everything in there, except for the Schema.
// This serializer is very slow, but using the GenericData.Records of Kryo is in general a bad idea.
// we add the serializer as a default serializer because Avro is using a private sub-type at runtime.
reg.addDefaultKryoSerializer(Schema.class, AvroSchemaSerializer.class);
}
}
示例2: addStormConfigToTopology
import org.apache.flink.api.common.ExecutionConfig; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
static void addStormConfigToTopology(FlinkTopology topology, Map conf) throws ClassNotFoundException {
if (conf != null) {
ExecutionConfig flinkConfig = topology.getExecutionEnvironment().getConfig();
flinkConfig.setGlobalJobParameters(new StormConfig(conf));
// add all registered types to ExecutionConfig
List<?> registeredClasses = (List<?>) conf.get(Config.TOPOLOGY_KRYO_REGISTER);
if (registeredClasses != null) {
for (Object klass : registeredClasses) {
if (klass instanceof String) {
flinkConfig.registerKryoType(Class.forName((String) klass));
} else {
for (Entry<String, String> register : ((Map<String, String>) klass).entrySet()) {
flinkConfig.registerTypeWithKryoSerializer(Class.forName(register.getKey()),
(Class<? extends Serializer<?>>) Class.forName(register.getValue()));
}
}
}
}
}
}
示例3: createSerializer
import org.apache.flink.api.common.ExecutionConfig; //导入方法依赖的package包/类
@Override
protected <T> TypeSerializer<T> createSerializer(Class<T> type) {
ExecutionConfig conf = new ExecutionConfig();
conf.registerTypeWithKryoSerializer(LocalDate.class, LocalDateSerializer.class);
TypeInformation<T> typeInfo = new GenericTypeInfo<T>(type);
return typeInfo.createSerializer(conf);
}
示例4: testOutputBufferedBeingClearedInCaseOfException
import org.apache.flink.api.common.ExecutionConfig; //导入方法依赖的package包/类
/**
* Tests that the kryo output buffer is cleared in case of an exception. Flink uses the
* EOFException to signal that a buffer is full. In such a case, the record which was tried
* to be written will be rewritten. Therefore, eventually buffered data of this record has
* to be cleared.
*/
@Test
public void testOutputBufferedBeingClearedInCaseOfException() throws Exception {
ExecutionConfig executionConfig = new ExecutionConfig();
executionConfig.registerTypeWithKryoSerializer(TestRecord.class, new TestRecordSerializer());
executionConfig.registerKryoType(TestRecord.class);
KryoSerializer<TestRecord> kryoSerializer = new KryoSerializer<TestRecord>(
TestRecord.class,
executionConfig);
int size = 94;
int bufferSize = 150;
TestRecord testRecord = new TestRecord(size);
TestDataOutputView target = new TestDataOutputView(bufferSize);
kryoSerializer.serialize(testRecord, target);
try {
kryoSerializer.serialize(testRecord, target);
Assert.fail("Expected an EOFException.");
} catch(EOFException eofException) {
// expected exception
// now the Kryo Output should have been cleared
}
TestRecord actualRecord = kryoSerializer.deserialize(
new DataInputViewStreamWrapper(new ByteArrayInputStream(target.getBuffer())));
Assert.assertEquals(testRecord, actualRecord);
target.clear();
// if the kryo output has been cleared then we can serialize our test record into the target
// because the target buffer 150 bytes can host one TestRecord (total serialization size 100)
kryoSerializer.serialize(testRecord, target);
byte[] buffer = target.getBuffer();
int counter = 0;
for (int i = 0; i < buffer.length; i++) {
if(buffer[i] == 42) {
counter++;
}
}
Assert.assertEquals(size, counter);
}
示例5: testRegisterStatesWithoutTypeSerializer
import org.apache.flink.api.common.ExecutionConfig; //导入方法依赖的package包/类
@Test
public void testRegisterStatesWithoutTypeSerializer() throws Exception {
// prepare an execution config with a non standard type registered
final Class<?> registeredType = FutureTask.class;
// validate the precondition of this test - if this condition fails, we need to pick a different
// example serializer
assertFalse(new KryoSerializer<>(File.class, new ExecutionConfig()).getKryo().getDefaultSerializer(registeredType)
instanceof com.esotericsoftware.kryo.serializers.JavaSerializer);
final ExecutionConfig cfg = new ExecutionConfig();
cfg.registerTypeWithKryoSerializer(registeredType, com.esotericsoftware.kryo.serializers.JavaSerializer.class);
final OperatorStateBackend operatorStateBackend = new DefaultOperatorStateBackend(classLoader, cfg, false);
ListStateDescriptor<File> stateDescriptor = new ListStateDescriptor<>("test", File.class);
ListStateDescriptor<String> stateDescriptor2 = new ListStateDescriptor<>("test2", String.class);
ListState<File> listState = operatorStateBackend.getListState(stateDescriptor);
assertNotNull(listState);
ListState<String> listState2 = operatorStateBackend.getListState(stateDescriptor2);
assertNotNull(listState2);
assertEquals(2, operatorStateBackend.getRegisteredStateNames().size());
// make sure that type registrations are forwarded
TypeSerializer<?> serializer = ((PartitionableListState<?>) listState).getStateMetaInfo().getPartitionStateSerializer();
assertTrue(serializer instanceof KryoSerializer);
assertTrue(((KryoSerializer<?>) serializer).getKryo().getSerializer(registeredType)
instanceof com.esotericsoftware.kryo.serializers.JavaSerializer);
Iterator<String> it = listState2.get().iterator();
assertFalse(it.hasNext());
listState2.add("kevin");
listState2.add("sunny");
it = listState2.get().iterator();
assertEquals("kevin", it.next());
assertEquals("sunny", it.next());
assertFalse(it.hasNext());
}