try { sc.invoke(shutdownLoggerObjectName, "stop", new Object[0], new String[0]); sc.invoke(shutdownLoggerObjectName, "destroy", new Object[0], new String[0]); sc.unregisterService(shutdownLoggerObjectName); } catch (Exception ignore) {     }
   public void stopServerPeer() throws Exception   {      try      {         // if we don't find a ServerPeer instance registered under the serverPeerObjectName         // ObjectName, we assume that the server was already stopped and we silently exit         if (sc.query(serverPeerObjectName).isEmpty())         {            log.warn("ServerPeer already stopped");            return;         }            // unbind the JCA ConnectionFactory; nothing happens if no connection factory is bound         sc.unbindJCAJMSConnectionFactory();         sc.unbindDefaultJMSProvider();            log.debug("stopping connection factories");            for(Iterator i = connFactoryObjectNames.iterator(); i.hasNext(); )         {            try            {               ObjectName on = (ObjectName)i.next();               sc.invoke(on, "stop", new Object[0], new String[0]);               sc.invoke(on, "destroy", new Object[0], new String[0]);               sc.unregisterService(on);            }            catch (Exception ignore)            {               //If the serverpeer failed when starting up previously, then only some of the               //services may be started. The ones that didn't start will fail when attempting to shut               //them down.               //Hence we must catch and ignore or we won't shut everything down            }         }         connFactoryObjectNames.clear();            log.debug("stopping all destinations");            Set destinations = (Set)sc.getAttribute(serverPeerObjectName, "Destinations");            for(Iterator i = destinations.iterator(); i.hasNext(); )         {            String name;            boolean isQueue = true;            Destination d = (Destination)i.next();            if (d instanceof Queue)            {               name = ((Queue)d).getQueueName();            }            else            {               isQueue = false;               name = ((Topic)d).getTopicName();            }               undeployDestination(isQueue, name);         }            log.debug("stopping JMS server");            try         {            sc.invoke(serverPeerObjectName, "stop", new Object[0], new String[0]);            sc.invoke(serverPeerObjectName, "destroy", new Object[0], new String[0]);            sc.unregisterService(serverPeerObjectName);         }         catch (Exception ignore)         {            //If the serverpeer failed when starting up previously, then only some of the            //services may be started. The ones that didn't start will fail when attempting to shut            //them down.            //Hence we must catch and ignore or we won't shut everything down         }                        log.debug("stopping ServerPeer's plug-in dependencies");                  try         {            sc.invoke(shutdownLoggerObjectName, "stop", new Object[0], new String[0]);            sc.invoke(shutdownLoggerObjectName, "destroy", new Object[0], new String[0]);            sc.unregisterService(shutdownLoggerObjectName);         }         catch (Exception ignore)         {            //If the serverpeer failed when starting up previously, then only some of the            //services may be started. The ones that didn't start will fail when attempting to shut            //them down.            //Hence we must catch and ignore or we won't shut everything down         }                  try         {            sc.invoke(jmsUserManagerObjectName, "stop", new Object[0], new String[0]);            sc.invoke(jmsUserManagerObjectName, "destroy", new Object[0], new String[0]);            sc.unregisterService(jmsUserManagerObjectName);         }         catch (Exception ignore)         {            //If the serverpeer failed when starting up previously, then only some of the            //services may be started. The ones that didn't start will fail when attempting to shut            //them down.            //Hence we must catch and ignore or we won't shut everything down         }            try         {            sc.invoke(queuePostOfficeObjectName, "stop", new Object[0], new String[0]);            sc.invoke(queuePostOfficeObjectName, "destroy", new Object[0], new String[0]);            sc.unregisterService(queuePostOfficeObjectName);         }         catch (Exception ignore)         {            //If the serverpeer failed when starting up previously, then only some of the            //services may be started. The ones that didn't start will fail when attempting to shut            //them down.            //Hence we must catch and ignore or we won't shut everything down         }                  try         {            sc.invoke(topicPostOfficeObjectName, "stop", new Object[0], new String[0]);            sc.invoke(topicPostOfficeObjectName, "destroy", new Object[0], new String[0]);            sc.unregisterService(topicPostOfficeObjectName);         }         catch (Exception ignore)         {            //If the serverpeer failed when starting up previously, then only some of the            //services may be started. The ones that didn't start will fail when attempting to shut            //them down.            //Hence we must catch and ignore or we won't shut everything down         }            try         {            sc.invoke(persistenceManagerObjectName, "stop", new Object[0], new String[0]);            sc.invoke(persistenceManagerObjectName, "destroy", new Object[0], new String[0]);            sc.unregisterService(persistenceManagerObjectName);         }         catch (Exception ignore)         {            //If the serverpeer failed when starting up previously, then only some of the            //services may be started. The ones that didn't start will fail when attempting to shut            //them down.            //Hence we must catch and ignore or we won't shut everything down         }      }      catch (Exception e)      {         log.error("Failed to stop server peer", e);         throw e;      }   }