Package com.google.appengine.api.labs.taskqueue

Examples of com.google.appengine.api.labs.taskqueue.Queue


    final String ssKey = (String) control.getProperty(GbControl.SPREADSHEET_KEY);
    final String kind = (String) control.getProperty(GbControl.KIND_NAME);
    final Integer rowNum = ((Long) control.getProperty(GbControl.COUNT)).intValue();
    final String token = (String) control.getProperty(GbControl.AUTH_SUB_TOKEN);
    logger.info("Restore:kind=" + kind + ":rowNum=" + rowNum);
    Queue queue = QueueFactory.getDefaultQueue();

    // Spreadsheetからデータを取得
    GbSpreadsheetService service = new GbSpreadsheetService(token);
    List<GbEntity> data = service.getDataOrNull(ssKey, kind, rowNum + 1, RANGE);

    if (data == null) {
      // Call the final task
      queue.add(TaskOptions.Builder.url("/tasks/restoreEnd.gobo").param(
        "controlKey",
        KeyFactory.keyToString(controlKey)).method(Method.GET));
      return null;
    }

    // Restoring to Datastore.
    GbDatastoreService.restoreData(kind, data);

    // Update control row.
    control.setProperty(GbControl.COUNT, rowNum + RANGE);
    control.setProperty(GbControl.UPDATE_DATE, new Date());
    datastore.put(control);

    // タスクチェーンを継続
    queue.add(TaskOptions.Builder.url("/tasks/restore.gobo").param(
      "controlKey",
      KeyFactory.keyToString(controlKey)).method(Method.GET));

    return null;
  }
