/*
(non-Javadoc)

@see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.
ServletContextEvent)
483190
public final void contextDestroyed(final ServletContextEvent sce) {
		// Stop the TciIpServer
		if (this.tcpIpServer != null) {
			this.tcpIpServer.stop();
		}

		// Stop the JmxServer
		if (this.jmxServer != null) {
			this.jmxServer.stop();
		}

		// Stop the SshServer
		if (this.sshServer != null) {
			try {
				this.sshServer.stop();
			} catch (InterruptedException e) {
				LaunchingMessageKind.ESSH0002.format(e);
			}
		}
	}
23795
@Override
    public void contextDestroyed(ServletContextEvent arg0) {
        if (endpointManager != null) {
            if (!FrameworkState.isStopping()) {
                endpointManager.closeAllOpenSessions();
                endpointManager.clear();
            }
            else {
                if (tc.isDebugEnabled()) {
                    Tr.debug(tc, "Server is being shutdown, no need to stop stop clients");
                }
            }
        }

    }
363041
@Override
    public final void contextDestroyed(final ServletContextEvent sce) {

        Collection<AbstractMockEc2Instance> instances = MockEc2Controller.getInstance()
                    .getAllMockEc2Instances();

        for (AbstractMockEc2Instance instance : instances) {
                // cancel and destroy the internal timers for all instances on
                // web app stopping
            instance.destroyInternalTimer();
        }

        if (persistenceEnabled) {

            // put all instances into an array which is serializable and type-cast safe for persistence
            AbstractMockEc2Instance[] array = new AbstractMockEc2Instance[instances.size()];
            instances.toArray(array);
            PersistenceUtils.saveAll(array, PersistenceStoreType.EC2);


            Collection<MockVpc> vpcs = MockVpcController.getInstance()
                    .describeVpcs();
            MockVpc[] vpcArray = new MockVpc[vpcs.size()];
            vpcs.toArray(vpcArray);
            PersistenceUtils.saveAll(vpcArray, PersistenceStoreType.VPC);

            Collection<MockVolume> volumes = MockVolumeController.getInstance()
                    .describeVolumes();
            MockVolume[] volumeArray = new MockVolume[volumes.size()];
            volumes.toArray(volumeArray);
            PersistenceUtils.saveAll(volumeArray, PersistenceStoreType.VOLUME);

            Collection<MockTags> tags = MockTagsController.getInstance().describeTags();

            MockTags[] tagArray = new MockTags[tags.size()];
            tags.toArray(tagArray);
            PersistenceUtils.saveAll(tagArray, PersistenceStoreType.TAGS);

            Collection<MockSubnet> subnets = MockSubnetController.getInstance().describeSubnets();

            MockSubnet[] subnetArray = new MockSubnet[subnets.size()];
            subnets.toArray(subnetArray);
            PersistenceUtils.saveAll(subnetArray, PersistenceStoreType.SUBNET);

            Collection<MockRouteTable> routetables = MockRouteTableController.getInstance().describeRouteTables();

            MockRouteTable[] routetableArray = new MockRouteTable[routetables.size()];
            routetables.toArray(routetableArray);
            PersistenceUtils.saveAll(routetableArray, PersistenceStoreType.ROUTETABLE);

            Collection<MockInternetGateway> internetgateways = MockInternetGatewayController.getInstance()
                    .describeInternetGateways();

            MockInternetGateway[] internetgatewayArray = new MockInternetGateway[internetgateways.size()];
            internetgateways.toArray(internetgatewayArray);
            PersistenceUtils.saveAll(internetgatewayArray, PersistenceStoreType.INTERNETGATEWAY);
        }

        MockEc2Controller.getInstance().destroyCleanupTerminatedInstanceTimer();

        log.info("aws-mock stopped.");
    }
3724
@Deactivate
    protected void deactivate(ComponentContext context) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(this, tc, "Deactivating");
        }
        instance.get().compareAndSet(this, null);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(this, tc, "Destroying all endpoints");
        }
        EndPointMgrImpl.destroyEndpoints();

        try {
            this.chfw.destroy();
        } catch (Throwable t) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(this, tc, "Error destroying framework: " + t);
            }
        }

        this.chfw.deregisterFactory("TCPChannel");
        this.chfw.deregisterFactory("UDPChannel");
    }
1264810
public static void unregisterLogListener(@NonNull final Context context, @NonNull final DfuLogListener listener) {
		if (mLogBroadcastReceiver != null) {
			final boolean empty = mLogBroadcastReceiver.removeLogListener(listener);

			if (empty) {
				LocalBroadcastManager.getInstance(context).unregisterReceiver(mLogBroadcastReceiver);
				mLogBroadcastReceiver = null;
			}
		}
	}
406477
public synchronized void destroyed(AppContextWrapper context) {
		try {
			ContainerRegistryBuilder cb = (ContainerRegistryBuilder) context
					.getAttribute(ContainerRegistryBuilder.APPLICATION_CONTEXT_ATTRIBUTE_NAME);
			if (cb != null) {
				ContainerDirector cd = new ContainerDirector(cb);
				cd.shutdown();
				context.removeAttribute(ContainerRegistryBuilder.APPLICATION_CONTEXT_ATTRIBUTE_NAME);
				containerBuilderContext = null;
				// context.removeAttribute(ContainerBuilder.APPLICATION_CONTEXT_ATTRIBUTE_NAME);
				Debug.logVerbose("[JdonFramework] stop the container ..", module);
			}
		} catch (Exception e) {
			Debug.logError("[JdonFramework] destroyed error: " + e, module);
		}

	}
192708
protected synchronized void deactivate(ComponentContext context) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Unregistering JNDIEntry " + serviceRegistration);
        }
        if (this.serviceRegistration != null) {
            this.serviceRegistration.unregister();
        }
    }
1337451
public void logout(Context context, ResponseListener listener) {
        AuthorizationRequestManager.RequestOptions options = new AuthorizationRequestManager.RequestOptions();
        options.parameters = new HashMap<String,String>(1);
        options.parameters.put("client_id", preferences.clientId.get());
        options.headers = new HashMap<>(1);
        addSessionIdHeader(options.headers);
        options.requestMethod = Request.GET;
        try {
            authorizationRequestSend(context,"logout", options, listener);
        } catch (Exception e) {
            logger.debug("Could not log out");
        }
    }
405140
public static void popContext() {
        Context context = LOCAL.get();
        if (context != null) {
            Context parent = context.getParent();
            if (parent != null) {
                LOCAL.set(parent);
            } else {
                LOCAL.remove();
            }
        }
    }
1016693
@SuppressWarnings("unused")
    @Deactivate
    protected void deactivate(ComponentContext context) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Deactivating the HTTP pipeline event handler");
        }
    }
356187
protected void deactivate(ComponentContext context) {
        final boolean trace = TraceComponent.isAnyTracingEnabled();
        if (trace && tc.isEntryEnabled())
            Tr.entry(this, tc, "deactivate", name);

        lock.writeLock().lock();
        try {
            if (pmMBean != null) {
                pmMBean.unregister();
                pmMBean = null;
            }
            pm = null;
            properties = null;
        } finally {
            lock.writeLock().unlock();
        }

        if (trace && tc.isEntryEnabled())
            Tr.exit(this, tc, "deactivate");
    }
1336234
protected void deactivate(ComponentContext context) {
		log.info("deactivate");

		bundleContext = context.getBundleContext();
		bundleContext.removeServiceListener(sl);

		log.info("Deactivate successful");
	}
993715
@Override
  public void contextInitialized(ServletContextEvent event) {
    this.event = event;
    this.serverContainer = getServerContainer(event);
    super.contextInitialized(event);
  }
1318568
protected void destroy() {
        ContextLogger.LOG.contextCleared(this);
        final BeanStore beanStore = getBeanStore();
        if (beanStore == null) {
            throw ContextLogger.LOG.noBeanStoreAvailable(this);
        }
        for (BeanIdentifier id : beanStore) {
            destroyContextualInstance(beanStore.get(id));
        }
        beanStore.clear();
    }
131017
@Override
	public synchronized void removeContext(Context context) {

        if( log.isDebugEnabled() )
            log.debug("Removing context[" + context.getPath() + "]");

        boolean isContextExists = isContextExists(context);
        if(!isContextExists)
        	return;
        
        // Remove this Context from the associated Host
        if( log.isDebugEnabled() )
            log.debug(" Removing this Context");
        context.getParent().removeChild(context);

    }
723774
private void releaseContext(String contextId) {
        if (mode == ContextLockingMode.DEACTIVATED) {
            return;
        }
        synchronized (activeWritingContexts) {
            activeWritingContexts.remove(contextId);
        }
    }
531538
@Override
    public void removedService(ServiceReference<SessionDestroyedListener> serviceReference,
            SessionDestroyedListener object) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Listener [" + serviceReference + "] has been removed.");
        }

        final SessionDestroyedListener listener = context.getService(serviceReference);
        handler.removeListener(listener);
    }