Return-Path: X-Original-To: apmail-apex-commits-archive@minotaur.apache.org Delivered-To: apmail-apex-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5DEEC18E5A for ; Fri, 28 Aug 2015 22:02:29 +0000 (UTC) Received: (qmail 14652 invoked by uid 500); 28 Aug 2015 22:02:29 -0000 Delivered-To: apmail-apex-commits-archive@apex.apache.org Received: (qmail 14611 invoked by uid 500); 28 Aug 2015 22:02:29 -0000 Mailing-List: contact commits-help@apex.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@apex.incubator.apache.org Delivered-To: mailing list commits@apex.incubator.apache.org Received: (qmail 14601 invoked by uid 99); 28 Aug 2015 22:02:29 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Aug 2015 22:02:29 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id B9313EF3AF for ; Fri, 28 Aug 2015 22:02:28 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.646 X-Spam-Level: X-Spam-Status: No, score=-0.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.427, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id ry4L_6H9EQVu for ; Fri, 28 Aug 2015 22:02:24 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 9DB1050718 for ; Fri, 28 Aug 2015 22:02:18 +0000 (UTC) Received: (qmail 14020 invoked by uid 99); 28 Aug 2015 22:02:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Aug 2015 22:02:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BE172E0F7C; Fri, 28 Aug 2015 22:02:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: thw@apache.org To: commits@apex.incubator.apache.org Date: Fri, 28 Aug 2015 22:02:19 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [03/11] incubator-apex-core git commit: SPOI-1770 exposing list of latest 100 topics SPOI-1770 exposing list of latest 100 topics Project: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/commit/4e5c9e56 Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/tree/4e5c9e56 Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/diff/4e5c9e56 Branch: refs/heads/devel-3 Commit: 4e5c9e561f34aed94f6f205f8b13cd290419f5a9 Parents: 0e3a272 Author: David Yan Authored: Thu Jan 16 18:02:44 2014 -0800 Committer: David Yan Committed: Fri Aug 28 10:56:56 2015 -0700 ---------------------------------------------------------------------- PubSubWebSocketServlet.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/4e5c9e56/PubSubWebSocketServlet.java ---------------------------------------------------------------------- diff --git a/PubSubWebSocketServlet.java b/PubSubWebSocketServlet.java index cd7a71f..21bfd73 100644 --- a/PubSubWebSocketServlet.java +++ b/PubSubWebSocketServlet.java @@ -8,11 +8,10 @@ import com.datatorrent.api.util.JacksonObjectMapperProvider; import com.datatorrent.api.util.PubSubMessage; import com.datatorrent.api.util.PubSubMessage.PubSubMessageType; import com.datatorrent.api.util.PubSubMessageCodec; +import com.datatorrent.stram.util.LRUCache; import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; +import java.util.*; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import javax.servlet.http.HttpServletRequest; @@ -37,6 +36,17 @@ public class PubSubWebSocketServlet extends WebSocketServlet private ObjectMapper mapper = (new JacksonObjectMapperProvider()).getContext(null); private PubSubMessageCodec codec = new PubSubMessageCodec(mapper); private InternalMessageHandler internalMessageHandler = null; + private static final int latestTopicCount = 100; + private LRUCache latestTopics = new LRUCache(latestTopicCount, false) + { + @Override + public Long put(String key, Long value) + { + remove(key); // this is to make the key the most recently inserted entry + return super.put(key, value); + } + + }; public interface InternalMessageHandler { @@ -153,6 +163,7 @@ public class PubSubWebSocketServlet extends WebSocketServlet public synchronized void publish(String topic, Object data) { + latestTopics.put(topic, System.currentTimeMillis()); HashSet wsSet = topicToSocketMap.get(topic); if (wsSet != null) { Iterator it = wsSet.iterator(); @@ -220,6 +231,11 @@ public class PubSubWebSocketServlet extends WebSocketServlet unsubscribe(this, topic + ".numSubscribers"); } } + else if (type.equals(PubSubMessageType.GET_LATEST_TOPICS)) { + synchronized (this) { + sendData(this, "_latestTopics", latestTopics.keySet()); + } + } } } }