- view API calls in correct date-order

- execute recorded API calls in date-order

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6646 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent 74e736c903
commit fe78edac32

@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeSet;
import net.yacy.kelondro.blob.Tables;
import net.yacy.kelondro.logging.Log;
@ -55,22 +56,30 @@ public class Table_API_p {
prop.put("showtable", 0);
if (post != null && post.get("execrows", "").length() > 0) {
// create a time-ordered list of events to execute
TreeSet<String> pks = new TreeSet<String>();
for (Map.Entry<String, String> entry: post.entrySet()) {
if (entry.getKey().startsWith("mark_") && entry.getValue().equals("on")) {
pks.add(entry.getKey().substring(5));
}
}
// now call the api URLs and store the result status
final RequestHeader reqHeader = new RequestHeader();
final Client client = new Client(120000, reqHeader);
ResponseContainer result;
LinkedHashMap<String, Integer> l = new LinkedHashMap<String, Integer>();
for (Map.Entry<String, String> entry: post.entrySet()) {
if (entry.getKey().startsWith("mark_") && entry.getValue().equals("on")) {
try {
Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, entry.getKey().substring(5).getBytes());
String url = "http://localhost:" + sb.getConfig("port", "8080") + new String(row.from(WorkTables.TABLE_API_COL_URL));
result = client.GET(url);
l.put(url, result.getStatusCode());
} catch (IOException e) {
Log.logException(e);
}
for (String pk: pks) {
try {
Tables.Row row = sb.tables.select(WorkTables.TABLE_API_NAME, pk.getBytes());
String url = "http://localhost:" + sb.getConfig("port", "8080") + new String(row.from(WorkTables.TABLE_API_COL_URL));
result = client.GET(url);
l.put(url, result.getStatusCode());
} catch (IOException e) {
Log.logException(e);
}
}
// construct result table
prop.put("showexec", 1);
@ -93,19 +102,12 @@ public class Table_API_p {
prop.put("showtable", 1);
// insert rows
int maxCount;
try {
maxCount = Math.min(1000, sb.tables.size(WorkTables.TABLE_API_NAME));
} catch (IOException e) {
Log.logException(e);
maxCount = 0;
}
int count = 0;
try {
final Iterator<Tables.Row> mapIterator = sb.tables.iterator(WorkTables.TABLE_API_NAME);
final Iterator<Tables.Row> mapIterator = sb.tables.orderBy(WorkTables.TABLE_API_NAME, -1, WorkTables.TABLE_API_COL_DATE).iterator();
Tables.Row row;
boolean dark = true;
while ((mapIterator.hasNext()) && (count < maxCount)) {
while (mapIterator.hasNext()) {
row = mapIterator.next();
if (row == null) continue;
prop.put("showtable_list_" + count + "_dark", ((dark) ? 1 : 0) ); dark=!dark;

@ -117,7 +117,7 @@ public class Tables_p {
}
count = 0;
try {
final Iterator<Tables.Row> mapIterator = sb.tables.iterator(table);
final Iterator<Tables.Row> mapIterator = sb.tables.orderByPK(table, maxCount).iterator();
Tables.Row row;
boolean dark = true;
byte[] cell;

@ -186,7 +186,7 @@ public class BEncodedHeap implements Iterable<Map.Entry<byte[], Map<String, byte
return map.get(key);
}
private static Map<String, byte[]> b2m(byte[] b) {
static Map<String, byte[]> b2m(byte[] b) {
if (b == null) return null;
//System.out.println("b = " + new String(b));
BDecoder decoder = new BDecoder(b);

@ -29,10 +29,12 @@ package net.yacy.kelondro.blob;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import net.yacy.kelondro.index.RowSpaceExceededException;
@ -50,7 +52,7 @@ public class Tables {
private File location;
private ConcurrentHashMap<String, BEncodedHeap> tables;
private int keymaxlen;
int keymaxlen;
public Tables(final File location, final int keymaxlen) {
this.location = new File(location.getAbsolutePath());
@ -110,7 +112,7 @@ public class Tables {
}
}
private BEncodedHeap getHeap(final String tablename) throws IOException {
BEncodedHeap getHeap(final String tablename) throws IOException {
final String table = tablename + suffix;
BEncodedHeap heap = this.tables.get(tablename);
if (heap != null) return heap;
@ -329,6 +331,36 @@ public class Tables {
return new RowIterator(table, whereKey, whereValue);
}
public Collection<Row> orderByPK(String table, int maxcount) throws IOException {
return orderByPK(table, maxcount, null, null);
}
public Collection<Row> orderByPK(String table, int maxcount, String whereKey, byte[] whereValue) throws IOException {
TreeMap<String, Row> sortTree = new TreeMap<String, Row>();
Iterator<Row> i = iterator(table, whereKey, whereValue);
Row row;
while ((maxcount < 0 || maxcount-- > 0) && i.hasNext()) {
row = i.next();
sortTree.put(new String(row.pk), row);
}
return sortTree.values();
}
public Collection<Row> orderBy(String table, int maxcount, String sortField) throws IOException {
return orderBy(table, maxcount, sortField, null, null);
}
public Collection<Row> orderBy(String table, int maxcount, String sortField, String whereKey, byte[] whereValue) throws IOException {
TreeMap<String, Row> sortTree = new TreeMap<String, Row>();
Iterator<Row> i = iterator(table, whereKey, whereValue);
Row row;
while ((maxcount < 0 || maxcount-- > 0) && i.hasNext()) {
row = i.next();
sortTree.put(new String(row.from(sortField)) + new String(row.pk), row);
}
return sortTree.values();
}
public List<String> columns(String table) throws IOException {
BEncodedHeap heap = getHeap(table);
return heap.columns();
@ -367,8 +399,8 @@ public class Tables {
public class Row {
private final byte[] pk;
private final Map<String, byte[]> map;
final byte[] pk;
final Map<String, byte[]> map;
public Row(final Map.Entry<byte[], Map<String, byte[]>> entry) {
this.pk = entry.getKey();

@ -34,11 +34,11 @@ import java.util.Map;
public class BDecoder {
private final static byte[] _e = "e".getBytes();
private final static byte[] _i = "i".getBytes();
private final static byte[] _d = "d".getBytes();
private final static byte[] _l = "l".getBytes();
private final static byte[] _p = ":".getBytes();
final static byte[] _e = "e".getBytes();
final static byte[] _i = "i".getBytes();
final static byte[] _d = "d".getBytes();
final static byte[] _l = "l".getBytes();
final static byte[] _p = ":".getBytes();
private final byte[] b;
private int pos;

Loading…
Cancel
Save