Exemplo n.º 1
0
class NMSQueue(Queue):
    """Create a queue object with a given maximum size.

    """
    # Override these methods to implement other queue organizations
    # (e.g. stack or priority queue).
    # These will only be called with appropriate locks held

    # Initialize the queue representation
    def _init(self, maxsize):
        """ internal constructor """
        self.queue = TokyoCabinetQueue()
        #self.queue = SQLQueue()

    def _qsize(self, len=len):
        """ return queue size """
        return self.queue.size()

    # Put a new item in the queue
    def _put(self, item):
        
        t = type(item)
        
        if t.__name__=='instance':
            if item.__class__.__name__== 'NMSQueueItem':
                item.set_uuid()
        
                self.queue.put( item.dictify() )
        else:
            raise Exception("This queue only accepts NMSQueueItem. Found a %s" % (t)) 

    # Get an item from the queue
    def _get(self):
        the_dict = self.queue.pop()
        return NMSQueueItem.create_from_dict(the_dict)
    
    #operating, visitor interface
    def get_item(self, uuid):
        """ Return an item that has the following id """
        the_dict = self.queue.get_from_uuid(uuid)
        return NMSQueueItem.create_from_dict(the_dict) if the_dict else None
    
    def delete_item(self,uuid):
        """ delete an item from the queue """
        self.queue.delete_from_uuid(uuid)
    
    def get_items_with_priority(self, a_beg_priority, a_end_priority, a_beg_offset, a_end_offset):
        """ Return items with priority """
        
        db_cursor = self.queue.get_from_priority_range(a_beg_priority, a_end_priority, a_beg_offset, a_end_offset)
        return NMSQueueItemSet(db_cursor)
    
    def change_item_status(self,a_uuid, a_status):
        """ Change item status """
        self.queue.change_status(a_uuid,a_status)   
Exemplo n.º 2
0
 def ztest_tokyo_queue(self):
     """ test for the internal tokyo cabinet queue """
     
     sql_queue = TokyoCabinetQueue()
     
     print("Queue size = %d\n" %(sql_queue.size()) )
                  
     #insertion
     for i in range(10):
         if i % 2 == 0:
             p = 0
         else:
             p = 1
         item = NMSQueueItem(p,"data %s" % (i))
         item.set_uuid()
         sql_queue.put(item.dictify())
         #time.sleep(0.5)
     
     size = sql_queue.size()
         
     while size != 0:
         the_dict = sql_queue.pop()
         item = NMSQueueItem.create_from_dict(the_dict)
         print("size = %d, item = %s\n" % (size, item))
         size = sql_queue.size()
     
     print("size = %s" % size )
     
     
     
     
     
         
         
Exemplo n.º 3
0
 def _init(self, maxsize):
     """ internal constructor """
     self.queue = TokyoCabinetQueue()