use of com.google.appengine.api.taskqueue.TaskOptions in project iosched by google.
the class MessageSender method multicastSend.
public void multicastSend(List<Device> devices, String action, String extraData) {
Queue queue = QueueFactory.getQueue("MulticastMessagesQueue");
// Split messages into batches for multicast
// GCM limits maximum devices per multicast request. AppEngine also limits the size of
// lists stored in the datastore.
int total = devices.size();
List<String> partialDevices = new ArrayList<String>(total);
int counter = 0;
for (Device device : devices) {
counter++;
partialDevices.add(device.getGcmId());
int partialSize = partialDevices.size();
if (partialSize == MAX_DEVICES || counter == total) {
// Send multicast message
Long multicastKey = MessageStore.createMulticast(partialDevices, action, extraData);
mLogger.fine("Queuing " + partialSize + " devices on multicast " + multicastKey);
TaskOptions taskOptions = TaskOptions.Builder.withUrl("/queue/send").param("multicastKey", Long.toString(multicastKey)).method(TaskOptions.Method.POST);
queue.add(taskOptions);
partialDevices.clear();
}
}
mLogger.fine("Queued message to " + total + " devices");
}
use of com.google.appengine.api.taskqueue.TaskOptions in project google-app-engine-jappstart by taylorleese.
the class UserDetailsServiceImpl method addUser.
/**
* Adds a user.
*
* @param user the user
* @param locale the locale
*/
@Override
@Transactional
public final void addUser(final UserAccount user, final Locale locale) {
final UserAccount cachedUser = (UserAccount) memcacheService.get(user.getUsername());
if (cachedUser != null) {
throw new DuplicateUserException();
}
final Query query = entityManager.createQuery("SELECT u FROM UserAccount u WHERE username = :username");
query.setParameter(USERNAME, user.getUsername());
@SuppressWarnings("unchecked") final List results = query.getResultList();
if (results != null && !results.isEmpty()) {
throw new DuplicateUserException();
}
entityManager.persist(user);
memcacheService.put(user.getUsername(), user, Expiration.byDeltaSeconds(DEFAULT_EXPIRATION));
final TaskOptions taskOptions = TaskOptions.Builder.withUrl(mailTaskUrl).param("username", user.getUsername()).param("locale", locale.toString());
final Queue queue = QueueFactory.getQueue(mailTaskName);
queue.add(datastoreService.getCurrentTransaction(), taskOptions);
}
Aggregations