All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.eureka2.server.registry.MultiSourcedDataHolder Maven / Gradle / Ivy

The newest version!
package com.netflix.eureka2.server.registry;

import com.netflix.eureka2.interests.ChangeNotification;
import com.netflix.eureka2.server.interests.SourcedChangeNotification;
import com.netflix.eureka2.server.registry.EurekaServerRegistry.Status;
import rx.Observable;

/**
 * A holder object that maintains copies of the same data (as defined by some metric, such as id) that are
 * from different sources. Updates/removes to this holder are only done to the copy from the corresponding source.
 *
 * The holder should maintain a consistent view (w.r.t. to it's view, but not necessarily to a particular copy)
 * of this data to return.
 *
 * @param  the data type
 *
 * @author David Liu
 */
public interface MultiSourcedDataHolder {

    /**
     * @return the uuid that is common to all the data copies
     */
    String getId();

    /**
     * @return the number of copies of data currently in this holder
     */
    int size();

    /**
     * @return the view copy of the data, if exists
     */
    V get();

    /**
     * @return the copy of data for the given source, if exists
     */
    V get(Source source);

    /**
     * @return the source of the view copy of the data, if exists
     */
    Source getSource();

    /**
     * @return the view copy of the data as a change notification, if exists
     */
    SourcedChangeNotification getChangeNotification();

    /**
     * @param source the source to update
     * @param data the data copy
     */
    Observable update(Source source, V data);

    /**
     * @param source the source to delete
     */
    Observable remove(Source source, V data);


    final class Snapshot {
        private final SourcedChangeNotification notification;

        protected Snapshot(Source source, V data) {
            this.notification = new SourcedChangeNotification<>(ChangeNotification.Kind.Add, data, source);
        }

        Source getSource() {
            return notification.getSource();
        }

        V getData() {
            return notification.getData();
        }

        SourcedChangeNotification getNotification() {
            return notification;
        }
    }


    /**
     * An interface for an accessor to the data store that holds th
     */
    interface HolderStoreAccessor {
        void add(E holder);
        E get(String id);
        void remove(String id);
        boolean contains(String id);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy