container/services/src/main/java/org/mobicents/slee/container/management/ServiceManagementImpl.java
public void uninstallService(final ServiceComponent serviceComponent)
			throws SystemException, UnrecognizedServiceException,
			InstanceNotFoundException, MBeanRegistrationException,
			NullPointerException, UnrecognizedResourceAdaptorEntityException,
			ManagementException, InvalidStateException {

		if (logger.isDebugEnabled()) {
			logger.debug("Uninstalling service with id "
					+ serviceComponent.getServiceID());
		}

		if (serviceComponent.getServiceState().isStopping()) {
			// let's be friendly and give it a few secs
			for (int i = 0; i < 15; i++) {
				try {
					Thread.sleep(1000);
					logger.info("Waiting for "
							+ serviceComponent.getServiceID()
							+ " to stop, current state is "
							+ serviceComponent.getServiceState());
					if (serviceComponent.getServiceState().isInactive()) {
						break;
					}
				} catch (Throwable e) {
					logger.error(e.getMessage(), e);
				}
			}
		}
		if (!serviceComponent.getServiceState().isInactive()) {
			throw new InvalidStateException(serviceComponent.toString()
					+ " is not inactive");
		}

		final TransactionContext txContext = sleeContainer
				.getTransactionManager().getTransactionContext();

		if (logger.isDebugEnabled()) {
			logger.debug("Closing Usage MBean of service "
					+ serviceComponent.getServiceID());
		}

		ServiceUsageMBean serviceUsageMBean = serviceComponent.getServiceUsageMBean();
		if (serviceUsageMBean != null) {
			serviceUsageMBean.remove();
			// add rollback action to re-create the mbean
			// FIXME this doesn't make sense, this restore looses all old data,
			// it shoudl only remove on
			// commit but as it is right now, the needed sbb components are
			// already removed
			TransactionalAction action = new TransactionalAction() {
				public void execute() {
					try {
						sleeContainer.getUsageParametersManagement()
								.newServiceUsageMBean(serviceComponent);
					} catch (Throwable e) {
						logger.error(e.getMessage(), e);
					}
				}
			};
			txContext.getAfterRollbackActions().add(action);
		}

		// register notification sources for all sbbs
		final TraceManagement traceMBeanImpl = sleeContainer
				.getTraceManagement();
		for (final SbbID sbbID : serviceComponent
				.getSbbIDs(componentRepositoryImpl)) {

			// Tracer must be available for both 1.1 and 1.0 sbb components
			// SbbComponent sbbComponent =
			// componentRepositoryImpl.getComponentByID(sbbID);
			// if(sbbComponent.isSlee11())
			{
				traceMBeanImpl
						.deregisterNotificationSource(new SbbNotification(
								serviceComponent.getServiceID(), sbbID));

				// add rollback action to re-add state removed
				TransactionalAction action = new TransactionalAction() {
					public void execute() {
						// remove notification sources for all sbbs
						traceMBeanImpl
								.registerNotificationSource(new SbbNotification(
										serviceComponent.getServiceID(), sbbID));
					}

				};
				txContext.getAfterRollbackActions().add(action);
			}
		}

		// warn sbb management that the service is being uninstalled, giving it
		// the option to clear any related resources
		sleeContainer.getSbbManagement().serviceUninstall(serviceComponent);

	}
public void uninstallService(final ServiceComponent serviceComponent)
			throws SystemException, UnrecognizedServiceException,
			InstanceNotFoundException, MBeanRegistrationException,
			NullPointerException, UnrecognizedResourceAdaptorEntityException,
			ManagementException, InvalidStateException {

		if (logger.isDebugEnabled()) {
			logger.debug("Uninstalling service with id "
					+ serviceComponent.getServiceID());
		}

		if (serviceComponent.getServiceState().isStopping()) {
			// let's be friendly and give it a few secs
			for (int i = 0; i < 15; i++) {
				try {
					Thread.sleep(1000);
					logger.info("Waiting for "
							+ serviceComponent.getServiceID()
							+ " to stop, current state is "
							+ serviceComponent.getServiceState());
					if (serviceComponent.getServiceState().isInactive()) {
						break;
					}
				} catch (Throwable e) {
					logger.error(e.getMessage(), e);
				}
			}
		}
		if (!serviceComponent.getServiceState().isInactive()) {
			throw new InvalidStateException(serviceComponent.toString()
					+ " is not inactive");
		}

		final TransactionContext txContext = sleeContainer
				.getTransactionManager().getTransactionContext();

		if (logger.isDebugEnabled()) {
			logger.debug("Closing Usage MBean of service "
					+ serviceComponent.getServiceID());
		}

		ServiceUsageMBean serviceUsageMBean = serviceComponent.getServiceUsageMBean();
		if (serviceUsageMBean != null) {
			serviceUsageMBean.remove();
			// add rollback action to re-create the mbean
			// FIXME this doesn't make sense, this restore looses all old data,
			// it shoudl only remove on
			// commit but as it is right now, the needed sbb components are
			// already removed
			TransactionalAction action = new TransactionalAction() {
				public void execute() {
					try {
						sleeContainer.getUsageParametersManagement()
								.newServiceUsageMBean(serviceComponent);
					} catch (Throwable e) {
						logger.error(e.getMessage(), e);
					}
				}
			};
			txContext.getAfterRollbackActions().add(action);
		}

		// register notification sources for all sbbs
		final TraceManagement traceMBeanImpl = sleeContainer
				.getTraceManagement();
		for (final SbbID sbbID : serviceComponent
				.getSbbIDs(componentRepositoryImpl)) {

			// Tracer must be available for both 1.1 and 1.0 sbb components
			// SbbComponent sbbComponent =
			// componentRepositoryImpl.getComponentByID(sbbID);
			// if(sbbComponent.isSlee11())
			{
				traceMBeanImpl
						.deregisterNotificationSource(new SbbNotification(
								serviceComponent.getServiceID(), sbbID));

				// add rollback action to re-add state removed
				TransactionalAction action = new TransactionalAction() {
					public void execute() {
						// remove notification sources for all sbbs
						traceMBeanImpl
								.registerNotificationSource(new SbbNotification(
										serviceComponent.getServiceID(), sbbID));
					}

				};
				txContext.getAfterRollbackActions().add(action);
			}
		}

		// warn sbb management that the service is being uninstalled, giving it
		// the option to clear any related resources
		sleeContainer.getSbbManagement().serviceUninstall(serviceComponent);

	}
uninstall a service.

@throws SystemException
@throws UnrecognizedServiceException
@throws MBeanRegistrationException
@throws InstanceNotFoundException
@throws UnrecognizedResourceAdaptorEntityException
@throws NullPointerException
@throws InvalidStateException