/*
(non-Javadoc)

@see com.ibm.ws.sib.processor.MPCoreConnection#deleteDurableSubscription(java.lang.String, java.lang.String, java.lang.String)
19088
@Override
    public void deleteDurableSubscription(String subscriptionName,
                                          String durableSubscriptionHome,
                                          String alternateUser)

                    throws SIConnectionUnavailableException, SIConnectionDroppedException,
                    SIResourceException, SIConnectionLostException,
                    SIErrorException,
                    SINotAuthorizedException,
                    SIIncorrectCallException,
                    SIDurableSubscriptionNotFoundException,
                    SIDestinationLockedException
    {

        //liberty code change : chetan
        //Since there is no ME-ME communication the durableSubscriptionHome is always the local ME 
        durableSubscriptionHome = _messageProcessor.getMessagingEngineName();

        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
            SibTr.entry(CoreSPIConnection.tc, "deleteDurableSubscription",
                        new Object[] { this, subscriptionName, durableSubscriptionHome, alternateUser });

        // Synchronize on the connection object, we don't want the connection closing
        // while we try to delete the subscription.
        synchronized (this)
        {
            SIBUuid8 durableHomeID =
                            checkDurableSubscriptionInformation(subscriptionName,
                                                                durableSubscriptionHome,
                                                                null,
                                                                false,
                                                                false,
                                                                true,
                                                                false);

            HashMap durableSubs = _destinationManager.getDurableSubscriptionsTable();

            // Is durableHome local?
            if (durableHomeID.equals(_messageProcessor.getMessagingEngineUuid()))
            {
                // Yes, then there should be an existing consumer dispatcher which we'll
                // invoke directly
                synchronized (durableSubs)
                {
                    //Look up the consumer dispatcher for this subId in the system durable subs list
                    ConsumerDispatcher cd =
                                    (ConsumerDispatcher) durableSubs.get(subscriptionName);

                    // Check that the durable subscription existed
                    if (cd == null)
                    {
                        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
                            SibTr.exit(CoreSPIConnection.tc, "deleteDurableSubscription");

                        throw new SIDurableSubscriptionNotFoundException(
                                        nls.getFormattedMessage(
                                                                "SUBSCRIPTION_DOESNT_EXIST_ERROR_CWSIP0072",
                                                                new Object[] { subscriptionName,
                                                                              _messageProcessor.getMessagingEngineName() },
                                                                null));
                    }

                    //Obtain the destination from the consumer dispatcher
                    DestinationHandler destination = cd.getDestination();

                    // Check that the destination is a TopicSpace
                    if (!destination.isPubSub())
                    {
                        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
                            SibTr.exit(CoreSPIConnection.tc, "deleteDurableSubscription", "SIDestinationWrongTypeException");

                        SibTr.error(tc, "INTERNAL_MESSAGING_ERROR_CWSIP0001",
                                    new Object[] {
                                                  "com.ibm.ws.sib.processor.impl.ConnectionImpl",
                                                  "1:2759:1.347.1.25" });

                        throw new SIErrorException(
                                        nls.getFormattedMessage(
                                                                "INTERNAL_MESSAGING_ERROR_CWSIP0001",
                                                                new Object[] { "ConnectionImpl",
                                                                              "1:2765:1.347.1.25" },
                                                                null));
                    }

                    // decalre variables used in security checks
                    AuthUtils sibAuthUtils = _messageProcessor.getAuthorisationUtils();
                    String topicName = null;
                    String topicSpaceName = null;
                    String theUser = null;

                    // If security is disabled then we'll bypass the check
                    if (_isBusSecure)
                    {
                        // get the consumer dispatcher state from the consumer dispatcher
                        ConsumerDispatcherState subState = cd.getConsumerDispatcherState();

                        topicName = subState.getTopic();
                        topicSpaceName = subState.getTopicSpaceName();

                        // Check that the user who is attempting to delete this durable subscription
                        // matches that set in the CD state when the subscription was created           
                        boolean isPriv = false;
                        if (alternateUser == null)
                        {
                            theUser = getResolvedUserid();
                            isPriv = isSIBServerSubject();
                        }
                        else
                        {
                            theUser = alternateUser;
                        }

                        boolean userMatch = subState.equalUser(theUser, isPriv);

                        // Throw not auth exception if the user who is trying to delete the durable
                        // subscription isn't the same user that created the subscription
                        if (!userMatch)
                        {
                            // ensure that a security audit event takes place for this authorization failure
                            sibAuthUtils.deleteDurSubAuthorizationFailed(theUser, topicName, topicSpaceName, 0L);

                            // trace the exception
                            if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
                                SibTr.exit(CoreSPIConnection.tc, "deleteDurableSubscription", "SINotAuthorizedException");

                            // throw the exception
                            throw new SINotAuthorizedException(
                                            nls.getFormattedMessage(
                                                                    "USER_NOT_AUTH_DELETE_ERROR_CWSIP0311",
                                                                    new Object[] { theUser, subscriptionName, destination.getName() },
                                                                    null));
                        }
                    }

                    //Call the deleteDurableSubscription method on the destination
                    destination.deleteDurableSubscription(subscriptionName, durableSubscriptionHome);

                    if (_isBusSecure)
                    {
                        // ensure that a security audit event takes place for this successful dur sub delete
                        sibAuthUtils.deleteDurSubAuthorizationPassed(theUser, topicName, topicSpaceName, 0L);
                    }
                }
            }
            else
            {
                // No, issue a remote request
                DurableInputHandler.deleteRemoteDurableSub(_messageProcessor,
                                                           subscriptionName,
                                                           getResolvedUserid(),
                                                           durableHomeID);
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
            SibTr.exit(CoreSPIConnection.tc, "deleteDurableSubscription");

    }
488243
public void terminateSubscription(IoSession session, String heapUri, String subscriptionId, Subscription.CloseReason reason) {
        Lock heapUpdateLock = null;
        try {
            HeapState state = heapStates.get(heapUri);
            if (state != null) {
                heapUpdateLock = state.getUpdateLock();
                heapUpdateLock.lock();
            }
            subTermLock.lock();

            if (state != null) {
                if (!state.isTerminated()) {
                    state.terminateSubscription(session, subscriptionId, reason);
                    // notify client
                    if (reason == REQUESTED_BY_PUBLISHER || reason == Subscription.CloseReason.REQUESTED_BY_PUBLISHER_ADMINISTRATOR) {
                        try {
                            nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, session, "Notifying client that publisher has terminated subscription %s", subscriptionId);
                            NioUtils.writeEventMessageToSession(session, new TerminateSubscription(state.getHeapId(), subscriptionId, reason.name()), objectIOFactory);
                        } catch (Exception e) {
                            // if we can't tell them about it then something more serious has just happened.
                            // the client will likely find out anyway since this will likely mean a dead session
                            // we'll just log some info to the log to aid any debugging. We won't change the closure reason.
                            LOGGER.info("Error occurred whilst trying to inform client of subscription termination", e);
                            nioLogger.log(NioLogger.LoggingLevel.SESSION, session, "Error occurred whilst trying to inform client of subscription termination, closing session");
                            // we'll request a closure of the session too to make sure everything gets cleaned up, although chances are it's already closed
                            session.close();
                        }
                    }

                    if (state.hasSubscriptions()) {
                        terminateSubscriptions(heapUri, reason);
                    } else if (state.getSubscriptions(session).isEmpty()) {
                        terminateSubscriptions(session, heapUri, reason);
                    }
                }
            }

            Multiset<String> heapsForSession = heapsByClient.get(session);
            if (heapsForSession != null) {
                heapsForSession.remove(heapUri);
                if (heapsForSession.isEmpty()) {
                    terminateSubscriptions(session, reason);
                }
            }
        } finally {
            subTermLock.unlock();
            if (heapUpdateLock != null) {
                heapUpdateLock.unlock();
            }
        }
    }
207922
public void delete(Offer offer, boolean removeWithSubscriptions) {
        ParameterMap<String, String> params = new ParameterMap<String, String>();
        params.add("remove_with_subscriptions", String.valueOf(removeWithSubscriptions));
        RestfulUtils.delete(OfferService.PATH, offer, params, Offer.class, super.httpClient);
    }
83619
public void delete() throws JMSException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "delete");

    //check to see if this has already been deleted.
    //If it has return with out doing anything
    if(!deleted) {
      session.deleteTemporaryDestination(getConsumerSIDestinationAddress());
      deleted = true;
      ((JmsConnectionImpl)session.getConnection()).removeTemporaryDestination(this);
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "delete");
  }
709991
public Subscription reactivateSubscription(final Subscription subscription) {
        return doPUT(Subscription.SUBSCRIPTION_RESOURCE + "/" + subscription.getUuid() + "/reactivate",
                     subscription, Subscription.class);
    }
584829
public boolean removeSubscribeListener(SubscribeListener subscribeListener) {
        boolean removed = subscribeListeners.remove(subscribeListener);
        if (removed && subscribeListeners.isEmpty()) {
            setSubscriptionMode(previousSubscriptionMode);
        }
        return removed;
    }
756954
@Override
	public TopicSubscriber createDurableSubscriber(Topic topic, String subscriptionName, String messageSelector, boolean noLocal) throws JMSException
    {
    	return createDurableSubscriber(idProvider.createID(), topic, subscriptionName, messageSelector, noLocal);
    }
251884
void setRequestedProxySubscriptionsResponded()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "setRequestedProxySubscriptionsResponded");

    synchronized (this)
    {
      iRequestSent = false;

      if (!iAlarmCancelled)
        iAlarm.cancel();

      iAlarmCancelled = true;
    }

    String meName = JsAdminUtils.getMENameByUuidForMessage(iMEUuid.toString());

    if (meName == null)
      meName = iMEUuid.toString();

    SibTr.push(iProxyHandler.getMessageProcessor().getMessagingEngine());
    SibTr.info(tc, "NEIGHBOUR_REPLY_RECIEVED_INFO_CWSIP0382",
               new Object[]{meName});
    SibTr.pop();

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "setRequestedProxySubscriptionsResponded");
  }
944334
public SubscriptionEnvelope deleteSubscription(String subId) throws ApiException {
        ApiResponse<SubscriptionEnvelope> resp = deleteSubscriptionWithHttpInfo(subId);
        return resp.getData();
    }
536280
@Override
    public String getDurableSubscriptionHome() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "getDurableSubscriptionHome");
        String dsh = jcaConnectionFactory.getDurableSubscriptionHome();
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "getDurableSubscriptionHome", dsh);
        return dsh;
    }
955934
public void deleteCurrent(SITransaction simpTran)
  throws SISessionUnavailableException, SISessionDroppedException,
         SIIncorrectCallException,
         SIErrorException
  {
    if (TraceComponent.isAnyTracingEnabled() && CoreSPILockedMessageEnumeration.tc.isEntryEnabled())
      SibTr.entry(CoreSPILockedMessageEnumeration.tc, "deleteCurrent", this);
      
    checkValidState("deleteCurrent");
    
    _localConsumerPoint.checkNotClosed();
    
    if (!_messageAvailable)
    {
      if (TraceComponent.isAnyTracingEnabled() && CoreSPILockedMessageEnumeration.tc.isEntryEnabled())
        SibTr.exit(CoreSPILockedMessageEnumeration.tc, "deleteCurrent", "Invalid current Message");
        
      throw new SIIncorrectCallException(
        nls.getFormattedMessage("INVALID_MESSAGE_ERROR_CWSIP0191", 
          new Object[] { _localConsumerPoint.getConsumerManager().getDestination().getName(),
            _localConsumerPoint.getConsumerManager().getMessageProcessor().getMessagingEngineName() }, 
          null));
    }
    
    _singleMessage = null;
    _messageAvailable = false;
    
    if (TraceComponent.isAnyTracingEnabled() && CoreSPILockedMessageEnumeration.tc.isEntryEnabled())
      SibTr.exit(CoreSPILockedMessageEnumeration.tc, "deleteCurrent");
  }
1060558
public void unsubscribeAllDeletedResources(CmsObject cms, long deletedTo) throws CmsException {

        if (!isEnabled()) {
            throw new CmsRuntimeException(Messages.get().container(Messages.ERR_SUBSCRIPTION_MANAGER_DISABLED_0));
        }
        m_securityManager.unsubscribeAllDeletedResources(cms.getRequestContext(), getPoolName(), deletedTo);
    }
117654
private void removeOverlappingSubscriptionEvents(final LinkedList<SubscriptionEvent> events) {
        final Iterator<SubscriptionEvent> iterator = events.iterator();
        final Map<String, DefaultSubscriptionEvent> prevPerService = new HashMap<String, DefaultSubscriptionEvent>();
        while (iterator.hasNext()) {
            final DefaultSubscriptionEvent current = (DefaultSubscriptionEvent) iterator.next();
            final DefaultSubscriptionEvent prev = prevPerService.get(current.getServiceName());
            if (prev != null) {
                if (current.overlaps(prev)) {
                    iterator.remove();
                } else {
                    prevPerService.put(current.getServiceName(), current);
                }
            } else {
                prevPerService.put(current.getServiceName(), current);
            }
        }
    }
230074
public static ApruveResponse<SubscriptionCancelResponse> cancel(
			String subscriptionId) {
		return ApruveClient.getInstance().post(getCancelPath(subscriptionId),
				"", SubscriptionCancelResponse.class);
	}
746367
@Override
    public FilterMutableType removeDescription(final String value) throws IllegalArgumentException {
        // Precondition checks
        if (value == null || value.length() == 0) {
            throw new IllegalArgumentException("value must be specified");
        }

        // Get all "description" elements
        final List<Node> descriptions = this.getRootNode().get("description");
        if (descriptions != null) {
            // For each description
            for (final Node description : descriptions) {
                // If matches
                if (description.getText().equals(value)) {
                    // Remove
                    description.getParent().removeChild(description);
                    System.out.println(description);
                }
            }
        }

        // Return
        return this;
    }
570564
protected void removeGrantedRequest(
    ResourceRequestInfo req, boolean isRevoked) {
    Context c = getContext(req.getType());
    Utilities.removeReference(c.grantedRequests, req);

    // if revoked - we didn't fulfill this request
    if (isRevoked) {
      c.fulfilledRequestCount--;
      c.revokedRequestCount++;
    }
  }
921710
public ProjectSubscriptionName deleteSubscription(String subscriptionId) throws Exception {
    // [START pubsub_delete_subscription]
    try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
      ProjectSubscriptionName subscriptionName =
          ProjectSubscriptionName.of(projectId, subscriptionId);
      subscriptionAdminClient.deleteSubscription(subscriptionName);
      return subscriptionName;
    }
    // [END pubsub_delete_subscription]
  }