Package org.xmlBlaster.engine.msgstore

Examples of org.xmlBlaster.engine.msgstore.I_MapEntry


            assertEquals("", 3, i_map.getNumOfEntries());
            assertEquals("", 2, i_map.getNumOfPersistentEntries());

            for (int ii=0; ii<10; ii++) {
               I_MapEntry result = i_map.get(queueEntries[0].getUniqueId());
               assertTrue("Missing entry", result != null);
               assertEquals(ME+": Wrong result", queueEntries[0].getUniqueId(), result.getUniqueId());

               result = i_map.get(queueEntries[1].getUniqueId());
               assertTrue("Missing entry", result != null);
               assertEquals(ME+": Wrong result", queueEntries[1].getUniqueId(), result.getUniqueId());

               result = i_map.get(queueEntries[2].getUniqueId());
               assertTrue("Missing entry", result != null);
               assertEquals(ME+": Wrong result", queueEntries[2].getUniqueId(), result.getUniqueId());
            }
            assertEquals("", 3, i_map.getNumOfEntries());
            assertEquals("", 2, i_map.getNumOfPersistentEntries());

            log.info("storage before remove [0], bytes sum=" + i_map.getNumOfBytes() + " with persistent bytes=" + i_map.getNumOfPersistentBytes());
            i_map.remove(queueEntries[0]); // Remove one
            log.info("storage after remove [0], bytes sum=" + i_map.getNumOfBytes() + " with persistent bytes=" + i_map.getNumOfPersistentBytes());
            ArrayList list = new ArrayList();
            list.add(queueEntries[1]);
            list.add(queueEntries[2]);
            this.checkSizeAndEntries(" getMsg() ", list, i_map);

            for (int ii=0; ii<10; ii++) {
               I_MapEntry result = i_map.get(queueEntries[1].getUniqueId());
               assertTrue("Missing entry", result != null);
               assertEquals(ME+": Wrong result", queueEntries[1].getUniqueId(), result.getUniqueId());
            }
            i_map.remove(queueEntries[1].getUniqueId()); // Remove one
            assertEquals("", 1, i_map.getNumOfEntries());
            assertEquals("", 1, i_map.getNumOfPersistentEntries());

            for (int ii=0; ii<10; ii++) {
               I_MapEntry result = i_map.get(queueEntries[2].getUniqueId());
               assertTrue("Missing entry", result != null);
               assertEquals(ME+": Wrong result", queueEntries[2].getUniqueId(), result.getUniqueId());
            }
            i_map.remove(queueEntries[2]); // Remove one
            for (int ii=0; ii<10; ii++) {
               I_MapEntry result = i_map.get(queueEntries[0].getUniqueId());
               assertTrue("Unexpected entry", result == null);
            }
            assertEquals("", 0, i_map.getNumOfEntries());
            assertEquals("", 0, i_map.getNumOfPersistentEntries());
            log.info("#1 Success, get()");
View Full Code Here


      long sizeOfTransients = 0L;
      long numOfPersistents = 0;
      long numOfTransients = 0;
      long sizeOfPersistents = 0L;
      for (int i=0; i < queueEntries.length; i++) {
         I_MapEntry entry = queueEntries[i];
         if (entry.isPersistent()) {
            sizeOfPersistents += entry.getSizeInBytes();
            numOfPersistents++;
         }
         else {
            sizeOfTransients += entry.getSizeInBytes();
            numOfTransients++;
         }
      }

      long queueNumOfPersistents = i_map.getNumOfPersistentEntries();
