-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathGetMotdServiceImpl.java
More file actions
68 lines (54 loc) · 2.18 KB
/
Copy pathGetMotdServiceImpl.java
File metadata and controls
68 lines (54 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the MIT License https://raw.github.com/mit-cml/app-inventor/master/mitlicense.txt
package com.google.appinventor.server;
import com.google.appinventor.server.flags.Flag;
import com.google.appinventor.server.storage.StorageIo;
import com.google.appinventor.server.storage.StorageIoInstanceHolder;
import com.google.appinventor.shared.rpc.GetMotdService;
import com.google.appinventor.shared.rpc.Motd;
import java.util.logging.Logger;
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import com.google.appengine.api.memcache.Expiration;
/**
* Implementation of the get motd service.
*
* <p>Note that this service must be state-less so that it can be run on
* multiple servers.
*
* @author kerr@google.com (Debby Wallach)
*/
public class GetMotdServiceImpl extends OdeRemoteServiceServlet implements GetMotdService {
// Logging support
private static final Logger LOG = Logger.getLogger(GetMotdServiceImpl.class.getName());
// The value of this flag can be changed in appengine-web.xml
private static final Flag<Integer> motdCheckIntervalSecs =
Flag.createFlag("motd.check.interval.secs", 300);
private final StorageIo storageIo = StorageIoInstanceHolder.INSTANCE;
private final MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
private final String motdcachekey = "c3c61e03-5f77-4107-8714-0d1faa3df325"; // UUID Generated by JIS
/**
* Gets the current Motd
*
* @return the current Motd
*/
@Override
public Motd getMotd() {
Motd motd = (Motd) memcache.get(motdcachekey); // Attempt to use memcache to fetch it
if (motd != null)
return motd;
motd = storageIo.getCurrentMotd();
memcache.put(motdcachekey, motd, Expiration.byDeltaSeconds(600)); // Hold it for ten minutes
return motd;
}
/**
* Returns the value, in seconds, of the motd.check.interval.secs flag.
* 0 means don't check motd.
*/
@Override
public int getCheckInterval() {
return motdCheckIntervalSecs.get();
}
}