mirror of https://github.com/zlatinb/muwire
publish results piecemally
parent
27fcb84197
commit
3344b8ef8b
|
@ -46,6 +46,8 @@ import net.i2p.data.Base64
|
||||||
@Log
|
@Log
|
||||||
class ConnectionAcceptor {
|
class ConnectionAcceptor {
|
||||||
|
|
||||||
|
private static final int RESULT_BATCH_SIZE = 128
|
||||||
|
|
||||||
final EventBus eventBus
|
final EventBus eventBus
|
||||||
final UltrapeerConnectionManager manager
|
final UltrapeerConnectionManager manager
|
||||||
final MuWireSettings settings
|
final MuWireSettings settings
|
||||||
|
@ -344,18 +346,25 @@ class ConnectionAcceptor {
|
||||||
throw new IOException("too many results $nResults")
|
throw new IOException("too many results $nResults")
|
||||||
|
|
||||||
dis = new DataInputStream(new GZIPInputStream(dis))
|
dis = new DataInputStream(new GZIPInputStream(dis))
|
||||||
UIResultEvent[] results = new UIResultEvent[nResults]
|
UIResultEvent[] results = new UIResultEvent[Math.min(RESULT_BATCH_SIZE, nResults)]
|
||||||
|
int j = 0
|
||||||
for (int i = 0; i < nResults; i++) {
|
for (int i = 0; i < nResults; i++) {
|
||||||
int jsonSize = dis.readUnsignedShort()
|
int jsonSize = dis.readUnsignedShort()
|
||||||
byte [] payload = new byte[jsonSize]
|
byte [] payload = new byte[jsonSize]
|
||||||
dis.readFully(payload)
|
dis.readFully(payload)
|
||||||
def json = slurper.parse(payload)
|
def json = slurper.parse(payload)
|
||||||
results[i] = ResultsParser.parse(sender, resultsUUID, json)
|
results[j] = ResultsParser.parse(sender, resultsUUID, json)
|
||||||
results[i].chat = chat
|
results[j].chat = chat
|
||||||
results[i].messages = messages
|
results[j].messages = messages
|
||||||
results[i].feed = feed
|
results[j].feed = feed
|
||||||
}
|
j++
|
||||||
|
|
||||||
|
if (j == results.length) {
|
||||||
eventBus.publish(new UIResultBatchEvent(uuid: resultsUUID, results: results))
|
eventBus.publish(new UIResultBatchEvent(uuid: resultsUUID, results: results))
|
||||||
|
j = 0
|
||||||
|
results = new UIResultEvent[Math.min(nResults - i - 1, RESULT_BATCH_SIZE)]
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (IOException bad) {
|
} catch (IOException bad) {
|
||||||
log.log(Level.WARNING, "failed to process RESULTS", bad)
|
log.log(Level.WARNING, "failed to process RESULTS", bad)
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue