more generics

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4311 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 17 years ago
parent ecd7f8ba4e
commit 016fc594af

@ -255,7 +255,8 @@ public class indexCachedRI implements indexRI {
return wordContainers(startHash, false, rot); return wordContainers(startHash, false, rot);
} }
public kelondroCloneableIterator<indexContainer> wordContainers(String startHash, boolean ramOnly, boolean rot) { @SuppressWarnings("unchecked")
public kelondroCloneableIterator<indexContainer> wordContainers(String startHash, boolean ramOnly, boolean rot) {
kelondroCloneableIterator<indexContainer> i; kelondroCloneableIterator<indexContainer> i;
if (ramOnly) { if (ramOnly) {
i = riExtern.wordContainers(startHash, false); i = riExtern.wordContainers(startHash, false);

@ -457,13 +457,13 @@ public class indexContainer extends kelondroRowSet {
public static final serverByteBuffer compressIndex(indexContainer inputContainer, indexContainer excludeContainer, long maxtime) { public static final serverByteBuffer compressIndex(indexContainer inputContainer, indexContainer excludeContainer, long maxtime) {
// collect references according to domains // collect references according to domains
long timeout = (maxtime < 0) ? Long.MAX_VALUE : System.currentTimeMillis() + maxtime; long timeout = (maxtime < 0) ? Long.MAX_VALUE : System.currentTimeMillis() + maxtime;
TreeMap doms = new TreeMap(); TreeMap<String, String> doms = new TreeMap<String, String>();
synchronized (inputContainer) { synchronized (inputContainer) {
Iterator i = inputContainer.entries(); Iterator<indexRWIRowEntry> i = inputContainer.entries();
indexRWIEntry iEntry; indexRWIEntry iEntry;
String dom, paths; String dom, paths;
while (i.hasNext()) { while (i.hasNext()) {
iEntry = (indexRWIEntry) i.next(); iEntry = i.next();
if ((excludeContainer != null) && (excludeContainer.get(iEntry.urlHash()) != null)) continue; // do not include urls that are in excludeContainer if ((excludeContainer != null) && (excludeContainer.get(iEntry.urlHash()) != null)) continue; // do not include urls that are in excludeContainer
dom = iEntry.urlHash().substring(6); dom = iEntry.urlHash().substring(6);
if ((paths = (String) doms.get(dom)) == null) { if ((paths = (String) doms.get(dom)) == null) {
@ -478,10 +478,10 @@ public class indexContainer extends kelondroRowSet {
// construct a result string // construct a result string
serverByteBuffer bb = new serverByteBuffer(inputContainer.size() * 6); serverByteBuffer bb = new serverByteBuffer(inputContainer.size() * 6);
bb.append('{'); bb.append('{');
Iterator i = doms.entrySet().iterator(); Iterator<Map.Entry<String, String>> i = doms.entrySet().iterator();
Map.Entry entry; Map.Entry<String, String> entry;
while (i.hasNext()) { while (i.hasNext()) {
entry = (Map.Entry) i.next(); entry = i.next();
bb.append((String) entry.getKey()); bb.append((String) entry.getKey());
bb.append(':'); bb.append(':');
bb.append((String) entry.getValue()); bb.append((String) entry.getValue());
@ -494,7 +494,7 @@ public class indexContainer extends kelondroRowSet {
return bb; return bb;
} }
public static final void decompressIndex(TreeMap target, serverByteBuffer ci, String peerhash) { public static final void decompressIndex(TreeMap<String, String> target, serverByteBuffer ci, String peerhash) {
// target is a mapping from url-hashes to a string of peer-hashes // target is a mapping from url-hashes to a string of peer-hashes
if ((ci.byteAt(0) == '{') && (ci.byteAt(ci.length() - 1) == '}')) { if ((ci.byteAt(0) == '{') && (ci.byteAt(ci.length() - 1) == '}')) {
//System.out.println("DEBUG-DECOMPRESS: input is " + ci.toString()); //System.out.println("DEBUG-DECOMPRESS: input is " + ci.toString());
@ -508,7 +508,7 @@ public class indexContainer extends kelondroRowSet {
assert ci.length() >= 6 : "ci.length() = " + ci.length(); assert ci.length() >= 6 : "ci.length() = " + ci.length();
url = ci.toString(0, 6) + dom; url = ci.toString(0, 6) + dom;
ci.trim(6); ci.trim(6);
peers = (String) target.get(url); peers = target.get(url);
if (peers == null) { if (peers == null) {
target.put(url, peerhash); target.put(url, peerhash);
} else { } else {

@ -43,6 +43,7 @@ import de.anomic.kelondro.kelondroFixedWidthArray;
import de.anomic.kelondro.kelondroMScoreCluster; import de.anomic.kelondro.kelondroMScoreCluster;
import de.anomic.kelondro.kelondroNaturalOrder; import de.anomic.kelondro.kelondroNaturalOrder;
import de.anomic.kelondro.kelondroRow; import de.anomic.kelondro.kelondroRow;
import de.anomic.kelondro.kelondroRow.EntryIndex;
import de.anomic.server.serverByteBuffer; import de.anomic.server.serverByteBuffer;
import de.anomic.server.serverFileUtils; import de.anomic.server.serverFileUtils;
import de.anomic.server.serverMemory; import de.anomic.server.serverMemory;
@ -53,7 +54,7 @@ public final class indexRAMRI implements indexRI {
// class variables // class variables
private final File databaseRoot; private final File databaseRoot;
protected final SortedMap cache; // wordhash-container protected final SortedMap<String, indexContainer> cache; // wordhash-container
private final kelondroMScoreCluster<String> hashScore; private final kelondroMScoreCluster<String> hashScore;
private final kelondroMScoreCluster<String> hashDate; private final kelondroMScoreCluster<String> hashDate;
private long initTime; private long initTime;
@ -70,7 +71,7 @@ public final class indexRAMRI implements indexRI {
// creates a new index cache // creates a new index cache
// the cache has a back-end where indexes that do not fit in the cache are flushed // the cache has a back-end where indexes that do not fit in the cache are flushed
this.databaseRoot = databaseRoot; this.databaseRoot = databaseRoot;
this.cache = Collections.synchronizedSortedMap(new TreeMap()); this.cache = Collections.synchronizedSortedMap(new TreeMap<String, indexContainer>());
this.hashScore = new kelondroMScoreCluster<String>(); this.hashScore = new kelondroMScoreCluster<String>();
this.hashDate = new kelondroMScoreCluster<String>(); this.hashDate = new kelondroMScoreCluster<String>();
this.initTime = System.currentTimeMillis(); this.initTime = System.currentTimeMillis();
@ -124,7 +125,7 @@ public final class indexRAMRI implements indexRI {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
long messageTime = System.currentTimeMillis() + 5000; long messageTime = System.currentTimeMillis() + 5000;
long wordsPerSecond = 0, wordcount = 0, urlcount = 0; long wordsPerSecond = 0, wordcount = 0, urlcount = 0;
Map.Entry entry; Map.Entry<String, indexContainer> entry;
String wordHash; String wordHash;
indexContainer container; indexContainer container;
long updateTime; long updateTime;
@ -134,21 +135,21 @@ public final class indexRAMRI implements indexRI {
// write wCache // write wCache
synchronized (cache) { synchronized (cache) {
Iterator i = cache.entrySet().iterator(); Iterator<Map.Entry<String, indexContainer>> i = cache.entrySet().iterator();
while (i.hasNext()) { while (i.hasNext()) {
// get entries // get entries
entry = (Map.Entry) i.next(); entry = i.next();
wordHash = (String) entry.getKey(); wordHash = entry.getKey();
updateTime = getUpdateTime(wordHash); updateTime = getUpdateTime(wordHash);
container = (indexContainer) entry.getValue(); container = entry.getValue();
// put entries on stack // put entries on stack
if (container != null) { if (container != null) {
Iterator ci = container.entries(); Iterator<indexRWIRowEntry> ci = container.entries();
occ = kelondroNaturalOrder.encodeLong(container.size(), 4); occ = kelondroNaturalOrder.encodeLong(container.size(), 4);
time = kelondroNaturalOrder.encodeLong(updateTime, 8); time = kelondroNaturalOrder.encodeLong(updateTime, 8);
while (ci.hasNext()) { while (ci.hasNext()) {
iEntry = (indexRWIEntry) ci.next(); iEntry = ci.next();
row.setCol(0, wordHash.getBytes()); row.setCol(0, wordHash.getBytes());
row.setCol(1, occ); row.setCol(1, occ);
row.setCol(2, time); row.setCol(2, time);
@ -203,7 +204,7 @@ public final class indexRAMRI implements indexRI {
long urlCount = 0, urlsPerSecond = 0; long urlCount = 0, urlsPerSecond = 0;
try { try {
synchronized (cache) { synchronized (cache) {
Iterator i = dumpArray.contentRows(-1); Iterator<EntryIndex> i = dumpArray.contentRows(-1);
String wordHash; String wordHash;
//long creationTime; //long creationTime;
indexRWIEntry wordEntry; indexRWIEntry wordEntry;
@ -211,7 +212,7 @@ public final class indexRAMRI implements indexRI {
//Runtime rt = Runtime.getRuntime(); //Runtime rt = Runtime.getRuntime();
while (i.hasNext()) { while (i.hasNext()) {
// get out one entry // get out one entry
row = (kelondroRow.EntryIndex) i.next(); row = i.next();
if ((row == null) || (row.empty(0)) || (row.empty(3))) continue; if ((row == null) || (row.empty(0)) || (row.empty(3))) continue;
wordHash = row.getColString(0, "UTF-8"); wordHash = row.getColString(0, "UTF-8");
//creationTime = kelondroRecords.bytes2long(row[2]); //creationTime = kelondroRecords.bytes2long(row[2]);
@ -293,7 +294,7 @@ public final class indexRAMRI implements indexRI {
// plus the mentioned features // plus the mentioned features
private boolean rot; private boolean rot;
private Iterator iterator; private Iterator<indexContainer> iterator;
public wordContainerIterator(String startWordHash, boolean rot) { public wordContainerIterator(String startWordHash, boolean rot) {
this.rot = rot; this.rot = rot;
@ -393,7 +394,7 @@ public final class indexRAMRI implements indexRI {
return (c == null) ? 0 : c.size(); return (c == null) ? 0 : c.size();
} }
public synchronized indexContainer getContainer(String wordHash, Set urlselection) { public synchronized indexContainer getContainer(String wordHash, Set<String> urlselection) {
if (wordHash == null) return null; if (wordHash == null) return null;
// retrieve container // retrieve container
@ -435,7 +436,7 @@ public final class indexRAMRI implements indexRI {
return false; return false;
} }
public synchronized int removeEntries(String wordHash, Set urlHashes) { public synchronized int removeEntries(String wordHash, Set<String> urlHashes) {
if (urlHashes.size() == 0) return 0; if (urlHashes.size() == 0) return 0;
indexContainer c = (indexContainer) cache.get(wordHash); indexContainer c = (indexContainer) cache.get(wordHash);
int count; int count;
@ -458,16 +459,16 @@ public final class indexRAMRI implements indexRI {
// urlHash assigned. This can only work if the entry is really fresh // urlHash assigned. This can only work if the entry is really fresh
// Such entries must be searched in the latest entries // Such entries must be searched in the latest entries
int delCount = 0; int delCount = 0;
Iterator i = cache.entrySet().iterator(); Iterator<Map.Entry<String, indexContainer>> i = cache.entrySet().iterator();
Map.Entry entry; Map.Entry<String, indexContainer> entry;
String wordhash; String wordhash;
indexContainer c; indexContainer c;
while (i.hasNext()) { while (i.hasNext()) {
entry = (Map.Entry) i.next(); entry = i.next();
wordhash = (String) entry.getKey(); wordhash = entry.getKey();
// get container // get container
c = (indexContainer) entry.getValue(); c = entry.getValue();
if (c.remove(urlHash) != null) { if (c.remove(urlHash) != null) {
if (c.size() == 0) { if (c.size() == 0) {
i.remove(); i.remove();

@ -36,19 +36,15 @@ public interface indexRI {
public int size(); public int size();
public int minMem(); public int minMem();
public kelondroCloneableIterator<indexContainer> wordContainers(String startWordHash, boolean rot); // method to replace wordHashes
public kelondroCloneableIterator wordContainers(String startWordHash, boolean rot); // method to replace wordHashes
public long getUpdateTime(String wordHash); public long getUpdateTime(String wordHash);
public int indexSize(String wordHash); public int indexSize(String wordHash);
public boolean hasContainer(String wordHash); // should only be used if in case that true is returned the getContainer is NOT called public boolean hasContainer(String wordHash); // should only be used if in case that true is returned the getContainer is NOT called
public indexContainer getContainer(String wordHash, Set<String> urlselection); // if urlselection != null all url references which are not in urlselection are removed from the container public indexContainer getContainer(String wordHash, Set<String> urlselection); // if urlselection != null all url references which are not in urlselection are removed from the container
public indexContainer deleteContainer(String wordHash); public indexContainer deleteContainer(String wordHash);
public boolean removeEntry(String wordHash, String urlHash); public boolean removeEntry(String wordHash, String urlHash);
public int removeEntries(String wordHash, Set<String> urlHashes); public int removeEntries(String wordHash, Set<String> urlHashes);
public void addEntries(indexContainer newEntries, long creationTime, boolean dhtCase); public void addEntries(indexContainer newEntries, long creationTime, boolean dhtCase);
public void close(); public void close();
} }

@ -46,7 +46,6 @@ import de.anomic.server.serverDate;
import de.anomic.tools.crypt; import de.anomic.tools.crypt;
import de.anomic.tools.nxTools; import de.anomic.tools.nxTools;
import de.anomic.yacy.yacyURL; import de.anomic.yacy.yacyURL;
import de.anomic.index.indexRWIEntry;
public class indexURLEntry { public class indexURLEntry {
@ -310,7 +309,7 @@ public class indexURLEntry {
} }
public indexURLEntry.Components comp() { public indexURLEntry.Components comp() {
ArrayList cl = nxTools.strings(this.entry.getCol("comp", null), "UTF-8"); ArrayList<String> cl = nxTools.strings(this.entry.getCol("comp", null), "UTF-8");
return new indexURLEntry.Components( return new indexURLEntry.Components(
(cl.size() > 0) ? ((String) cl.get(0)).trim() : "", (cl.size() > 0) ? ((String) cl.get(0)).trim() : "",
hash(), hash(),

@ -91,11 +91,11 @@ public class kelondroBytesIntMap {
return index.size(); return index.size();
} }
public synchronized kelondroCloneableIterator keys(boolean up, byte[] firstKey) throws IOException { public synchronized kelondroCloneableIterator<byte[]> keys(boolean up, byte[] firstKey) throws IOException {
return index.keys(up, firstKey); return index.keys(up, firstKey);
} }
public synchronized kelondroCloneableIterator rows(boolean up, byte[] firstKey) throws IOException { public synchronized kelondroCloneableIterator<kelondroRow.Entry> rows(boolean up, byte[] firstKey) throws IOException {
return index.rows(up, firstKey); return index.rows(up, firstKey);
} }

@ -145,14 +145,14 @@ public class kelondroFlexSplitTable implements kelondroIndex {
public synchronized kelondroProfile profile() { public synchronized kelondroProfile profile() {
kelondroProfile[] profiles = new kelondroProfile[tables.size()]; kelondroProfile[] profiles = new kelondroProfile[tables.size()];
Iterator i = tables.values().iterator(); Iterator<kelondroIndex> i = tables.values().iterator();
int c = 0; int c = 0;
while (i.hasNext()) profiles[c++] = ((kelondroIndex) i.next()).profile(); while (i.hasNext()) profiles[c++] = ((kelondroIndex) i.next()).profile();
return kelondroProfile.consolidate(profiles); return kelondroProfile.consolidate(profiles);
} }
public int writeBufferSize() { public int writeBufferSize() {
Iterator i = tables.values().iterator(); Iterator<kelondroIndex> i = tables.values().iterator();
int s = 0; int s = 0;
kelondroIndex ki; kelondroIndex ki;
while (i.hasNext()) { while (i.hasNext()) {
@ -163,7 +163,7 @@ public class kelondroFlexSplitTable implements kelondroIndex {
} }
public void flushSome() { public void flushSome() {
Iterator i = tables.values().iterator(); Iterator<kelondroIndex> i = tables.values().iterator();
kelondroIndex ki; kelondroIndex ki;
while (i.hasNext()) { while (i.hasNext()) {
ki = ((kelondroIndex) i.next()); ki = ((kelondroIndex) i.next());
@ -177,7 +177,7 @@ public class kelondroFlexSplitTable implements kelondroIndex {
} }
public boolean has(byte[] key) throws IOException { public boolean has(byte[] key) throws IOException {
Iterator i = tables.values().iterator(); Iterator<kelondroIndex> i = tables.values().iterator();
kelondroIndex table; kelondroIndex table;
while (i.hasNext()) { while (i.hasNext()) {
table = (kelondroIndex) i.next(); table = (kelondroIndex) i.next();
@ -218,7 +218,7 @@ public class kelondroFlexSplitTable implements kelondroIndex {
} }
public synchronized Object[] keeperOf(byte[] key) throws IOException { public synchronized Object[] keeperOf(byte[] key) throws IOException {
Iterator i = tables.values().iterator(); Iterator<kelondroIndex> i = tables.values().iterator();
kelondroIndex table; kelondroIndex table;
kelondroRow.Entry entry; kelondroRow.Entry entry;
while (i.hasNext()) { while (i.hasNext()) {

@ -344,19 +344,19 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
return r; return r;
} }
public synchronized kelondroCloneableIterator keys(boolean up, byte[] firstKey) throws IOException { public synchronized kelondroCloneableIterator<byte[]> keys(boolean up, byte[] firstKey) throws IOException {
return index.keys(up, firstKey); return index.keys(up, firstKey);
} }
public synchronized kelondroCloneableIterator rows(boolean up, byte[] firstKey) throws IOException { public synchronized kelondroCloneableIterator<kelondroRow.Entry> rows(boolean up, byte[] firstKey) throws IOException {
if (index == null) return new rowIterator(index, up, firstKey); if (index == null) return new rowIterator(index, up, firstKey);
assert this.size() == index.size() : "content.size() = " + this.size() + ", index.size() = " + index.size(); assert this.size() == index.size() : "content.size() = " + this.size() + ", index.size() = " + index.size();
return new rowIterator(index, up, firstKey); return new rowIterator(index, up, firstKey);
} }
public class rowIterator implements kelondroCloneableIterator { public class rowIterator implements kelondroCloneableIterator<kelondroRow.Entry> {
kelondroCloneableIterator indexIterator; kelondroCloneableIterator<kelondroRow.Entry> indexIterator;
kelondroBytesIntMap index; kelondroBytesIntMap index;
boolean up; boolean up;
@ -378,7 +378,7 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
return indexIterator.hasNext(); return indexIterator.hasNext();
} }
public Object next() { public kelondroRow.Entry next() {
kelondroRow.Entry idxEntry = null; kelondroRow.Entry idxEntry = null;
while ((indexIterator.hasNext()) && (idxEntry == null)) { while ((indexIterator.hasNext()) && (idxEntry == null)) {
idxEntry = (kelondroRow.Entry) indexIterator.next(); idxEntry = (kelondroRow.Entry) indexIterator.next();

@ -164,11 +164,11 @@ public class kelondroMHashMap {
int newspace = mem.length * 2; int newspace = mem.length * 2;
int newcapacity = capacity() * 2; int newcapacity = capacity() * 2;
byte[] newmem = new byte[newspace]; byte[] newmem = new byte[newspace];
Iterator i = entries(); Iterator<entry> i = entries();
kelondroMHashMap.entry e; kelondroMHashMap.entry e;
int mempos; int mempos;
while (i.hasNext()) { while (i.hasNext()) {
e = (kelondroMHashMap.entry) i.next(); e = i.next();
hash = findSpace(newmem, e.key, reclen, newspace, newcapacity); hash = findSpace(newmem, e.key, reclen, newspace, newcapacity);
mempos = hash * reclen; mempos = hash * reclen;
System.arraycopy(e.key, 0, newmem, mempos, keylen); System.arraycopy(e.key, 0, newmem, mempos, keylen);
@ -233,11 +233,11 @@ public class kelondroMHashMap {
} }
} }
Iterator entries() { Iterator<entry> entries() {
return new entryIterator(); return new entryIterator();
} }
public class entryIterator implements Iterator { public class entryIterator implements Iterator<entry> {
int hashkey; int hashkey;
@ -249,7 +249,7 @@ public class kelondroMHashMap {
return hashkey >= 0; return hashkey >= 0;
} }
public Object next() { public entry next() {
int i = hashkey; int i = hashkey;
hashkey = anyhashpos(hashkey + 1); hashkey = anyhashpos(hashkey + 1);
return new entry(i); return new entry(i);
@ -320,12 +320,12 @@ public class kelondroMHashMap {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
kelondroMHashMap map = new kelondroMHashMap(4); kelondroMHashMap map = new kelondroMHashMap(4);
for (int i = 0; i < 100; i++) map.put(3333 + i, ("" + (1000 + i)).getBytes()); for (int i = 0; i < 100; i++) map.put(3333 + i, ("" + (1000 + i)).getBytes());
Iterator i = map.entries(); Iterator<entry> i = map.entries();
kelondroMHashMap.entry e; kelondroMHashMap.entry e;
System.out.println("Enumeration of elements: count=" + map.size()); System.out.println("Enumeration of elements: count=" + map.size());
int c = 0; int c = 0;
while (i.hasNext()) { while (i.hasNext()) {
e = (kelondroMHashMap.entry) i.next(); e = i.next();
System.out.println("key=" + new String(e.key) + ", value=" + new String(e.value) + ", retrieved=" + new String(map.get(e.key))); System.out.println("key=" + new String(e.key) + ", value=" + new String(e.value) + ", retrieved=" + new String(map.get(e.key)));
c++; c++;
} }

@ -152,13 +152,13 @@ public class kelondroMSetTools {
Iterator<Map.Entry<A, B>> mi = small.entrySet().iterator(); Iterator<Map.Entry<A, B>> mi = small.entrySet().iterator();
TreeMap<A, B> result = new TreeMap<A, B>(large.comparator()); TreeMap<A, B> result = new TreeMap<A, B>(large.comparator());
Map.Entry<A, B> mentry1; Map.Entry<A, B> mentry1;
Object mobj2; B mobj2;
while (mi.hasNext()) { while (mi.hasNext()) {
mentry1 = mi.next(); mentry1 = mi.next();
mobj2 = large.get(mentry1.getKey()); mobj2 = large.get(mentry1.getKey());
if (mobj2 != null) { if (mobj2 != null) {
if (mentry1.getValue() instanceof String) { if (mentry1.getValue() instanceof String) {
result.put(mentry1.getKey(), (B) ((concatStrings) ? ((String) mentry1.getValue() + (String) mobj2) : (String) mentry1.getValue())); result.put(mentry1.getKey(), (B) ((concatStrings) ? (mentry1.getValue() + (String) mobj2) : mentry1.getValue()));
} else { } else {
result.put(mentry1.getKey(), mentry1.getValue()); result.put(mentry1.getKey(), mentry1.getValue());
} }

@ -45,7 +45,8 @@ public class kelondroMapObjects extends kelondroObjects {
this(dyn, cachesize, null, null, null, null, null); this(dyn, cachesize, null, null, null, null, null);
} }
public kelondroMapObjects(kelondroDyn dyn, int cachesize, String[] sortfields, String[] longaccfields, String[] doubleaccfields, Method externalInitializer, Object externalHandler) { @SuppressWarnings("unchecked")
public kelondroMapObjects(kelondroDyn dyn, int cachesize, String[] sortfields, String[] longaccfields, String[] doubleaccfields, Method externalInitializer, Object externalHandler) {
super(dyn, cachesize); super(dyn, cachesize);
// create fast ordering clusters and acc fields // create fast ordering clusters and acc fields

@ -50,13 +50,15 @@ import java.util.Map;
public class kelondroMapTable { public class kelondroMapTable {
HashMap mTables, tTables, sTables; private HashMap<String, kelondroMapObjects> mTables;
File tablesPath; private HashMap<String, kelondroIndex> tTables;
//private HashMap sTables;
private File tablesPath;
public kelondroMapTable(File tablesPath) { public kelondroMapTable(File tablesPath) {
this.mTables = new HashMap(); this.mTables = new HashMap<String, kelondroMapObjects>();
this.tTables = new HashMap(); this.tTables = new HashMap<String, kelondroIndex>();
this.sTables = new HashMap(); //this.sTables = new HashMap();
this.tablesPath = tablesPath; this.tablesPath = tablesPath;
if (!(tablesPath.exists())) tablesPath.mkdirs(); if (!(tablesPath.exists())) tablesPath.mkdirs();
} }
@ -95,7 +97,7 @@ public class kelondroMapTable {
tTables.put(tablename, Tree); tTables.put(tablename, Tree);
} }
public synchronized void update(String tablename, String key, Map map) throws IOException { public synchronized void update(String tablename, String key, Map<String, String> map) throws IOException {
kelondroMapObjects table = (kelondroMapObjects) mTables.get(tablename); kelondroMapObjects table = (kelondroMapObjects) mTables.get(tablename);
if (table == null) throw new RuntimeException("kelondroTables.update: map table '" + tablename + "' does not exist."); if (table == null) throw new RuntimeException("kelondroTables.update: map table '" + tablename + "' does not exist.");
if (key.length() > table.keySize()) key = key.substring(0, table.keySize()); if (key.length() > table.keySize()) key = key.substring(0, table.keySize());
@ -110,7 +112,7 @@ public class kelondroMapTable {
tTables.put(tablename, tree); tTables.put(tablename, tree);
} }
public synchronized Map selectMap(String tablename, String key) { public synchronized Map<String, String> selectMap(String tablename, String key) {
kelondroMapObjects table = (kelondroMapObjects) mTables.get(tablename); kelondroMapObjects table = (kelondroMapObjects) mTables.get(tablename);
if (table == null) throw new RuntimeException("kelondroTables.selectMap: map table '" + tablename + "' does not exist."); if (table == null) throw new RuntimeException("kelondroTables.selectMap: map table '" + tablename + "' does not exist.");
if (key.length() > table.keySize()) key = key.substring(0, table.keySize()); if (key.length() > table.keySize()) key = key.substring(0, table.keySize());
@ -141,11 +143,11 @@ public class kelondroMapTable {
return table.maps(up, field); return table.maps(up, field);
} }
public synchronized kelondroCloneableIterator /* of kelondroRow.Entry-Elements */ rows(String tablename, boolean up, boolean rotating, byte[] firstKey, byte[] secondKey) throws IOException { public synchronized kelondroCloneableIterator<kelondroRow.Entry> /* of kelondroRow.Entry-Elements */ rows(String tablename, boolean up, boolean rotating, byte[] firstKey, byte[] secondKey) throws IOException {
kelondroIndex tree = (kelondroIndex) tTables.get(tablename); kelondroIndex tree = (kelondroIndex) tTables.get(tablename);
if (tree == null) throw new RuntimeException("kelondroTables.bytes: tree table '" + tablename + "' does not exist."); if (tree == null) throw new RuntimeException("kelondroTables.bytes: tree table '" + tablename + "' does not exist.");
kelondroCloneableIterator i = tree.rows(up, firstKey); kelondroCloneableIterator<kelondroRow.Entry> i = tree.rows(up, firstKey);
if (rotating) return new kelondroRotateIterator(i, secondKey); else return i; if (rotating) return new kelondroRotateIterator<kelondroRow.Entry>(i, secondKey); else return i;
} }
// if you need the long-values from a row-iteration, please use kelondroRecords.bytes2long to convert from byte[] to long // if you need the long-values from a row-iteration, please use kelondroRecords.bytes2long to convert from byte[] to long
@ -184,11 +186,11 @@ public class kelondroMapTable {
} }
public void close() { public void close() {
Iterator tablesIt = mTables.values().iterator(); Iterator<kelondroMapObjects> tablesIt = mTables.values().iterator();
while (tablesIt.hasNext()) ((kelondroMapObjects) tablesIt.next()).close(); while (tablesIt.hasNext()) ((kelondroMapObjects) tablesIt.next()).close();
mTables = null; mTables = null;
Iterator TreeIt = tTables.values().iterator(); Iterator<kelondroIndex> TreeIt = tTables.values().iterator();
while (TreeIt.hasNext()) ((kelondroIndex) TreeIt.next()).close(); while (TreeIt.hasNext()) ((kelondroIndex) TreeIt.next()).close();
tTables = null; tTables = null;
} }

@ -47,24 +47,24 @@ import java.util.HashMap;
public final class serverClassLoader extends ClassLoader { public final class serverClassLoader extends ClassLoader {
private final HashMap classes; private final HashMap<File, Class<?>> classes;
public serverClassLoader() { public serverClassLoader() {
//super(ClassLoader.getSystemClassLoader()); //super(ClassLoader.getSystemClassLoader());
super(Thread.currentThread().getContextClassLoader()); super(Thread.currentThread().getContextClassLoader());
this.classes = new HashMap(); this.classes = new HashMap<File, Class<?>>();
} }
public serverClassLoader(ClassLoader parent) { public serverClassLoader(ClassLoader parent) {
super(parent); super(parent);
classes = new HashMap(); classes = new HashMap<File, Class<?>>();
} }
public Package[] packages() { public Package[] packages() {
return super.getPackages(); return super.getPackages();
} }
public Class loadClass(File classfile) throws ClassNotFoundException { public Class<?> loadClass(File classfile) throws ClassNotFoundException {
// we consider that the classkey can either be only the name of a class, or a partial or // we consider that the classkey can either be only the name of a class, or a partial or
// complete path to a class file // complete path to a class file
@ -81,7 +81,7 @@ public final class serverClassLoader extends ClassLoader {
// try to load the class // try to load the class
synchronized(classFileName.intern()) { synchronized(classFileName.intern()) {
// first try: take the class out of the cache, denoted by the classname // first try: take the class out of the cache, denoted by the classname
Class c = (Class) this.classes.get(classfile); Class<?> c = (Class<?>) this.classes.get(classfile);
if (c != null) return c; if (c != null) return c;
// consider classkey as a file and extract the file name // consider classkey as a file and extract the file name

@ -53,13 +53,13 @@ public final class serverInstantThread extends serverAbstractThread implements s
private Long handle; private Long handle;
public static int instantThreadCounter = 0; public static int instantThreadCounter = 0;
public static TreeMap jobs = new TreeMap(); public static TreeMap<Long, String> jobs = new TreeMap<Long, String>();
public serverInstantThread(Object env, String jobExec, String jobCount, String freemem) { public serverInstantThread(Object env, String jobExec, String jobCount, String freemem) {
// jobExec is the name of a method of the object 'env' that executes the one-step-run // jobExec is the name of a method of the object 'env' that executes the one-step-run
// jobCount is the name of a method that returns the size of the job // jobCount is the name of a method that returns the size of the job
// freemem is the name of a method that tries to free memory and returns void // freemem is the name of a method that tries to free memory and returns void
Class theClass = (env instanceof Class) ? (Class) env : env.getClass(); Class<?> theClass = (env instanceof Class) ? (Class<?>) env : env.getClass();
try { try {
this.jobExecMethod = theClass.getMethod(jobExec, new Class[0]); this.jobExecMethod = theClass.getMethod(jobExec, new Class[0]);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {

@ -34,15 +34,15 @@ import java.util.TreeMap;
public class serverProfiling extends Thread { public class serverProfiling extends Thread {
private static Map historyMaps; // key=name of history, value=TreeMap of Long/Event private static Map<String, TreeMap<Long, Event>> historyMaps; // key=name of history, value=TreeMap of Long/Event
private static Map eventCounter; // key=name of history, value=Integer of event counter private static Map<String, Integer> eventCounter; // key=name of history, value=Integer of event counter
private static long lastCompleteCleanup; private static long lastCompleteCleanup;
private static serverProfiling systemProfiler; private static serverProfiling systemProfiler;
static { static {
// initialize profiling // initialize profiling
historyMaps = Collections.synchronizedMap(new HashMap()); historyMaps = Collections.synchronizedMap(new HashMap<String, TreeMap<Long, Event>>());
eventCounter = Collections.synchronizedMap(new HashMap()); eventCounter = Collections.synchronizedMap(new HashMap<String, Integer>());
lastCompleteCleanup = System.currentTimeMillis(); lastCompleteCleanup = System.currentTimeMillis();
systemProfiler = null; systemProfiler = null;
} }
@ -78,7 +78,7 @@ public class serverProfiling extends Thread {
public static void update(String eventName, Object eventPayload) { public static void update(String eventName, Object eventPayload) {
// get event history container // get event history container
int counter = eventCounter.containsKey(eventName) ? ((Integer) eventCounter.get(eventName)).intValue() : 0; int counter = eventCounter.containsKey(eventName) ? ((Integer) eventCounter.get(eventName)).intValue() : 0;
TreeMap history = historyMaps.containsKey(eventName) ? ((TreeMap) historyMaps.get(eventName)) : new TreeMap(); TreeMap<Long, Event> history = historyMaps.containsKey(eventName) ? (historyMaps.get(eventName)) : new TreeMap<Long, Event>();
// update entry // update entry
Long time = new Long(System.currentTimeMillis()); Long time = new Long(System.currentTimeMillis());
@ -105,7 +105,7 @@ public class serverProfiling extends Thread {
private static void cleanup(String eventName) { private static void cleanup(String eventName) {
if (historyMaps.containsKey(eventName)) { if (historyMaps.containsKey(eventName)) {
TreeMap history = (TreeMap) historyMaps.get(eventName); TreeMap<Long, Event> history = historyMaps.get(eventName);
cleanup(history); cleanup(history);
if (history.size() > 0) { if (history.size() > 0) {
historyMaps.put(eventName, history); historyMaps.put(eventName, history);
@ -115,18 +115,18 @@ public class serverProfiling extends Thread {
} }
} }
private static void cleanup(TreeMap history) { private static void cleanup(TreeMap<Long, Event> history) {
// clean up too old entries // clean up too old entries
while (history.size() > 0) { while (history.size() > 0) {
Long time = (Long) history.firstKey(); Long time = history.firstKey();
if (System.currentTimeMillis() - time.longValue() < 600000) break; if (System.currentTimeMillis() - time.longValue() < 600000) break;
history.remove(time); history.remove(time);
} }
} }
public static Iterator history(String eventName) { public static Iterator<Event> history(String eventName) {
return (historyMaps.containsKey(eventName) ? ((TreeMap) historyMaps.get(eventName)) : new TreeMap()).values().iterator(); return (historyMaps.containsKey(eventName) ? (historyMaps.get(eventName)) : new TreeMap<Long, Event>()).values().iterator();
} }
public static class Event { public static class Event {

@ -72,19 +72,17 @@ public final class serverSystem {
public static int maxPathLength = 65535; public static int maxPathLength = 65535;
// Macintosh-specific statics // Macintosh-specific statics
private static Class macMRJFileUtils = null; private static Class<?> macMRJFileUtils = null;
private static Class macMRJOSType = null; private static Class<?> macMRJOSType = null;
private static Constructor macMRJOSTypeConstructor = null; private static Constructor<?> macMRJOSTypeConstructor = null;
private static Object macMRJOSNullObj = null; private static Object macMRJOSNullObj = null;
private static Method macGetFileCreator = null; private static Method macGetFileCreator = null;
private static Method macGetFileType = null; private static Method macGetFileType = null;
private static Method macSetFileCreator = null; private static Method macSetFileCreator = null;
private static Method macSetFileType = null; private static Method macSetFileType = null;
private static Method macOpenURL = null; private static Method macOpenURL = null;
public static Hashtable macFSTypeCache = null; public static Hashtable<String, String> macFSTypeCache = null;
public static Hashtable macFSCreatorCache = null; public static Hashtable<String, String> macFSCreatorCache = null;
// static initialization // static initialization
static { static {
@ -114,8 +112,8 @@ public final class serverSystem {
byte[] nullb = new byte[4]; byte[] nullb = new byte[4];
for (int i = 0; i < 4; i++) nullb[i] = 0; for (int i = 0; i < 4; i++) nullb[i] = 0;
macMRJOSNullObj = macMRJOSTypeConstructor.newInstance(new Object[] {new String(nullb)}); macMRJOSNullObj = macMRJOSTypeConstructor.newInstance(new Object[] {new String(nullb)});
macFSTypeCache = new Hashtable(); macFSTypeCache = new Hashtable<String, String>();
macFSCreatorCache = new Hashtable(); macFSCreatorCache = new Hashtable<String, String>();
} catch (Exception e) { } catch (Exception e) {
//e.printStackTrace(); //e.printStackTrace();
macMRJFileUtils = null; macMRJOSType = null; macMRJFileUtils = null; macMRJOSType = null;
@ -349,13 +347,13 @@ public final class serverSystem {
starterFile.delete(); starterFile.delete();
} }
public static Vector execSynchronous(String command) throws IOException { public static Vector<String> execSynchronous(String command) throws IOException {
// runs a unix/linux command and returns output as Vector of Strings // runs a unix/linux command and returns output as Vector of Strings
// this method blocks until the command is executed // this method blocks until the command is executed
Process p = Runtime.getRuntime().exec(command); Process p = Runtime.getRuntime().exec(command);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String text; String text;
Vector output = new Vector(); Vector<String> output = new Vector<String>();
while ((text = in.readLine()) != null) { while ((text = in.readLine()) != null) {
output.add(text); output.add(text);
} }

Loading…
Cancel
Save