Ejemplo n.º 1
0
 /**
  * Fetches data for the given primary keys.
  *
  * @param pksToDo a Map of the primary keys to fetch
  * @param results a Map to hold results that are to be added to the cache
  * @param cldToObjectsForCld a Map of Lists of objects relevant to PrimaryKeys
  * @param time1 the time that processing started
  * @throws ObjectStoreException if something goes wrong
  */
 protected void doPks(
     Map<PrimaryKey, ClassDescriptor> pksToDo,
     Map<InterMineObject, Set<InterMineObject>> results,
     Map<ClassDescriptor, List<InterMineObject>> cldToObjectsForCld,
     long time1)
     throws ObjectStoreException {
   Set<Integer> fetchedObjectIds = Collections.synchronizedSet(new HashSet<Integer>());
   Map<PrimaryKey, ClassDescriptor> pksNotDone =
       new IdentityHashMap<PrimaryKey, ClassDescriptor>(pksToDo);
   while (!pksToDo.isEmpty()) {
     int startPksToDoSize = pksToDo.size();
     Iterator<PrimaryKey> pkIter = pksToDo.keySet().iterator();
     while (pkIter.hasNext()) {
       PrimaryKey pk = pkIter.next();
       ClassDescriptor cld = pksToDo.get(pk);
       if (canDoPkNow(pk, cld, pksNotDone)) {
         // LOG.error("Running pk " + cld.getName() + "." + pk.getName());
         doPk(pk, cld, results, cldToObjectsForCld.get(cld), fetchedObjectIds);
         pkIter.remove();
         pksNotDone.remove(pk);
       } else {
         // LOG.error("Cannot do pk " + cld.getName() + "." + pk.getName() + " yet");
       }
     }
     if (pksToDo.size() == startPksToDoSize) {
       throw new RuntimeException("Error - cannot fetch any pks: " + pksToDo.keySet());
     }
   }
   long time2 = System.currentTimeMillis();
   timeSpentPrefetchEquiv += time2 - time1;
   dataTracker.prefetchIds(fetchedObjectIds);
   time1 = System.currentTimeMillis();
   timeSpentPrefetchTracker += time1 - time2;
 }
 @Override
 public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
   if (bb != null) totalRead += bb.remaining();
   Util.emitAllData(this, bb);
   if (bb != null) totalRead -= bb.remaining();
   if (tracker != null && bb != null) tracker.onData(totalRead);
   // if there's data after the emitting, and it is paused... the underlying implementation
   // is obligated to cache the byte buffer list.
 }