Shut down adapter through code


We have SOAP adapters for several legacy applications. If one of these applications is down, messages start erroring out. I am trying to figure out how I can shut down an Adapter through code so that the messages start queueing instead of erroring. Any ideas how this can be done?

Thanks in advance for your help.