private void retry(String token, String collapseKey,
Map<String, String[]> params, boolean delayWhileIdle) {
Queue dmQueue = QueueFactory.getQueue("c2dm");
try {
TaskOptions url =
TaskOptions.Builder.url(C2DMRetryServlet.URI)
.param(C2DMessaging.PARAM_REGISTRATION_ID, token)
.param(C2DMessaging.PARAM_COLLAPSE_KEY, collapseKey);
if (delayWhileIdle) {
url.param(PARAM_DELAY_WHILE_IDLE, "1");
}
for (String key: params.keySet()) {
String[] values = (String[]) params.get(key);
url.param(key, URLEncoder.encode(values[0], UTF8));
}
// Task queue implements the exponential backoff
long jitter = (int) Math.random() * C2DM_MAX_JITTER_MSEC;
url.countdownMillis(jitter);
TaskHandle add = dmQueue.add(url);
} catch (UnsupportedEncodingException e) {
// Ignore - UTF8 should be supported
log.log(Level.SEVERE, "Unexpected error", e);