Package dijjer.util

Examples of dijjer.util.VeryLongInteger


  }
 
  public void testHashStore() throws Exception {
    for (int x=0; x<HS_INSERTS; x++) {
      VeryLongIntegerKey key = new VeryLongIntegerKey(x,x);
      VeryLongInteger hash = new VeryLongInteger(x*x, x*x);
      _hs.put(key, hash);
    }
   
    _hs.close();
   
    assertEquals("File length doesn't correspond to HashStore size", _index.length(), HS_SIZE*40);
   
    _hs = new HashStore(_index, HS_SIZE);
   
    VeryLongInteger v = _hs.getHash(new VeryLongIntegerKey(2,2));
    assertEquals("Retrieved VLI was not as expected", v, new VeryLongInteger(4,4));

    // This shouldn't be in there any more as it should have been displayed
    v = _hs.getHash(new VeryLongIntegerKey(0,0));
    assertNull("Object should have been deleted, but wasn't", v);
   
    _hs.put(new VeryLongIntegerKey(20, 20), new VeryLongInteger(400, 400));
   
    v = _hs.getHash(new VeryLongIntegerKey(3,3));
    assertNull("Object should have been deleted, but wasn't", v);
   
    v = _hs.getHash(new VeryLongIntegerKey(2,2));
   
    assertNotNull("Object should have been retained, but wasn't", v);
    assertEquals("Retrieved VLI was not as expected", v, new VeryLongInteger(4,4));
   
    _hs.close();
   
    _hs = new HashStore(_index, HS_SIZE);
   
    v = _hs.getHash(new VeryLongIntegerKey(4,4));
    assertNotNull("Failed to retrieve hash", v);
    assertEquals("Retrieved VLI is not as expected", v, new VeryLongInteger(16, 16));
   
    v = _hs.getHash(new VeryLongIntegerKey(3,3));
    assertNull(v);
   
    _hs.delete(new VeryLongIntegerKey(4,4));
    assertNull(_hs.getHash(new VeryLongIntegerKey(4,4)));
   
    _hs.close();
   
    _hs = new HashStore(_index, HS_SIZE);
   
    assertNull(_hs.getHash(new VeryLongIntegerKey(4,4)));
   
    v = _hs.getHash(new VeryLongIntegerKey(2,2));
   
    assertNotNull("Object should have been retained, but wasn't", v);
    assertEquals("Retrieved VLI was not as expected", v, new VeryLongInteger(4,4));
  }
View Full Code Here


  protected synchronized void readStore() throws IOException {
    getBlockStore().seek(0);
    int recordNum = 0;
    while (getBlockStore().getFilePointer() < getBlockStore().length()) {
      VeryLongInteger key = new VeryLongInteger(getBlockStore().readLong(), getBlockStore().readLong());
      VeryLongInteger hash =  new VeryLongInteger(getBlockStore().readLong(), getBlockStore().readLong());
      long accessTime = getBlockStore().readLong();
      addBlock(new HashBlock(recordNum++, key,accessTime, hash));
    }
  }
View Full Code Here

      try {
        Logger.info("Starting transfer of block " + block);
        osbt.start();
        Logger.info("Completed transfer of block " + block);
        // Confirm that the hash matches
        VeryLongInteger retrievedHash = (VeryLongInteger) _retrievedHashes.get(new Integer(block));
        if (retrievedHash != null) {
          Logger.info("Verifying hash for block "+block);
          VeryLongInteger actualHash = new VeryLongInteger(bp.getPartiallyReceivedBlock().getBlock());
          if (!actualHash.equals(retrievedHash)) {
            Logger.warning("Hash check for block "+block+" failed");
            handleHashVerificationFailure(retrievedHash, actualHash, bp.getBlockInfo());
          }
        }
      } catch (Exception e) {
View Full Code Here

        blockNo = _nextHashToDownload++;
      }
      Logger.info("Prepairing to retrieve hash " + blockNo);
      int uid = Misc.nextInt();
      Dispatcher.getDispatcher().registerUid(uid);
      VeryLongInteger checkHash = null;
      try {
        checkHash = Dispatcher.getDispatcher().retrieveHash(
            new BlockInfo(_url, _length, _lastModified, blockNo), 10, uid, false);
      } catch (Exception e) {
        Logger.warning("Failed to retrieve hash " + e.getMessage());
View Full Code Here

    try {
      (new HttpBlockReceiver(bi, prb)).start();
    } catch (Exception e) {
      Logger.warning("Exception while trying to deal with hash verification failure", e);
    }
    VeryLongInteger confirmHash = new VeryLongInteger(prb.getBlock());
    boolean dataHashFailure = !confirmHash.equals(actualHash);
    boolean hashHashFailure = !confirmHash.equals(retrievedHash);
    Logger.info("Sending corruptionNotification for " + bi + " (" + dataHashFailure + ", " + hashHashFailure + ")");
    for (Iterator i = ((ArrayList) RoutingTable.getRoutingTable().getPeers().clone()).iterator(); i.hasNext();) {
      Peer p = (Peer) i.next();
      if (dataHashFailure) {
        UdpSocketManager.getUdpSocketManager().send(p,
View Full Code Here

    int recordNum = 0;

    while (_index.getFilePointer() < _index.length()) {

      DataBlock dataBlock = new DataBlock(recordNum,
          new VeryLongInteger(_index.readLong(), _index.readLong()),
          _index.readLong());

      getKeyMap().put(dataBlock.getKey(), dataBlock);
      getRecordNumberList().add(recordNum, dataBlock);
View Full Code Here

    written[4] = new Long(r.nextLong());
    written[5] = Long.toString(r.nextLong());
    byte[] buf = new byte[r.nextInt() % 100];
    r.nextBytes(buf);
    written[6] = new Buffer(buf);
    written[7] = new VeryLongInteger(r.nextLong(), r.nextLong());
    written[8] = new Peer(InetAddress.getByName("google.com"), 1234);
    BitArray ba = new BitArray(r.nextInt() % 100);
    for (int x=0; x<ba.getSize(); x++) {
      ba.setBit(x, r.nextBoolean());
    }
View Full Code Here

* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class VeryLongIntegerTest extends TestCase {
  public void testCloserTo() {
    VeryLongInteger vli1 = new VeryLongInteger(10, 0);
    VeryLongInteger vli2 = new VeryLongInteger(20, 0);
    VeryLongInteger vli3 = new VeryLongInteger(25, 0);
    assertTrue(vli1.closerTo(vli2, vli3));
    assertFalse(vli1.closerTo(vli3, vli2));
    assertTrue(vli2.closerTo(vli3, vli1));
    assertFalse(vli2.closerTo(vli1, vli3));
   
    Random r = new Random(0);
    for (int x=0; x<100; x++) {
      vli1 = new VeryLongInteger(r.nextLong(), r.nextLong());
      vli2 = new VeryLongInteger(r.nextLong(), r.nextLong());
      vli3 = new VeryLongInteger(r.nextLong(), r.nextLong());
      assertTrue(vli1.closerTo(vli1, vli2) != vli1.closerTo(vli2, vli1));
    }
  }
View Full Code Here

      red[x][0] = (byte) 220;
      green[x][0] = (byte) 220;
      blue[x][0] = (byte) 220;
    }
    for (Iterator i = DataStore.getDataStore().getAllKeys().iterator(); i.hasNext();) {
      VeryLongInteger vli = (VeryLongInteger) i.next();
      int ppos = vli.getMostSignificantByte();
      blue[ppos][0] = (byte) 255;
      red[ppos][0] = (byte) (220 * DataStore.getDataStore().getAgeByKey(vli));
      green[ppos][0] = (byte) (220 * DataStore.getDataStore().getAgeByKey(vli));
    }
    for (Iterator i = ((ArrayList) RoutingTable.getRoutingTable().getPeers().clone()).iterator(); i.hasNext();) {
View Full Code Here

  public Peer(DataInputStream dis) throws IOException {
    byte[] ba = new byte[4];
    dis.read(ba);
    _address = InetAddress.getByAddress(ba);
    _port = dis.readInt();
    _hash = new VeryLongInteger(toString());
  }
View Full Code Here

TOP

Related Classes of dijjer.util.VeryLongInteger

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.