<commit_before>package ac.at.tuwien.infosys.fakeload.internal;

import ac.at.tuwien.infosys.fakeload.FakeLoad;

import javax.annotation.concurrent.GuardedBy;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by martensigwart on 04.07.17.
 */
final class Connection {


    @GuardedBy("this") private long cpuLoad;
    @GuardedBy("this") private long memoryLoad;
    @GuardedBy("this") private long diskIOLoad;
    @GuardedBy("this") private long netIOLoad;


    Connection() {
        cpuLoad     = 0L;
        memoryLoad  = 0L;
        diskIOLoad  = 0L;
        netIOLoad   = 0L;
    }

    synchronized long getCpuLoad() {
        return cpuLoad;
    }

    synchronized long getMemoryLoad() {
        return memoryLoad;
    }

    synchronized long getDiskIOLoad() {
        return diskIOLoad;
    }

    synchronized long getNetIOLoad() {
        return netIOLoad;
    }

    // TODO is synchronized enough synchronization
    synchronized void increaseBy(FakeLoad load) throws MaximumLoadExceededException {
        checkMaximumLoadNotExceeded(load);

        this.cpuLoad    += load.getCpuLoad();
        this.memoryLoad += load.getMemoryLoad();
        this.diskIOLoad += load.getDiskIOLoad();
        this.netIOLoad  += load.getNetIOLoad();

    }

    // TODO is synchronized enough synchronization
    synchronized void decreaseBy(FakeLoad load) {
        checkNotBelowMinimumLoad(load);

        this.cpuLoad    -= load.getCpuLoad();
        this.memoryLoad -= load.getMemoryLoad();
        this.diskIOLoad -= load.getDiskIOLoad();
        this.netIOLoad  -= load.getNetIOLoad();

    }


    private synchronized void checkMaximumLoadNotExceeded(FakeLoad load) throws MaximumLoadExceededException {
        if (this.cpuLoad + load.getCpuLoad() > 100)
            throw new MaximumLoadExceededException(String.format("Increase by %d would cause a CPU load of over 100%", load.getCpuLoad()));

        // check other load limits
    }

    private synchronized void checkNotBelowMinimumLoad(FakeLoad load) {
        if (this.cpuLoad - load.getCpuLoad() < 0) {
            throw new RuntimeException(String.format("Decrease by %d would cause a negative CPU load", load.getCpuLoad()));
        }

        if (this.memoryLoad - load.getMemoryLoad() < 0) {
            throw new RuntimeException(String.format("Decrease by %d would cause a negative memory load", load.getMemoryLoad()));
        }

        if (this.diskIOLoad - load.getDiskIOLoad() < 0) {
            throw new RuntimeException(String.format("Decrease by %d would cause a negative disk IO load", load.getDiskIOLoad()));
        }

        if (this.netIOLoad - load.getNetIOLoad() < 0) {
            throw new RuntimeException(String.format("Decrease by %d would cause a negative net IO load", load.getNetIOLoad()));
        }
    }


}<commit_msg>changed variable names<commit_after>package ac.at.tuwien.infosys.fakeload.internal;

import ac.at.tuwien.infosys.fakeload.FakeLoad;

import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;

/**
 * Created by martensigwart on 04.07.17.
 */
@ThreadSafe
final class SystemLoad {


    @GuardedBy("this") private long cpu;
    @GuardedBy("this") private long memory;
    @GuardedBy("this") private long diskIO;
    @GuardedBy("this") private long netIO;


    SystemLoad() {
        cpu     = 0L;
        memory  = 0L;
        diskIO  = 0L;
        netIO   = 0L;
    }

    synchronized long getCpu() {
        return cpu;
    }

    synchronized long getMemory() {
        return memory;
    }

    synchronized long getDiskIO() {
        return diskIO;
    }

    synchronized long getNetIO() {
        return netIO;
    }

    // TODO is synchronized enough synchronization
    synchronized void increaseBy(FakeLoad load) throws MaximumLoadExceededException {
        checkMaximumLoadNotExceeded(load);

        this.cpu    += load.getCpuLoad();
        this.memory += load.getMemoryLoad();
        this.diskIO += load.getDiskIOLoad();
        this.netIO  += load.getNetIOLoad();

    }

    // TODO is synchronized enough synchronization
    synchronized void decreaseBy(FakeLoad load) {
        checkNotBelowMinimumLoad(load);

        this.cpu -= load.getCpuLoad();
        this.memory -= load.getMemoryLoad();
        this.diskIO -= load.getDiskIOLoad();
        this.netIO -= load.getNetIOLoad();

    }


    private synchronized void checkMaximumLoadNotExceeded(FakeLoad load) throws MaximumLoadExceededException {
        if (this.cpu + load.getCpuLoad() > 100)
            throw new MaximumLoadExceededException(String.format("Increase by %d would cause a CPU load of over 100%%", load.getCpuLoad()));

        // check other load limits
    }

    private synchronized void checkNotBelowMinimumLoad(FakeLoad load) {
        if (this.cpu - load.getCpuLoad() < 0) {
            throw new RuntimeException(String.format("Decrease by %d would cause a negative CPU load", load.getCpuLoad()));
        }

        if (this.memory - load.getMemoryLoad() < 0) {
            throw new RuntimeException(String.format("Decrease by %d would cause a negative memory load", load.getMemoryLoad()));
        }

        if (this.diskIO - load.getDiskIOLoad() < 0) {
            throw new RuntimeException(String.format("Decrease by %d would cause a negative disk IO load", load.getDiskIOLoad()));
        }

        if (this.netIO - load.getNetIOLoad() < 0) {
            throw new RuntimeException(String.format("Decrease by %d would cause a negative net IO load", load.getNetIOLoad()));
        }
    }


}
{'fraction_non_alphanumeric': 0.10391459074733096, 'fraction_numerical': 0.0071174377224199285, 'mean_word_length': 2.7348837209302324, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3957154', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1649, 'n_words': 403}