Search in sources :

Example 1 with Vertex

use of nl.uva.cs.lobcder.optimization.Vertex in project lobcder by skoulouzis.

the class MyFilter method predict.

private void predict(Method method, String reqURL) throws Exception {
    String strPath = null;
    try {
        strPath = new URL(reqURL).getPath();
    } catch (MalformedURLException ex) {
        strPath = reqURL;
    }
    String[] parts = strPath.split("/lobcder/dav");
    String resource = null;
    if (parts != null && parts.length > 1) {
        resource = parts[1];
    } else {
        resource = strPath;
    }
    switch(type) {
        case state:
            break;
        case resource:
            method = null;
            break;
        case method:
            resource = "";
            break;
        default:
            break;
    }
    Vertex currentState = new Vertex(method, Path.path(resource).toString());
    Vertex nextState = null;
    nextState = getPredictor().getNextState(currentState);
    Logger.getLogger(MyFilter.class.getName()).log(Level.INFO, "Predictior: {0}", getPredictor().getClass().getName());
    if (prevState != null) {
        getPredictor().setPreviousStateForCurrent(prevState, currentState);
    }
    if (prevPrediction != null) {
        if (currentState.getID().equals(prevPrediction.getID())) {
            Logger.getLogger(MyFilter.class.getName()).log(Level.INFO, "Prediction Result: Hit");
        } else {
            Logger.getLogger(MyFilter.class.getName()).log(Level.INFO, "Prediction Result: Miss");
        }
    } else {
        Logger.getLogger(MyFilter.class.getName()).log(Level.INFO, "Prediction Result: Non");
    }
    prevState = currentState;
    prevPrediction = nextState;
}
Also used : Vertex(nl.uva.cs.lobcder.optimization.Vertex) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL)

Example 2 with Vertex

use of nl.uva.cs.lobcder.optimization.Vertex in project lobcder by skoulouzis.

the class DBMapPredictor method getSuccessor.

protected Vertex getSuccessor(String key) throws SQLException {
    Vertex ls = null;
    try (Connection connection = getConnection()) {
        try (PreparedStatement ps = connection.prepareStatement("select " + "lobStateID from successor_table WHERE keyVal = ? ")) {
            ps.setString(1, key);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                String id = rs.getString(1);
                Request.Method method;
                String resource;
                switch(type) {
                    case state:
                        method = Request.Method.valueOf(id.split(",")[0]);
                        resource = id.split(",")[1];
                        break;
                    case resource:
                        resource = id;
                        method = null;
                        break;
                    case method:
                        resource = "";
                        method = Request.Method.valueOf(id);
                        break;
                    default:
                        method = Request.Method.valueOf(id.split(",")[0]);
                        resource = id.split(",")[1];
                        break;
                }
                ls = new Vertex(method, resource);
            }
        }
        connection.commit();
    }
    return ls;
}
Also used : Vertex(nl.uva.cs.lobcder.optimization.Vertex) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Request(io.milton.http.Request) PreparedStatement(java.sql.PreparedStatement)

Example 3 with Vertex

use of nl.uva.cs.lobcder.optimization.Vertex in project lobcder by skoulouzis.

the class LastSuccessor method getNextState.

@Override
public Vertex getNextState(Vertex currentState) {
    try {
        String currentID;
        switch(type) {
            case state:
                currentID = currentState.getID();
                break;
            case resource:
                currentID = currentState.getResourceName();
                break;
            case method:
                currentID = currentState.getMethod().code;
                break;
            default:
                currentID = currentState.getID();
                break;
        }
        // LobState nextState = lastS.get(currentState.getID());
        Vertex nextState = getSuccessor(currentID);
        return nextState;
    } catch (SQLException ex) {
        Logger.getLogger(LastSuccessor.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
Also used : Vertex(nl.uva.cs.lobcder.optimization.Vertex) SQLException(java.sql.SQLException)

Example 4 with Vertex

use of nl.uva.cs.lobcder.optimization.Vertex in project lobcder by skoulouzis.

the class StableSuccessor method getNextState.

@Override
public Vertex getNextState(Vertex currentState) {
    try {
        String currentID;
        switch(type) {
            case state:
                currentID = currentState.getID();
                break;
            case resource:
                currentID = currentState.getResourceName();
                break;
            case method:
                currentID = currentState.getMethod().code;
                break;
            default:
                currentID = currentState.getID();
                break;
        }
        Vertex nextState = getSuccessor(currentID);
        // if (lastS.containsKey(currentState.getID())) {
        // nextState = lastS.get(currentState.getID());
        // }
        Integer occurrences = null;
        // }
        if (nextState != null) {
            occurrences = getOoccurrences(currentID + nextState.getID());
        }
        if (occurrences != null && occurrences >= N) {
            return nextState;
        }
        return null;
    } catch (SQLException ex) {
        Logger.getLogger(StableSuccessor.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
Also used : Vertex(nl.uva.cs.lobcder.optimization.Vertex) SQLException(java.sql.SQLException)

Example 5 with Vertex

use of nl.uva.cs.lobcder.optimization.Vertex in project lobcder by skoulouzis.

the class FirstSuccessor method getNextState.

@Override
public Vertex getNextState(Vertex currentState) {
    try {
        String currentID = null;
        switch(type) {
            case state:
                currentID = currentState.getID();
                break;
            case resource:
                currentID = currentState.getResourceName();
                break;
            case method:
                currentID = currentState.getMethod().code;
                break;
            default:
                currentID = currentState.getID();
                break;
        }
        // LobState nextState = fos.get(currentState.getID());
        Vertex nextState = getSuccessor(currentID);
        // LobState nextState = getSuccessor(currentState.getMethod().code);
        return nextState;
    } catch (SQLException ex) {
        Logger.getLogger(FirstSuccessor.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
Also used : Vertex(nl.uva.cs.lobcder.optimization.Vertex) SQLException(java.sql.SQLException)

Aggregations

Vertex (nl.uva.cs.lobcder.optimization.Vertex)7 SQLException (java.sql.SQLException)4 Request (io.milton.http.Request)1 Method (io.milton.http.Request.Method)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1