Package com.twitter.chill

Examples of com.twitter.chill.KryoInstantiator


* To set this up, you probably want to use ConfiguredInstantitator with
* the JavaMapConfig.
*/
public class BlizzardKryoFactory implements IKryoFactory {
  public Kryo getKryo(Map conf) {
    KryoInstantiator kryoInst;
    try {
      kryoInst = new ConfiguredInstantiator(new JavaMapConfig(conf));
      return kryoInst.newKryo();
    }
    catch(ConfigurationException cx) { throw new RuntimeException(cx); }
  }
View Full Code Here


  public static final String KEY = "com.twitter.chill.config.configuredinstantiator";

  public ConfiguredInstantiator(Config conf) throws ConfigurationException {
    String key = conf.get(KEY);
    if (null == key) {
      delegate = new KryoInstantiator();
    }
    else {
      String[] parts = key.split(":");
      if(parts.length != 1 && parts.length != 2) {
        throw new ConfigurationException("Invalid Config Key: " + conf.get(KEY));
      }
      KryoInstantiator reflected = null;
      try { reflected = reflect((Class<? extends KryoInstantiator>)Class.forName(parts[0]), conf); }
      catch(ClassNotFoundException x) {
        throw new ConfigurationException("Could not find class for: " + parts[0], x);
      }

      if(parts.length == 2) {
        delegate = deserialize(reflected.newKryo(), parts[1]);
        if(null == delegate) {
          throw new ConfigurationException("Null delegate from: " + parts[1]);
        }
      }
      else {
View Full Code Here

   * This mode serializes an instance (ki) to be used as the delegate.
   * Only use this mode if reflection alone will not work.
   */
  public static void setSerialized(Config conf, Class<? extends KryoInstantiator> reflector, KryoInstantiator ki)
    throws ConfigurationException {
    KryoInstantiator refki = reflect(reflector, conf);
    String kistr = serialize(refki.newKryo(), ki);
    // Verify, that deserialization works:
    KryoInstantiator deser = deserialize(refki.newKryo(), kistr); // ignore the result, just see if it throws
    deser.newKryo(); // just see if we can still create it
    conf.set(KEY, reflector.getName() + ":" + kistr);
  }
View Full Code Here

    }

    @Override
    public void setConf(Configuration conf) {
      try {
        KryoInstantiator kryoInst = new ConfiguredInstantiator(new HadoopConfig(conf));
        testKryo = kryoInst.newKryo();
        kryoPool = KryoPool.withByteArrayOutputStream(MAX_CACHED_KRYO, kryoInst);
      }
      catch(ConfigurationException cx) {
        // This interface can't throw
        throw new RuntimeException(cx);
View Full Code Here

        fiscalRecord = FiscalRecord.newBuilder().setCalendarDate("2012-01-01").setFiscalWeek(1).setFiscalYear(2012).build();

    }

    public <T> KryoPool getKryo(final ClassTag<T> tag, final Serializer<T> serializer){
        KryoInstantiator kryoInstantiator = new KryoInstantiator() {
            public Kryo newKryo() {
                Kryo k =super.newKryo();
                k.setInstantiatorStrategy(new StdInstantiatorStrategy());
                k.register(tag.runtimeClass(), serializer);
                return k;
View Full Code Here

  public static KryoPool defaultPool() {
    synchronized(mutex) {
      if (kpool == null) {
        try {
          KryoInstantiator kryoInst = new ConfiguredInstantiator(new HadoopConfig(clojureConf()));
          kpool = KryoPool.withByteArrayOutputStream(MAX_CACHED_KRYO, kryoInst);
        } catch (ConfigurationException cx) {
          throw new RuntimeException(cx);
        }
      }
View Full Code Here

TOP

Related Classes of com.twitter.chill.KryoInstantiator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.