Register the DataVec writable classes for Kryo
422344
public static void registerKryoClasses(SparkConf conf) {
        List<Class<?>> classes = Arrays.<Class<?>>asList(BooleanWritable.class, ByteWritable.class,
                        DoubleWritable.class, FloatWritable.class, IntWritable.class, LongWritable.class,
                        NullWritable.class, Text.class);

        conf.registerKryoClasses((Class<?>[]) classes.toArray());
    }
1134994
def register_enum_for_json(*args, **kwargs) -> Any:
    
    if len(args) == 1 and len(kwargs) == 0 and callable(args[0]):
        # called as @register_enum_for_json
        cls = args[0]  # type: ClassType
        register_class_for_json(
            cls,
            obj_to_dict_fn=enum_to_dict_fn,
            dict_to_obj_fn=dict_to_enum_fn
        )
        return cls
    else:
        # called as @register_enum_for_json(*args, **kwargs)
        raise AssertionError("Use as plain @register_enum_for_json, "
                             "without arguments")
650525
@SuppressWarnings({"rawtypes", "unchecked"})
  public static Kryo getKryo(Map conf) {
    IKryoFactory kryoFactory =
        (IKryoFactory) Utils.newInstance((String) conf.get(Config.TOPOLOGY_KRYO_FACTORY));
    Kryo k = kryoFactory.getKryo(conf);
    k.register(byte[].class);
    k.register(ListDelegate.class);
    k.register(ArrayList.class, new ArrayListSerializer());
    k.register(HashMap.class, new HashMapSerializer());
    k.register(HashSet.class, new HashSetSerializer());
    k.register(BigInteger.class, new BigIntegerSerializer());
    // k.register(TransactionAttempt.class);
    k.register(Values.class);
    // k.register(backtype.storm.metric.api.IMetricsConsumer.DataPoint.class);
    // k.register(backtype.storm.metric.api.IMetricsConsumer.TaskInfo.class);
        /*
        try {
            JavaBridge.registerPrimitives(k);
            JavaBridge.registerCollections(k);
        } catch(Exception e) {
            throw new RuntimeException(e);
        }
        */

    Map<String, String> registrations = normalizeKryoRegister(conf);

    kryoFactory.preRegister(k, conf);

    boolean skipMissing = (Boolean) conf.get(Config.TOPOLOGY_SKIP_MISSING_KRYO_REGISTRATIONS);
    for (String klassName : registrations.keySet()) {
      String serializerClassName = registrations.get(klassName);
      try {
        Class klass = Class.forName(klassName);
        Class serializerClass = null;
        if (serializerClassName != null) {
          serializerClass = Class.forName(serializerClassName);
        }
        LOG.info("Doing kryo.register for class " + klass);
        if (serializerClass == null) {
          k.register(klass);
        } else {
          k.register(klass, resolveSerializerInstance(k, klass, serializerClass));
        }

      } catch (ClassNotFoundException e) {
        if (skipMissing) {
          LOG.info("Could not find serialization or class for "
              + serializerClassName + ". Skipping registration...");
        } else {
          throw new RuntimeException(e);
        }
      }
    }

    kryoFactory.postRegister(k, conf);

    if (conf.get(Config.TOPOLOGY_KRYO_DECORATORS) != null) {
      for (String klassName : (List<String>) conf.get(Config.TOPOLOGY_KRYO_DECORATORS)) {
        try {
          Class klass = Class.forName(klassName);
          IKryoDecorator decorator = (IKryoDecorator) klass.newInstance();
          decorator.decorate(k);
        } catch (ClassNotFoundException e) {
          if (skipMissing) {
            LOG.info("Could not find kryo decorator named "
                + klassName + ". Skipping registration...");
          } else {
            throw new RuntimeException(e);
          }
        } catch (InstantiationException e) {
          throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
          throw new RuntimeException(e);
        }
      }
    }

    kryoFactory.postDecorate(k, conf);

    return k;
  }
1076819
public void registerJsonValueProcessor( Class beanClass, Class propertyType, JsonValueProcessor jsonValueProcessor ) {
      if( beanClass != null && propertyType != null && jsonValueProcessor != null ) {
         beanTypeMap.put( beanClass, propertyType, jsonValueProcessor );
      }
   }
475029
private VarSymbol getDefinedSerializableFields(ClassSymbol def) {
        Names names = def.name.table.names;

        /* SERIALIZABLE_FIELDS can be private,
         * so must lookup by ClassSymbol, not by ClassDocImpl.
         */
        for (Scope.Entry e = def.members().lookup(names.fromString(SERIALIZABLE_FIELDS)); e.scope != null; e = e.next()) {
            if (e.sym.kind == Kinds.VAR) {
                VarSymbol f = (VarSymbol)e.sym;
                if ((f.flags() & Flags.STATIC) != 0 &&
                    (f.flags() & Flags.PRIVATE) != 0) {
                    return f;
                }
            }
        }
        return null;
    }
