mirror of https://github.com/zlatinb/muwire
skeleton of hostcache client
parent
a233876c4e
commit
5407aa8616
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,5 +19,7 @@ abstract class ConnectionManager {
|
|||
drop(e.destination)
|
||||
}
|
||||
|
||||
abstract void drop(Destination d);
|
||||
abstract void drop(Destination d)
|
||||
|
||||
abstract boolean hasConnection()
|
||||
}
|
||||
|
|
|
@ -19,4 +19,9 @@ class LeafConnectionManager extends ConnectionManager {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasConnection() {
|
||||
// TODO implement
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,4 +19,9 @@ class UltrapeerConnectionManager extends ConnectionManager {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasConnection() {
|
||||
// TODO: implement
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue