mirror of
				https://github.com/opennetworkinglab/onos.git
				synced 2025-11-04 02:01:11 +01:00 
			
		
		
		
	Serializer for DefaultAnnotations. This allows Annotated objects to be correctly
used as keys in ConsistentMaps. Fixes ONOS-2128. Change-Id: Ia21a25712351b99bc1b79dc231be8187cf3d3a0b
This commit is contained in:
		
							parent
							
								
									43e9c9cfb5
								
							
						
					
					
						commit
						08e457ab8b
					
				@ -21,6 +21,8 @@ import java.util.Map;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
import com.google.common.collect.Maps;
 | 
			
		||||
 | 
			
		||||
import static com.google.common.base.Preconditions.checkNotNull;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -58,6 +60,15 @@ public final class DefaultAnnotations implements SparseAnnotations {
 | 
			
		||||
        return Objects.hashCode(this.map);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the annotations as a map.
 | 
			
		||||
     *
 | 
			
		||||
     * @return a copy of the contents of the annotations as a map.
 | 
			
		||||
     */
 | 
			
		||||
    public HashMap<String, String> asMap() {
 | 
			
		||||
        return Maps.newHashMap(this.map);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a new set of annotations using clone of the specified hash map.
 | 
			
		||||
     *
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,32 @@
 | 
			
		||||
package org.onosproject.store.serializers;
 | 
			
		||||
 | 
			
		||||
import org.onosproject.net.DefaultAnnotations;
 | 
			
		||||
 | 
			
		||||
import com.esotericsoftware.kryo.Kryo;
 | 
			
		||||
import com.esotericsoftware.kryo.Serializer;
 | 
			
		||||
import com.esotericsoftware.kryo.io.Input;
 | 
			
		||||
import com.esotericsoftware.kryo.io.Output;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
public class AnnotationsSerializer extends Serializer<DefaultAnnotations> {
 | 
			
		||||
 | 
			
		||||
    public AnnotationsSerializer() {
 | 
			
		||||
        super(false, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void write(Kryo kryo, Output output, DefaultAnnotations object) {
 | 
			
		||||
        kryo.writeObject(output, object.asMap());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public DefaultAnnotations read(Kryo kryo, Input input, Class<DefaultAnnotations> type) {
 | 
			
		||||
        DefaultAnnotations.Builder b = DefaultAnnotations.builder();
 | 
			
		||||
        HashMap<String, String> map = kryo.readObject(input, HashMap.class);
 | 
			
		||||
        map.forEach((k, v) -> b.set(k, v));
 | 
			
		||||
 | 
			
		||||
        return b.build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -264,7 +264,6 @@ public final class KryoNamespaces {
 | 
			
		||||
                    Device.Type.class,
 | 
			
		||||
                    Port.Type.class,
 | 
			
		||||
                    ChassisId.class,
 | 
			
		||||
                    DefaultAnnotations.class,
 | 
			
		||||
                    DefaultControllerNode.class,
 | 
			
		||||
                    DefaultDevice.class,
 | 
			
		||||
                    DefaultDeviceDescription.class,
 | 
			
		||||
@ -411,6 +410,7 @@ public final class KryoNamespaces {
 | 
			
		||||
            .register(new MastershipTermSerializer(), MastershipTerm.class)
 | 
			
		||||
            .register(new HostLocationSerializer(), HostLocation.class)
 | 
			
		||||
            .register(new DefaultOutboundPacketSerializer(), DefaultOutboundPacket.class)
 | 
			
		||||
            .register(new AnnotationsSerializer(), DefaultAnnotations.class)
 | 
			
		||||
            .register(Versioned.class)
 | 
			
		||||
            .register(MapEvent.class)
 | 
			
		||||
            .register(MapEvent.Type.class)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user