1328474
def registerXmlType(typ, encoder, decoder):
        
        DataSet._xmlTypes[nstr(typ)] = (encoder, decoder)
316501
def _generate_union_class_variant_creators(self, ns, data_type):
        
        for field in data_type.fields:
            if not is_void_type(field.data_type):
                field_name = fmt_func(field.name)
                field_name_reserved_check = fmt_func(field.name, check_reserved=True)
                if is_nullable_type(field.data_type):
                    field_dt = field.data_type.data_type
                else:
                    field_dt = field.data_type
                self.emit('@classmethod')
                self.emit('def {}(cls, val):'.format(field_name_reserved_check))
                with self.indent():
                    self.emit('"""')
                    self.emit_wrapped_text(
                        'Create an instance of this class set to the ``%s`` '
                        'tag with value ``val``.' % field_name)
                    self.emit()
                    self.emit(':param {} val:'.format(
                        self._python_type_mapping(ns, field_dt)))
                    self.emit(':rtype: {}'.format(
                        self._python_type_mapping(ns, data_type)))
                    self.emit('"""')
                    self.emit("return cls('{}', val)".format(field_name))
                self.emit()
1372843
def create(cls, data):
        
        try:
            json_data = json.loads(data)
        except ValueError as err:
            logging.debug("Failed to load json data: %s: [%s]", str(err), data)
            json_data = json.loads(ErrorEvent.error_json(err))

        if "type" not in json_data:
            raise GerritError("`type` not in json_data")
        name = json_data["type"]
        if name not in cls._events:
            name = 'unhandled-event'
        event = cls._events[name]
        module_name = event[0]
        class_name = event[1]
        module = __import__(module_name, fromlist=[module_name])
        klazz = getattr(module, class_name)
        return klazz(json_data)
1012545
private static LinkedHashMap<String, KryoRegistration> buildKryoRegistrations(
			Class<?> serializedType,
			LinkedHashSet<Class<?>> registeredTypes,
			LinkedHashMap<Class<?>, Class<? extends Serializer<?>>> registeredTypesWithSerializerClasses,
			LinkedHashMap<Class<?>, ExecutionConfig.SerializableSerializer<?>> registeredTypesWithSerializers) {

		final LinkedHashMap<String, KryoRegistration> kryoRegistrations = new LinkedHashMap<>();

		kryoRegistrations.put(serializedType.getName(), new KryoRegistration(serializedType));

		for (Class<?> registeredType : checkNotNull(registeredTypes)) {
			kryoRegistrations.put(registeredType.getName(), new KryoRegistration(registeredType));
		}

		for (Map.Entry<Class<?>, Class<? extends Serializer<?>>> registeredTypeWithSerializerClassEntry :
				checkNotNull(registeredTypesWithSerializerClasses).entrySet()) {

			kryoRegistrations.put(
					registeredTypeWithSerializerClassEntry.getKey().getName(),
					new KryoRegistration(
							registeredTypeWithSerializerClassEntry.getKey(),
							registeredTypeWithSerializerClassEntry.getValue()));
		}

		for (Map.Entry<Class<?>, ExecutionConfig.SerializableSerializer<?>> registeredTypeWithSerializerEntry :
				checkNotNull(registeredTypesWithSerializers).entrySet()) {

			kryoRegistrations.put(
					registeredTypeWithSerializerEntry.getKey().getName(),
					new KryoRegistration(
							registeredTypeWithSerializerEntry.getKey(),
							registeredTypeWithSerializerEntry.getValue()));
		}

		// add Avro support if flink-avro is available; a dummy otherwise
		AvroUtils.getAvroUtils().addAvroGenericDataArrayRegistration(kryoRegistrations);

		return kryoRegistrations;
	}
522959
public void registerJsonValueProcessor( Class propertyType, JsonValueProcessor jsonValueProcessor ) {
      if( propertyType != null && jsonValueProcessor != null ) {
         typeMap.put( propertyType, jsonValueProcessor );
      }
   }
873790
@SuppressWarnings("unchecked")
    public static <T> T fromByteArrayKryo(byte[] data, Class<T> clazz, ClassLoader classLoader) {
        if (data == null) {
            return null;
        }
        Kryo kryo = kryoPool.obtain();
        try {
            ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
            if (classLoader != null) {
                Thread.currentThread().setContextClassLoader(classLoader);
            }
            try {
                Input input = kryoInputPool.obtain();
                try {
                    kryo.setClassLoader(classLoader != null ? classLoader : oldClassLoader);
                    input.setInputStream(new ByteArrayInputStream(data));
                    Object obj = kryo.readClassAndObject(input);
                    input.close();
                    return obj != null && clazz.isAssignableFrom(obj.getClass()) ? (T) obj : null;
                } finally {
                    kryoInputPool.free(input);
                }
            } finally {
                Thread.currentThread().setContextClassLoader(oldClassLoader);
            }
        } finally {
            kryoPool.free(kryo);
        }
    }
151158
private void registerTypeMappings(
      TypeMapping registryTypeMapping, List<TypeMapping> typeMappings) {
    Preconditions.checkNotNull(registryTypeMapping, "Null registry type mapping");
    Preconditions.checkNotNull(typeMappings, "Null type mappings");
    Preconditions.checkArgument(!typeMappings.isEmpty(), "Empty type mappings");
    for (TypeMapping typeMapping : typeMappings) {
      for (Class<?> mappingClass : typeMapping.getAllClasses()) {
        QName classQName = typeMapping.getTypeQName(mappingClass);
        DeserializerFactory deserializer = typeMapping.getDeserializer(mappingClass, classQName);
        if (deserializer != null && !registryTypeMapping.isRegistered(mappingClass, classQName)) {
          registryTypeMapping.register(
              mappingClass, classQName, (SerializerFactory) null, deserializer);
        }
      }
    }
  }
141656
protected T create (Kryo kryo, Input input, Class<? extends T> type) {
		return kryo.newInstance(type);
	}
766012
function MapEntriesRW(ktype, vtype) {
    this.ktype = ktype;
    this.vtype = vtype;

    if (this.ktype.rw.width && this.vtype.rw.width) {
        this.poolByteLength = this.mapFixFixbyteLength;
    } else if (this.ktype.rw.width) {
        this.poolByteLength = this.mapFixVarbyteLength;
    } else if (this.vtype.rw.width) {
        this.poolByteLength = this.mapVarFixbyteLength;
    }

    bufrw.Base.call(this);
}
774173
@SuppressWarnings("unchecked")
  private static void registerValue(BytesRef term,
      ComponentTermVector termVector, TermvectorNumberFull number,
      String[] mutableKey) throws IOException {
    if (number.docNumber > 0) {
      if (mutableKey[0] == null) {
        mutableKey[0] = MtasToken.getPostfixFromValue(term);
      }
      MtasDataCollector<Long, ?> dataCollector = (MtasDataCollector<Long, ?>) termVector.subComponentFunction.dataCollector;
      long[] valuesLong = new long[number.docNumber];
      for (int i = 0; i < number.docNumber; i++) {
        try {
          valuesLong[i] = termVector.subComponentFunction.parserFunction
              .getValueLong(new long[] { number.args[i] }, number.positions[i]);
        } catch (IOException e) {
          log.debug(e);
          dataCollector.error(mutableKey[0], e.getMessage());
        }
      }
      if (!termVector.subComponentFunction.statsType
          .equals(CodecUtil.STATS_BASIC)) {
        dataCollector.add(mutableKey[0], valuesLong, valuesLong.length);
      }
      for (SubComponentFunction function : termVector.functions) {
        if (!function.parserFunction.sumRule()
            || function.parserFunction.needPositions()
            || !function.statsType.equals(CodecUtil.STATS_BASIC)) {
          if (function.dataType.equals(CodecUtil.DATA_TYPE_LONG)) {
            valuesLong = new long[number.docNumber];
            for (int i = 0; i < number.docNumber; i++) {
              try {
                valuesLong[i] = function.parserFunction.getValueLong(
                    new long[] { number.args[i] }, number.positions[i]);
              } catch (IOException e) {
                log.debug(e);
                function.dataCollector.error(mutableKey[0], e.getMessage());
              }
            }
            function.dataCollector.add(mutableKey[0], valuesLong,
                valuesLong.length);
          } else if (function.dataType.equals(CodecUtil.DATA_TYPE_DOUBLE)) {
            double[] valuesDouble = new double[number.docNumber];
            for (int i = 0; i < number.docNumber; i++) {
              try {
                valuesDouble[i] = function.parserFunction.getValueDouble(
                    new long[] { number.args[i] }, number.positions[i]);
              } catch (IOException e) {
                log.debug(e);
                function.dataCollector.error(mutableKey[0], e.getMessage());
              }
            }
            function.dataCollector.add(mutableKey[0], valuesDouble,
                valuesDouble.length);
          }
        }
      }
    }
  }
1304224
def build(self) -> RegisteredTypeJSONEncoderType:
        
        class_name = "%s_%s" % (_RegisteredTypeJSONEncoder.__class__.__name__, id(self))
        # Use encoders set at the point in time at which the encoder was built
        builder_snapshot = copy.deepcopy(self)
        return type(
                class_name,
                (_RegisteredTypeJSONEncoder, ),
                {
                    "_get_json_encoders_for_type": builder_snapshot.get_json_encoders_for_type
                }
        )
682993
public void registerChannel(FileChannel channel, boolean writable) {
		readableChannels.add(channel);
		if (writable) {
			writableChannels.add(channel);
		}
	}