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

org.browsermob.proxy.Block Maven / Gradle / Ivy

There is a newer version: 2.0-beta-7
Show newest version
package org.browsermob.proxy;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


public class Block {
    // TODO: Is this needed at all?
    //private String id = GUID.generateGUID();
    private Date start = new Date(Long.MAX_VALUE);
    private Date end = new Date(0);
    private long responseTime;
    private long bytes;
    private List objects = new ArrayList();

    public boolean add(HttpObject object) {
        if (!allowed(object)) {
            return false;
        }

        if (object.getStart().before(start)) {
            start = object.getStart();
        }

        if (object.getEnd().after(end)) {
            end = object.getEnd();
        }

        objects.add(object);
        object.setObjectNum(objects.size());

        bytes += object.getBytes();
        responseTime += object.getTimeToLastByte();

        return true;
    }

    private boolean allowed(HttpObject object) {
        // if we don't have any objects, don't reject anyone since we want some!
        if (objects.isEmpty()) {
            return true;
        }

        // a range of +- 1 second
        long start = this.start.getTime() - 1000;
        long end = this.end.getTime() + 1000;

        // todo: this doesn't seem right
        if (object.getStart().getTime() >= start && object.getStart().getTime() <= end) {
            return true;
        } else {
            return false;
        }
    }

    public Date getStart() {
        return start;
    }

    public Date getEnd() {
        return end;
    }

    public List getObjects() {
        return objects;
    }

    public long getResponseTime() {
        return responseTime;
    }

    public long getBytes() {
        return bytes;
    }

    // public String getId() {
    //     return id;
    // }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy