Search in sources :

Example 6 with Input

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);
    }
}
Also used : Input(com.esotericsoftware.kryo.io.Input) KryoException(com.esotericsoftware.kryo.KryoException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Example 7 with Input

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();
}
Also used : OutputCollector(backtype.storm.task.OutputCollector) InvalidTopologyException(backtype.storm.generated.InvalidTopologyException) SerializationFactory(backtype.storm.serialization.SerializationFactory) BatchCache(com.alibaba.jstorm.transactional.BatchCache) Input(com.esotericsoftware.kryo.io.Input) GlobalStreamId(backtype.storm.generated.GlobalStreamId) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 8 with Input

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);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 9 with Input

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);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 10 with Input

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);
    }
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) TypeGraphSerializer(com.datatorrent.stram.webapp.TypeGraph.TypeGraphSerializer) Kryo(com.esotericsoftware.kryo.Kryo)

Aggregations

Input (com.esotericsoftware.kryo.io.Input)49 Kryo (com.esotericsoftware.kryo.Kryo)31 Output (com.esotericsoftware.kryo.io.Output)21 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 Test (org.junit.Test)8 Test (org.testng.annotations.Test)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Schema (co.cask.cdap.api.data.schema.Schema)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 ArrayList (java.util.ArrayList)2 HiveKey (org.apache.hadoop.hive.ql.io.HiveKey)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2