@Test public void testIndividualPackets() { IndexPacket indexPacket1 = new IndexPacket(destination1); indexPacket1.put(emailPacket1); IndexPacket indexPacket2 = new IndexPacket(destination2); IndexPacket indexPacket3 = new IndexPacket(destination3); indexPacket2.put(emailPacket1); indexPacket2.put(emailPacket2); folder.store(indexPacket1); folder.store(indexPacket2); folder.store(indexPacket3); Iterator<IndexPacket> iterator = folder.individualPackets(); int numIndivEntries = 0; while (iterator.hasNext()) { iterator.next(); numIndivEntries++; } assertEquals(3, numIndivEntries); }
@Override public Iterator<IndexPacket> individualPackets() { final Iterator<IndexPacket> bigPackets = super.individualPackets(); return new Iterator<IndexPacket>() { IndexPacket currentPacket; Iterator<IndexPacketEntry> currentPacketIterator; @Override public boolean hasNext() { if (currentPacketIterator!=null && currentPacketIterator.hasNext()) return true; while (bigPackets.hasNext()) { currentPacket = bigPackets.next(); currentPacketIterator = currentPacket.iterator(); if (currentPacketIterator.hasNext()) return true; } return false; } @Override public IndexPacket next() { if (currentPacketIterator==null || !currentPacketIterator.hasNext()) { currentPacket = bigPackets.next(); currentPacketIterator = currentPacket.iterator(); } IndexPacketEntry entry = currentPacketIterator.next(); IndexPacket indexPacket = new IndexPacket(currentPacket.getDhtKey()); indexPacket.put(entry); return indexPacket; } @Override public void remove() { throw new UnsupportedOperationException("Not supported!"); } }; }
IndexPacketFolder extends DeletionAwareDhtFolder<IndexPacket> implements PacketListener, ExpirationListener { @Override public Iterator<IndexPacket> individualPackets() { final Iterator<IndexPacket> bigPackets = super.individualPackets(); return new Iterator<IndexPacket>() { IndexPacket currentPacket; Iterator<IndexPacketEntry> currentPacketIterator; @Override public boolean hasNext() { if (currentPacketIterator!=null && currentPacketIterator.hasNext()) return true; while (bigPackets.hasNext()) { currentPacket = bigPackets.next(); currentPacketIterator = currentPacket.iterator(); if (currentPacketIterator.hasNext()) return true; } return false; } @Override public IndexPacket next() { if (currentPacketIterator==null || !currentPacketIterator.hasNext()) { currentPacket = bigPackets.next(); currentPacketIterator = currentPacket.iterator(); } IndexPacketEntry entry = currentPacketIterator.next(); IndexPacket indexPacket = new IndexPacket(currentPacket.getDhtKey()); indexPacket.put(entry); return indexPacket; } @Override public void remove() { throw new UnsupportedOperationException("Not supported!"); } }; } }
IndexPacketFolder extends DeletionAwareDhtFolder<IndexPacket> implements PacketListener, ExpirationListener { @Override public Iterator<IndexPacket> individualPackets() { final Iterator<IndexPacket> bigPackets = super.individualPackets(); return new Iterator<IndexPacket>() { IndexPacket currentPacket; Iterator<IndexPacketEntry> currentPacketIterator; @Override public boolean hasNext() { if (currentPacketIterator!=null && currentPacketIterator.hasNext()) return true; while (bigPackets.hasNext()) { currentPacket = bigPackets.next(); currentPacketIterator = currentPacket.iterator(); if (currentPacketIterator.hasNext()) return true; } return false; } @Override public IndexPacket next() { if (currentPacketIterator==null || !currentPacketIterator.hasNext()) { currentPacket = bigPackets.next(); currentPacketIterator = currentPacket.iterator(); } IndexPacketEntry entry = currentPacketIterator.next(); IndexPacket indexPacket = new IndexPacket(currentPacket.getDhtKey()); indexPacket.put(entry); return indexPacket; } @Override public void remove() { throw new UnsupportedOperationException("Not supported!"); } }; } IndexPacketFolder(File storageDir); }
IndexPacketFolder extends DeletionAwareDhtFolder<IndexPacket> implements PacketListener, ExpirationListener { @Override public Iterator<IndexPacket> individualPackets() { final Iterator<IndexPacket> bigPackets = super.individualPackets(); return new Iterator<IndexPacket>() { IndexPacket currentPacket; Iterator<IndexPacketEntry> currentPacketIterator; @Override public boolean hasNext() { if (currentPacketIterator!=null && currentPacketIterator.hasNext()) return true; while (bigPackets.hasNext()) { currentPacket = bigPackets.next(); currentPacketIterator = currentPacket.iterator(); if (currentPacketIterator.hasNext()) return true; } return false; } @Override public IndexPacket next() { if (currentPacketIterator==null || !currentPacketIterator.hasNext()) { currentPacket = bigPackets.next(); currentPacketIterator = currentPacket.iterator(); } IndexPacketEntry entry = currentPacketIterator.next(); IndexPacket indexPacket = new IndexPacket(currentPacket.getDhtKey()); indexPacket.put(entry); return indexPacket; } @Override public void remove() { throw new UnsupportedOperationException("Not supported!"); } }; } IndexPacketFolder(File storageDir); @Override synchronized void store(DhtStorablePacket packetToStore); @Override DhtStorablePacket retrieve(Hash dhtKey); @Override synchronized void deleteExpired(); @Override Iterator<IndexPacket> individualPackets(); @Override UniqueId getDeleteAuthorization(Hash dhtKey); @Override DeleteRequest storeAndCreateDeleteRequest(DhtStorablePacket packetToStore); @Override void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime); @Override synchronized void process(DeleteRequest delRequest); }
IndexPacketFolder extends DeletionAwareDhtFolder<IndexPacket> implements PacketListener, ExpirationListener { @Override public Iterator<IndexPacket> individualPackets() { final Iterator<IndexPacket> bigPackets = super.individualPackets(); return new Iterator<IndexPacket>() { IndexPacket currentPacket; Iterator<IndexPacketEntry> currentPacketIterator; @Override public boolean hasNext() { if (currentPacketIterator!=null && currentPacketIterator.hasNext()) return true; while (bigPackets.hasNext()) { currentPacket = bigPackets.next(); currentPacketIterator = currentPacket.iterator(); if (currentPacketIterator.hasNext()) return true; } return false; } @Override public IndexPacket next() { if (currentPacketIterator==null || !currentPacketIterator.hasNext()) { currentPacket = bigPackets.next(); currentPacketIterator = currentPacket.iterator(); } IndexPacketEntry entry = currentPacketIterator.next(); IndexPacket indexPacket = new IndexPacket(currentPacket.getDhtKey()); indexPacket.put(entry); return indexPacket; } @Override public void remove() { throw new UnsupportedOperationException("Not supported!"); } }; } IndexPacketFolder(File storageDir); @Override synchronized void store(DhtStorablePacket packetToStore); @Override DhtStorablePacket retrieve(Hash dhtKey); @Override synchronized void deleteExpired(); @Override Iterator<IndexPacket> individualPackets(); @Override UniqueId getDeleteAuthorization(Hash dhtKey); @Override DeleteRequest storeAndCreateDeleteRequest(DhtStorablePacket packetToStore); @Override void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime); @Override synchronized void process(DeleteRequest delRequest);  }