'Put a bunch of objects into the mq. The objects will be distributed
to different mq nodes according to the instance of
:class:`~cola.core.mq.distributor.Distributor`.
There also exists a cache which will not flush out unless the parameter flush
is true or a single destination cache is full.
:param objects: objects to put into mq, an object is mostly the instance of
:class:`~cola.core.unit.Url` or :class:`~cola.core.unit.Bundle`
:param flush: flush out the cache all if set to true'

def put(self, objects, flush=False):

    self.init()
    (addrs_objs, backup_addrs_objs) = self.distributor.distribute(objects)
    if (flush is True):
        for addr in self.addrs:
            if (addr not in addrs_objs):
                addrs_objs[addr] = []
            if (addr not in backup_addrs_objs):
                backup_addrs_objs[addr] = {}
    for (addr, objs) in addrs_objs.iteritems():
        self.caches[addr].extend(objs)
        if ((not self.caches_inited[addr]) or (len(self.caches[addr]) >= CACHE_SIZE) or flush):
            try:
                self._remote_or_local_batch_put(addr, self.caches[addr])
            except socket.error as e:
                if self.logger:
                    self.logger.exception(e)
            else:
                self.caches[addr] = []
        if (not self.caches_inited[addr]):
            self.caches_inited[addr] = True
    for (addr, m) in backup_addrs_objs.iteritems():
        for (backup_addr, objs) in m.iteritems():
            self.backup_caches[addr][backup_addr].extend(objs)
        size = sum([len(obs) for obs in self.backup_caches[addr].values()])
        if ((size >= CACHE_SIZE) or flush):
            for (backup_addr, objs) in self.backup_caches[addr].iteritems():
                try:
                    self._remote_or_local_put_backup(addr, backup_addr, objs)
                except socket.error as e:
                    if self.logger:
                        self.logger.exception(e)
                else:
                    self.backup_caches[addr][backup_addr] = []
