private void emit(Map<Object, Long> counts, int actualWindowLengthInSeconds) { for (Entry<Object, Long> entry : counts.entrySet()) { String referrer = entry.getKey().toString(); Long count = entry.getValue(); long currentEPOCH = java.lang.System.currentTimeMillis(); if (jedis.llen("l:" + referrer) > 100) { String lastEPOCH = jedis.lpop("l:" + referrer); jedis.hdel("h:" + referrer, lastEPOCH); } jedis.hset("h:" + referrer, String.valueOf(currentEPOCH), count.toString()); jedis.rpush("l:" + referrer, String.valueOf(currentEPOCH)); JSONObject msg = new JSONObject(); try { msg.put("name", referrer); msg.put("time", currentEPOCH); msg.put("count", count); } catch (JSONException e) { LOG.error("Exception when creating JSON Message", e); } jedis.publish("pubsubCounters", msg.toString()); } }
/** * Returns a JSONObject representation of the instruction object. * * @deprecated no longer used and will be removed in the future */ @Deprecated private static JSONObject convertInstructionToJSONObject(EncryptionInstruction instruction) { JSONObject instructionJSON = new JSONObject(); try { JSONObject materialsDescriptionJSON = new JSONObject(instruction.getMaterialsDescription()); instructionJSON.put(Headers.MATERIALS_DESCRIPTION, materialsDescriptionJSON.toString()); instructionJSON.put( Headers.CRYPTO_KEY, Base64.encodeAsString(instruction.getEncryptedSymmetricKey())); byte[] iv = instruction.getSymmetricCipher().getIV(); instructionJSON.put(Headers.CRYPTO_IV, Base64.encodeAsString(iv)); } catch (JSONException e) { } // Keys are never null, so JSONException will never be thrown. return instructionJSON; }