Java Code Examples for com.esotericsoftware.kryo.Kryo.getRegistration()

The following are Jave code examples for showing how to use getRegistration() of the com.esotericsoftware.kryo.Kryo class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: athena   File:   Source Code and License Vote up 5 votes
 * Register {@code type} and {@code serializer} to {@code kryo} instance.
 * @param kryo       Kryo instance
 * @param type       type to register
 * @param serializer Specific serializer to register or null to use default.
 * @param id         type registration id to use
private void register(Kryo kryo, Class<?> type, Serializer<?> serializer, int id) {
    Registration existing = kryo.getRegistration(id);
    if (existing != null) {
        if (existing.getType() != type) {
            log.error("{}: Failed to register {} as {}, {} was already registered.",
                      friendlyName(), type, id, existing.getType());

            throw new IllegalStateException(String.format(
                      "Failed to register %s as %s, %s was already registered.",
                      type, id, existing.getType()));
        // falling through to register call for now.
        // Consider skipping, if there's reasonable
        // way to compare serializer equivalence.
    Registration r;
    if (serializer == null) {
        r = kryo.register(type, id);
    } else {
        r = kryo.register(type, serializer, id);
    if (r.getId() != id) {
        log.warn("{}: {} already registed as {}. Skipping {}.",
                 friendlyName(), r.getType(), r.getId(), id);
    log.trace("{} registered as {}", r.getType(), r.getId());