skeleton of hostcache client

pull/4/head
Zlatin Balevsky 2018-07-22 16:41:09 +01:00
parent a233876c4e
commit 5407aa8616
6 changed files with 77 additions and 1 deletions

View File

@ -1,5 +1,7 @@
package com.muwire.core
import com.muwire.core.hostcache.CrawlerResponse
class MuWireSettings {
boolean isLeaf() {
@ -11,4 +13,9 @@ class MuWireSettings {
// TODO: implement
true
}
CrawlerResponse getCrawlerResponse() {
// TODO: implement
CrawlerResponse.REGISTERED
}
}

View File

@ -19,5 +19,7 @@ abstract class ConnectionManager {
drop(e.destination)
}
abstract void drop(Destination d);
abstract void drop(Destination d)
abstract boolean hasConnection()
}

View File

@ -19,4 +19,9 @@ class LeafConnectionManager extends ConnectionManager {
}
@Override
public boolean hasConnection() {
// TODO implement
false
}
}

View File

@ -19,4 +19,9 @@ class UltrapeerConnectionManager extends ConnectionManager {
}
@Override
public boolean hasConnection() {
// TODO: implement
false
}
}

View File

@ -0,0 +1,47 @@
package com.muwire.core.hostcache
import com.muwire.core.EventBus
import com.muwire.core.MuWireSettings
import com.muwire.core.connection.ConnectionManager
import net.i2p.client.I2PSession
class CacheClient {
final EventBus eventBus
final HostCache cache
final ConnectionManager manager
final I2PSession session
final long interval
final MuWireSettings settings
final Timer timer
public CacheClient(EventBus eventBus, HostCache cache,
ConnectionManager manager, I2PSession session,
MuWireSettings settings, long interval) {
this.eventBus = eventBus
this.cache = cache
this.manager = manager
this.session = session
this.settings = settings
this.timer = new Timer("hostcache-client",true)
}
void start() {
timer.schedule({queryIfNeeded()} as TimerTask, 1, interval)
}
void stop() {
timer.cancel()
}
private void queryIfNeeded() {
if (manager.hasConnection())
return
if (!cache.getHosts(1).isEmpty())
return
}
}

View File

@ -0,0 +1,10 @@
package com.muwire.core.hostcache;
/**
* Whether this host should answer to crawler queries
* @author zab
*
*/
public enum CrawlerResponse {
ALL, REGISTERED, NONE
}