View Full Code Here

    * @see I_Map#change(I_MapEntry, I_ChangeCallback)
    */
   public I_MapEntry change(I_MapEntry entry, I_ChangeCallback callback) throws XmlBlasterException {
      synchronized(this) { // is this the correct synchronization ??
         entry.getSizeInBytes(); // must be here since newEntry could reference same obj.
         I_MapEntry newEntry = entry;
         if (callback != null) newEntry = callback.changeEntry(entry);
         if (newEntry == null) return entry;
         if (newEntry.isPersistent() != entry.isPersistent()) {
            throw new XmlBlasterException(this.glob, ErrorCode.INTERNAL_UNKNOWN, ME + ".change",
                  "changing  oldEntry.isPersistent=" + entry.isPersistent() + " to newEntry.isPersistent=" + newEntry.isPersistent() + "differs. This is not allowed");
         }

         long diffSize = this.manager.modifyEntry(getStorageId().getStrippedId(), newEntry, entry);
         this.numOfBytes += diffSize;
         if (entry.isPersistent())
View Full Code Here

   /**
    * @see I_Map#change(long, I_ChangeCallback)
    */
   public I_MapEntry change(long uniqueId, I_ChangeCallback callback) throws XmlBlasterException {
      synchronized (this) {
         I_MapEntry oldEntry = get(uniqueId);
         return change(oldEntry, callback);
      }
   }
View Full Code Here

    * @see I_Map#get(long)
    */
   public I_MapEntry get(final long uniqueId) throws XmlBlasterException {
      if (log.isLoggable(Level.FINER)) log.finer("Entering get(" + uniqueId + ")");

      I_MapEntry mapEntry = null;
      synchronized(this) {
         mapEntry = this.transientStore.get(uniqueId);
         if (mapEntry != null) {
            mapEntry.isSwapped(false);
            return mapEntry;
         }

         if (this.persistentStore == null)
            return null;

         mapEntry = this.persistentStore.get(uniqueId);
         if (mapEntry == null) {
            return null;
         }

         // Ok, we need to swap transient entry back from persistence store
         if (!mapEntry.isPersistent()) {
            this.persistentStore.remove(mapEntry);
         }

         assureTransientSpace(mapEntry);
        
         this.transientStore.put(mapEntry);
         mapEntry.isSwapped(false);
      } // synchronized(this)
      return mapEntry;
   }
View Full Code Here

    */
   public int remove(final long uniqueId) throws XmlBlasterException {
      if (log.isLoggable(Level.FINER)) log.finer("remove(" + uniqueId + ")");
      int ret = 0;
      synchronized (this) {
         I_MapEntry mapEntry = get(uniqueId);
         if (mapEntry != null)
            ret = removeNoNotify(mapEntry);
      }
      this.storageSizeListenerHelper.invokeStorageSizeListener();
      return ret;
View Full Code Here

    */
   public I_MapEntry change(I_MapEntry oldEntry, I_ChangeCallback callback) throws XmlBlasterException {
      if (oldEntry == null) return null;
      synchronized(this) { // is this the correct synchronization ??
         oldEntry.getSizeInBytes(); // must be here since newEntry could reference same obj.
         I_MapEntry newEntry = oldEntry;
         boolean oldIsPersistent = oldEntry.isPersistent();
         if (callback != null) newEntry = callback.changeEntry(oldEntry);
         if (newEntry == null) return oldEntry;

         final I_MapEntry newEntryFinal = newEntry;
         I_MapEntry retEntry = this.transientStore.change(oldEntry, new I_ChangeCallback() {
            public final I_MapEntry changeEntry(I_MapEntry entry)
                  throws XmlBlasterException {
               return newEntryFinal;
            }
         });
        
         if (oldIsPersistent != retEntry.isPersistent()) {
            throw new XmlBlasterException(glob, ErrorCode.INTERNAL_NOTIMPLEMENTED, ME, "Changing of persistence flag of '" + oldEntry.getLogId() + "' to persistent=" + retEntry.isPersistent() + " is not implemented");
            // TODO: In case we changed the entry flag from persistent to transient it should be removed from the persistence.
         }
        
         if (newEntry.isPersistent()) {
            if (this.persistentStore != null && this.isConnected) {
View Full Code Here

   /**
    * @see I_Map#change(long, I_ChangeCallback)
    */
   public I_MapEntry change(long uniqueId, I_ChangeCallback callback) throws XmlBlasterException {
      synchronized (this) {
         I_MapEntry oldEntry = get(uniqueId);
         return change(oldEntry, callback);
      }
   }
View Full Code Here

    */
   public I_MapEntry get(final long uniqueId) throws XmlBlasterException {
      final String key = ""+uniqueId;
      if (log.isLoggable(Level.FINER)) log.finer("get(" + key + ")");
      synchronized (this.storage) {
         I_MapEntry entry = (I_MapEntry)this.storage.get(key);
         touch(entry);
         return entry;
      }
   }
View Full Code Here

      if (entryFilter == null)
         return entries;
         
      ArrayList list = new ArrayList();
      for (int i=0; i<entries.length; i++) {
         I_MapEntry entry = (I_MapEntry)entryFilter.intercept(entries[i], this);
         if (entry != null)
                list.add(entry);
      }
      return (I_MapEntry[])list.toArray(new I_MapEntry[list.size()]);
   }
View Full Code Here

TOP

Related Classes of org.xmlBlaster.engine.msgstore.I_MapEntry

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.