View Full Code Here


    try {

      // Prepare Control Table.
      Key controlId = datastore.allocateIds("restore", 1).getStart();
      List<Entity> list = new ArrayList<Entity>();
      Queue queue = QueueFactory.getDefaultQueue();
      List<TaskOptions> taskList = Lists.newArrayList();
      for (int i = 0; i < wsTitles.length; i++) {
        Key childKey = KeyFactory.createKey(controlId, GbControl.NAME, wsTitles[i]);
        Entity control = new Entity(childKey);
        control.setProperty(GbControl.KIND_NAME, wsTitles[i]);
        control.setProperty(GbControl.COUNT, 2); // ignore header!
        if (currentUser != null) {
          control.setProperty(GbControl.REPORT_TO, new Email(currentUser.getEmail()));
        }
        control.setProperty(GbControl.AUTH_SUB_TOKEN, token);
        control.setProperty(GbControl.SPREADSHEET_KEY, ssKey);
        control.setProperty(GbControl.UPDATE_DATE, new Date());
        list.add(control);

        // Start task queue chain for each kind.
        taskList.add(TaskOptions.Builder.url("/tasks/restore.gobo").param(
          "controlKey",
          KeyFactory.keyToString(childKey)).countdownMillis(10000).method(Method.GET));
      }
      putKeys = datastore.put(list);
      queue.add(taskList);

    } catch (Exception e) {
      if (putKeys != null) {
        try {
          datastore.delete(putKeys);
View Full Code Here

    // Get data from datastore.
    GbEntityList<GbEntity> list = GbDatastoreService.getData(cursor, kind, RANGE);

    // Call the last chain.
    Queue queue = QueueFactory.getDefaultQueue();
    if ((list == null) || (list.size() == 0)) {
      queue.add(TaskOptions.Builder.url("/tasks/dumpEnd.gobo").param(
        "controlKey",
        KeyFactory.keyToString(controlKey)).method(Method.GET));
      return null;
    }

    // Add to Spreadsheet.
    gss.dumpData(ssKey, kind, tableId, list, retry);

    // Update the control table.
    control.setProperty(GbControl.CURSOR, list.getCursor().toWebSafeString());
    control.setProperty(GbControl.TABLE_ID, tableId);
    control.setProperty(GbControl.COUNT, rowNum + RANGE);
    control.setProperty(GbControl.UPDATE_DATE, new Date());
    datastore.put(control);

    // Call the next chain.
    queue.add(TaskOptions.Builder.url("/tasks/dump.gobo").param(
      "controlKey",
      KeyFactory.keyToString(controlKey)).method(Method.GET));

    return null;
  }
View Full Code Here

    List<Key> putKeys = null;
    try {
      // Prepare control table.
      Key controlId = datastore.allocateIds("drop", 1).getStart();
      List<Entity> list = new ArrayList<Entity>();
      Queue queue = QueueFactory.getDefaultQueue();
      List<TaskOptions> taskList = Lists.newArrayList();
      for (int i = 0; i < kinds.length; i++) {

        Key childKey = KeyFactory.createKey(controlId, GbControl.NAME, kinds[i]);
        Entity control = new Entity(childKey);
        control.setProperty(GbControl.KIND_NAME, kinds[i]);
        control.setProperty(GbControl.COUNT, 0);
        if (currentUser != null) {
          control.setProperty(GbControl.REPORT_TO, new Email(currentUser.getEmail()));
        }
        control.setProperty(GbControl.UPDATE_DATE, new Date());
        list.add(control);

        // Start task queue chain for each kind.
        taskList.add(TaskOptions.Builder.url("/tasks/drop.gobo").param(
          "controlKey",
          KeyFactory.keyToString(childKey)).method(Method.GET));
      }
      putKeys = datastore.put(list);
      queue.add(taskList);

    } catch (Exception e) {
      if (putKeys != null) {
        try {
          datastore.delete(putKeys);
View Full Code Here

        }
    }
   
    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);
        }
       
View Full Code Here

          byte[] data = Utils.serialize(hm);

          // add transactional task to update the url information
          // will not be added to the queue if the transaction does not
          // commit.
          Queue queue = QueueFactory.getDefaultQueue();
          queue.add(url("/updatefeedurls").payload(data,
            "application/x-java-serialized-object"));
        }
        try {
          logger.fine("about to start commit");
          pm.currentTransaction().commit();
View Full Code Here

          hm.put("fid", fid);
          byte[] data = Utils.serialize(hm);
          // add transactional task to update the url information
          // will not be added to the queue if the transaction does not
          // commit.
          Queue queue = QueueFactory.getDefaultQueue();
          queue.add(url("/updatefeedurls").payload(data,
            "application/x-java-serialized-object"));
        }

        try {
          logger.fine("starting commit");
View Full Code Here

          pm.deletePersistent(friend);

          // add transactional task to update the url information
          // will not be added to the queue if the transaction does
          // not commit.
          Queue queue = QueueFactory.getDefaultQueue();
          queue.add(url("/updatefeedurls").payload(data,
          "application/x-java-serialized-object"));
        }
        try {
          pm.currentTransaction().commit();
          retval = id;
View Full Code Here

        return;
      }
      for (UserAccount user : results) {
      // For each active user, spawn tasks to update their feeds
      // and push an update notification as necessary
        Queue queue = QueueFactory.getQueue("userfeedupdates");
        queue.add(url("/feedupdateuser").param("uid", user.getUniqueId()).param("notify", "true"));
        logger.info("queueing feedupdateuser for " + user.getUniqueId());
      }
    }
    catch (Exception e) {
      // e.printStackTrace();
View Full Code Here

    try {
      userPrefs = getUserAccount(userId, pm);
      if (userPrefs != null) {
        Set<Friend> friends = userPrefs.getFriends();
        // get the default queue
        Queue queue = QueueFactory.getQueue("userfeedupdates");
        for (Friend fr : friends ){
          // spawn off tasks to fetch the Friend-associated urls
          queue.add(url("/feedupdatefr").param("fkey", fr.getId()));
          // logger.fine("queueing for " + fr.getId());
        }
        if (notify != null && notify.equalsIgnoreCase("true") && ChannelServer.channelAPIEnabled()) {
          // now add task, to run later, to see if a notification needs to be sent for that user.
          queue.add(url("/usernotif").param("uniqueid", userPrefs.getUniqueId()).countdownMillis(1000 * DELAY));
          logger.info("queueing usernotif for " + userPrefs.getUniqueId());
        }
      }
    }
    finally {
View Full Code Here

TOP

Related Classes of com.google.appengine.api.labs.taskqueue.Queue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.