Package com.metadot.book.connectr.server.domain

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


      }
      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

  }

  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

  @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

  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

Related Classes of com.metadot.book.connectr.server.domain.StreamItem

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.