// evict public boolean evict() { this.dropQueryString = ""; // limit the eviction times so as to save time during benchmark if (this.evictCounter > this.totalEvictTimes) { this.evictCounter = 1; return false; } else { this.evictCounter++; } // if evict the whole cache each time if (this.evictAmount == this.size) { while (this.cacheContentOfGraphIds.size() != 0) { GraphIdCounterPair x = this.cacheContentOfGraphIds.poll(); this.dropQueryString += "drop graph <" + x.graphId + ">;"; } } // when evictAmount < size else { // check if the amount of the expired data exceeds the evictAmount while (this.toDeleteCounter < this.evictAmount) { GraphIdCounterPair x = this.cacheContentOfGraphIds.poll(); this.dropQueryString += "drop graph <" + x.graphId + ">;"; ++toDeleteCounter; } } // if this.toDeleteCounter >= this.evictAmount, dropQueryString will be // empty. if (!this.dropQueryString.equals("")) { // delete the data from the database AGQuery sparql = AGQueryFactory.create(dropQueryString); QueryExecution qe = AGQueryExecutionFactory.create(sparql, model); qe.execAsk(); qe.close(); } return true; }
// sparql public void sparql() throws IOException, RepositoryException, QueryEvaluationException { // find all expired data to avoid them participating the query: this.toDeleteCounter = 0; this.dropQueryString = ""; ArrayList<GraphIdCounterPair> expiredData = new ArrayList<GraphIdCounterPair>(); LocalTime evictionTime = LocalTime.now(); for (GraphIdCounterPair x : this.cacheContentOfGraphIds) { System.out.print( this.evictCounter + ", " + this.size + ", " + this.evictAmount + ", " + x.graphId + ", " + x.arrivalTime + ", " + x.expirationTime); if (x.expirationTime.isBefore(evictionTime)) { expiredData.add(x); dropQueryString += "drop graph <" + x.graphId + ">;"; System.out.println(", expired"); ++toDeleteCounter; } else { System.out.println(); } } System.out.println("[INFO] " + expiredData.size() + " data expired!"); if (!expiredData.isEmpty()) { // delete expired data from the cache for (GraphIdCounterPair x : expiredData) { this.cacheContentOfGraphIds.remove(x); } // delete the expired data from the database QueryExecution qe = AGQueryExecutionFactory.create(AGQueryFactory.create(dropQueryString), model); qe.execAsk(); qe.close(); } // after deleting expired data, load the cache again this.streamEmulation(); System.out.println(this.reasoner.getEntailmentRegime()); this.infModel = new AGInfModel(this.reasoner, this.model); String queryString = "select distinct ?s " + "where { ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>" + "<http://swat.cse.lehigh.edu/onto/univ-bench.owl#Professor>.}"; AGRepositoryConnection conn = this.client.getAGConn(); TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); tupleQuery.setIncludeInferred(true); long sparqlStartTime = System.currentTimeMillis(); TupleQueryResult resultSet = tupleQuery.evaluate(); long sparqlEndTime = System.currentTimeMillis(); this.aveSparql += (sparqlEndTime - sparqlStartTime); ArrayList<String> results = new ArrayList<String>(); while (resultSet.hasNext()) { String result = resultSet.next().toString(); System.out.println("result"); int length = result.length(); results.add(result.substring(3, length - 1)); } resultSet.close(); this.fMeasureBench(results); this.infModel.close(); }