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()); } } }
/** * Returns all the subscription messages the client has sent in the past. This method is * operational only when the store_detail_state option is switched ON. * * @return * @throws ClientException If the client.store_detail_state option is OFF */ public Map<String, SubscriptionMessage> getSubscriptions() throws ClientException { if (!clientConfig.detailState) throw new ClientException( "getSubscriptions() not supported with client.store_detail_state=OFF"); HashMap<String, SubscriptionMessage> idMsgMap = new HashMap<String, SubscriptionMessage>(); for (BrokerState brokerState : brokerStates.values()) { Set<SubscriptionMessage> subs = brokerState.getSubMessages(); for (SubscriptionMessage subMsg : subs) idMsgMap.put(subMsg.getMessageID(), subMsg); } return idMsgMap; }