protected void unsubscribeAll(BrokerState brokerState) throws ClientException { if (!clientConfig.detailState) throw new ClientException( "unsubscribeAll() not supported with client.store_detail_state=OFF"); MessageDestination clientDest = MessageDestination.formatClientDestination( clientID, brokerState.getBrokerAddress().getNodeURI()); MessageSender msgSender = brokerState.getMsgSender(); if (msgSender == null) throw new ClientException( "Connection not found for broker " + brokerState.getBrokerAddress()); SubscriptionMessage[] subMsgArray = brokerState.getSubMessages().toArray(new SubscriptionMessage[0]); for (SubscriptionMessage subMsg : subMsgArray) { Unsubscription unSub = new Unsubscription(subMsg.getMessageID()); UnsubscriptionMessage unSubMsg = new UnsubscriptionMessage( unSub, getNextMessageID(brokerState.getBrokerAddress().getNodeURI()), clientDest); try { msgSender.send(unSubMsg, HostType.CLIENT); if (clientConfig.detailState) brokerState.removeSubMsg(subMsg); } catch (CommunicationException e) { throw new ClientException(e.getMessage()); } } }
protected UnsubscriptionMessage unSubscribe(String subID, BrokerState brokerState) throws ClientException { try { Unsubscription unSub = new Unsubscription(subID); MessageDestination clientDest = MessageDestination.formatClientDestination( clientID, brokerState.getBrokerAddress().getNodeURI()); UnsubscriptionMessage unSubMsg = new UnsubscriptionMessage( unSub, getNextMessageID(brokerState.getBrokerAddress().getNodeURI()), clientDest); String msgID = brokerState.getMsgSender().send(unSubMsg, HostType.CLIENT); unSubMsg.setMessageID(msgID); if (clientConfig.detailState) brokerState.removeSubMsg(subID); return unSubMsg; } catch (CommunicationException e) { throw new ClientException(e.getMessage()); } }