use of com.esotericsoftware.kryo.io.Input in project Paper by pilgr.
the class DbStoragePlainFile method readTableFile.
private <E> E readTableFile(String key, File originalFile, boolean v1CompatibilityMode) {
try {
final Input i = new Input(new FileInputStream(originalFile));
final Kryo kryo = getKryo();
if (v1CompatibilityMode) {
// Set temporary generic optimization to support Kryo 3.x format
kryo.getFieldSerializerConfig().setOptimizedGenerics(true);
}
//noinspection unchecked
final PaperTable<E> paperTable = kryo.readObject(i, PaperTable.class);
i.close();
if (v1CompatibilityMode) {
kryo.getFieldSerializerConfig().setOptimizedGenerics(false);
}
return paperTable.mContent;
} catch (FileNotFoundException | KryoException | ClassCastException e) {
// Give one more chance, reread data in compatibility mode
if (!v1CompatibilityMode) {
return readTableFile(key, originalFile, true);
}
// Clean up an unsuccessfully written file
if (originalFile.exists()) {
if (!originalFile.delete()) {
throw new PaperDbException("Couldn't clean up broken/unserializable file " + originalFile, e);
}
}
String errorMessage = "Couldn't read/deserialize file " + originalFile + " for table " + key;
throw new PaperDbException(errorMessage, e);
}
}
use of com.esotericsoftware.kryo.io.Input in project jstorm by alibaba.
the class TransactionBolt method prepare.
@Override
public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
this.conf = stormConf;
this.topologyContext = context;
this.topologyId = topologyContext.getTopologyId();
this.taskId = topologyContext.getThisTaskId();
this.componentId = topologyContext.getThisComponentId();
this.upstreamTasks = TransactionCommon.getUpstreamTasks(componentId, topologyContext);
this.downstreamTasks = TransactionCommon.getDownstreamTasks(componentId, topologyContext);
this.topologyMasterId = context.getTopologyMasterId();
LOG.info("TransactionBolt: upstreamTasks=" + upstreamTasks + ", downstreamTasks=" + downstreamTasks);
this.outputCollector = new TransactionOutputCollector(this, collector);
this.boltExecutor.prepare(conf, context, new OutputCollector(outputCollector));
this.boltStatus = State.INIT;
if (sysTopology == null) {
try {
sysTopology = Common.system_topology(stormConf, context.getRawTopology());
} catch (InvalidTopologyException e) {
LOG.error("Failed to build system topology", e);
throw new RuntimeException(e);
}
}
this.lastSuccessfulBatch = new ConcurrentHashMap<Integer, Long>();
this.processingBatches = new HashMap<Integer, Map<Long, BatchTracker>>();
Set<String> upstreamSpoutNames = TransactionCommon.getUpstreamSpouts(componentId, topologyContext);
for (String spoutName : upstreamSpoutNames) {
int groupId = TransactionCommon.groupIndex(topologyContext.getRawTopology(), spoutName);
lastSuccessfulBatch.put(groupId, TransactionCommon.INIT_BATCH_ID);
processingBatches.put(groupId, new HashMap<Long, BatchTracker>());
}
this.batchCache = new BatchCache(context, upstreamSpoutNames, sysTopology);
this.kryoInput = new Input(1);
this.streamIds = new SerializationFactory.IdDictionary(sysTopology);
this.inputStreamIds = new HashSet<Integer>();
Set<GlobalStreamId> inputs = topologyContext.getThisSources().keySet();
for (GlobalStreamId stream : inputs) {
inputStreamIds.add(streamIds.getStreamId(stream.get_componentId(), stream.get_streamId()));
}
for (String upstreamComponentId : TransactionCommon.getUpstreamComponents(componentId, topologyContext)) {
inputStreamIds.add(streamIds.getStreamId(upstreamComponentId, TransactionCommon.BARRIER_STREAM_ID));
}
//LOG.info("Stream info prepare: streamIds={}, inputStreams={}, inputStreamIds={}", streamIds, inputs, inputStreamIds);
startInitState();
}
use of com.esotericsoftware.kryo.io.Input in project Gaffer by gchq.
the class RegistratorTest method testEntity.
@Test
public void testEntity() {
// Given
Entity entity = new Entity("group");
entity.setVertex("abc");
entity.putProperty("property1", 1);
// When
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Output output = new Output(baos);
kryo.writeObject(output, entity);
output.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
Input input = new Input(bais);
Entity read = kryo.readObject(input, Entity.class);
input.close();
// Then
assertEquals(entity, read);
}
use of com.esotericsoftware.kryo.io.Input in project Gaffer by gchq.
the class RegistratorTest method testEdge.
@Test
public void testEdge() {
// Given
Edge edge = new Edge("group");
edge.setSource("abc");
edge.setDestination("xyz");
edge.setDirected(true);
edge.putProperty("property1", 1);
// When
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Output output = new Output(baos);
kryo.writeObject(output, edge);
output.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
Input input = new Input(bais);
Edge read = kryo.readObject(input, Edge.class);
input.close();
// Then
assertEquals(edge, read);
}
use of com.esotericsoftware.kryo.io.Input in project apex-core by apache.
the class TypeGraphFactory method createTypeGraphProtoType.
public static TypeGraph createTypeGraphProtoType() {
Input input = null;
try {
input = new Input(new ByteArrayInputStream(preComputeGraph));
Kryo kryo = new Kryo();
TypeGraphSerializer tgs = new TypeGraphSerializer();
kryo.register(TypeGraph.class, tgs);
return kryo.readObject(input, TypeGraph.class);
} finally {
IOUtils.closeQuietly(input);
}
}
Aggregations