Java Code Examples for org.apache.storm.Config#registerSerialization()

The following examples show how to use org.apache.storm.Config#registerSerialization() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurableTopology.java    From storm-crawler with Apache License 2.0 6 votes vote down vote up
/** Submits the topology under a specific name **/
protected int submit(String name, Config conf, TopologyBuilder builder) {

    // register Metadata for serialization with FieldsSerializer
    Config.registerSerialization(conf, Metadata.class);

    if (isLocal) {
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology(name, conf, builder.createTopology());
        if (ttl != -1) {
            Utils.sleep(ttl * 1000);
            cluster.shutdown();
        }
    }

    else {
        try {
            StormSubmitter.submitTopology(name, conf,
                    builder.createTopology());
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
    }
    return 0;
}
 
Example 2
Source File: ThresholdingEngine.java    From monasca-thresh with Apache License 2.0 5 votes vote down vote up
protected void run() throws Exception {
  Config config = Injector.getInstance(Config.class);
  StormTopology topology = Injector.getInstance(StormTopology.class);
  config.registerSerialization(monasca.thresh.domain.model.SubAlarm.class);
  config.registerSerialization(monasca.thresh.domain.model.SubExpression.class);

  if (local) {
    logger.info("submitting topology {} to local storm cluster", topologyName);
    new LocalCluster().submitTopology(topologyName, config, topology);
  } else {
    logger.info("submitting topology {} to non-local storm cluster", topologyName);
    StormSubmitter.submitTopology(topologyName, config, topology);
  }
}
 
Example 3
Source File: TestMetadataSerialization.java    From storm-crawler with Apache License 2.0 5 votes vote down vote up
@Test
public void testSerialization() throws IOException {
    Map conf = Utils.readDefaultConfig();
    Config.registerSerialization(conf, Metadata.class);

    KryoValuesSerializer kvs = new KryoValuesSerializer(conf);
    Metadata md = new Metadata();
    md.addValue("this_key", "has a value");
    // defensive lock
    md.lock();

    boolean exception = false;
    try {
        md.addValue("this_should", "fail");
    } catch (Exception e) {
        exception = true;
    }

    assertTrue(exception);

    byte[] content = kvs.serializeObject(md);

    KryoValuesDeserializer kvd = new KryoValuesDeserializer(conf);
    Metadata md2 = (Metadata) kvd.deserializeObject(content);

    // compare md1 and md2
    assertEquals(md.toString(), md2.toString());

}