git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6644 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
85ca96227f
commit
308a973503
@ -1,151 +0,0 @@
|
||||
package de.anomic.data;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.yacy.kelondro.blob.BEncodedHeapArray;
|
||||
import net.yacy.kelondro.index.RowSpaceExceededException;
|
||||
import net.yacy.kelondro.logging.Log;
|
||||
import net.yacy.kelondro.util.DateFormatter;
|
||||
import de.anomic.server.serverObjects;
|
||||
|
||||
public class Tables {
|
||||
|
||||
public final static String API_TABLENAME = "api";
|
||||
public final static String API_TYPE_STEERING = "steering";
|
||||
public final static String API_TYPE_CONFIGURATION = "configuration";
|
||||
public final static String API_TYPE_CRAWLER = "crawler";
|
||||
|
||||
public final static String API_COL_TYPE = "type";
|
||||
public final static String API_COL_COMMENT = "comment";
|
||||
public final static String API_COL_DATE = "date";
|
||||
public final static String API_COL_URL = "url";
|
||||
|
||||
private BEncodedHeapArray tables;
|
||||
|
||||
public Tables(File workPath) {
|
||||
this.tables = new BEncodedHeapArray(workPath, 12);
|
||||
}
|
||||
|
||||
public boolean has(String table) {
|
||||
return tables.hasHeap(table);
|
||||
}
|
||||
|
||||
public boolean has(String table, byte[] pk) {
|
||||
try {
|
||||
return tables.has(table, pk);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<String> tables() {
|
||||
return this.tables.tables();
|
||||
}
|
||||
|
||||
public List<String> columns(String table) {
|
||||
try {
|
||||
return this.tables.columns(table);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
return new ArrayList<String>(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear(String table) {
|
||||
try {
|
||||
this.tables.clear(table);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String table, byte[] pk) {
|
||||
try {
|
||||
this.tables.delete(table, pk);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int size(String table) {
|
||||
try {
|
||||
return this.tables.size(table);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<Map.Entry<byte[], Map<String, byte[]>>> iterator(String table) {
|
||||
try {
|
||||
return this.tables.iterator(table);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
return new TreeMap<byte[], Map<String, byte[]>>().entrySet().iterator();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.tables.close();
|
||||
}
|
||||
|
||||
public Map<String, byte[]> select(String table, byte[] pk) {
|
||||
try {
|
||||
return tables.select(table, pk);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
return new TreeMap<String, byte[]>();
|
||||
}
|
||||
}
|
||||
|
||||
public void insert(String table, byte[] pk, Map<String, byte[]> map) {
|
||||
try {
|
||||
this.tables.insert(table, pk, map);
|
||||
} catch (RowSpaceExceededException e) {
|
||||
Log.logException(e);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String createRow(String table) {
|
||||
try {
|
||||
return new String(this.tables.insert(table, new HashMap<String, byte[]>()));
|
||||
} catch (RowSpaceExceededException e) {
|
||||
Log.logException(e);
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void recordAPICall(final serverObjects post, final String servletName, String type, String comment) {
|
||||
String apiurl = /*"http://localhost:" + getConfig("port", "8080") +*/ "/" + servletName + "?" + post.toString();
|
||||
try {
|
||||
this.tables.insert(
|
||||
API_TABLENAME,
|
||||
API_COL_TYPE, type.getBytes(),
|
||||
API_COL_COMMENT, comment.getBytes(),
|
||||
API_COL_DATE, DateFormatter.formatShortMilliSecond(new Date()).getBytes(),
|
||||
API_COL_URL, apiurl.getBytes()
|
||||
);
|
||||
} catch (RowSpaceExceededException e2) {
|
||||
Log.logException(e2);
|
||||
} catch (IOException e2) {
|
||||
Log.logException(e2);
|
||||
}
|
||||
Log.logInfo("APICALL", apiurl);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
// Work.java
|
||||
// (C) 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
// first published 04.02.2010 on http://yacy.net
|
||||
//
|
||||
// This is a part of YaCy, a peer-to-peer based web search engine
|
||||
//
|
||||
// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
|
||||
// $LastChangedRevision: 6539 $
|
||||
// $LastChangedBy: low012 $
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package de.anomic.data;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import net.yacy.kelondro.blob.Tables;
|
||||
import net.yacy.kelondro.logging.Log;
|
||||
import net.yacy.kelondro.util.DateFormatter;
|
||||
import de.anomic.server.serverObjects;
|
||||
|
||||
public class WorkTables extends Tables {
|
||||
|
||||
public final static String TABLE_API_NAME = "api";
|
||||
public final static String TABLE_API_TYPE_STEERING = "steering";
|
||||
public final static String TABLE_API_TYPE_CONFIGURATION = "configuration";
|
||||
public final static String TABLE_API_TYPE_CRAWLER = "crawler";
|
||||
|
||||
public final static String TABLE_API_COL_TYPE = "type";
|
||||
public final static String TABLE_API_COL_COMMENT = "comment";
|
||||
public final static String TABLE_API_COL_DATE = "date";
|
||||
public final static String TABLE_API_COL_URL = "url";
|
||||
|
||||
|
||||
public WorkTables(File workPath) {
|
||||
super(workPath, 12);
|
||||
}
|
||||
|
||||
public void recordAPICall(final serverObjects post, final String servletName, String type, String comment) {
|
||||
String apiurl = /*"http://localhost:" + getConfig("port", "8080") +*/ "/" + servletName + "?" + post.toString();
|
||||
try {
|
||||
super.insert(
|
||||
TABLE_API_NAME,
|
||||
TABLE_API_COL_TYPE, type.getBytes(),
|
||||
TABLE_API_COL_COMMENT, comment.getBytes(),
|
||||
TABLE_API_COL_DATE, DateFormatter.formatShortMilliSecond(new Date()).getBytes(),
|
||||
TABLE_API_COL_URL, apiurl.getBytes()
|
||||
);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
Log.logInfo("APICALL", apiurl);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
// LookAheadIterator.java
|
||||
// (C) 2010 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||||
// first published 04.02.2010 on http://yacy.net
|
||||
//
|
||||
// This is a part of YaCy, a peer-to-peer based web search engine
|
||||
//
|
||||
// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
|
||||
// $LastChangedRevision: 6539 $
|
||||
// $LastChangedBy: low012 $
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package net.yacy.kelondro.util;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* convenience class for iterator implementations that naturally terminate
|
||||
* when the next() method would return null. This is usually implemented using
|
||||
* a next0() method and a wrapper for next() and hasNext() that evaluates the
|
||||
* latest return value of next0()
|
||||
* To use this class just implement the next0() method
|
||||
*/
|
||||
public abstract class LookAheadIterator<A> implements Iterator<A> {
|
||||
|
||||
private boolean fresh = true;
|
||||
private A next = null;
|
||||
|
||||
public LookAheadIterator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* the internal next-method
|
||||
* @return a value of type A if available or null if no more value are available
|
||||
*/
|
||||
protected abstract A next0() ;
|
||||
|
||||
private final void checkInit() {
|
||||
if (fresh) {
|
||||
next = next0();
|
||||
fresh = false;
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean hasNext() {
|
||||
checkInit();
|
||||
return next != null;
|
||||
}
|
||||
|
||||
public final A next() {
|
||||
checkInit();
|
||||
A n = next;
|
||||
next = next0();
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* a remove is not possible with this implementation
|
||||
*/
|
||||
public final void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue