This deletes the notification when all messages have been processed.
330195
def DeleteNotifications(self, session_ids, start=None, end=None):
    """"""
    if not session_ids:
      return

    for session_id in session_ids:
      if not isinstance(session_id, rdfvalue.SessionID):
        raise RuntimeError(
            "Can only delete notifications for rdfvalue.SessionIDs.")

    if start is None:
      start = 0
    else:
      start = int(start)

    if end is None:
      end = self.frozen_timestamp or rdfvalue.RDFDatetime.Now()

    for queue, ids in iteritems(
        collection.Group(session_ids, lambda session_id: session_id.Queue())):
      queue_shards = self.GetAllNotificationShards(queue)
      self.data_store.DeleteNotifications(queue_shards, ids, start, end)
1137640
public void removeMessageFromCache(long messageId) {
        WeakReference<Message> messageRef = messages.remove(messageId);
        if (messageRef != null) {
            messageIdByRef.remove(messageRef, messageId);
        }
    }
1196368
protected void cleanup() {

        final String methodName = "cleanup";
        if (TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, methodName);
        }

        if (_unsuccessfulMessages.size() > 0) {

            try {

                // 250710: Fix to workaround the problem where failed messages are
                // unlocked but the retry count is not incremented. Perform a
                // delete on the messages under a transaction and then roll back
                // the transaction - this will cause the messages to be unlocked
                // and have their retry count incremented. If the an exception
                // is thrown during this processing the messages will remain locked.
                try
				{
                	SIUncoordinatedTransaction localTran = _connection.createUncoordinatedTransaction();
                	deleteMessages(getMessageHandles(_unsuccessfulMessages), localTran);
                	localTran.rollback();
				}
                catch (SIException ex)
				{
                    FFDCFilter.processException(ex, CLASS_NAME + "."
                            + methodName, FFDC_PROBE_2, this);
                    if (TRACE.isEventEnabled()) {
                        SibTr.exception(this, TRACE, ex);
                    }
				}
//                unlockMessages(_unsuccessfulMessages);

            } catch (final ResourceException exception) {

                FFDCFilter.processException(exception, CLASS_NAME + "."
                        + methodName, FFDC_PROBE_1, this);
                if (TRACE.isEventEnabled()) {
                    SibTr.exception(this, TRACE, exception);
                }

            } finally {

                _unsuccessfulMessages.clear();

            }

        }

        if (TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, methodName);
        }

    }
936306
@Override
	public synchronized void flush()
    {
        if (!transport.isClosed())
        {
            try
            {
                int len = notificationBuffer.size();
                for (int i = 0 ; i < len ; i++)
                {
                	NotificationPacket notifPacket = notificationBuffer.get(i);
                	notifPacket.setDonePrefetching(i == len-1);
                    transport.send(notifPacket);
                }
            }
            catch (Exception e)
            {
                log.error("Could not send notification packet",e);
                transport.close();
            }
        }
        
        notificationBuffer.clear();
    }
514749
def destroy(self):
        
        builder = self.builder
        NotificationManager.cancel_notification(builder)
        del self.builder
        super(AndroidNotification, self).destroy()
852759
public static function cancelAllNonPersistent()
    {
        foreach (static::getAllNotifications() as $id => $notification) {
            if (Notification::TYPE_PERSISTENT != $notification->type) {
                static::removeNotification($id);
            }
        }
    }
374889
function _clearMessagePopover() {
            if (self._$messagePopover && self._$messagePopover.length > 0) {
                // self._$messagePopover.remove() is done by PopUpManager
                self._$messagePopover = null;
            }
            _removeListeners();
        }
223314
def delete_messages(self, only_processed=True):
        
        messages = self._processed_messages
        if not only_processed:
            messages += self._messages

        if messages:
            try:
                self.queue.delete_tasks(messages)
            except Exception:
                logging.exception("Error deleting messages")
                raise
980351
protected void cleanup() {

        final String methodName = "cleanup";
        if (TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, methodName);
        }

        super.cleanup();

        if (_successfulMessages.size() > 0) {

            try {

                deleteMessages(getMessageHandles(_successfulMessages), null);

            } catch (final ResourceException exception) {

                FFDCFilter.processException(exception, CLASS_NAME + "."
                        + methodName, FFDC_PROBE_1, this);
                if (TRACE.isEventEnabled()) {
                    SibTr.exception(this, TRACE, exception);
                }

            } finally {

                _successfulMessages.clear();

            }

        }

        if (TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, methodName);
        }

    }
