<commit_before>package fr.eurecom.hybris.kvs;

import java.io.Serializable;

import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;

/**
 * Class for storing cloud storage provider details.
 * @author p.viotti
 */
public class CloudProvider implements Comparable<CloudProvider>, Serializable {

    private String id;

    private transient boolean enabled;
    private transient boolean alreadyUsed; /* whether the storage provider
                                            * has already been used
                                            * (to initialize the container */
    private transient BlobStore blobStore;

    /* measures to compare the providers */
    private transient long writeLatency;
    private transient long readLatency;
    private transient int cost; // $ cents per GB

    private static final long serialVersionUID = 1L;

    public CloudProvider(String id, String accessKey, String secretKey,
                            boolean enabled, int cost) {
        this.id = id;
        this.enabled = enabled;
        this.cost = cost;

        this.readLatency = 0;
        this.writeLatency = 0;
        this.alreadyUsed = false;

        BlobStoreContext context = ContextBuilder.newBuilder(id)
                                                .credentials(accessKey, secretKey)
                                                .buildView(BlobStoreContext.class);
        this.blobStore = context.getBlobStore();
    }

    public String getId()           { return this.id; }
    public void setId(String id)    { this.id = id; }
    public boolean isAlreadyUsed()  { return this.alreadyUsed; }
    public void setAlreadyUsed(boolean alreadyUsed) { this.alreadyUsed = alreadyUsed; }
    public boolean isEnabled()      { return this.enabled; }
    public void setEnabled(boolean enabled)         { this.enabled = enabled; }
    public long getWriteLatency()   { return this.writeLatency; }
    public void setWriteLatency(long writeLatency) { this.writeLatency = writeLatency; }
    public long getReadLatency()    { return this.readLatency; }
    public void setReadLatency(long readLatency)    { this.readLatency = readLatency; }
    public int getCost()            { return this.cost; }
    public void setCost(int cost)   { this.cost = cost; }
    public BlobStore getBlobStore() { return this.blobStore; }

    /*
     * TODO should they be comparable both in terms of cost and latency? if so,
     * which weight should be given to each of them
     */
    @Override
    public int compareTo(CloudProvider o) {
        if (this.writeLatency + this.readLatency < o.getWriteLatency()
                + o.getReadLatency()
                || !o.isEnabled())
            return -1;
        else if (this.writeLatency + this.readLatency > o.getWriteLatency()
                + o.getReadLatency()
                || !this.isEnabled())
            return 1;
        else
            return 0;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (this.id == null ? 0 : this.id.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (this.getClass() != obj.getClass())
            return false;
        CloudProvider other = (CloudProvider) obj;
        if (this.id == null) {
            if (other.id != null)
                return false;
        } else if (!this.id.equals(other.id))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return this.id;
    }

    public String toVerboseString() {
        return "CloudProvider (" + this.id + ") [alreadyUsed="
                + this.alreadyUsed + ", enabled=" + this.enabled
                + ", writeLatency=" + this.writeLatency + ", readLatency="
                + this.readLatency + ", cost=" + this.cost + "]";
    }
}<commit_msg>added jClouds properties tweaks (commented out)<commit_after>package fr.eurecom.hybris.kvs;

import java.io.Serializable;

import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;

/**
 * Class for storing cloud storage provider details.
 * @author p.viotti
 */
public class CloudProvider implements Comparable<CloudProvider>, Serializable {

    private String id;

    private transient boolean enabled;
    private transient boolean alreadyUsed; /* whether the storage provider
                                            * has already been used
                                            * (to initialize the container */
    private transient BlobStore blobStore;

    /* measures to compare the providers */
    private transient long writeLatency;
    private transient long readLatency;
    private transient int cost; // $ cents per GB

    private static final long serialVersionUID = 1L;

    public CloudProvider(String id, String accessKey, String secretKey,
                            boolean enabled, int cost) {
        this.id = id;
        this.enabled = enabled;
        this.cost = cost;

        this.readLatency = 0;
        this.writeLatency = 0;
        this.alreadyUsed = false;

        /*Properties overrides = new Properties();
        overrides.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, "30");
        overrides.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, "0");  // limited by MAX_CONNECTIONS_PER_CONTEXT
        overrides.setProperty(PROPERTY_IO_WORKER_THREADS, "30");
        overrides.setProperty(PROPERTY_USER_THREADS, "0");              // unlimited */
        BlobStoreContext context = ContextBuilder.newBuilder(id)
                                                .credentials(accessKey, secretKey)
                                                //.overrides(overrides)
                                                .buildView(BlobStoreContext.class);
        this.blobStore = context.getBlobStore();
    }

    public String getId()           { return this.id; }
    public void setId(String id)    { this.id = id; }
    public boolean isAlreadyUsed()  { return this.alreadyUsed; }
    public void setAlreadyUsed(boolean alreadyUsed) { this.alreadyUsed = alreadyUsed; }
    public boolean isEnabled()      { return this.enabled; }
    public void setEnabled(boolean enabled)         { this.enabled = enabled; }
    public long getWriteLatency()   { return this.writeLatency; }
    public void setWriteLatency(long writeLatency) { this.writeLatency = writeLatency; }
    public long getReadLatency()    { return this.readLatency; }
    public void setReadLatency(long readLatency)    { this.readLatency = readLatency; }
    public int getCost()            { return this.cost; }
    public void setCost(int cost)   { this.cost = cost; }
    public BlobStore getBlobStore() { return this.blobStore; }

    /*
     * TODO should they be comparable both in terms of cost and latency? if so,
     * which weight should be given to each of them
     */
    @Override
    public int compareTo(CloudProvider o) {
        if (this.writeLatency + this.readLatency < o.getWriteLatency()
                + o.getReadLatency()
                || !o.isEnabled())
            return -1;
        else if (this.writeLatency + this.readLatency > o.getWriteLatency()
                + o.getReadLatency()
                || !this.isEnabled())
            return 1;
        else
            return 0;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (this.id == null ? 0 : this.id.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (this.getClass() != obj.getClass())
            return false;
        CloudProvider other = (CloudProvider) obj;
        if (this.id == null) {
            if (other.id != null)
                return false;
        } else if (!this.id.equals(other.id))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return this.id;
    }

    public String toVerboseString() {
        return "CloudProvider (" + this.id + ") [alreadyUsed="
                + this.alreadyUsed + ", enabled=" + this.enabled
                + ", writeLatency=" + this.writeLatency + ", readLatency="
                + this.readLatency + ", cost=" + this.cost + "]";
    }
}
{'fraction_non_alphanumeric': 0.09290755524702071, 'fraction_numerical': 0.003008214740252227, 'mean_word_length': 2.0076548364648574, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2364869', 'n_tokens_mistral': 2324, 'n_tokens_neox': 2241, 'n_words': 640}