Example #1
0
 public synchronized void ReviseItemsInReflectionWindow(
     TReflectionWindowStruc RW, byte[] ExistingItemsBA, TCanceller Canceller)
     throws IOException, CancelException {
   TSpaceHint LastItem = null;
   TSpaceHint Item = Items;
   while (Item != null) {
     boolean flRemove = false;
     if (RW.Container_IsNodeVisible(Item.BindingPointX, Item.BindingPointY)) {
       flRemove = true;
       int Idx = 0;
       int _ItemsCount = TDataConverter.ConvertLEByteArrayToInt32(ExistingItemsBA, Idx);
       Idx += 4;
       for (int I = 0; I < _ItemsCount; I++) {
         int ItemID = TDataConverter.ConvertLEByteArrayToInt32(ExistingItemsBA, Idx);
         Idx += 8; // . Int64
         if (ItemID == Item.ID) {
           flRemove = false;
           break; // . >
         }
         Idx = Item.ByteArraySkip(ExistingItemsBA, Idx);
       }
     }
     if (flRemove) {
       if (LastItem != null) LastItem.Next = Item.Next;
       else Items = Item.Next;
       ItemsTable.remove(Item.ID);
       ItemsCount--;
     } else LastItem = Item;
     // .
     if (Canceller != null) Canceller.Check();
     // .
     Item = Item.Next;
   }
 }
Example #2
0
 public synchronized void FromByteArray(byte[] BA, TCanceller Canceller)
     throws IOException, CancelException {
   RemoveOldItems();
   // .
   int Idx = 0;
   int _ItemsCount = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 4;
   for (int I = 0; I < _ItemsCount; I++) {
     int ItemID = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
     Idx += 8; // . Int64
     TSpaceHint Item = ItemsTable.get(ItemID);
     if (Item == null) {
       Item = new TSpaceHint(ItemID, Reflector.metrics);
       // .
       Item.Next = Items;
       Items = Item;
       ItemsCount++;
       // .
       ItemsTable.put(ItemID, Item);
     }
     Idx = Item.FromByteArray(BA, Idx);
     // .
     if (Canceller != null) Canceller.Check();
   }
 }
Example #3
0
 public synchronized void LoadItems() throws IOException {
   Items = null;
   ItemsCount = 0;
   TSpaceHint LastItem = null;
   // .
   File F = new File(HintsFileName);
   if (F.exists()) {
     FileInputStream FIS = new FileInputStream(HintsFileName);
     try {
       byte[] ItemsCountBA = new byte[4];
       FIS.read(ItemsCountBA);
       int _ItemsCount = TDataConverter.ConvertLEByteArrayToInt32(ItemsCountBA, 0);
       // .
       byte[] ItemData = new byte[1024]; // . max item data size
       for (int I = 0; I < _ItemsCount; I++) {
         byte[] ItemDataSizeBA = new byte[2];
         FIS.read(ItemDataSizeBA);
         short ItemDataSize = TDataConverter.ConvertLEByteArrayToInt16(ItemDataSizeBA, 0);
         FIS.read(ItemData, 0, ItemDataSize);
         // .
         int Idx = 0;
         int ItemID = TDataConverter.ConvertLEByteArrayToInt32(ItemData, Idx);
         Idx += 8; // . Int64
         TSpaceHint NewItem = new TSpaceHint(ItemID, Reflector.metrics);
         NewItem.FromByteArray(ItemData, Idx);
         if (ItemsTable.get(ItemID) == null) {
           // . insert into queue
           if (LastItem != null) LastItem.Next = NewItem;
           else Items = NewItem;
           ItemsTable.put(ItemID, NewItem);
           ItemsCount++;
           // .
           LastItem = NewItem;
         }
       }
     } finally {
       FIS.close();
     }
   }
 }
Example #4
0
 private synchronized void RemoveOldItems() {
   if (ItemsCount < (1.1 * MaxItemsCount)) return; // . ->
   TSpaceHint RemoveItem = null;
   ItemsCount = 0;
   TSpaceHint Item = Items;
   while (Item != null) {
     ItemsCount++;
     if (ItemsCount >= MaxItemsCount) {
       RemoveItem = Item.Next;
       Item.Next = null;
       // .
       break; // . >
     }
     // .
     Item = Item.Next;
   }
   while (RemoveItem != null) {
     ItemsTable.remove(RemoveItem.ID);
     // .
     RemoveItem = RemoveItem.Next;
   }
 }