Last active
December 27, 2015 16:09
-
-
Save witoldsz/7352959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vertx = require('vertx') | |
var console = require('vertx/console') | |
var eb = vertx.eventBus; | |
var address = 'example.address' | |
var creditsAddress = 'example.credits' | |
var batchSize = 10000; | |
var received = 0 | |
var count = 0 | |
var start = null; | |
// Start the handler first, then the sender | |
result = {"status":"ok", "result":[{"id":1234, "random":3456.0}, {"id":2345, "random":4567.0}]} | |
command = {"command":"find", "collection":"helloword"} | |
var handler = function(message, replier) { | |
replier(result); | |
} | |
function send() { | |
eb.send(address, command, send); | |
received++; | |
count++; | |
if (count % batchSize == 0) { | |
console.log("Received " + count); | |
if (start == null) { | |
start = new Date(); | |
} else { | |
var now = new Date(); | |
var elapsed = now.getTime() - start.getTime(); | |
var rate = 1000 * (count + 0.0) / (elapsed); | |
console.log("rate: " + rate + " msgs/sec"); | |
start = now; | |
count = 0; | |
} | |
} | |
} | |
eb.registerHandler(address, handler); | |
eb.send(address, command, send); | |
function vertxStop() { | |
eb.unregisterHandler(address, handler); | |
} | |
console.log("Started"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public JsonObject copy() { | |
return new JsonObject(deepCopyMap(map)); | |
//return new JsonObject(encode()); | |
} | |
Object deepCopy(Object val) { | |
if (val == null || val instanceof String || val instanceof Integer || val instanceof Float | |
|| val instanceof Long || val instanceof Double || val instanceof BigDecimal | |
|| val instanceof BigInteger) { | |
return val; | |
} | |
if (val instanceof Map) { | |
return deepCopyMap((Map<String, Object>) val); | |
} | |
if (val instanceof List) { | |
return deepCopyList((List<Object>) val); | |
} | |
System.err.println("can't deepcopy " + val.getClass()); | |
return null; | |
} | |
Map<String, Object> deepCopyMap(Map<String, Object> m) { | |
Map<String, Object> ret = new HashMap<>(m.size()); | |
for (String key : m.keySet()) { | |
ret.put(key, deepCopy(m.get(key))); | |
} | |
return ret; | |
} | |
List<Object> deepCopyList(List<Object> m) { | |
List<Object> ret = new ArrayList<>(m.size()); | |
for (Object val : m) { | |
ret.add(deepCopy(val)); | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment