6 |
import java.util.ArrayList; |
import java.util.ArrayList; |
7 |
import java.util.Collections; |
import java.util.Collections; |
8 |
import java.util.Date; |
import java.util.Date; |
|
import java.util.Formatter; |
|
9 |
import java.util.Locale; |
import java.util.Locale; |
10 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
11 |
|
|
17 |
import net.spy.memcached.MemcachedClient; |
import net.spy.memcached.MemcachedClient; |
18 |
|
|
19 |
import com.gc.android.market.api.MarketSession; |
import com.gc.android.market.api.MarketSession; |
|
import com.gc.android.market.api.MarketSession.Callback; |
|
|
import com.gc.android.market.api.model.Market.App; |
|
20 |
import com.gc.android.market.api.model.Market.AppsRequest; |
import com.gc.android.market.api.model.Market.AppsRequest; |
|
import com.gc.android.market.api.model.Market.AppsResponse; |
|
21 |
import com.gc.android.market.api.model.Market.CommentsRequest; |
import com.gc.android.market.api.model.Market.CommentsRequest; |
22 |
import com.gc.android.market.api.model.Market.ResponseContext; |
|
23 |
|
|
24 |
|
|
25 |
public class ShowStats extends HttpServlet { |
public class ShowStats extends HttpServlet { |
30 |
|
|
31 |
String login; |
String login; |
32 |
String password; |
String password; |
33 |
|
|
34 |
|
MemcachedClient memcache = null; |
35 |
|
|
36 |
|
|
37 |
@Override |
@Override |
40 |
|
|
41 |
login = getServletContext().getInitParameter("login"); |
login = getServletContext().getInitParameter("login"); |
42 |
password = getServletContext().getInitParameter("password"); |
password = getServletContext().getInitParameter("password"); |
43 |
|
|
44 |
|
try { |
45 |
|
memcache = new MemcachedClient(new InetSocketAddress("localhost", 11211)); |
46 |
|
} catch (IOException e) { |
47 |
|
throw new ServletException(e); |
48 |
|
} |
49 |
} |
} |
50 |
|
|
51 |
protected String doLookup(String appId) throws IOException { |
protected String doLookup(String appId) throws IOException { |
52 |
MemcachedClient c = new MemcachedClient(new InetSocketAddress("localhost", 11211)); |
|
|
|
|
53 |
|
|
54 |
String key = "marketstats:" + appId; |
String key = "marketstats:" + appId; |
55 |
String response = (String) c.get(key); |
String response = (String) memcache.get(key); |
56 |
|
|
57 |
if (response == null) { |
if (response == null) { |
58 |
response = doLookupWorker(appId); |
response = doLookupWorker(appId); |
59 |
c.set(key, TIMEOUT, response); |
memcache.set(key, TIMEOUT, response); |
60 |
response += "<!-- new lookup -->"; |
response += "<!-- new lookup -->"; |
61 |
} else { |
} else { |
62 |
response += "<!-- from memcached -->"; |
response += "<!-- from memcached -->"; |
78 |
if (start > 0) |
if (start > 0) |
79 |
count = Math.min(10, commentsCb.getEntryCount() ); |
count = Math.min(10, commentsCb.getEntryCount() ); |
80 |
|
|
81 |
log.warning("count=" + count + " start=" + start + " " + locale); |
//log.warning("count=" + count + " start=" + start + " " + locale); |
82 |
CommentsRequest commentsRequest = CommentsRequest.newBuilder() |
CommentsRequest commentsRequest = CommentsRequest.newBuilder() |
83 |
.setAppId(appId) |
.setAppId(appId) |
84 |
.setStartIndex(start) |
.setStartIndex(start) |
89 |
session.flush(); |
session.flush(); |
90 |
start +=10; |
start +=10; |
91 |
|
|
92 |
if (start >= 30) |
if (start >= 20) |
93 |
break; //emergency brake |
break; //emergency brake |
94 |
|
|
95 |
} while ( start < commentsCb.getEntryCount() ); |
} while ( start < commentsCb.getEntryCount() ); |
135 |
sb.append("\n"); |
sb.append("\n"); |
136 |
|
|
137 |
} |
} |
138 |
sb.append("Comments: " + commentBeans.size() ); |
sb.append("Comments: " + commentBeans.size() + "\n"); |
139 |
|
sb.append("Cache.Timeout=" + TIMEOUT/60 + " minutes"); |
140 |
|
|
141 |
|
|
142 |
return sb.toString(); |
return sb.toString(); |