Fix device pruning

This commit is contained in:
burke.davey
2011-08-20 23:49:20 +00:00
parent 1deb93bfbf
commit 5c5bbbb65a
2 changed files with 14 additions and 14 deletions

View File

@@ -51,12 +51,12 @@ public class RegisterServlet extends HttpServlet {
*/ */
@Override @Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
RequestInfo reqInfo = RequestInfo.processRequest(req, resp, getServletContext()); RequestInfo reqInfo = RequestInfo.processRequest(req, resp, getServletContext());
if (reqInfo == null) { if (reqInfo == null) {
return; return;
} }
resp.setContentType("application/json"); resp.setContentType("application/json");
JSONObject regs = new JSONObject(); JSONObject regs = new JSONObject();
try { try {
@@ -79,20 +79,20 @@ public class RegisterServlet extends HttpServlet {
} catch (JSONException e) { } catch (JSONException e) {
throw new IOException(e); throw new IOException(e);
} }
} }
@Override @Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain"); resp.setContentType("text/plain");
RequestInfo reqInfo = RequestInfo.processRequest(req, resp, RequestInfo reqInfo = RequestInfo.processRequest(req, resp,
getServletContext()); getServletContext());
if (reqInfo == null) { if (reqInfo == null) {
return; return;
} }
if (reqInfo.deviceRegistrationID == null) { if (reqInfo.deviceRegistrationID == null) {
resp.setStatus(400); resp.setStatus(400);
resp.getWriter().println(ERROR_STATUS + "(Must specify devregid)"); resp.getWriter().println(ERROR_STATUS + "(Must specify devregid)");
@@ -105,7 +105,7 @@ public class RegisterServlet extends HttpServlet {
deviceName = "Phone"; deviceName = "Phone";
} }
// TODO: generate the device name by adding a number suffix for multiple // TODO: generate the device name by adding a number suffix for multiple
// devices of same type. Change android app to send model/type. // devices of same type. Change android app to send model/type.
String deviceType = reqInfo.getParameter("deviceType"); String deviceType = reqInfo.getParameter("deviceType");
if (deviceType == null) { if (deviceType == null) {
@@ -115,14 +115,14 @@ public class RegisterServlet extends HttpServlet {
// Because the deviceRegistrationId isn't static, we use a static // Because the deviceRegistrationId isn't static, we use a static
// identifier for the device. (Can be null in older clients) // identifier for the device. (Can be null in older clients)
String deviceId = reqInfo.getParameter("deviceId"); String deviceId = reqInfo.getParameter("deviceId");
// Context-shared PMF. // Context-shared PMF.
PersistenceManager pm = PersistenceManager pm =
C2DMessaging.getPMF(getServletContext()).getPersistenceManager(); C2DMessaging.getPMF(getServletContext()).getPersistenceManager();
try { try {
List<DeviceInfo> registrations = reqInfo.devices; List<DeviceInfo> registrations = reqInfo.devices;
if (registrations.size() > MAX_DEVICES) { if (registrations.size() > MAX_DEVICES) {
// we could return an error - but user can't handle it yet. // we could return an error - but user can't handle it yet.
// we can't let it grow out of bounds. // we can't let it grow out of bounds.
@@ -130,7 +130,7 @@ public class RegisterServlet extends HttpServlet {
// unused registrations // unused registrations
DeviceInfo oldest = registrations.get(0); DeviceInfo oldest = registrations.get(0);
if (oldest.getRegistrationTimestamp() == null) { if (oldest.getRegistrationTimestamp() == null) {
pm.deletePersistent(oldest); reqInfo.deleteRegistration(oldest.getDeviceRegistrationID());
} else { } else {
long oldestTime = oldest.getRegistrationTimestamp().getTime(); long oldestTime = oldest.getRegistrationTimestamp().getTime();
for (int i = 1; i < registrations.size(); i++) { for (int i = 1; i < registrations.size(); i++) {
@@ -140,7 +140,7 @@ public class RegisterServlet extends HttpServlet {
oldestTime = oldest.getRegistrationTimestamp().getTime(); oldestTime = oldest.getRegistrationTimestamp().getTime();
} }
} }
pm.deletePersistent(oldest); reqInfo.deleteRegistration(oldest.getDeviceRegistrationID());
} }
} }
@@ -167,7 +167,7 @@ public class RegisterServlet extends HttpServlet {
// TODO: only need to write if something changed, for chrome nothing // TODO: only need to write if something changed, for chrome nothing
// changes, we just create a new channel // changes, we just create a new channel
pm.makePersistent(device); pm.makePersistent(device);
log.log(Level.INFO, "Registered device " + reqInfo.userName + " " + log.log(Level.INFO, "Registered device " + reqInfo.userName + " " +
deviceType); deviceType);
if (device.getType().equals(DeviceInfo.TYPE_CHROME)) { if (device.getType().equals(DeviceInfo.TYPE_CHROME)) {

View File

@@ -16,7 +16,7 @@
--> -->
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>chrometophone</application> <application>chrometophone</application>
<version>10</version> <version>11</version>
<system-properties> <system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/> <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties> </system-properties>