1264205
function cleanup() {
      res.removeListener('finish', sendStats);
      res.removeListener('error', cleanup);
      res.removeListener('close', cleanup);
    }
1233445
public function cleanUp()
    {
        $this->status = self::STATUS_CLEANINGUP;
        if ($this->process->isRunning()) {
            $this->sendTERMSignal();
        } else {
            $this->status = self::STATUS_CLEANEDUP;
        }

    }
1081504
def delete(self, event):
        """"""
        assert self.receiver_id == event.receiver_id
        event.response = {'status': 410, 'message': 'Gone.'}
        event.response_code = 410
629439
public void clear() {
        @SuppressWarnings("unchecked") SparseArray<BaseNotificationItem> cloneArray =
                (SparseArray<BaseNotificationItem>) notificationArray.clone();
        notificationArray.clear();

        for (int i = 0; i < cloneArray.size(); i++) {
            final BaseNotificationItem n = cloneArray.get(cloneArray.keyAt(i));
            n.cancel();
        }

    }
444303
def NotificationsDelete(self, notification_id):
        
        if self.__SenseApiCall__('/notifications/{0}.json'.format(notification_id), 'DELETE'):
            return True
        else:
            self.__error__ = "api call unsuccessful"
            return False
1246835
private void cleanUpHistory() {
    long oldestAllowedTimestamp = System.currentTimeMillis() - historyLength;
    int trashedNotifications = 0;
    
    if (LOG.isDebugEnabled()) {
      LOG.debug("History cleanup: Checking old notifications to remove from history list ...");
    }
    
    HistoryTreeEntry key = new HistoryTreeEntry(oldestAllowedTimestamp, 0, (byte)0);
    int notificationsCount = 0;
    historyLock.writeLock().lock();
    try {
      notificationsCount = orderedHistoryList.size();
      LOG.warn("History cleanup: size of the history before cleanup: " + notificationsCount);

      if (!historyLimitDisabled && notificationsCount > historyLimit) {
        LOG.warn("History cleanup: Reached physical limit. Number of stored notifications: " + 
            notificationsCount + ". Clearing ...");
      }
      
      int index = Collections.binarySearch(orderedHistoryList, key, comparatorByTS);
      int toDeleteByTS = index >= 0 ? index : - (index + 1);
      int toDeleteByLimit = historyLimitDisabled ? 0 : notificationsCount - (int)historyLimit;
      toDeleteByLimit = toDeleteByLimit > 0 ? toDeleteByLimit : 0;
      
      int toDelete = Math.max(toDeleteByTS, toDeleteByLimit);
      
      // Delete items which are too old
      if (toDelete > 0) {
        LOG.warn("History cleanup: number of the history to cleanup: " + toDelete);
        for (int i = 0; i < toDelete; i++) {
          orderedHistoryList.get(i).removeFromTree();
        }
        
        orderedHistoryList.subList(0, toDelete).clear();
        
        if (toDeleteByLimit > toDeleteByTS) {
          // If we delete a notification because we don't have space left
          trashedNotifications ++;
        }
        notificationsCount = orderedHistoryList.size();
        LOG.warn("History cleanup: size of the history after cleanup: " + notificationsCount);
        
        // clean up history tree, remove the node that has no children and
        // no notifications associated with them.
        cleanUpHistoryTree(historyTree);
      }
      
    } finally {
      historyLock.writeLock().unlock();
    }
    
    core.getMetrics().trashedHistoryNotifications.inc(trashedNotifications);
    core.getMetrics().historySize.set(notificationsCount);
    core.getMetrics().historyQueues.set(historyQueuesCount);
  }
804742
@Override
  @SuppressWarnings("unchecked")
  public void clear() {
    message =
        (MType) (message != null ? message.getDefaultInstanceForType() : builder
            .getDefaultInstanceForType());
    if (builder != null) {
      dispose(builder);
      builder = null;
    }
    onChanged();
  }
1084790
@Override
    public void removeNotificationHandler(String serviceName, NotificationHandler handler) throws ServiceException {

        ServiceInstanceUtils.validateManagerIsStarted(isStarted.get());
        ServiceInstanceUtils.validateServiceName(serviceName);
        if (handler == null) {
            throw new ServiceException(ErrorCode.SERVICE_DIRECTORY_NULL_ARGUMENT_ERROR,
                    ErrorCode.SERVICE_DIRECTORY_NULL_ARGUMENT_ERROR.getMessageTemplate(),
                    "NotificationHandler");
        }
        
        getLookupService().removeNotificationHandler(serviceName, handler);
    }