code: def disconnect(self):
          '''
          This is called as part of the agency shutdown.
          '''
          self.log("Disconnecting broker %r.", self)
          d = defer.succeed(None)
          if self.is_master():
              if self.listener is not None:
                  d.addCallback(defer.drop_param, self.listener.stopListening)
                  d.addCallback(defer.drop_param, self.factory.disconnect)
          elif self.is_slave():
              d = defer.maybeDeferred(self.factory.disconnect)
          elif self._cmp_state(BrokerRole.disconnected):
              return defer.succeed(None)
          d.addCallback(defer.drop_param, self.become_disconnected)
          return f disconnect(self):
          '''
          This is called as part of the agency shutdown.
          '''
          self.log("Disconnecting broker %r.", self)
          d = defer.succeed(None)
          if self.is_master():
              if self.listener is not None:
                  d.addCallback(defer.drop_param, self.listener.stopListening)
                  d.addCallback(defer.drop_param, self.factory.disconnect)
          elif self.is_slave():
              d = defer.maybeDeferred(self.factory.disconnect)
          elif self._cmp_state(BrokerRole.disconnected):
              return defer.succeed(None)
          d.addCallback(defer.drop_param, self.become_disconnected)
          return d
docs: This is called as part of the agency shutdown.