Search in sources :

Example 1 with TaskOptions

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");
}
Also used : TaskOptions(com.google.appengine.api.taskqueue.TaskOptions) Device(com.google.samples.apps.iosched.server.gcm.db.models.Device) ArrayList(java.util.ArrayList) Queue(com.google.appengine.api.taskqueue.Queue)

Example 2 with TaskOptions

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);
}
Also used : TaskOptions(com.google.appengine.api.taskqueue.TaskOptions) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) UserAccount(com.jappstart.model.auth.UserAccount) DuplicateUserException(com.jappstart.exception.DuplicateUserException) Queue(com.google.appengine.api.taskqueue.Queue) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Queue (com.google.appengine.api.taskqueue.Queue)2 TaskOptions (com.google.appengine.api.taskqueue.TaskOptions)2 ArrayList (java.util.ArrayList)2 Device (com.google.samples.apps.iosched.server.gcm.db.models.Device)1 DuplicateUserException (com.jappstart.exception.DuplicateUserException)1 UserAccount (com.jappstart.model.auth.UserAccount)1 List (java.util.List)1 Query (javax.persistence.Query)1 Transactional (org.springframework.transaction.annotation.Transactional)1