Examples of StreamItem


Examples of com.google.caliper.runner.StreamService.StreamItem

  }

  @Test public void testReadOutput() throws Exception {
    makeService(FakeWorkers.PrintClient.class, "foo", "bar");
    service.startAsync().awaitRunning();
    StreamItem item1 = readItem();
    assertEquals(Kind.DATA, item1.kind());
    Set<String> lines = Sets.newHashSet();
    lines.add(item1.content().toString());
    StreamItem item2 = readItem();
    assertEquals(Kind.DATA, item2.kind());
    lines.add(item2.content().toString());
    assertEquals(Sets.newHashSet("foo", "bar"), lines);
    assertEquals(State.RUNNING, service.state());
    StreamItem item3 = readItem();
    assertEquals(Kind.EOF, item3.kind());
    awaitStopped(100, TimeUnit.MILLISECONDS);
    assertTerminated();
  }
View Full Code Here

Examples of com.google.caliper.runner.StreamService.StreamItem

    try {
      long timeLimitNanos = getTrialTimeLimitTrialNanos();
      boolean doneCollecting = false;
      boolean done = false;
      while (!done) {
        StreamItem item = streamService.readItem(
            timeLimitNanos - trialStopwatch.elapsed(NANOSECONDS),
            NANOSECONDS);
        switch (item.kind()) {
          case DATA:
            LogMessage logMessage = item.content();
            logMessage.accept(measurementCollectingVisitor);
            logMessage.accept(dataCollectingVisitor);
            if (!doneCollecting && measurementCollectingVisitor.isDoneCollecting()) {
              doneCollecting = true;
              // We have received all the measurements we need and are about to tell the worker to
View Full Code Here

Examples of com.google.caliper.runner.StreamService.StreamItem

    assertEquals(SocketException.class, service.failureCause().getClass());
  }

  /** Reads an item, asserting that there was no timeout. */
  private StreamItem readItem() throws InterruptedException {
    StreamItem item = service.readItem(100, TimeUnit.SECONDS);
    assertNotSame("Timed out while reading item from worker", Kind.TIMEOUT, item.kind());
    return item;
  }
View Full Code Here

Examples of com.metadot.book.connectr.server.domain.StreamItem

        q.setRange(0, 1);
        @SuppressWarnings("unchecked")
        List<StreamItem> sitems = (List<StreamItem>) q.execute(user.getLastReported(), user.getId());
        if (sitems.iterator().hasNext()) {
           // if so (if newer), call pushMessage to trigger the 'push' of the new content notification
           StreamItem sitem = sitems.iterator().next();
           user.setLastReported(sitem.getDate());
           logger.info("pushing 'new content' notification");
           ChannelServer.pushMessage(user, new ContentAvailableMessage());
        }
      }
    }
View Full Code Here

Examples of com.metadot.book.connectr.server.domain.StreamItem

      }
      else {
        // process message as a 'SimpleItem' (a special-purpose class schema known by the
        // sender as well, and used only for this communication)
        Gson gson = new Gson();
        StreamItem sitem;
        SimpleItem[] sitems = gson.fromJson(body, SimpleItem[].class);
        for (SimpleItem tw: sitems) {
          // create a stream item from the data
          logger.info("conversion: " + tw);
          sitem = new StreamItem(tw.getTtext(), tw.getTtext() + " [XMPP]", tw.getSource(), tw.getTdate(),
            "", """http://twitter.com/" +tw.getTname() + "/status/"+ tw.getTid(),
            "xmpp", "http://connectr.s3.amazonaws.com/xmpp-logo2.gif", null);
          pm.makePersistent(sitem);
        }
      }
View Full Code Here

Examples of com.metadot.book.connectr.server.domain.StreamItem

  }

  public StreamItemDTO getStreamItemDetails(String id) {

    PersistenceManager pm = PMF.getNonTxnPm();
    StreamItem streamItem = null;

    try {
      // first see if object is in cache-- it should be
      Object o = CacheSupport.cacheGet(StreamItem.class.getName(), id);
      if (o != null && o instanceof StreamItem) {
        streamItem = (StreamItem) o;
        // logger.fine("in getStreamItemDetails, got cache hit");
      }
      else {
        streamItem = pm.detachCopy(pm.getObjectById(StreamItem.class, id));
      }
    }
    catch (Exception e) {
      // e.printStackTrace();
      logger.warning("exception: " + e.getMessage());
    }
    finally {
      pm.close();
    }
    // can't just use the detached StreamItem as a DTO,
    // as it has an App Engine Text field
    // that needs to be converted to a String.
    return streamItem.toDTO();
  }
View Full Code Here

Examples of com.metadot.book.connectr.server.domain.StreamItem

  @SuppressWarnings("unchecked")
  private void fetchBatch(Date sdate, PersistenceManager pm, boolean fetchEntries, boolean prior, int range) {

    List<String> fetchlist = new ArrayList<String>();
    StreamItem entry = null;

    try {
      // do a query that fetches the stream items based on the UserAccount id.
      UserAccount user = LoginHelper.getLoggedInUser(getThreadLocalRequest().getSession(), pm);
      Long userid = user.getId();
      String qstring = null;
      if (sdate == null) {
        qstring = " where ukeys == :u1";
      }
      else if (prior) {
        qstring = " where date < :d1 && ukeys == :u1";
      }
      else {
        qstring = " where date >= :d1 && ukeys == :u1";
      }
      Query q = pm.newQuery("select id from " + StreamItem.class.getName() + qstring);
      q.setOrdering("date desc");
      if (prior) {
        q.setRange(0, range);
      }
      q.addExtension("datanucleus.appengine.datastoreReadConsistency", "EVENTUAL");
      List<String> entryids;
      if (sdate != null) {
        entryids = (List<String>) q.execute(sdate, userid);
      }
      else {
        entryids = (List<String>) q.execute(userid);
      }
      // for each id, check for cached object(s) as appropriate;
      // if not available, add to list of streamitem ids for which the objects
      // need to be fetched
      // if available, add to list which will eventually need to be sorted.
      Object o = null, o2 = null;
      for (String eid : entryids) {
        if (fetchEntries) {
          o = CacheSupport.cacheGet(StreamItem.class.getName(), eid);
          if (o != null && o instanceof StreamItem) {
            entry = (StreamItem) o;
            entries.add(entry);
            // add summary to summaries list
            o2 = CacheSupport.cacheGet(StreamItemSummaryDTO.class.getName(), eid);
            if (o2 != null && o2 instanceof StreamItemSummaryDTO) {
              summaries.add((StreamItemSummaryDTO) o2);
            }
            else {
              // this case should not come up unless item removed from cache by system
              summaries.add(entry.addSummaryToCache());
            }
          }
          else {
            fetchlist.add(eid);
          }
        }
        else {
          // fetch just summaries
          o2 = CacheSupport.cacheGet(StreamItemSummaryDTO.class.getName(), eid);
          if (o2 != null && o2 instanceof StreamItemSummaryDTO) {
            // logger.info("got cache hit");
            summaries.add((StreamItemSummaryDTO) o2);
          }
          else {
            // is the stream item cached?
            o = CacheSupport.cacheGet(StreamItem.class.getName(), eid);
            if (o != null && o instanceof StreamItem) {
              // logger.info("got cache hit on stream item " + StreamItem.class.getName() + ", \n" + eid);
              entry = (StreamItem) o;
              // add summary to summaries list
              summaries.add(entry.addSummaryToCache());
            }
            else {
              fetchlist.add(eid);
            }
          }}
View Full Code Here

Examples of com.metadot.book.connectr.server.domain.StreamItem

  private void fetchForFeeds(Date sdate, Set<String> feedids, PersistenceManager pm,
      boolean fetchEntries, boolean prior, int range) {

    try {
      List<String> fetchlist = new ArrayList<String>();
      StreamItem entry = null;
      Query dq = null, q2 = null;
      String qstring = null;
      if (sdate == null) {
        qstring = " where :f1.contains(feedUrl)";
      }
      else if (prior) {
        qstring = " where date < :d1 && :f1.contains(feedUrl)";
      }
      else {
        qstring = " where date >= :d1 && :f1.contains(feedUrl)";
      }

      // break feedids list into sublists so don't reach Datastore query max
      List<List<String>> partition = ListPartition.partition(new ArrayList<String>(feedids),
          MAXFLIST);

      // for each sublist of feed ids
      for (List<String> fsublist : partition) {
        dq = pm.newQuery("select id from " + StreamItem.class.getName() + qstring);
        dq.setOrdering("date desc");
        if (prior) {
          dq.setRange(0, range);
        }
        dq.addExtension("datanucleus.appengine.datastoreReadConsistency", "EVENTUAL");

        List<String> entryids;
        if (sdate != null) {
          entryids = (List<String>) dq.execute(sdate, fsublist);
        }
        else {
          entryids = (List<String>) dq.execute(fsublist);
        }

        // for each id, check for cached object(s) as appropriate;
        // if not available, add to list of streamitem ids for which the objects
        // need to be fetched
        // if available, add to list which will eventually need to be sorted.
        Object o = null, o2 = null;
        for (String eid : entryids) {
          if (fetchEntries) {
            o = CacheSupport.cacheGet(StreamItem.class.getName(), eid);
            if (o != null && o instanceof StreamItem) {
              entry = (StreamItem) o;
              entries.add(entry);
              // add summary to summaries list
              o2 = CacheSupport.cacheGet(StreamItemSummaryDTO.class.getName(), eid);
              if (o2 != null && o2 instanceof StreamItemSummaryDTO) {
                // cache hit
                summaries.add((StreamItemSummaryDTO) o2);
              }
              else {
                // this case should not come up unless item removed from cache by system
                summaries.add(entry.addSummaryToCache());
              }
            }
            else {
              fetchlist.add(eid);
            }
          }
          else {
            // fetch just summaries
            o2 = CacheSupport.cacheGet(StreamItemSummaryDTO.class.getName(), eid);
            if (o2 != null && o2 instanceof StreamItemSummaryDTO) {
              // cache hit
              summaries.add((StreamItemSummaryDTO) o2);
            }
            else {
              // is the stream item itself cached?
              o = CacheSupport.cacheGet(StreamItem.class.getName(), eid);
              if (o != null && o instanceof StreamItem) {
                // logger.info("got cache hit on stream item " + StreamItem.class.getName() + ", \n" + eid);
                entry = (StreamItem) o;
                // add summary to summaries list
                summaries.add(entry.addSummaryToCache());
              }
              else {
                fetchlist.add(eid);
              }
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.