case 2: outboundQoS2.put(new Integer(message.getMessageId()), message); persistence.put(getSendPersistenceKey(message), (MqttPublish) message); break; case 1: outboundQoS1.put(new Integer(message.getMessageId()), message); persistence.put(getSendPersistenceKey(message), (MqttPublish) message); break; persistence.put(getSendConfirmPersistenceKey(message), (MqttPubRel) message); persistence.remove(getReceivedPersistenceKey(message));
/** * Start the connect processing * @throws MqttPersistenceException if an error is thrown whilst setting up persistence */ public void connect() throws MqttPersistenceException { MqttToken token = new MqttToken(client.getClientId()); token.setActionCallback(this); token.setUserContext(this); persistence.open(client.getClientId(), client.getServerURI()); if (options.isCleanSession()) { persistence.clear(); } if (options.getMqttVersion() == MqttConnectOptions.MQTT_VERSION_DEFAULT) { options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1); } try { comms.connect(options, token); } catch (MqttException e) { onFailure(token, e); } }
Enumeration messageKeys = persistence.keys(); MqttPersistable persistable; String key; persistable = persistence.get(key); MqttWireMessage message = restoreMessage(key, persistable); if (message != null) { MqttPublish sendMessage = (MqttPublish) message; highestMsgId = Math.max(sendMessage.getMessageId(), highestMsgId); if (persistence.containsKey(getSendConfirmPersistenceKey(sendMessage))) { MqttPersistable persistedConfirm = persistence.get(getSendConfirmPersistenceKey(sendMessage)); outboundQoS0.put(new Integer(sendMessage.getMessageId()), sendMessage); persistence.remove(key); if (!persistence.containsKey(getSendPersistenceKey(pubRelMessage))) { orphanedPubRels.addElement(key); persistence.remove(key);
/** * Persists a buffered message to the persistence layer * * @param message The {@link MqttWireMessage} to persist */ public void persistBufferedMessage(MqttWireMessage message) { final String methodName = "persistBufferedMessage"; String key = getSendBufferedPersistenceKey(message); // Because the client will have disconnected, we will want to re-open persistence try { message.setMessageId(getNextMessageId()); key = getSendBufferedPersistenceKey(message); try { persistence.put(key, (MqttPublish) message); } catch (MqttPersistenceException mpe){ //@TRACE 515=Could not Persist, attempting to Re-Open Persistence Store log.fine(CLASS_NAME,methodName, "515"); persistence.open(this.clientComms.getClient().getClientId(), this.clientComms.getClient().getServerURI()); persistence.put(key, (MqttPublish) message); } //@TRACE 513=Persisted Buffered Message key={0} log.fine(CLASS_NAME,methodName, "513", new Object[]{key}); } catch (MqttException ex){ //@TRACE 514=Failed to persist buffered message key={0} log.warning(CLASS_NAME,methodName, "513", new Object[]{key}); } }
protected void deliveryComplete(int messageId) throws MqttPersistenceException { final String methodName = "deliveryComplete"; //@TRACE 641=remove publish from persistence. key={0} log.fine(CLASS_NAME,methodName,"641", new Object[]{new Integer(messageId)}); persistence.remove(getReceivedPersistenceKey(messageId)); inboundQoS2.remove(new Integer(messageId)); }
/** * After a successful disconnect, the underlying library objects need to be closed and connection observers want to * be notified. * * @param v A passthrough boolean value * @return Returns the value of the parameter v. */ protected boolean finalizeStopAfterDisconnect(boolean v) { if (client != null) { try { client.close(); } catch (Exception ignore) { } } client = null; if (dataStore != null) { try { dataStore.close(); } catch (Exception ignore) { } dataStore = null; } connectionObservers.forEach(o -> o.connectionStateChanged(MqttConnectionState.DISCONNECTED, null)); return v; }
persistence.put(getReceivedPersistenceKey(message), (MqttPublish) message); inboundQoS2.put(new Integer(send.getMessageId()), send);
protected void clearState() throws MqttException { final String methodName = "clearState"; //@TRACE 603=clearState log.fine(CLASS_NAME, methodName,">"); persistence.clear(); inUseMsgIds.clear(); pendingMessages.clear(); pendingFlows.clear(); outboundQoS2.clear(); outboundQoS1.clear(); outboundQoS0.clear(); inboundQoS2.clear(); tokenStore.clear(); }
Enumeration messageKeys = persistence.keys(); MqttPersistable persistable; String key; persistable = persistence.get(key); MqttWireMessage message = restoreMessage(key, persistable); if (message != null) { MqttPublish sendMessage = (MqttPublish) message; highestMsgId = Math.max(sendMessage.getMessageId(), highestMsgId); if (persistence.containsKey(getSendConfirmPersistenceKey(sendMessage))) { MqttPersistable persistedConfirm = persistence.get(getSendConfirmPersistenceKey(sendMessage)); if (!persistence.containsKey(getSendPersistenceKey(pubRelMessage))) { orphanedPubRels.addElement(key); persistence.remove(key);
protected void deliveryComplete(MqttPublish message) throws MqttPersistenceException { final String methodName = "deliveryComplete"; //@TRACE 641=remove publish from persistence. key={0} log.fine(CLASS_NAME,methodName,"641", new Object[]{new Integer(message.getMessageId())}); persistence.remove(getReceivedPersistenceKey(message)); inboundQoS2.remove(new Integer(message.getMessageId())); }
/** * Persists a buffered message to the persistence layer * * @param message The {@link MqttWireMessage} to persist */ public void persistBufferedMessage(MqttWireMessage message) { final String methodName = "persistBufferedMessage"; String key = getSendBufferedPersistenceKey(message); // Because the client will have disconnected, we will want to re-open persistence try { message.setMessageId(getNextMessageId()); key = getSendBufferedPersistenceKey(message); try { persistence.put(key, (MqttPublish) message); } catch (MqttPersistenceException mpe){ //@TRACE 515=Could not Persist, attempting to Re-Open Persistence Store log.fine(CLASS_NAME,methodName, "515"); persistence.open(this.clientComms.getClient().getClientId(), this.clientComms.getClient().getServerURI()); persistence.put(key, (MqttPublish) message); } //@TRACE 513=Persisted Buffered Message key={0} log.fine(CLASS_NAME,methodName, "513", new Object[]{key}); } catch (MqttException ex){ //@TRACE 514=Failed to persist buffered message key={0} log.warning(CLASS_NAME,methodName, "513", new Object[]{key}); } }
persistence.close();
/*** NodeContainer Implementation *****************************************************************************/ @Override public void attributeHasChangedByEndpoint(CloudioAttribute.InternalAttribute attribute) { // Create the MQTT message using the given message format. byte[] data = messageFormat.serializeAttribute(attribute); // Try to send the message if the MQTT client is connected. boolean messageSend = false; if (mqtt.isConnected()) { try { mqtt.publish("@update/" + attribute.getUuid().toString(), data, 1, false); messageSend = true; } catch (MqttException exception) { log.error("Exception :" + exception.getMessage()); exception.printStackTrace(); } } // If the message could not be send for any reason, add the message to the pending updates persistence if // available. if (!messageSend && persistence != null) { try { persistence.put("PendingUpdate-" + attribute.getUuid().toString().replace("/", ";") + "-" + Calendar.getInstance().getTimeInMillis(), new PendingUpdate(data)); } catch (MqttPersistenceException exception) { log.error("Exception :" + exception.getMessage()); exception.printStackTrace(); } } }
protected void clearState() throws MqttException { final String methodName = "clearState"; //@TRACE 603=clearState log.fine(className, methodName,">"); persistence.clear(); inUseMsgIds.clear(); pendingMessages.clear(); pendingFlows.clear(); outboundQoS2.clear(); outboundQoS1.clear(); inboundQoS2.clear(); tokenStore.clear(); }
Enumeration messageKeys = persistence.keys(); MqttPersistable persistable; String key; persistable = persistence.get(key); MqttWireMessage message = restoreMessage(key, persistable); if (message != null) { MqttPublish sendMessage = (MqttPublish) message; highestMsgId = Math.max(sendMessage.getMessageId(), highestMsgId); if (persistence.containsKey(getSendConfirmPersistenceKey(sendMessage))) { MqttPersistable persistedConfirm = persistence.get(getSendConfirmPersistenceKey(sendMessage)); outboundQoS0.put(new Integer(sendMessage.getMessageId()), sendMessage); persistence.remove(key); if (!persistence.containsKey(getSendPersistenceKey(pubRelMessage))) { orphanedPubRels.addElement(key); persistence.remove(key);
/** * @param message The {@link MqttWireMessage} to un-persist */ public void unPersistBufferedMessage(MqttWireMessage message){ final String methodName = "unPersistBufferedMessage"; try{ //@TRACE 517=Un-Persisting Buffered message key={0} log.fine(CLASS_NAME,methodName, "517", new Object[]{message.getKey()}); persistence.remove(getSendBufferedPersistenceKey(message)); } catch (MqttPersistenceException mpe){ //@TRACE 518=Failed to Un-Persist Buffered message key={0} log.fine(CLASS_NAME,methodName, "518", new Object[]{message.getKey()}); } }
case 2: outboundQoS2.put(new Integer(message.getMessageId()), message); persistence.put(getSendPersistenceKey(message), (MqttPublish) message); break; case 1: outboundQoS1.put(new Integer(message.getMessageId()), message); persistence.put(getSendPersistenceKey(message), (MqttPublish) message); break; persistence.put(getSendConfirmPersistenceKey(message), (MqttPubRel) message); persistence.remove(getReceivedPersistenceKey(message));
/** * Persists a buffered message to the persistence layer * * @param message The {@link MqttWireMessage} to persist */ public void persistBufferedMessage(MqttWireMessage message) { final String methodName = "persistBufferedMessage"; String key = getSendBufferedPersistenceKey(message); // Because the client will have disconnected, we will want to re-open persistence try { message.setMessageId(getNextMessageId()); key = getSendBufferedPersistenceKey(message); try { persistence.put(key, (MqttPublish) message); } catch (MqttPersistenceException mpe){ //@TRACE 515=Could not Persist, attempting to Re-Open Persistence Store log.fine(CLASS_NAME,methodName, "515"); persistence.open(this.clientComms.getClient().getClientId(), this.clientComms.getClient().getServerURI()); persistence.put(key, (MqttPublish) message); } //@TRACE 513=Persisted Buffered Message key={0} log.fine(CLASS_NAME,methodName, "513", new Object[]{key}); } catch (MqttException ex){ //@TRACE 514=Failed to persist buffered message key={0} log.warning(CLASS_NAME,methodName, "513", new Object[]{key}); } }