diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fa54c57 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/doc/ +/EasyModbus/ +/nbproject/ +/manifest.mf +target +*.iml +.idea diff --git a/EasyModbus/EasyModbus/src/ModbusRTU/ModbusRTU.java b/EasyModbus/EasyModbus/src/ModbusRTU/ModbusRTU.java index 8f3d27a..4de43c0 100644 --- a/EasyModbus/EasyModbus/src/ModbusRTU/ModbusRTU.java +++ b/EasyModbus/EasyModbus/src/ModbusRTU/ModbusRTU.java @@ -2,14 +2,14 @@ * Creative Commons license: Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) *You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *The licensor cannot revoke these freedoms as long as you follow the license terms. * *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NonCommercial — You may not use the material for commercial purposes. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NonCommercial - You may not use the material for commercial purposes. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. */ package ModbusRTU; import java.io.IOException; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/ModbusClient.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/ModbusClient.java index 4c009ad..f9212e0 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/ModbusClient.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/ModbusClient.java @@ -2,14 +2,14 @@ * Creative Commons license: Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) *You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *The licensor cannot revoke these freedoms as long as you follow the license terms. * *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NonCommercial — You may not use the material for commercial purposes. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NonCommercial - You may not use the material for commercial purposes. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. */ package de.re.easymodbus.modbusclient; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/ReceiveDataChangedListener.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/ReceiveDataChangedListener.java index 0f4dfb5..b69d0bf 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/ReceiveDataChangedListener.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/ReceiveDataChangedListener.java @@ -3,14 +3,14 @@ * Creative Commons license: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) * You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *for any purpose, even commercially. *The licensor cannot revoke these freedoms as long as you follow the license terms. *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. - *No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. + *No additional restrictions - You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. */ package de.re.easymodbus.modbusclient; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/SendDataChangedListener.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/SendDataChangedListener.java index c3d062f..0d933f1 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/SendDataChangedListener.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/SendDataChangedListener.java @@ -3,14 +3,14 @@ * Creative Commons license: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) * You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *for any purpose, even commercially. *The licensor cannot revoke these freedoms as long as you follow the license terms. *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. - *No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. + *No additional restrictions - You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. */ package de.re.easymodbus.modbusclient; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleGUI.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleGUI.java index a6200b3..e0d644a 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleGUI.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleGUI.java @@ -6,14 +6,14 @@ * Creative Commons license: Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) *You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *The licensor cannot revoke these freedoms as long as you follow the license terms. * *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NonCommercial — You may not use the material for commercial purposes. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NonCommercial - You may not use the material for commercial purposes. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. */ package de.re.easymodbus.modbusclient.gui; @@ -28,7 +28,7 @@ import java.awt.event.ItemEvent; /** * - * @author Stefan Roßmann + * @author Stefan Roßmann */ @SuppressWarnings("serial") public class EasyModbusTCPClientExampleGUI extends javax.swing.JFrame diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleJava.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleJava.java index 4ec59bf..241ecf5 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleJava.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleJava.java @@ -2,14 +2,14 @@ * Creative Commons license: Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) *You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *The licensor cannot revoke these freedoms as long as you follow the license terms. * *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NonCommercial — You may not use the material for commercial purposes. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NonCommercial - You may not use the material for commercial purposes. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. */ package de.re.easymodbus.modbusclient.gui; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTcpClient.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTcpClient.java index 5a36398..2e38758 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTcpClient.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/modbusclient/gui/EasyModbusTcpClient.java @@ -4,14 +4,14 @@ * Creative Commons license: Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) *You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *The licensor cannot revoke these freedoms as long as you follow the license terms. * *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NonCommercial — You may not use the material for commercial purposes. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NonCommercial - You may not use the material for commercial purposes. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. */ package de.re.easymodbus.modbusclient.gui; @@ -26,7 +26,7 @@ import java.awt.event.ItemEvent; /** * - * @author Stefan Roßmann + * @author Stefan Roßmann */ @SuppressWarnings("serial") public class EasyModbusTcpClient extends javax.swing.JFrame diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ClientConnectionThread.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ClientConnectionThread.java index 59eb81d..9e2e446 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ClientConnectionThread.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ClientConnectionThread.java @@ -3,14 +3,14 @@ * Creative Commons license: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) * You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *for any purpose, even commercially. *The licensor cannot revoke these freedoms as long as you follow the license terms. *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. - *No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. + *No additional restrictions - You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. */ package de.re.easymodbus.server; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ICoilsChangedDelegator.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ICoilsChangedDelegator.java index a293564..dc5235e 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ICoilsChangedDelegator.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ICoilsChangedDelegator.java @@ -3,14 +3,14 @@ * Creative Commons license: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) * You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *for any purpose, even commercially. *The licensor cannot revoke these freedoms as long as you follow the license terms. *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. - *No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. + *No additional restrictions - You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. */ package de.re.easymodbus.server; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/IHoldingRegistersChangedDelegator.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/IHoldingRegistersChangedDelegator.java index 6f0c2bf..0dff03e 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/IHoldingRegistersChangedDelegator.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/IHoldingRegistersChangedDelegator.java @@ -3,14 +3,14 @@ * Creative Commons license: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) * You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *for any purpose, even commercially. *The licensor cannot revoke these freedoms as long as you follow the license terms. *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. - *No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. + *No additional restrictions - You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. */ package de.re.easymodbus.server; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ILogDataChangedDelegator.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ILogDataChangedDelegator.java index 34b5262..5e810a6 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ILogDataChangedDelegator.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ILogDataChangedDelegator.java @@ -3,14 +3,14 @@ * Creative Commons license: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) * You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *for any purpose, even commercially. *The licensor cannot revoke these freedoms as long as you follow the license terms. *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. - *No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. + *No additional restrictions - You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. */ package de.re.easymodbus.server; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/INumberOfConnectedClientsChangedDelegator.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/INumberOfConnectedClientsChangedDelegator.java index 362b23e..ea7afe3 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/INumberOfConnectedClientsChangedDelegator.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/INumberOfConnectedClientsChangedDelegator.java @@ -3,14 +3,14 @@ * Creative Commons license: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) * You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *for any purpose, even commercially. *The licensor cannot revoke these freedoms as long as you follow the license terms. *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. - *No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. + *No additional restrictions - You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. */ package de.re.easymodbus.server; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ListenerThread.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ListenerThread.java index bdcc79c..379a105 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ListenerThread.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ListenerThread.java @@ -3,14 +3,14 @@ * Creative Commons license: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) * You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *for any purpose, even commercially. *The licensor cannot revoke these freedoms as long as you follow the license terms. *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. - *No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. + *No additional restrictions - You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. */ package de.re.easymodbus.server; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ModbusProtocoll.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ModbusProtocoll.java index b8638e1..3e4e5ba 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ModbusProtocoll.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ModbusProtocoll.java @@ -3,14 +3,14 @@ * Creative Commons license: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) * You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *for any purpose, even commercially. *The licensor cannot revoke these freedoms as long as you follow the license terms. *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. - *No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. + *No additional restrictions - You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. */ package de.re.easymodbus.server; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ModbusServer.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ModbusServer.java index d9740eb..89876c5 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ModbusServer.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ModbusServer.java @@ -2,14 +2,14 @@ * Creative Commons license: Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) *You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *The licensor cannot revoke these freedoms as long as you follow the license terms. * *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NonCommercial — You may not use the material for commercial purposes. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NonCommercial - You may not use the material for commercial purposes. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. */ package de.re.easymodbus.server; diff --git a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ProcessReceivedDataThread.java b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ProcessReceivedDataThread.java index 0071894..c67e60a 100644 --- a/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ProcessReceivedDataThread.java +++ b/EasyModbus/EasyModbus/src/de/re/easymodbus/server/ProcessReceivedDataThread.java @@ -3,14 +3,14 @@ * Creative Commons license: Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) * You are free to: * - *Share — copy and redistribute the material in any medium or format + *Share - copy and redistribute the material in any medium or format *for any purpose, even commercially. *The licensor cannot revoke these freedoms as long as you follow the license terms. *Under the following terms: * - *Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. - *NoDerivatives — If you remix, transform, or build upon the material, you may not distribute the modified material. - *No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. + *Attribution - You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. + *NoDerivatives - If you remix, transform, or build upon the material, you may not distribute the modified material. + *No additional restrictions - You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits. */ package de.re.easymodbus.server; diff --git a/EasyModbus/doc/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleGUI.html b/EasyModbus/doc/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleGUI.html index dd71bfa..475467c 100644 --- a/EasyModbus/doc/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleGUI.html +++ b/EasyModbus/doc/de/re/easymodbus/modbusclient/gui/EasyModbusTCPClientExampleGUI.html @@ -143,7 +143,7 @@
DisconnectedBufferOptions object using the
- * default values.
- *
- * The defaults are:
- * A listener is registered on an MqttToken and a token is associated - * with an action like connect or publish. When used with tokens on the MqttAsyncClient - * the listener will be called back on the MQTT client's thread. The listener will be informed - * if the action succeeds or fails. It is important that the listener returns control quickly - * otherwise the operation of the MQTT client will be stalled. - *
- */ -public interface IMqttActionListener { - /** - * This method is invoked when an action has completed successfully. - * @param asyncActionToken associated with the action that has completed - */ - public void onSuccess(IMqttToken asyncActionToken ); - /** - * This method is invoked when an action fails. - * If a client is disconnected while an action is in progress - * onFailure will be called. For connections - * that use cleanSession set to false, any QoS 1 and 2 messages that - * are in the process of being delivered will be delivered to the requested - * quality of service next time the client connects. - * @param asyncActionToken associated with the action that has failed - * @param exception thrown by the action that has failed - */ - public void onFailure(IMqttToken asyncActionToken, Throwable exception); -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttAsyncClient.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttAsyncClient.java deleted file mode 100644 index b0a1e32..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttAsyncClient.java +++ /dev/null @@ -1,875 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013, 2015 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - * Ian Craggs - MQTT 3.1.1 support - * Ian Craggs - per subscription message handlers (bug 466579) - * Ian Craggs - ack control (bug 472172) - */ - -package org.eclipse.paho.client.mqttv3; - -/** - * Enables an application to communicate with an MQTT server using non-blocking methods. - *- * It provides applications a simple programming interface to all features of the MQTT version 3.1 - * specification including: - *
- *- * There are two styles of MQTT client, this one and {@link IMqttClient}.
- *- * An application is not restricted to using one style if an IMqttAsyncClient based client is used - * as both blocking and non-blocking methods can be used in the same application. If an IMqttClient - * based client is used then only blocking methods are available to the application. - * For more details on the blocking client see {@link IMqttClient}
- * - *There are two forms of non-blocking method: - *
- * IMqttToken token = asyncClient.method(parms) - *- *
In this form the method returns a token that can be used to track the - * progress of the action (method). The method provides a waitForCompletion() - * method that once invoked will block until the action completes. Once - * completed there are method on the token that can be used to check if the - * action completed successfully or not. For example - * to wait until a connect completes:
- *- * IMqttToken conToken; - * conToken = asyncClient.client.connect(conToken); - * ... do some work... - * conToken.waitForCompletion(); - *- *
To turn a method into a blocking invocation the following form can be used:
- *- * IMqttToken token; - * token = asyncClient.method(parms).waitForCompletion(); - *- *
- * IMqttToken token method(parms, Object userContext, IMqttActionListener callback) - *- *
In this form a callback is registered with the method. The callback will be - * notified when the action succeeds or fails. The callback is invoked on the thread - * managed by the MQTT client so it is important that processing is minimised in the - * callback. If not the operation of the MQTT client will be inhibited. For example - * to be notified (called back) when a connect completes:
- *
- * IMqttToken conToken;
- * conToken = asyncClient.connect("some context",new new MqttAsyncActionListener() {
- * public void onSuccess(IMqttToken asyncActionToken) {
- * log("Connected");
- * }
- *
- * public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
- * log ("connect failed" +exception);
- * }
- * });
- *
- * An optional context object can be passed into the method which will then be made - * available in the callback. The context is stored by the MQTT client) in the token - * which is then returned to the invoker. The token is provided to the callback methods - * where the context can then be accessed. - *
- *To understand when the delivery of a message is complete either of the two methods above - * can be used to either wait on or be notified when the publish completes. An alternative is to - * use the {@link MqttCallback#deliveryComplete(IMqttDeliveryToken)} method which will - * also be notified when a message has been delivered to the requested quality of service.
- * - */ -public interface IMqttAsyncClient { - /** - * Connects to an MQTT server using the default options. - *The default options are specified in {@link MqttConnectOptions} class. - *
- * - * @throws MqttSecurityException for security related problems - * @throws MqttException for non security related problems - * @return token used to track and wait for the connect to complete. The token - * will be passed to the callback methods if a callback is set. - * @see #connect(MqttConnectOptions, Object, IMqttActionListener) - */ - public IMqttToken connect() throws MqttException, MqttSecurityException; - - /** - * Connects to an MQTT server using the provided connect options. - *The connection will be established using the options specified in the - * {@link MqttConnectOptions} parameter. - *
- * - * @param options a set of connection parameters that override the defaults. - * @throws MqttSecurityException for security related problems - * @throws MqttException for non security related problems - * @return token used to track and wait for the connect to complete. The token - * will be passed to any callback that has been set. - * @see #connect(MqttConnectOptions, Object, IMqttActionListener) - */ - public IMqttToken connect(MqttConnectOptions options) throws MqttException, MqttSecurityException ; - /** - * Connects to an MQTT server using the default options. - *The default options are specified in {@link MqttConnectOptions} class. - *
- * - * @param userContext optional object used to pass context to the callback. Use - * null if not required. - * @param callback optional listener that will be notified when the connect completes. Use - * null if not required. - * @throws MqttSecurityException for security related problems - * @throws MqttException for non security related problems - * @return token used to track and wait for the connect to complete. The token - * will be passed to any callback that has been set. - * @see #connect(MqttConnectOptions, Object, IMqttActionListener) - */ - public IMqttToken connect(Object userContext, IMqttActionListener callback) throws MqttException, MqttSecurityException; - - - /** - * Connects to an MQTT server using the specified options. - *The server to connect to is specified on the constructor. - * It is recommended to call {@link #setCallback(MqttCallback)} prior to - * connecting in order that messages destined for the client can be accepted - * as soon as the client is connected. - *
- *The method returns control before the connect completes. Completion can - * be tracked by: - *
- *An attempt is made to quiesce the client allowing outstanding - * work to complete before disconnecting. It will wait - * for a maximum of 30 seconds for work to quiesce before disconnecting. - * This method must not be called from inside {@link MqttCallback} methods. - *
- * - * @return token used to track and wait for disconnect to complete. The token - * will be passed to any callback that has been set. - * @throws MqttException for problems encountered while disconnecting - * @see #disconnect(long, Object, IMqttActionListener) - */ - public IMqttToken disconnect( ) throws MqttException; - - /** - * Disconnects from the server. - *An attempt is made to quiesce the client allowing outstanding - * work to complete before disconnecting. It will wait - * for a maximum of the specified quiesce time for work to complete before disconnecting. - * This method must not be called from inside {@link MqttCallback} methods. - *
- * @param quiesceTimeout the amount of time in milliseconds to allow for - * existing work to finish before disconnecting. A value of zero or less - * means the client will not quiesce. - * @return token used to track and wait for disconnect to complete. The token - * will be passed to the callback methods if a callback is set. - * @throws MqttException for problems encountered while disconnecting - * @see #disconnect(long, Object, IMqttActionListener) - */ - public IMqttToken disconnect(long quiesceTimeout) throws MqttException; - - /** - * Disconnects from the server. - *An attempt is made to quiesce the client allowing outstanding - * work to complete before disconnecting. It will wait - * for a maximum of 30 seconds for work to quiesce before disconnecting. - * This method must not be called from inside {@link MqttCallback} methods. - *
- * - * @param userContext optional object used to pass context to the callback. Use - * null if not required. - * @param callback optional listener that will be notified when the disconnect completes. Use - * null if not required. - * @return token used to track and wait for the disconnect to complete. The token - * will be passed to any callback that has been set. - * @throws MqttException for problems encountered while disconnecting - * @see #disconnect(long, Object, IMqttActionListener) - */ - public IMqttToken disconnect( Object userContext, IMqttActionListener callback) throws MqttException; - - /** - * Disconnects from the server. - *- * The client will wait for {@link MqttCallback} methods to - * complete. It will then wait for up to the quiesce timeout to allow for - * work which has already been initiated to complete. For instance when a QoS 2 - * message has started flowing to the server but the QoS 2 flow has not completed.It - * prevents new messages being accepted and does not send any messages that have - * been accepted but not yet started delivery across the network to the server. When - * work has completed or after the quiesce timeout, the client will disconnect from - * the server. If the cleanSession flag was set to false and is set to false the - * next time a connection is made QoS 1 and 2 messages that - * were not previously delivered will be delivered.
- *This method must not be called from inside {@link MqttCallback} methods.
- *The method returns control before the disconnect completes. Completion can - * be tracked by: - *
- *- * Because the client is able to establish the TCP/IP connection to a none MQTT server and it will certainly fail to - * send the disconnect packet. It will wait for a maximum of 30 seconds for work to quiesce before disconnecting and - * wait for a maximum of 10 seconds for sending the disconnect packet to server. - * - * @throws MqttException if any unexpected error - * @since 0.4.1 - */ - public void disconnectForcibly() throws MqttException; - - /** - * Disconnects from the server forcibly to reset all the states. Could be useful when disconnect attempt failed. - *
- * Because the client is able to establish the TCP/IP connection to a none MQTT server and it will certainly fail to - * send the disconnect packet. It will wait for a maximum of 30 seconds for work to quiesce before disconnecting. - * - * @param disconnectTimeout the amount of time in milliseconds to allow send disconnect packet to server. - * @throws MqttException if any unexpected error - * @since 0.4.1 - */ - public void disconnectForcibly(long disconnectTimeout) throws MqttException; - - /** - * Disconnects from the server forcibly to reset all the states. Could be useful when disconnect attempt failed. - *
- * Because the client is able to establish the TCP/IP connection to a none MQTT server and it will certainly fail to
- * send the disconnect packet.
- *
- * @param quiesceTimeout the amount of time in milliseconds to allow for existing work to finish before
- * disconnecting. A value of zero or less means the client will not quiesce.
- * @param disconnectTimeout the amount of time in milliseconds to allow send disconnect packet to server.
- * @throws MqttException if any unexpected error
- * @since 0.4.1
- */
- public void disconnectForcibly(long quiesceTimeout, long disconnectTimeout) throws MqttException;
-
- /**
- * Determines if this client is currently connected to the server.
- *
- * @return true if connected, false otherwise.
- */
- public boolean isConnected();
-
- /**
- * Returns the client ID used by this client.
- *
All clients connected to the - * same server or server farm must have a unique ID. - *
- * - * @return the client ID used by this client. - */ - public String getClientId(); - - /** - * Returns the address of the server used by this client. - *The format of the returned String is the same as that used on the constructor. - *
- * - * @return the server's address, as a URI String. - * @see MqttAsyncClient#MqttAsyncClient(String, String) - */ - public String getServerURI(); - - /** - * Publishes a message to a topic on the server. - *A convenience method, which will - * create a new {@link MqttMessage} object with a byte array payload and the - * specified QoS, and then publish it. - *
- * - * @param topic to deliver the message to, for example "finance/stock/ibm". - * @param payload the byte array to use as the payload - * @param qos the Quality of Service to deliver the message at. Valid values are 0, 1 or 2. - * @param retained whether or not this message should be retained by the server. - * @return token used to track and wait for the publish to complete. The token - * will be passed to any callback that has been set. - * @throws MqttPersistenceException when a problem occurs storing the message - * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. - * @throws MqttException for other errors encountered while publishing the message. - * For instance if too many messages are being processed. - * @see #publish(String, MqttMessage, Object, IMqttActionListener) - * @see MqttMessage#setQos(int) - * @see MqttMessage#setRetained(boolean) - */ - public IMqttDeliveryToken publish(String topic, byte[] payload, int qos, - boolean retained ) throws MqttException, MqttPersistenceException; - - /** - * Publishes a message to a topic on the server. - *A convenience method, which will - * create a new {@link MqttMessage} object with a byte array payload and the - * specified QoS, and then publish it. - *
- * - * @param topic to deliver the message to, for example "finance/stock/ibm". - * @param payload the byte array to use as the payload - * @param qos the Quality of Service to deliver the message at. Valid values are 0, 1 or 2. - * @param retained whether or not this message should be retained by the server. - * @param userContext optional object used to pass context to the callback. Use - * null if not required. - * @param callback optional listener that will be notified when message delivery - * hsa completed to the requested quality of service - * @return token used to track and wait for the publish to complete. The token - * will be passed to any callback that has been set. - * @throws MqttPersistenceException when a problem occurs storing the message - * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. - * @throws MqttException for other errors encountered while publishing the message. - * For instance client not connected. - * @see #publish(String, MqttMessage, Object, IMqttActionListener) - * @see MqttMessage#setQos(int) - * @see MqttMessage#setRetained(boolean) - */ - public IMqttDeliveryToken publish(String topic, byte[] payload, int qos, - boolean retained, Object userContext, IMqttActionListener callback ) throws MqttException, MqttPersistenceException; - - /** - * Publishes a message to a topic on the server. - * Takes an {@link MqttMessage} message and delivers it to the server at the - * requested quality of service. - * - * @param topic to deliver the message to, for example "finance/stock/ibm". - * @param message to deliver to the server - * @return token used to track and wait for the publish to complete. The token - * will be passed to any callback that has been set. - * @throws MqttPersistenceException when a problem occurs storing the message - * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. - * @throws MqttException for other errors encountered while publishing the message. - * For instance client not connected. - * @see #publish(String, MqttMessage, Object, IMqttActionListener) - */ - public IMqttDeliveryToken publish(String topic, MqttMessage message ) throws MqttException, MqttPersistenceException; - - /** - * Publishes a message to a topic on the server. - *- * Once this method has returned cleanly, the message has been accepted for publication by the - * client and will be delivered on a background thread. - * In the event the connection fails or the client stops. Messages will be delivered to the - * requested quality of service once the connection is re-established to the server on condition that: - *
- *When building an application, - * the design of the topic tree should take into account the following principles - * of topic name syntax and semantics:
- * - *\x0000) in - * any topic.
The following principles apply to the construction and content of a topic - * tree:
- *The method returns control before the publish completes. Completion can - * be tracked by: - *
- *Provides an optimized way to subscribe to multiple topics compared to - * subscribing to each one individually.
- * - * @see #subscribe(String[], int[], Object, IMqttActionListener) - * - * @param topicFilters one or more topics to subscribe to, which can include wildcards - * @param qos the maximum quality of service at which to subscribe. Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @return token used to track and wait for the subscribe to complete. The token - * will be passed to callback methods if set. - * @throws MqttException if there was an error registering the subscription. - */ - public IMqttToken subscribe(String[] topicFilters, int[] qos) throws MqttException; - - /** - * Subscribes to multiple topics, each of which may include wildcards. - *Provides an optimized way to subscribe to multiple topics compared to - * subscribing to each one individually.
- *The {@link #setCallback(MqttCallback)} method - * should be called before this method, otherwise any received messages - * will be discarded. - *
- *- * If (@link MqttConnectOptions#setCleanSession(boolean)} was set to true - * when when connecting to the server then the subscription remains in place - * until either:
- * - *- * If (@link MqttConnectOptions#setCleanSession(boolean)} was set to false - * when connecting to the server then the subscription remains in place - * until either:
- *- * With cleanSession set to false the MQTT server will store messages on - * behalf of the client when the client is not connected. The next time the - * client connects with the same client ID the server will - * deliver the stored messages to the client. - *
- * - *The "topic filter" string used when subscribing - * may contain special characters, which allow you to subscribe to multiple topics - * at once.
- *The topic level separator is used to introduce structure into the topic, and - * can therefore be specified within the topic for that purpose. The multi-level - * wildcard and single-level wildcard can be used for subscriptions, but they - * cannot be used within a topic by the publisher of a message. - *
The number sign (#) is a wildcard character that matches - * any number of levels within a topic. For example, if you subscribe to - * finance/stock/ibm/#, you receive - * messages on these topics:
- *The multi-level wildcard - * can represent zero or more levels. Therefore, finance/# can also match - * the singular finance, where # represents zero levels. The topic - * level separator is meaningless in this context, because there are no levels - * to separate.
- * - *The multi-level wildcard can - * be specified only on its own or next to the topic level separator character. - * Therefore, # and finance/# are both valid, but finance# is - * not valid. The multi-level wildcard must be the last character - * used within the topic tree. For example, finance/# is valid but - * finance/#/closingprice is not valid.
The plus sign (+) is a wildcard character that matches only one topic - * level. For example, finance/stock/+ matches - * finance/stock/ibm and finance/stock/xyz, - * but not finance/stock/ibm/closingprice. Also, because the single-level - * wildcard matches only a single level, finance/+ does not match finance.
- * - *Use - * the single-level wildcard at any level in the topic tree, and in conjunction - * with the multilevel wildcard. Specify the single-level wildcard next to the - * topic level separator, except when it is specified on its own. Therefore, - * + and finance/+ are both valid, but finance+ is - * not valid. The single-level wildcard can be used at the end of the - * topic tree or within the topic tree. - * For example, finance/+ and finance/+/ibm are both valid.
- *The method returns control before the subscribe completes. Completion can - * be tracked by:
- *Provides an optimized way to subscribe to multiple topics compared to - * subscribing to each one individually.
- * - * @see #subscribe(String[], int[], Object, IMqttActionListener) - * - * @param topicFilters one or more topics to subscribe to, which can include wildcards - * @param qos the maximum quality of service at which to subscribe. Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @param messageListeners one or more callbacks to handle incoming messages - * @return token used to track and wait for the subscribe to complete. The token - * will be passed to callback methods if set. - * @throws MqttException if there was an error registering the subscription. - */ - public IMqttToken subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) throws MqttException; - - - /** - * Subscribe to multiple topics, each of which may include wildcards. - * - *Provides an optimized way to subscribe to multiple topics compared to - * subscribing to each one individually.
- * - * @see #subscribe(String[], int[], Object, IMqttActionListener) - * - * @param topicFilters one or more topics to subscribe to, which can include wildcards - * @param qos the maximum quality of service at which to subscribe. Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @param userContext optional object used to pass context to the callback. Use - * null if not required. - * @param callback optional listener that will be notified when subscribe - * has completed - * @param messageListeners one or more callbacks to handle incoming messages - * @return token used to track and wait for the subscribe to complete. The token - * will be passed to callback methods if set. - * @throws MqttException if there was an error registering the subscription. - */ - public IMqttToken subscribe(String[] topicFilters, int[] qos, Object userContext, IMqttActionListener callback, IMqttMessageListener[] messageListeners) throws MqttException; - - - /** - * Requests the server unsubscribe the client from a topic. - * - * @see #unsubscribe(String[], Object, IMqttActionListener) - * @param topicFilter the topic to unsubscribe from. It must match a topicFilter - * specified on an earlier subscribe. - * @return token used to track and wait for the unsubscribe to complete. The token - * will be passed to callback methods if set. - * @throws MqttException if there was an error unregistering the subscription. - */ - public IMqttToken unsubscribe(String topicFilter) throws MqttException; - - /** - * Requests the server unsubscribe the client from one or more topics. - * - * @see #unsubscribe(String[], Object, IMqttActionListener) - * - * @param topicFilters one or more topics to unsubscribe from. Each topicFilter - * must match one specified on an earlier subscribe. * - * @return token used to track and wait for the unsubscribe to complete. The token - * will be passed to callback methods if set. - * @throws MqttException if there was an error unregistering the subscription. - */ - public IMqttToken unsubscribe(String[] topicFilters) throws MqttException; - - /** - * Requests the server unsubscribe the client from a topics. - * - * @see #unsubscribe(String[], Object, IMqttActionListener) - * - * @param topicFilter the topic to unsubscribe from. It must match a topicFilter - * specified on an earlier subscribe. - * @param userContext optional object used to pass context to the callback. Use - * null if not required. - * @param callback optional listener that will be notified when unsubscribe - * has completed - * @return token used to track and wait for the unsubscribe to complete. The token - * will be passed to callback methods if set. - * @throws MqttException if there was an error unregistering the subscription. - */ - public IMqttToken unsubscribe(String topicFilter, Object userContext, IMqttActionListener callback) - throws MqttException; - - /** - * Requests the server unsubscribe the client from one or more topics. - *- * Unsubcribing is the opposite of subscribing. When the server receives the - * unsubscribe request it looks to see if it can find a matching subscription for the - * client and then removes it. After this point the server will send no more - * messages to the client for this subscription. - *
- *The topic(s) specified on the unsubscribe must match the topic(s) - * specified in the original subscribe request for the unsubscribe to succeed - *
- *The method returns control before the unsubscribe completes. Completion can - * be tracked by: - *
- * - *There are a number of events that the listener will be notified about. - * These include: - *
- *Other events that track the progress of an individual operation such - * as connect and subscribe can be tracked using the {@link MqttToken} returned from - * each non-blocking method or using setting a {@link IMqttActionListener} on the - * non-blocking method.
- * @see MqttCallback - * @param callback which will be invoked for certain asynchronous events - */ - public void setCallback(MqttCallback callback); - - /** - * Returns the delivery tokens for any outstanding publish operations. - *
If a client has been restarted and there are messages that were in the - * process of being delivered when the client stopped this method - * returns a token for each in-flight message enabling the delivery to be tracked - * Alternately the {@link MqttCallback#deliveryComplete(IMqttDeliveryToken)} - * callback can be used to track the delivery of outstanding messages. - *
- *If a client connects with cleanSession true then there will be no - * delivery tokens as the cleanSession option deletes all earlier state. - * For state to be remembered the client must connect with cleanSession - * set to false
- * @return zero or more delivery tokens - */ - public IMqttDeliveryToken[] getPendingDeliveryTokens(); - - /** - * If manualAcks is set to true, then on completion of the messageArrived callback - * the MQTT acknowledgements are not sent. You must call messageArrivedComplete - * to send those acknowledgements. This allows finer control over when the acks are - * sent. The default behaviour, when manualAcks is false, is to send the MQTT - * acknowledgements automatically at the successful completion of the messageArrived - * callback method. - * @param manualAcks if set to true MQTT acknowledgements are not sent - */ - public void setManualAcks(boolean manualAcks); - - /** - * Indicate that the application has completed processing the message with id messageId. - * This will cause the MQTT acknowledgement to be sent to the server. - * @param messageId the MQTT message id to be acknowledged - * @param qos the MQTT QoS of the message to be acknowledged - * @throws MqttException if there was a problem sending the acknowledgement - */ - public void messageArrivedComplete(int messageId, int qos) throws MqttException; - - /** - * Close the client - * Releases all resource associated with the client. After the client has - * been closed it cannot be reused. For instance attempts to connect will fail. - * @throws MqttException if the client is not disconnected. - */ - public void close() throws MqttException; -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttClient.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttClient.java deleted file mode 100644 index 810dfed..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttClient.java +++ /dev/null @@ -1,966 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2015 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - * Ian Craggs - MQTT 3.1.1 support - * Ian Craggs - per subscription message handlers (bug 466579) - * Ian Craggs - ack control (bug 472172) - */ - -package org.eclipse.paho.client.mqttv3; - -/** - * Enables an application to communicate with an MQTT server using blocking methods. - *- * This interface allows applications to utilize all features of the MQTT version 3.1 - * specification including:
- *- * There are two styles of MQTT client, this one and {@link IMqttAsyncClient}.
- *- * The non-blocking client can also be used in a blocking form by turning a non-blocking - * method into a blocking invocation using the following pattern:
- *- * IMqttToken token; - * token = asyncClient.method(parms).waitForCompletion(); - *- *
- * Using the non-blocking client allows an application to use a mixture of blocking and - * non-blocking styles. Using the blocking client only allows an application to use one - * style. The blocking client provides compatibility with earlier versions - * of the MQTT client.
- */ -public interface IMqttClient { //extends IMqttAsyncClient { - /** - * Connects to an MQTT server using the default options. - *The default options are specified in {@link MqttConnectOptions} class. - *
- * - * @throws MqttSecurityException when the server rejects the connect for security - * reasons - * @throws MqttException for non security related problems - * @see #connect(MqttConnectOptions) - */ - public void connect() throws MqttSecurityException, MqttException; - - /** - * Connects to an MQTT server using the specified options. - *The server to connect to is specified on the constructor. - * It is recommended to call {@link #setCallback(MqttCallback)} prior to - * connecting in order that messages destined for the client can be accepted - * as soon as the client is connected. - *
- *This is a blocking method that returns once connect completes
- * - * @param options a set of connection parameters that override the defaults. - * @throws MqttSecurityException when the server rejects the connect for security - * reasons - * @throws MqttException for non security related problems including communication errors - */ - public void connect(MqttConnectOptions options) throws MqttSecurityException, MqttException; - - /** - * Connects to an MQTT server using the specified options. - *The server to connect to is specified on the constructor. - * It is recommended to call {@link #setCallback(MqttCallback)} prior to - * connecting in order that messages destined for the client can be accepted - * as soon as the client is connected. - *
- *This is a blocking method that returns once connect completes
- * - * @param options a set of connection parameters that override the defaults. - * @return the MqttToken used for the call. Can be used to obtain the session present flag - * @throws MqttSecurityException when the server rejects the connect for security - * reasons - * @throws MqttException for non security related problems including communication errors - */ -public IMqttToken connectWithResult(MqttConnectOptions options) throws MqttSecurityException, MqttException; - - /** - * Disconnects from the server. - *An attempt is made to quiesce the client allowing outstanding - * work to complete before disconnecting. It will wait - * for a maximum of 30 seconds for work to quiesce before disconnecting. - * This method must not be called from inside {@link MqttCallback} methods. - *
- * - *This is a blocking method that returns once disconnect completes
- * - * @throws MqttException if a problem is encountered while disconnecting - */ - public void disconnect() throws MqttException; - - /** - * Disconnects from the server. - *- * The client will wait for all {@link MqttCallback} methods to - * complete. It will then wait for up to the quiesce timeout to allow for - * work which has already been initiated to complete - for example, it will - * wait for the QoS 2 flows from earlier publications to complete. When work has - * completed or after the quiesce timeout, the client will disconnect from - * the server. If the cleanSession flag was set to false and is set to false the - * next time a connection is made QoS 1 and 2 messages that - * were not previously delivered will be delivered.
- * - *This is a blocking method that returns once disconnect completes
- * - * @param quiesceTimeout the amount of time in milliseconds to allow for - * existing work to finish before disconnecting. A value of zero or less - * means the client will not quiesce. - * @throws MqttException if a problem is encountered while disconnecting - */ - public void disconnect(long quiesceTimeout) throws MqttException; - - /** - * Disconnects from the server forcibly to reset all the states. Could be useful when disconnect attempt failed. - *- * Because the client is able to establish the TCP/IP connection to a none MQTT server and it will certainly fail to - * send the disconnect packet. It will wait for a maximum of 30 seconds for work to quiesce before disconnecting and - * wait for a maximum of 10 seconds for sending the disconnect packet to server. - * - * @throws MqttException if any unexpected error - * @since 0.4.1 - */ - public void disconnectForcibly() throws MqttException; - - /** - * Disconnects from the server forcibly to reset all the states. Could be useful when disconnect attempt failed. - *
- * Because the client is able to establish the TCP/IP connection to a none MQTT server and it will certainly fail to - * send the disconnect packet. It will wait for a maximum of 30 seconds for work to quiesce before disconnecting. - * - * @param disconnectTimeout the amount of time in milliseconds to allow send disconnect packet to server. - * @throws MqttException if any unexpected error - * @since 0.4.1 - */ - public void disconnectForcibly(long disconnectTimeout) throws MqttException; - - /** - * Disconnects from the server forcibly to reset all the states. Could be useful when disconnect attempt failed. - *
- * Because the client is able to establish the TCP/IP connection to a none MQTT server and it will certainly fail to - * send the disconnect packet. - * - * @param quiesceTimeout the amount of time in milliseconds to allow for existing work to finish before - * disconnecting. A value of zero or less means the client will not quiesce. - * @param disconnectTimeout the amount of time in milliseconds to allow send disconnect packet to server. - * @throws MqttException if any unexpected error - * @since 0.4.1 - */ - public void disconnectForcibly(long quiesceTimeout, long disconnectTimeout) throws MqttException; - - /** - * Subscribe to a topic, which may include wildcards using a QoS of 1. - * - * @see #subscribe(String[], int[]) - * - * @param topicFilter the topic to subscribe to, which can include wildcards. - * @throws MqttException if there was an error registering the subscription. - * @throws MqttSecurityException if the client is not authorized to register the subscription - */ - public void subscribe(String topicFilter) throws MqttException, MqttSecurityException; - - /** - * Subscribes to a one or more topics, which may include wildcards using a QoS of 1. - * - * @see #subscribe(String[], int[]) - * - * @param topicFilters the topic to subscribe to, which can include wildcards. - * @throws MqttException if there was an error registering the subscription. - */ - public void subscribe(String[] topicFilters) throws MqttException; - - /** - * Subscribe to a topic, which may include wildcards. - * - * @see #subscribe(String[], int[]) - * - * @param topicFilter the topic to subscribe to, which can include wildcards. - * @param qos the maximum quality of service at which to subscribe. Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @throws MqttException if there was an error registering the subscription. - */ - public void subscribe(String topicFilter, int qos) throws MqttException; - - /** - * Subscribes to multiple topics, each of which may include wildcards. - *
The {@link #setCallback(MqttCallback)} method - * should be called before this method, otherwise any received messages - * will be discarded. - *
- *- * If (@link MqttConnectOptions#setCleanSession(boolean)} was set to true - * when when connecting to the server then the subscription remains in place - * until either: - *
- *- * If (@link MqttConnectOptions#setCleanSession(boolean)} was set to false - * when when connecting to the server then the subscription remains in place - * until either:
- *- * With cleanSession set to false the MQTT server will store messages on - * behalf of the client when the client is not connected. The next time the - * client connects with the same client ID the server will - * deliver the stored messages to the client. - *
- * - *The "topic filter" string used when subscribing - * may contain special characters, which allow you to subscribe to multiple topics - * at once.
- *The topic level separator is used to introduce structure into the topic, and - * can therefore be specified within the topic for that purpose. The multi-level - * wildcard and single-level wildcard can be used for subscriptions, but they - * cannot be used within a topic by the publisher of a message. - *
The number sign (#) is a wildcard character that matches - * any number of levels within a topic. For example, if you subscribe to - * finance/stock/ibm/#, you receive - * messages on these topics:
- *finance/stock/ibm
finance/stock/ibm/closingprice
finance/stock/ibm/currentprice
The multi-level wildcard - * can represent zero or more levels. Therefore, finance/# can also match - * the singular finance, where # represents zero levels. The topic - * level separator is meaningless in this context, because there are no levels - * to separate.
- * - *The multi-level wildcard can - * be specified only on its own or next to the topic level separator character. - * Therefore, # and finance/# are both valid, but finance# is - * not valid. The multi-level wildcard must be the last character - * used within the topic tree. For example, finance/# is valid but - * finance/#/closingprice is not valid.
The plus sign (+) is a wildcard character that matches only one topic - * level. For example, finance/stock/+ matches - * finance/stock/ibm and finance/stock/xyz, - * but not finance/stock/ibm/closingprice. Also, because the single-level - * wildcard matches only a single level, finance/+ does not match finance.
- * - *Use - * the single-level wildcard at any level in the topic tree, and in conjunction - * with the multilevel wildcard. Specify the single-level wildcard next to the - * topic level separator, except when it is specified on its own. Therefore, - * + and finance/+ are both valid, but finance+ is - * not valid. The single-level wildcard can be used at the end of the - * topic tree or within the topic tree. - * For example, finance/+ and finance/+/ibm are both valid.
- *This is a blocking method that returns once subscribe completes
- * - * @param topicFilters one or more topics to subscribe to, which can include wildcards. - * @param qos the maximum quality of service to subscribe each topic at.Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @throws MqttException if there was an error registering the subscription. - * @throws IllegalArgumentException if the two supplied arrays are not the same size. - */ - public void subscribe(String[] topicFilters, int[] qos) throws MqttException; - - /** - * Subscribe to a topic, which may include wildcards using a QoS of 1. - * - * @see #subscribe(String[], int[]) - * - * @param topicFilter the topic to subscribe to, which can include wildcards. - * @param messageListener a callback to handle incoming messages - * @throws MqttException if there was an error registering the subscription. - * @throws MqttSecurityException if the client is not authorized to register the subscription - */ -public void subscribe(String topicFilter, IMqttMessageListener messageListener) throws MqttException, MqttSecurityException; - - /** - * Subscribes to a one or more topics, which may include wildcards using a QoS of 1. - * - * @see #subscribe(String[], int[]) - * - * @param topicFilters the topic to subscribe to, which can include wildcards. - * @param messageListeners one or more callbacks to handle incoming messages - * @throws MqttException if there was an error registering the subscription. - */ -public void subscribe(String[] topicFilters, IMqttMessageListener[] messageListeners) throws MqttException; - - /** - * Subscribe to a topic, which may include wildcards. - * - * @see #subscribe(String[], int[]) - * - * @param topicFilter the topic to subscribe to, which can include wildcards. - * @param qos the maximum quality of service at which to subscribe. Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @param messageListener a callback to handle incoming messages - * @throws MqttException if there was an error registering the subscription. - */ -public void subscribe(String topicFilter, int qos, IMqttMessageListener messageListener) throws MqttException; - - /** - * Subscribes to multiple topics, each of which may include wildcards. - *The {@link #setCallback(MqttCallback)} method - * should be called before this method, otherwise any received messages - * will be discarded. - *
- *- * If (@link MqttConnectOptions#setCleanSession(boolean)} was set to true - * when when connecting to the server then the subscription remains in place - * until either:
- *- * If (@link MqttConnectOptions#setCleanSession(boolean)} was set to false - * when when connecting to the server then the subscription remains in place - * until either:
- *- * With cleanSession set to false the MQTT server will store messages on - * behalf of the client when the client is not connected. The next time the - * client connects with the same client ID the server will - * deliver the stored messages to the client. - *
- * - *The "topic filter" string used when subscribing - * may contain special characters, which allow you to subscribe to multiple topics - * at once.
- *The topic level separator is used to introduce structure into the topic, and - * can therefore be specified within the topic for that purpose. The multi-level - * wildcard and single-level wildcard can be used for subscriptions, but they - * cannot be used within a topic by the publisher of a message. - *
The number sign (#) is a wildcard character that matches - * any number of levels within a topic. For example, if you subscribe to - * finance/stock/ibm/#, you receive - * messages on these topics:
- *finance/stock/ibm
finance/stock/ibm/closingprice
finance/stock/ibm/currentprice
The multi-level wildcard - * can represent zero or more levels. Therefore, finance/# can also match - * the singular finance, where # represents zero levels. The topic - * level separator is meaningless in this context, because there are no levels - * to separate.
- * - *The multi-level wildcard can - * be specified only on its own or next to the topic level separator character. - * Therefore, # and finance/# are both valid, but finance# is - * not valid. The multi-level wildcard must be the last character - * used within the topic tree. For example, finance/# is valid but - * finance/#/closingprice is not valid.
The plus sign (+) is a wildcard character that matches only one topic - * level. For example, finance/stock/+ matches - * finance/stock/ibm and finance/stock/xyz, - * but not finance/stock/ibm/closingprice. Also, because the single-level - * wildcard matches only a single level, finance/+ does not match finance.
- * - *Use - * the single-level wildcard at any level in the topic tree, and in conjunction - * with the multilevel wildcard. Specify the single-level wildcard next to the - * topic level separator, except when it is specified on its own. Therefore, - * + and finance/+ are both valid, but finance+ is - * not valid. The single-level wildcard can be used at the end of the - * topic tree or within the topic tree. - * For example, finance/+ and finance/+/ibm are both valid.
- *This is a blocking method that returns once subscribe completes
- * - * @param topicFilters one or more topics to subscribe to, which can include wildcards. - * @param qos the maximum quality of service to subscribe each topic at.Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @param messageListeners one or more callbacks to handle incoming messages - * @throws MqttException if there was an error registering the subscription. - * @throws IllegalArgumentException if the two supplied arrays are not the same size. - */ - public void subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) throws MqttException; - - /** - * Subscribe to a topic, which may include wildcards using a QoS of 1. - * - * @see #subscribeWithResponse(String[], int[]) - * - * @param topicFilter the topic to subscribe to, which can include wildcards. - * @return token used to track the subscribe after it has completed. - * @throws MqttException if there was an error registering the subscription. - */ - public IMqttToken subscribeWithResponse(String topicFilter) throws MqttException; - - /** - * Subscribe to a topic, which may include wildcards using a QoS of 1. - * - * @see #subscribeWithResponse(String[], int[]) - * - * @param topicFilter the topic to subscribe to, which can include wildcards. - * @param messageListener a callback to handle incoming messages - * @return token used to track the subscribe after it has completed. - * @throws MqttException if there was an error registering the subscription. - */ - public IMqttToken subscribeWithResponse(String topicFilter, IMqttMessageListener messageListener) throws MqttException; - - - /** - * Subscribe to a topic, which may include wildcards. - * - * @see #subscribeWithResponse(String[], int[]) - * - * @param topicFilter the topic to subscribe to, which can include wildcards. - * @param qos the maximum quality of service at which to subscribe. Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @return token used to track the subscribe after it has completed. - * @throws MqttException if there was an error registering the subscription. - */ - public IMqttToken subscribeWithResponse(String topicFilter, int qos) throws MqttException; - - /** - * Subscribe to a topic, which may include wildcards. - * - * @see #subscribeWithResponse(String[], int[]) - * - * @param topicFilter the topic to subscribe to, which can include wildcards. - * @param qos the maximum quality of service at which to subscribe. Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @param messageListener a callback to handle incoming messages - * @return token used to track the subscribe after it has completed. - * @throws MqttException if there was an error registering the subscription. - */ - public IMqttToken subscribeWithResponse(String topicFilter, int qos, IMqttMessageListener messageListener) throws MqttException; - - /** - * Subscribes to a one or more topics, which may include wildcards using a QoS of 1. - * - * @see #subscribeWithResponse(String[], int[]) - * - * @param topicFilters the topic to subscribe to, which can include wildcards. - * @return token used to track the subscribe after it has completed. - * @throws MqttException if there was an error registering the subscription. - */ - public IMqttToken subscribeWithResponse(String[] topicFilters) throws MqttException; - - /** - * Subscribes to a one or more topics, which may include wildcards using a QoS of 1. - * - * @see #subscribeWithResponse(String[], int[]) - * - * @param topicFilters the topic to subscribe to, which can include wildcards. - * @param messageListeners one or more callbacks to handle incoming messages - * @return token used to track the subscribe after it has completed. - * @throws MqttException if there was an error registering the subscription. - */ - public IMqttToken subscribeWithResponse(String[] topicFilters, IMqttMessageListener[] messageListeners) throws MqttException; - - /** - * Subscribes to multiple topics, each of which may include wildcards. - *The {@link #setCallback(MqttCallback)} method - * should be called before this method, otherwise any received messages - * will be discarded. - *
- *- * If (@link MqttConnectOptions#setCleanSession(boolean)} was set to true - * when when connecting to the server then the subscription remains in place - * until either:
- *- * If (@link MqttConnectOptions#setCleanSession(boolean)} was set to false - * when when connecting to the server then the subscription remains in place - * until either:
- *- * With cleanSession set to false the MQTT server will store messages on - * behalf of the client when the client is not connected. The next time the - * client connects with the same client ID the server will - * deliver the stored messages to the client. - *
- * - *The "topic filter" string used when subscribing - * may contain special characters, which allow you to subscribe to multiple topics - * at once.
- *The topic level separator is used to introduce structure into the topic, and - * can therefore be specified within the topic for that purpose. The multi-level - * wildcard and single-level wildcard can be used for subscriptions, but they - * cannot be used within a topic by the publisher of a message. - *
The number sign (#) is a wildcard character that matches - * any number of levels within a topic. For example, if you subscribe to - * finance/stock/ibm/#, you receive - * messages on these topics:
- *finance/stock/ibm
finance/stock/ibm/closingprice
finance/stock/ibm/currentprice
The multi-level wildcard - * can represent zero or more levels. Therefore, finance/# can also match - * the singular finance, where # represents zero levels. The topic - * level separator is meaningless in this context, because there are no levels - * to separate.
- * - *The multi-level wildcard can - * be specified only on its own or next to the topic level separator character. - * Therefore, # and finance/# are both valid, but finance# is - * not valid. The multi-level wildcard must be the last character - * used within the topic tree. For example, finance/# is valid but - * finance/#/closingprice is not valid.
The plus sign (+) is a wildcard character that matches only one topic - * level. For example, finance/stock/+ matches - * finance/stock/ibm and finance/stock/xyz, - * but not finance/stock/ibm/closingprice. Also, because the single-level - * wildcard matches only a single level, finance/+ does not match finance.
- * - *Use - * the single-level wildcard at any level in the topic tree, and in conjunction - * with the multilevel wildcard. Specify the single-level wildcard next to the - * topic level separator, except when it is specified on its own. Therefore, - * + and finance/+ are both valid, but finance+ is - * not valid. The single-level wildcard can be used at the end of the - * topic tree or within the topic tree. - * For example, finance/+ and finance/+/ibm are both valid.
- *This is a blocking method that returns once subscribe completes
- * - * @param topicFilters one or more topics to subscribe to, which can include wildcards. - * @param qos the maximum quality of service to subscribe each topic at.Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @throws MqttException if there was an error registering the subscription. - * @return token used to track the subscribe after it has completed. - * @throws IllegalArgumentException if the two supplied arrays are not the same size. - */ - public IMqttToken subscribeWithResponse(String[] topicFilters, int[] qos) throws MqttException; - - /** - * Subscribes to multiple topics, each of which may include wildcards. - *The {@link #setCallback(MqttCallback)} method - * should be called before this method, otherwise any received messages - * will be discarded. - *
- *- * If (@link MqttConnectOptions#setCleanSession(boolean)} was set to true - * when when connecting to the server then the subscription remains in place - * until either:
- *- * If (@link MqttConnectOptions#setCleanSession(boolean)} was set to false - * when when connecting to the server then the subscription remains in place - * until either:
- *- * With cleanSession set to false the MQTT server will store messages on - * behalf of the client when the client is not connected. The next time the - * client connects with the same client ID the server will - * deliver the stored messages to the client. - *
- * - *The "topic filter" string used when subscribing - * may contain special characters, which allow you to subscribe to multiple topics - * at once.
- *The topic level separator is used to introduce structure into the topic, and - * can therefore be specified within the topic for that purpose. The multi-level - * wildcard and single-level wildcard can be used for subscriptions, but they - * cannot be used within a topic by the publisher of a message. - *
The number sign (#) is a wildcard character that matches - * any number of levels within a topic. For example, if you subscribe to - * finance/stock/ibm/#, you receive - * messages on these topics:
- *finance/stock/ibm
finance/stock/ibm/closingprice
finance/stock/ibm/currentprice
The multi-level wildcard - * can represent zero or more levels. Therefore, finance/# can also match - * the singular finance, where # represents zero levels. The topic - * level separator is meaningless in this context, because there are no levels - * to separate.
- * - *The multi-level wildcard can - * be specified only on its own or next to the topic level separator character. - * Therefore, # and finance/# are both valid, but finance# is - * not valid. The multi-level wildcard must be the last character - * used within the topic tree. For example, finance/# is valid but - * finance/#/closingprice is not valid.
The plus sign (+) is a wildcard character that matches only one topic - * level. For example, finance/stock/+ matches - * finance/stock/ibm and finance/stock/xyz, - * but not finance/stock/ibm/closingprice. Also, because the single-level - * wildcard matches only a single level, finance/+ does not match finance.
- * - *Use - * the single-level wildcard at any level in the topic tree, and in conjunction - * with the multilevel wildcard. Specify the single-level wildcard next to the - * topic level separator, except when it is specified on its own. Therefore, - * + and finance/+ are both valid, but finance+ is - * not valid. The single-level wildcard can be used at the end of the - * topic tree or within the topic tree. - * For example, finance/+ and finance/+/ibm are both valid.
- *This is a blocking method that returns once subscribe completes
- * - * @param topicFilters one or more topics to subscribe to, which can include wildcards. - * @param qos the maximum quality of service to subscribe each topic at.Messages - * published at a lower quality of service will be received at the published - * QoS. Messages published at a higher quality of service will be received using - * the QoS specified on the subscribe. - * @param messageListeners one or more callbacks to handle incoming messages - * @throws MqttException if there was an error registering the subscription. - * @return token used to track the subscribe after it has completed. - * @throws IllegalArgumentException if the two supplied arrays are not the same size. - */ - public IMqttToken subscribeWithResponse(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) throws MqttException; - - /** - * Requests the server unsubscribe the client from a topic. - * - * @see #unsubscribe(String[]) - * @param topicFilter the topic to unsubscribe from. It must match a topicFilter - * specified on the subscribe. - * @throws MqttException if there was an error unregistering the subscription. - */ - public void unsubscribe(String topicFilter) throws MqttException; - - /** - * Requests the server unsubscribe the client from one or more topics. - *- * Unsubcribing is the opposite of subscribing. When the server receives the - * unsubscribe request it looks to see if it can find a subscription for the - * client and then removes it. After this point the server will send no more - * messages to the client for this subscription. - *
- *The topic(s) specified on the unsubscribe must match the topic(s) - * specified in the original subscribe request for the subscribe to succeed - *
- * - *This is a blocking method that returns once unsubscribe completes
- * - * @param topicFilters one or more topics to unsubscribe from. Each topicFilter - * must match one specified on a subscribe - * @throws MqttException if there was an error unregistering the subscription. - */ - public void unsubscribe(String[] topicFilters) throws MqttException; - - - /** - * Publishes a message to a topic on the server and return once it is delivered. - *This is a convenience method, which will - * create a new {@link MqttMessage} object with a byte array payload and the - * specified QoS, and then publish it. All other values in the - * message will be set to the defaults. - *
- * - * @param topic to deliver the message to, for example "finance/stock/ibm". - * @param payload the byte array to use as the payload - * @param qos the Quality of Service to deliver the message at. Valid values are 0, 1 or 2. - * @param retained whether or not this message should be retained by the server. - * @throws MqttPersistenceException when a problem with storing the message - * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. - * @throws MqttException for other errors encountered while publishing the message. - * For instance client not connected. - * @see #publish(String, MqttMessage) - * @see MqttMessage#setQos(int) - * @see MqttMessage#setRetained(boolean) - */ - public void publish(String topic, byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException; - - /** - * Publishes a message to a topic on the server. - *- * Delivers a message to the server at the requested quality of service and returns control - * once the message has been delivered. In the event the connection fails or the client - * stops, any messages that are in the process of being delivered will be delivered once - * a connection is re-established to the server on condition that:
- *In the event that the connection breaks or the client stops it is still possible to determine - * when the delivery of the message completes. Prior to re-establishing the connection to the server:
- *When building an application, - * the design of the topic tree should take into account the following principles - * of topic name syntax and semantics:
- * - *\x0000) in - * any topic.
The following principles apply to the construction and content of a topic - * tree:
- * - *This is a blocking method that returns once publish completes
* - * - * @param topic to deliver the message to, for example "finance/stock/ibm". - * @param message to delivery to the server - * @throws MqttPersistenceException when a problem with storing the message - * @throws MqttException for other errors encountered while publishing the message. - * For instance client not connected. - */ - public void publish(String topic, MqttMessage message) throws MqttException, MqttPersistenceException; - - /** - * Sets the callback listener to use for events that happen asynchronously. - *There are a number of events that listener will be notified about. These include:
- *Other events that track the progress of an individual operation such - * as connect and subscribe can be tracked using the {@link MqttToken} passed to the - * operation
- * @see MqttCallback - * @param callback the class to callback when for events related to the client - */ - public void setCallback(MqttCallback callback); - - /** - * Get a topic object which can be used to publish messages. - *
An alternative method that should be used in preference to this one when publishing a message is:
- *When building an application, - * the design of the topic tree should take into account the following principles - * of topic name syntax and semantics:
- * - *\x0000) in - * any topic.
The following principles apply to the construction and content of a topic - * tree:
- * - *true if connected, false otherwise.
- */
- public boolean isConnected();
-
- /**
- * Returns the client ID used by this client.
- * All clients connected to the - * same server or server farm must have a unique ID. - *
- * - * @return the client ID used by this client. - */ - public String getClientId(); - - /** - * Returns the address of the server used by this client, as a URI. - *The format is the same as specified on the constructor. - *
- * - * @return the server's address, as a URI String. - * @see MqttAsyncClient#MqttAsyncClient(String, String) - */ - public String getServerURI(); - - /** - * Returns the delivery tokens for any outstanding publish operations. - *If a client has been restarted and there are messages that were in the - * process of being delivered when the client stopped this method will - * return a token for each message enabling the delivery to be tracked - * Alternately the {@link MqttCallback#deliveryComplete(IMqttDeliveryToken)} - * callback can be used to track the delivery of outstanding messages. - *
- *If a client connects with cleanSession true then there will be no - * delivery tokens as the cleanSession option deletes all earlier state. - * For state to be remembered the client must connect with cleanSession - * set to false
- * @return zero or more delivery tokens - */ - public IMqttDeliveryToken[] getPendingDeliveryTokens(); - - /** - * If manualAcks is set to true, then on completion of the messageArrived callback - * the MQTT acknowledgements are not sent. You must call messageArrivedComplete - * to send those acknowledgements. This allows finer control over when the acks are - * sent. The default behaviour, when manualAcks is false, is to send the MQTT - * acknowledgements automatically at the successful completion of the messageArrived - * callback method. - * @param manualAcks if set to true, MQTT acknowledgements are not sent. - */ - public void setManualAcks(boolean manualAcks); - - /** - * Indicate that the application has completed processing the message with id messageId. - * This will cause the MQTT acknowledgement to be sent to the server. - * @param messageId the MQTT message id to be acknowledged - * @param qos the MQTT QoS of the message to be acknowledged - * @throws MqttException if there was a problem sending the acknowledgement - */ - public void messageArrivedComplete(int messageId, int qos) throws MqttException; - - /** - * Close the client - * Releases all resource associated with the client. After the client has - * been closed it cannot be reused. For instance attempts to connect will fail. - * @throws MqttException if the client is not disconnected. - */ - public void close() throws MqttException; -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttDeliveryToken.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttDeliveryToken.java deleted file mode 100644 index 8d74de9..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttDeliveryToken.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.eclipse.paho.client.mqttv3; -/** - * Provides a mechanism for tracking the delivery of a message. - * - *A subclass of IMqttToken that allows the delivery of a message to be tracked. - * Unlike instances of IMqttToken delivery tokens can be used across connection - * and client restarts. This enables the delivery of a messages to be tracked - * after failures. There are two approaches - *
- * An action is in progress until either:
- *Until the message has been delivered, the message being delivered will
- * be returned. Once the message has been delivered null will be
- * returned.
- * @return the message associated with this token or null if already delivered.
- * @throws MqttException if there was a problem completing retrieving the message
- */
- public MqttMessage getMessage() throws MqttException;
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttMessageListener.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttMessageListener.java
deleted file mode 100644
index 10ae31a..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttMessageListener.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2015 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Ian Craggs - initial API and implementation and/or initial documentation
- */
-
-package org.eclipse.paho.client.mqttv3;
-
-/**
- * Implementers of this interface will be notified when a message arrives.
- *
- */
-public interface IMqttMessageListener {
- /**
- * This method is called when a message arrives from the server.
- *
- *
- * This method is invoked synchronously by the MQTT client. An - * acknowledgment is not sent back to the server until this - * method returns cleanly.
- *
- * If an implementation of this method throws an Exception, then the
- * client will be shut down. When the client is next re-connected, any QoS
- * 1 or 2 messages will be redelivered by the server.
- * Any additional messages which arrive while an - * implementation of this method is running, will build up in memory, and - * will then back up on the network.
- *- * If an application needs to persist data, then it - * should ensure the data is persisted prior to returning from this method, as - * after returning from this method, the message is considered to have been - * delivered, and will not be reproducible.
- *- * It is possible to send a new message within an implementation of this callback - * (for example, a response to this message), but the implementation must not - * disconnect the client, as it will be impossible to send an acknowledgment for - * the message being processed, and a deadlock will occur.
- * - * @param topic name of the topic on the message was published to - * @param message the actual message. - * @throws Exception if a terminal error has occurred, and the client should be - * shut down. - */ - public void messageArrived(String topic, MqttMessage message) throws Exception; -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttToken.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttToken.java deleted file mode 100644 index d19ccde..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/IMqttToken.java +++ /dev/null @@ -1,163 +0,0 @@ -/************************************************************************** - * Copyright (c) 2009, 2012 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - * Ian Craggs - MQTT 3.1.1 support - */ -package org.eclipse.paho.client.mqttv3; - -import org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage; - -/** - * Provides a mechanism for tracking the completion of an asynchronous task. - * - *When using the asynchronous/non-blocking MQTT programming interface all - * methods/operations that take any time (and in particular those that involve - * any network operation) return control to the caller immediately. The operation - * then proceeds to run in the background so as not to block the invoking thread. - * An IMqttToken is used to track the state of the operation. An application can use the - * token to wait for an operation to complete. A token is passed to callbacks - * once the operation completes and provides context linking it to the original - * request. A token is associated with a single operation.
- *- * An action is in progress until either:
- *The timeout specifies the maximum time it will block for. If the action - * completes before the timeout then control returns immediately, if not - * it will block until the timeout expires.
- *If the action being tracked fails or the timeout expires an exception will - * be thrown. In the event of a timeout the action may complete after timeout. - *
- * - * @param timeout the maximum amount of time to wait for, in milliseconds. - * @throws MqttException if there was a problem with the action associated with the token. - */ - public void waitForCompletion(long timeout) throws MqttException; - - /** - * Returns whether or not the action has finished. - *True will be returned both in the case where the action finished successfully - * and in the case where it failed. If the action failed {@link #getException()} will - * be non null. - *
- * @return whether or not the action has finished. - */ - public boolean isComplete(); - - /** - * Returns an exception providing more detail if an operation failed. - *While an action in in progress and when an action completes successfully - * null will be returned. Certain errors like timeout or shutting down will not - * set the exception as the action has not failed or completed at that time - *
- * @return exception may return an exception if the operation failed. Null will be - * returned while action is in progress and if action completes successfully. - */ - public MqttException getException(); - - /** - * Register a listener to be notified when an action completes. - *Once a listener is registered it will be invoked when the action the token - * is associated with either succeeds or fails. - *
- * @param listener to be invoked once the action completes - */ - public void setActionCallback(IMqttActionListener listener); - - /** - * Return the async listener for this token. - * @return listener that is set on the token or null if a listener is not registered. - */ - public IMqttActionListener getActionCallback(); - - /** - * Returns the MQTT client that is responsible for processing the asynchronous - * action - * @return the client - */ - public IMqttAsyncClient getClient(); - - /** - * Returns the topic string(s) for the action being tracked by this - * token. If the action has not been initiated or the action has not - * topic associated with it such as connect then null will be returned. - * - * @return the topic string(s) for the subscribe being tracked by this token or null - */ - public String[] getTopics(); - - /** - * Store some context associated with an action. - *Allows the caller of an action to store some context that can be - * accessed from within the ActionListener associated with the action. This - * can be useful when the same ActionListener is associated with multiple - * actions
- * @param userContext to associate with an action - */ - public void setUserContext(Object userContext); - - /** - * Retrieve the context associated with an action. - *Allows the ActionListener associated with an action to retrieve any context - * that was associated with the action when the action was invoked. If not - * context was provided null is returned.
- - * @return Object context associated with an action or null if there is none. - */ - public Object getUserContext(); - - /** - * Returns the message ID of the message that is associated with the token. - * A message id of zero will be returned for tokens associated with - * connect, disconnect and ping operations as there can only ever - * be one of these outstanding at a time. For other operations - * the MQTT message id flowed over the network. - * @return the message ID of the message that is associated with the token - */ - public int getMessageId(); - - /** - * @return the granted QoS list from a suback - */ - public int[] getGrantedQos(); - - /** - * @return the session present flag from a connack - */ - public boolean getSessionPresent(); - - /** - * @return the response wire message - */ - public MqttWireMessage getResponse(); - -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttAsyncClient.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttAsyncClient.java deleted file mode 100644 index ae5150b..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttAsyncClient.java +++ /dev/null @@ -1,1610 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2016 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - * Ian Craggs - MQTT 3.1.1 support - * Ian Craggs - per subscription message handlers (bug 466579) - * Ian Craggs - ack control (bug 472172) - * James Sutton - Bug 459142 - WebSocket support for the Java client. - * James Sutton - Automatic Reconnect & Offline Buffering. - */ - -package org.eclipse.paho.client.mqttv3; - -import java.lang.reflect.Field; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Hashtable; -import java.util.Properties; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; - -import javax.net.SocketFactory; -import javax.net.ssl.SSLSocketFactory; - -import org.eclipse.paho.client.mqttv3.internal.ClientComms; -import org.eclipse.paho.client.mqttv3.internal.ConnectActionListener; -import org.eclipse.paho.client.mqttv3.internal.DisconnectedMessageBuffer; -import org.eclipse.paho.client.mqttv3.internal.ExceptionHelper; -import org.eclipse.paho.client.mqttv3.internal.NetworkModule; -import org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule; -import org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule; -import org.eclipse.paho.client.mqttv3.internal.security.SSLSocketFactoryFactory; -import org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketNetworkModule; -import org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttDisconnect; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttPublish; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttSubscribe; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttUnsubscribe; -import org.eclipse.paho.client.mqttv3.logging.Logger; -import org.eclipse.paho.client.mqttv3.logging.LoggerFactory; -import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; -import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; -import org.eclipse.paho.client.mqttv3.util.Debug; - -/** - * Lightweight client for talking to an MQTT server using non-blocking methods - * that allow an operation to run in the background. - * - *- * This class implements the non-blocking {@link IMqttAsyncClient} client - * interface allowing applications to initiate MQTT actions and then carry on - * working while the MQTT action completes on a background thread. This - * implementation is compatible with all Java SE runtimes from 1.7 and up. - *
- *- * An application can connect to an MQTT server using: - *
- *- * To enable messages to be delivered even across network and client restarts - * messages need to be safely stored until the message has been delivered at the - * requested quality of service. A pluggable persistence mechanism is provided - * to store the messages. - *
- *- * By default {@link MqttDefaultFilePersistence} is used to store messages to a - * file. If persistence is set to null then messages are stored in memory and - * hence can be lost if the client, Java runtime or device shuts down. - *
- *- * If connecting with {@link MqttConnectOptions#setCleanSession(boolean)} set to - * true it is safe to use memory persistence as all state is cleared when a - * client disconnects. If connecting with cleanSession set to false in order to - * provide reliable message delivery then a persistent message store such as the - * default one should be used. - *
- *- * The message store interface is pluggable. Different stores can be used by - * implementing the {@link MqttClientPersistence} interface and passing it to - * the clients constructor. - *
- * - * @see IMqttAsyncClient - */ -public class MqttAsyncClient implements IMqttAsyncClient { - private static final String CLASS_NAME = MqttAsyncClient.class.getName(); - private static final Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME); - - private static final String CLIENT_ID_PREFIX = "paho"; - private static final long QUIESCE_TIMEOUT = 30000; // ms - private static final long DISCONNECT_TIMEOUT = 10000; // ms - private static final char MIN_HIGH_SURROGATE = '\uD800'; - private static final char MAX_HIGH_SURROGATE = '\uDBFF'; - private String clientId; - private String serverURI; - protected ClientComms comms; - private Hashtable topics; - private MqttClientPersistence persistence; - private MqttCallback mqttCallback; - private MqttConnectOptions connOpts; - private Object userContext; - private Timer reconnectTimer; // Automatic reconnect timer - private static int reconnectDelay = 1000; // Reconnect delay, starts at 1 - // second - private boolean reconnecting = false; - private static Object clientLock = new Object(); // Simple lock - - private ScheduledExecutorService executorService; - - /** - * Create an MqttAsyncClient that is used to communicate with an MQTT - * server. - *- * The address of a server can be specified on the constructor. - * Alternatively a list containing one or more servers can be specified - * using the {@link MqttConnectOptions#setServerURIs(String[]) - * setServerURIs} method on MqttConnectOptions. - * - *
- * The serverURI parameter is typically used with the the
- * clientId parameter to form a key. The key is used to store
- * and reference messages while they are being delivered. Hence the
- * serverURI specified on the constructor must still be specified even if a
- * list of servers is specified on an MqttConnectOptions object. The
- * serverURI on the constructor must remain the same across restarts of the
- * client for delivery of messages to be maintained from a given client to a
- * given server or set of servers.
- *
- *
- * The address of the server to connect to is specified as a URI. Two types
- * of connection are supported tcp:// for a TCP connection and
- * ssl:// for a TCP connection secured by SSL/TLS. For example:
- *
tcp://localhost:1883ssl://localhost:8883
- * If the port is not specified, it will default to 1883 for
- * tcp://" URIs, and 8883 for ssl:// URIs.
- *
- * A client identifier clientId must be specified and be less
- * that 65535 characters. It must be unique across all clients connecting to
- * the same server. The clientId is used by the server to store data related
- * to the client, hence it is important that the clientId remain the same
- * when connecting to a server if durable subscriptions or reliable
- * messaging are required.
- *
- * A convenience method is provided to generate a random client id that - * should satisfy this criteria - {@link #generateClientId()}. As the client - * identifier is used by the server to identify a client when it reconnects, - * the client must use the same identifier between connections if durable - * subscriptions or reliable delivery of messages is required. - *
- *- * In Java SE, SSL can be configured in one of several ways, which the - * client will use in the following order: - *
- *SSLSocketFactory -
- * applications can use
- * {@link MqttConnectOptions#setSocketFactory(SocketFactory)} to supply a
- * factory with the appropriate SSL settings.- * In Java ME, the platform settings are used for SSL connections. - *
- * - *- * An instance of the default persistence mechanism - * {@link MqttDefaultFilePersistence} is used by the client. To specify a - * different persistence mechanism or to turn off persistence, use the - * {@link #MqttAsyncClient(String, String, MqttClientPersistence)} - * constructor. - * - * @param serverURI - * the address of the server to connect to, specified as a URI. - * Can be overridden using - * {@link MqttConnectOptions#setServerURIs(String[])} - * @param clientId - * a client identifier that is unique on the server being - * connected to - * @throws IllegalArgumentException - * if the URI does not start with "tcp://", "ssl://" or - * "local://". - * @throws IllegalArgumentException - * if the clientId is null or is greater than 65535 characters - * in length - * @throws MqttException - * if any other problem was encountered - */ - public MqttAsyncClient(String serverURI, String clientId) throws MqttException { - this(serverURI, clientId, new MqttDefaultFilePersistence()); - } - - /** - * Create an MqttAsyncClient that is used to communicate with an MQTT - * server. - *
- * The address of a server can be specified on the constructor. - * Alternatively a list containing one or more servers can be specified - * using the {@link MqttConnectOptions#setServerURIs(String[]) - * setServerURIs} method on MqttConnectOptions. - * - *
- * The serverURI parameter is typically used with the the
- * clientId parameter to form a key. The key is used to store
- * and reference messages while they are being delivered. Hence the
- * serverURI specified on the constructor must still be specified even if a
- * list of servers is specified on an MqttConnectOptions object. The
- * serverURI on the constructor must remain the same across restarts of the
- * client for delivery of messages to be maintained from a given client to a
- * given server or set of servers.
- *
- *
- * The address of the server to connect to is specified as a URI. Two types
- * of connection are supported tcp:// for a TCP connection and
- * ssl:// for a TCP connection secured by SSL/TLS. For example:
- *
tcp://localhost:1883ssl://localhost:8883
- * If the port is not specified, it will default to 1883 for
- * tcp://" URIs, and 8883 for ssl:// URIs.
- *
- * A client identifier clientId must be specified and be less
- * that 65535 characters. It must be unique across all clients connecting to
- * the same server. The clientId is used by the server to store data related
- * to the client, hence it is important that the clientId remain the same
- * when connecting to a server if durable subscriptions or reliable
- * messaging are required.
- *
- * A convenience method is provided to generate a random client id that - * should satisfy this criteria - {@link #generateClientId()}. As the client - * identifier is used by the server to identify a client when it reconnects, - * the client must use the same identifier between connections if durable - * subscriptions or reliable delivery of messages is required. - *
- *- * In Java SE, SSL can be configured in one of several ways, which the - * client will use in the following order: - *
- *SSLSocketFactory -
- * applications can use
- * {@link MqttConnectOptions#setSocketFactory(SocketFactory)} to supply a
- * factory with the appropriate SSL settings.- * In Java ME, the platform settings are used for SSL connections. - *
- *- * A persistence mechanism is used to enable reliable messaging. For - * messages sent at qualities of service (QoS) 1 or 2 to be reliably - * delivered, messages must be stored (on both the client and server) until - * the delivery of the message is complete. If messages are not safely - * stored when being delivered then a failure in the client or server can - * result in lost messages. A pluggable persistence mechanism is supported - * via the {@link MqttClientPersistence} interface. An implementer of this - * interface that safely stores messages must be specified in order for - * delivery of messages to be reliable. In addition - * {@link MqttConnectOptions#setCleanSession(boolean)} must be set to false. - * In the event that only QoS 0 messages are sent or received or - * cleanSession is set to true then a safe store is not needed. - *
- *
- * An implementation of file-based persistence is provided in class
- * {@link MqttDefaultFilePersistence} which will work in all Java SE based
- * systems. If no persistence is needed, the persistence parameter can be
- * explicitly set to null.
- *
- * The address of a server can be specified on the constructor. - * Alternatively a list containing one or more servers can be specified - * using the {@link MqttConnectOptions#setServerURIs(String[]) - * setServerURIs} method on MqttConnectOptions. - * - *
- * The serverURI parameter is typically used with the the
- * clientId parameter to form a key. The key is used to store
- * and reference messages while they are being delivered. Hence the
- * serverURI specified on the constructor must still be specified even if a
- * list of servers is specified on an MqttConnectOptions object. The
- * serverURI on the constructor must remain the same across restarts of the
- * client for delivery of messages to be maintained from a given client to a
- * given server or set of servers.
- *
- *
- * The address of the server to connect to is specified as a URI. Two types
- * of connection are supported tcp:// for a TCP connection and
- * ssl:// for a TCP connection secured by SSL/TLS. For example:
- *
tcp://localhost:1883ssl://localhost:8883
- * If the port is not specified, it will default to 1883 for
- * tcp://" URIs, and 8883 for ssl:// URIs.
- *
- * A client identifier clientId must be specified and be less
- * that 65535 characters. It must be unique across all clients connecting to
- * the same server. The clientId is used by the server to store data related
- * to the client, hence it is important that the clientId remain the same
- * when connecting to a server if durable subscriptions or reliable
- * messaging are required.
- *
- * A convenience method is provided to generate a random client id that - * should satisfy this criteria - {@link #generateClientId()}. As the client - * identifier is used by the server to identify a client when it reconnects, - * the client must use the same identifier between connections if durable - * subscriptions or reliable delivery of messages is required. - *
- *- * In Java SE, SSL can be configured in one of several ways, which the - * client will use in the following order: - *
- *SSLSocketFactory -
- * applications can use
- * {@link MqttConnectOptions#setSocketFactory(SocketFactory)} to supply a
- * factory with the appropriate SSL settings.- * In Java ME, the platform settings are used for SSL connections. - *
- *- * A persistence mechanism is used to enable reliable messaging. For - * messages sent at qualities of service (QoS) 1 or 2 to be reliably - * delivered, messages must be stored (on both the client and server) until - * the delivery of the message is complete. If messages are not safely - * stored when being delivered then a failure in the client or server can - * result in lost messages. A pluggable persistence mechanism is supported - * via the {@link MqttClientPersistence} interface. An implementer of this - * interface that safely stores messages must be specified in order for - * delivery of messages to be reliable. In addition - * {@link MqttConnectOptions#setCleanSession(boolean)} must be set to false. - * In the event that only QoS 0 messages are sent or received or - * cleanSession is set to true then a safe store is not needed. - *
- *
- * An implementation of file-based persistence is provided in class
- * {@link MqttDefaultFilePersistence} which will work in all Java SE based
- * systems. If no persistence is needed, the persistence parameter can be
- * explicitly set to null.
- *
- * Because the client is able to establish the TCP/IP connection to a none - * MQTT server and it will certainly fail to send the disconnect packet. - * - * @param quiesceTimeout - * the amount of time in milliseconds to allow for existing work - * to finish before disconnecting. A value of zero or less means - * the client will not quiesce. - * @param disconnectTimeout - * the amount of time in milliseconds to allow send disconnect - * packet to server. - * @param sendDisconnectPacket - * if true, will send the disconnect packet to the server - * @throws MqttException - * if any unexpected error - */ - public void disconnectForcibly(long quiesceTimeout, long disconnectTimeout, boolean sendDisconnectPacket) - throws MqttException { - comms.disconnectForcibly(quiesceTimeout, disconnectTimeout, sendDisconnectPacket); - } - - /* - * (non-Javadoc) - * - * @see IMqttAsyncClient#isConnected() - */ - public boolean isConnected() { - return comms.isConnected(); - } - - /* - * (non-Javadoc) - * - * @see IMqttAsyncClient#getClientId() - */ - public String getClientId() { - return clientId; - } - - /* - * (non-Javadoc) - * - * @see IMqttAsyncClient#getServerURI() - */ - public String getServerURI() { - return serverURI; - } - - /** - * Returns the currently connected Server URI Implemented due to: - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=481097 - * - * Where getServerURI only returns the URI that was provided in - * MqttAsyncClient's constructor, getCurrentServerURI returns the URI of the - * Server that the client is currently connected to. This would be different - * in scenarios where multiple server URIs have been provided to the - * MqttConnectOptions. - * - * @return the currently connected server URI - */ - public String getCurrentServerURI() { - return comms.getNetworkModules()[comms.getNetworkModuleIndex()].getServerURI(); - } - - /** - * Get a topic object which can be used to publish messages. - *
- * There are two alternative methods that should be used in preference to - * this one when publishing a message: - *
- *- * When you build an application, the design of the topic tree should take - * into account the following principles of topic name syntax and semantics: - *
- * - *- * The following principles apply to the construction and content of a topic - * tree: - *
- * - *By default, client - * sends PingReq to server to keep the connection to server. For some - * platforms which cannot use this mechanism, such as Android, developer - * needs to handle the ping request manually with this method.
- * - * @throws MqttException for other errors encountered while publishing the - * message. - */ - public IMqttToken checkPing(Object userContext, IMqttActionListener callback) throws MqttException { - final String methodName = "ping"; - MqttToken token; - // @TRACE 117=> - log.fine(CLASS_NAME, methodName, "117"); - - token = comms.checkForActivity(); - // @TRACE 118=< - log.fine(CLASS_NAME, methodName, "118"); - - return token; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#subscribe(java.lang. - * String, int, java.lang.Object, - * org.eclipse.paho.client.mqttv3.IMqttActionListener) - */ - public IMqttToken subscribe(String topicFilter, int qos, Object userContext, IMqttActionListener callback) - throws MqttException { - return this.subscribe(new String[] { topicFilter }, new int[] { qos }, userContext, callback); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#subscribe(java.lang. - * String, int) - */ - public IMqttToken subscribe(String topicFilter, int qos) throws MqttException { - return this.subscribe(new String[] { topicFilter }, new int[] { qos }, null, null); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#subscribe(java.lang. - * String[], int[]) - */ - public IMqttToken subscribe(String[] topicFilters, int[] qos) throws MqttException { - return this.subscribe(topicFilters, qos, null, null); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#subscribe(java.lang. - * String[], int[], java.lang.Object, - * org.eclipse.paho.client.mqttv3.IMqttActionListener) - */ - public IMqttToken subscribe(String[] topicFilters, int[] qos, Object userContext, IMqttActionListener callback) - throws MqttException { - final String methodName = "subscribe"; - - if (topicFilters.length != qos.length) { - throw new IllegalArgumentException(); - } - - // remove any message handlers for individual topics - for (int i = 0; i < topicFilters.length; ++i) { - this.comms.removeMessageListener(topicFilters[i]); - } - - // Only Generate Log string if we are logging at FINE level - if (log.isLoggable(Logger.FINE)) { - StringBuffer subs = new StringBuffer(); - for (int i = 0; i < topicFilters.length; i++) { - if (i > 0) { - subs.append(", "); - } - subs.append("topic=").append(topicFilters[i]).append(" qos=").append(qos[i]); - - // Check if the topic filter is valid before subscribing - MqttTopic.validate(topicFilters[i], true/* allow wildcards */); - } - // @TRACE 106=Subscribe topicFilter={0} userContext={1} callback={2} - log.fine(CLASS_NAME, methodName, "106", new Object[] { subs.toString(), userContext, callback }); - } - - MqttToken token = new MqttToken(getClientId()); - token.setActionCallback(callback); - token.setUserContext(userContext); - token.internalTok.setTopics(topicFilters); - - MqttSubscribe register = new MqttSubscribe(topicFilters, qos); - - comms.sendNoWait(register, token); - // @TRACE 109=< - log.fine(CLASS_NAME, methodName, "109"); - - return token; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#subscribe(java.lang. - * String, int, java.lang.Object, - * org.eclipse.paho.client.mqttv3.IMqttActionListener) - */ - public IMqttToken subscribe(String topicFilter, int qos, Object userContext, IMqttActionListener callback, - IMqttMessageListener messageListener) throws MqttException { - - return this.subscribe(new String[] { topicFilter }, new int[] { qos }, userContext, callback, - new IMqttMessageListener[] { messageListener }); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#subscribe(java.lang. - * String, int) - */ - public IMqttToken subscribe(String topicFilter, int qos, IMqttMessageListener messageListener) - throws MqttException { - return this.subscribe(new String[] { topicFilter }, new int[] { qos }, null, null, - new IMqttMessageListener[] { messageListener }); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#subscribe(java.lang. - * String[], int[]) - */ - public IMqttToken subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) - throws MqttException { - return this.subscribe(topicFilters, qos, null, null, messageListeners); - } - - public IMqttToken subscribe(String[] topicFilters, int[] qos, Object userContext, IMqttActionListener callback, - IMqttMessageListener[] messageListeners) throws MqttException { - - if ((messageListeners.length != qos.length) || (qos.length != topicFilters.length)) { - throw new IllegalArgumentException(); - } - - IMqttToken token = this.subscribe(topicFilters, qos, userContext, callback); - - // add message handlers to the list for this client - for (int i = 0; i < topicFilters.length; ++i) { - this.comms.setMessageListener(topicFilters[i], messageListeners[i]); - } - - return token; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.paho.client.mqttv3.IMqttAsyncClient#unsubscribe(java.lang. - * String, java.lang.Object, - * org.eclipse.paho.client.mqttv3.IMqttActionListener) - */ - public IMqttToken unsubscribe(String topicFilter, Object userContext, IMqttActionListener callback) - throws MqttException { - return unsubscribe(new String[] { topicFilter }, userContext, callback); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.paho.client.mqttv3.IMqttAsyncClient#unsubscribe(java.lang. - * String) - */ - public IMqttToken unsubscribe(String topicFilter) throws MqttException { - return unsubscribe(new String[] { topicFilter }, null, null); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.paho.client.mqttv3.IMqttAsyncClient#unsubscribe(java.lang. - * String[]) - */ - public IMqttToken unsubscribe(String[] topicFilters) throws MqttException { - return unsubscribe(topicFilters, null, null); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.paho.client.mqttv3.IMqttAsyncClient#unsubscribe(java.lang. - * String[], java.lang.Object, - * org.eclipse.paho.client.mqttv3.IMqttActionListener) - */ - public IMqttToken unsubscribe(String[] topicFilters, Object userContext, IMqttActionListener callback) - throws MqttException { - final String methodName = "unsubscribe"; - - // Only Generate Log string if we are logging at FINE level - if (log.isLoggable(Logger.FINE)) { - String subs = ""; - for (int i = 0; i < topicFilters.length; i++) { - if (i > 0) { - subs += ", "; - } - subs += topicFilters[i]; - } - - // @TRACE 107=Unsubscribe topic={0} userContext={1} callback={2} - log.fine(CLASS_NAME, methodName, "107", new Object[] { subs, userContext, callback }); - } - - for (int i = 0; i < topicFilters.length; i++) { - // Check if the topic filter is valid before unsubscribing - // Although we already checked when subscribing, but invalid - // topic filter is meanless for unsubscribing, just prohibit it - // to reduce unnecessary control packet send to broker. - MqttTopic.validate(topicFilters[i], true/* allow wildcards */); - } - - // remove message handlers from the list for this client - for (int i = 0; i < topicFilters.length; ++i) { - this.comms.removeMessageListener(topicFilters[i]); - } - - MqttToken token = new MqttToken(getClientId()); - token.setActionCallback(callback); - token.setUserContext(userContext); - token.internalTok.setTopics(topicFilters); - - MqttUnsubscribe unregister = new MqttUnsubscribe(topicFilters); - - comms.sendNoWait(unregister, token); - // @TRACE 110=< - log.fine(CLASS_NAME, methodName, "110"); - - return token; - } - - /* - * (non-Javadoc) - * - * @see IMqttAsyncClient#setCallback(MqttCallback) - */ - public void setCallback(MqttCallback callback) { - this.mqttCallback = callback; - comms.setCallback(callback); - } - - /* - * (non-Javadoc) - * - * @see IMqttAsyncClient#setManualAcks(manualAcks) - */ - public void setManualAcks(boolean manualAcks) { - comms.setManualAcks(manualAcks); - } - - public void messageArrivedComplete(int messageId, int qos) throws MqttException { - comms.messageArrivedComplete(messageId, qos); - } - - /** - * Returns a randomly generated client identifier based on the the fixed - * prefix (paho) and the system time. - *- * When cleanSession is set to false, an application must ensure it uses the - * same client identifier when it reconnects to the server to resume state - * and maintain assured message delivery. - *
- * - * @return a generated client identifier - * @see MqttConnectOptions#setCleanSession(boolean) - */ - public static String generateClientId() { - // length of nanoTime = 15, so total length = 19 < 65535(defined in - // spec) - return CLIENT_ID_PREFIX + System.nanoTime(); - - } - - /* - * (non-Javadoc) - * - * @see IMqttAsyncClient#getPendingDeliveryTokens() - */ - public IMqttDeliveryToken[] getPendingDeliveryTokens() { - return comms.getPendingDeliveryTokens(); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.paho.client.mqttv3.IMqttAsyncClient#publish(java.lang.String, - * byte[], int, boolean, java.lang.Object, - * org.eclipse.paho.client.mqttv3.IMqttActionListener) - */ - public IMqttDeliveryToken publish(String topic, byte[] payload, int qos, boolean retained, Object userContext, - IMqttActionListener callback) throws MqttException, MqttPersistenceException { - MqttMessage message = new MqttMessage(payload); - message.setQos(qos); - message.setRetained(retained); - return this.publish(topic, message, userContext, callback); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.paho.client.mqttv3.IMqttAsyncClient#publish(java.lang.String, - * byte[], int, boolean) - */ - public IMqttDeliveryToken publish(String topic, byte[] payload, int qos, boolean retained) - throws MqttException, MqttPersistenceException { - return this.publish(topic, payload, qos, retained, null, null); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.paho.client.mqttv3.IMqttAsyncClient#publish(java.lang.String, - * org.eclipse.paho.client.mqttv3.MqttMessage) - */ - public IMqttDeliveryToken publish(String topic, MqttMessage message) - throws MqttException, MqttPersistenceException { - return this.publish(topic, message, null, null); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.paho.client.mqttv3.IMqttAsyncClient#publish(java.lang.String, - * org.eclipse.paho.client.mqttv3.MqttMessage, java.lang.Object, - * org.eclipse.paho.client.mqttv3.IMqttActionListener) - */ - public IMqttDeliveryToken publish(String topic, MqttMessage message, Object userContext, - IMqttActionListener callback) throws MqttException, MqttPersistenceException { - final String methodName = "publish"; - // @TRACE 111=< topic={0} message={1}userContext={1} callback={2} - log.fine(CLASS_NAME, methodName, "111", new Object[] { topic, userContext, callback }); - - // Checks if a topic is valid when publishing a message. - MqttTopic.validate(topic, false/* wildcards NOT allowed */); - - MqttDeliveryToken token = new MqttDeliveryToken(getClientId()); - token.setActionCallback(callback); - token.setUserContext(userContext); - token.setMessage(message); - token.internalTok.setTopics(new String[] { topic }); - - MqttPublish pubMsg = new MqttPublish(topic, message); - comms.sendNoWait(pubMsg, token); - - // @TRACE 112=< - log.fine(CLASS_NAME, methodName, "112"); - - return token; - } - - /** - * User triggered attempt to reconnect - * - * @throws MqttException - * if there is an issue with reconnecting - */ - public void reconnect() throws MqttException { - final String methodName = "reconnect"; - // @Trace 500=Attempting to reconnect client: {0} - log.fine(CLASS_NAME, methodName, "500", new Object[] { this.clientId }); - // Some checks to make sure that we're not attempting to reconnect an - // already connected client - if (comms.isConnected()) { - throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_CLIENT_CONNECTED); - } - if (comms.isConnecting()) { - throw new MqttException(MqttException.REASON_CODE_CONNECT_IN_PROGRESS); - } - if (comms.isDisconnecting()) { - throw new MqttException(MqttException.REASON_CODE_CLIENT_DISCONNECTING); - } - if (comms.isClosed()) { - throw new MqttException(MqttException.REASON_CODE_CLIENT_CLOSED); - } - // We don't want to spam the server - stopReconnectCycle(); - - attemptReconnect(); - } - - /** - * Attempts to reconnect the client to the server. If successful it will - * make sure that there are no further reconnects scheduled. However if the - * connect fails, the delay will double up to 128 seconds and will - * re-schedule the reconnect for after the delay. - * - * Any thrown exceptions are logged but not acted upon as it is assumed that - * they are being thrown due to the server being offline and so reconnect - * attempts will continue. - */ - private void attemptReconnect() { - final String methodName = "attemptReconnect"; - // @Trace 500=Attempting to reconnect client: {0} - log.fine(CLASS_NAME, methodName, "500", new Object[] { this.clientId }); - try { - connect(this.connOpts, this.userContext, new MqttReconnectActionListener(methodName)); - } catch (MqttSecurityException ex) { - // @TRACE 804=exception - log.fine(CLASS_NAME, methodName, "804", null, ex); - } catch (MqttException ex) { - // @TRACE 804=exception - log.fine(CLASS_NAME, methodName, "804", null, ex); - } - } - - private void startReconnectCycle() { - String methodName = "startReconnectCycle"; - // @Trace 503=Start reconnect timer for client: {0}, delay: {1} - log.fine(CLASS_NAME, methodName, "503", new Object[] { this.clientId, new Long(reconnectDelay) }); - reconnectTimer = new Timer("MQTT Reconnect: " + clientId); - reconnectTimer.schedule(new ReconnectTask(), reconnectDelay); - } - - private void stopReconnectCycle() { - String methodName = "stopReconnectCycle"; - // @Trace 504=Stop reconnect timer for client: {0} - log.fine(CLASS_NAME, methodName, "504", new Object[] { this.clientId }); - synchronized (clientLock) { - if (this.connOpts.isAutomaticReconnect()) { - if (reconnectTimer != null) { - reconnectTimer.cancel(); - reconnectTimer = null; - } - reconnectDelay = 1000; // Reset Delay Timer - } - } - } - - private class ReconnectTask extends TimerTask { - private static final String methodName = "ReconnectTask.run"; - - public void run() { - // @Trace 506=Triggering Automatic Reconnect attempt. - log.fine(CLASS_NAME, methodName, "506"); - attemptReconnect(); - } - } - - class MqttReconnectCallback implements MqttCallbackExtended { - - final boolean automaticReconnect; - - MqttReconnectCallback(boolean isAutomaticReconnect) { - automaticReconnect = isAutomaticReconnect; - } - - public void connectionLost(Throwable cause) { - if (automaticReconnect) { - // Automatic reconnect is set so make sure comms is in resting - // state - comms.setRestingState(true); - reconnecting = true; - startReconnectCycle(); - } - } - - public void messageArrived(String topic, MqttMessage message) throws Exception { - } - - public void deliveryComplete(IMqttDeliveryToken token) { - } - - public void connectComplete(boolean reconnect, String serverURI) { - } - - } - - class MqttReconnectActionListener implements IMqttActionListener { - - final String methodName; - - MqttReconnectActionListener(String methodName) { - this.methodName = methodName; - } - - public void onSuccess(IMqttToken asyncActionToken) { - // @Trace 501=Automatic Reconnect Successful: {0} - log.fine(CLASS_NAME, methodName, "501", new Object[] { asyncActionToken.getClient().getClientId() }); - comms.setRestingState(false); - stopReconnectCycle(); - } - - public void onFailure(IMqttToken asyncActionToken, Throwable exception) { - // @Trace 502=Automatic Reconnect failed, rescheduling: {0} - log.fine(CLASS_NAME, methodName, "502", new Object[] { asyncActionToken.getClient().getClientId() }); - if (reconnectDelay < 128000) { - reconnectDelay = reconnectDelay * 2; - } - rescheduleReconnectCycle(reconnectDelay); - } - - private void rescheduleReconnectCycle(int delay) { - String reschedulemethodName = methodName + ":rescheduleReconnectCycle"; - // @Trace 505=Rescheduling reconnect timer for client: {0}, delay: - // {1} - log.fine(CLASS_NAME, reschedulemethodName, "505", - new Object[] { MqttAsyncClient.this.clientId, String.valueOf(reconnectDelay) }); - synchronized (clientLock) { - if (MqttAsyncClient.this.connOpts.isAutomaticReconnect()) { - if (reconnectTimer != null) { - reconnectTimer.schedule(new ReconnectTask(), delay); - } else { - // The previous reconnect timer was cancelled - reconnectDelay = delay; - startReconnectCycle(); - } - } - } - } - - } - - /** - * Sets the DisconnectedBufferOptions for this client - * - * @param bufferOpts - * the {@link DisconnectedBufferOptions} - */ - public void setBufferOpts(DisconnectedBufferOptions bufferOpts) { - this.comms.setDisconnectedMessageBuffer(new DisconnectedMessageBuffer(bufferOpts)); - } - - /** - * Returns the number of messages in the Disconnected Message Buffer - * - * @return Count of messages in the buffer - */ - public int getBufferedMessageCount() { - return this.comms.getBufferedMessageCount(); - } - - /** - * Returns a message from the Disconnected Message Buffer - * - * @param bufferIndex - * the index of the message to be retrieved. - * @return the message located at the bufferIndex - */ - public MqttMessage getBufferedMessage(int bufferIndex) { - return this.comms.getBufferedMessage(bufferIndex); - } - - /** - * Deletes a message from the Disconnected Message Buffer - * - * @param bufferIndex - * the index of the message to be deleted. - */ - public void deleteBufferedMessage(int bufferIndex) { - this.comms.deleteBufferedMessage(bufferIndex); - } - - /** - * Returns the current number of outgoing in-flight messages being sent by - * the client. Note that this number cannot be guaranteed to be 100% - * accurate as some messages may have been sent or queued in the time taken - * for this method to return. - * - * @return the current number of in-flight messages. - */ - public int getInFlightMessageCount() { - return this.comms.getActualInFlight(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#close() - */ - public void close() throws MqttException { - close(false); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#close() - */ - public void close(boolean force) throws MqttException { - final String methodName = "close"; - // @TRACE 113=< - log.fine(CLASS_NAME, methodName, "113"); - comms.close(force); - // @TRACE 114=> - log.fine(CLASS_NAME, methodName, "114"); - - } - - /** - * Return a debug object that can be used to help solve problems. - * - * @return the {@link Debug} object - */ - public Debug getDebug() { - return new Debug(clientId, comms); - } - -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttCallback.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttCallback.java deleted file mode 100644 index 21d9c10..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttCallback.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - */ -package org.eclipse.paho.client.mqttv3; - - -/** - * Enables an application to be notified when asynchronous - * events related to the client occur. - * Classes implementing this interface - * can be registered on both types of client: {@link IMqttClient#setCallback(MqttCallback)} - * and {@link IMqttAsyncClient#setCallback(MqttCallback)} - */ -public interface MqttCallback { - /** - * This method is called when the connection to the server is lost. - * - * @param cause the reason behind the loss of connection. - */ - public void connectionLost(Throwable cause); - - /** - * This method is called when a message arrives from the server. - * - *- * This method is invoked synchronously by the MQTT client. An - * acknowledgment is not sent back to the server until this - * method returns cleanly.
- *
- * If an implementation of this method throws an Exception, then the
- * client will be shut down. When the client is next re-connected, any QoS
- * 1 or 2 messages will be redelivered by the server.
- * Any additional messages which arrive while an - * implementation of this method is running, will build up in memory, and - * will then back up on the network.
- *- * If an application needs to persist data, then it - * should ensure the data is persisted prior to returning from this method, as - * after returning from this method, the message is considered to have been - * delivered, and will not be reproducible.
- *- * It is possible to send a new message within an implementation of this callback - * (for example, a response to this message), but the implementation must not - * disconnect the client, as it will be impossible to send an acknowledgment for - * the message being processed, and a deadlock will occur.
- * - * @param topic name of the topic on the message was published to - * @param message the actual message. - * @throws Exception if a terminal error has occurred, and the client should be - * shut down. - */ - public void messageArrived(String topic, MqttMessage message) throws Exception; - - /** - * Called when delivery for a message has been completed, and all - * acknowledgments have been received. For QoS 0 messages it is - * called once the message has been handed to the network for - * delivery. For QoS 1 it is called when PUBACK is received and - * for QoS 2 when PUBCOMP is received. The token will be the same - * token as that returned when the message was published. - * - * @param token the delivery token associated with the message. - */ - public void deliveryComplete(IMqttDeliveryToken token); - -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttCallbackExtended.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttCallbackExtended.java deleted file mode 100644 index 7c7adf2..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttCallbackExtended.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * James Sutton - Initial Contribution for Automatic Reconnect & Offline Buffering - */ -package org.eclipse.paho.client.mqttv3; - -/** - * Extension of {@link MqttCallback} to allow new callbacks - * without breaking the API for existing applications. - * Classes implementing this interface can be registered on - * both types of client: {@link IMqttClient#setCallback(MqttCallback)} - * and {@link IMqttAsyncClient#setCallback(MqttCallback)} - */ -public interface MqttCallbackExtended extends MqttCallback { - - /** - * Called when the connection to the server is completed successfully. - * @param reconnect If true, the connection was the result of automatic reconnect. - * @param serverURI The server URI that the connection was made to. - */ - public void connectComplete(boolean reconnect, String serverURI); - -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttClient.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttClient.java deleted file mode 100644 index c878441..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttClient.java +++ /dev/null @@ -1,735 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2015 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - * Ian Craggs - MQTT 3.1.1 support - * Ian Craggs - per subscription message handlers (bug 466579) - * Ian Craggs - ack control (bug 472172) - */ -package org.eclipse.paho.client.mqttv3; - -import java.util.Properties; -import java.util.concurrent.ScheduledExecutorService; - -import javax.net.SocketFactory; - -import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence; -import org.eclipse.paho.client.mqttv3.util.Debug; - -/** - * Lightweight client for talking to an MQTT server using methods that block - * until an operation completes. - * - *This class implements the blocking {@link IMqttClient} client interface where all - * actions block until they have completed (or timed out). - * This implementation is compatible with all Java SE runtimes from 1.7 and up. - *
- *An application can connect to an MQTT server using:
- *To enable messages to be delivered even across network and client restarts - * messages need to be safely stored until the message has been delivered at the requested - * quality of service. A pluggable persistence mechanism is provided to store the messages. - *
- *By default {@link MqttDefaultFilePersistence} is used to store messages to a file. - * If persistence is set to null then messages are stored in memory and hence can be lost - * if the client, Java runtime or device shuts down. - *
- *If connecting with {@link MqttConnectOptions#setCleanSession(boolean)} set to true it - * is safe to use memory persistence as all state it cleared when a client disconnects. If - * connecting with cleanSession set to false, to provide reliable message delivery - * then a persistent message store should be used such as the default one.
- *The message store interface is pluggable. Different stores can be used by implementing - * the {@link MqttClientPersistence} interface and passing it to the clients constructor. - *
- * - * @see IMqttClient - */ -public class MqttClient implements IMqttClient { //), DestinationProvider { - //private static final String CLASS_NAME = MqttClient.class.getName(); - //private static final Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT,CLASS_NAME); - - protected MqttAsyncClient aClient = null; // Delegate implementation to MqttAsyncClient - protected long timeToWait = -1; // How long each method should wait for action to complete - - /** - * Create an MqttClient that can be used to communicate with an MQTT server. - *- * The address of a server can be specified on the constructor. Alternatively - * a list containing one or more servers can be specified using the - * {@link MqttConnectOptions#setServerURIs(String[]) setServerURIs} method - * on MqttConnectOptions. - * - *
The serverURI parameter is typically used with the
- * the clientId parameter to form a key. The key
- * is used to store and reference messages while they are being delivered.
- * Hence the serverURI specified on the constructor must still be specified even if a list
- * of servers is specified on an MqttConnectOptions object.
- * The serverURI on the constructor must remain the same across
- * restarts of the client for delivery of messages to be maintained from a given
- * client to a given server or set of servers.
- *
- *
The address of the server to connect to is specified as a URI. Two types of
- * connection are supported tcp:// for a TCP connection and
- * ssl:// for a TCP connection secured by SSL/TLS.
- * For example:
tcp://localhost:1883ssl://localhost:8883
- * If the port is not specified, it will
- * default to 1883 for tcp://" URIs, and 8883 for ssl:// URIs.
- *
- * A client identifier clientId must be specified and be less that 65535 characters.
- * It must be unique across all clients connecting to the same
- * server. The clientId is used by the server to store data related to the client,
- * hence it is important that the clientId remain the same when connecting to a server
- * if durable subscriptions or reliable messaging are required.
- *
A convenience method is provided to generate a random client id that - * should satisfy this criteria - {@link #generateClientId()}. As the client identifier - * is used by the server to identify a client when it reconnects, the client must use the - * same identifier between connections if durable subscriptions or reliable - * delivery of messages is required. - *
- *- * In Java SE, SSL can be configured in one of several ways, which the - * client will use in the following order: - *
- *SSLSocketFactory - applications can
- * use {@link MqttConnectOptions#setSocketFactory(SocketFactory)} to supply
- * a factory with the appropriate SSL settings.In Java ME, the platform settings are used for SSL connections.
- * - *An instance of the default persistence mechanism {@link MqttDefaultFilePersistence} - * is used by the client. To specify a different persistence mechanism or to turn - * off persistence, use the {@link #MqttClient(String, String, MqttClientPersistence)} - * constructor. - * - * @param serverURI the address of the server to connect to, specified as a URI. Can be overridden using - * {@link MqttConnectOptions#setServerURIs(String[])} - * @param clientId a client identifier that is unique on the server being connected to - * @throws IllegalArgumentException if the URI does not start with - * "tcp://", "ssl://" or "local://". - * @throws IllegalArgumentException if the clientId is null or is greater than 65535 characters in length - * @throws MqttException if any other problem was encountered - */ - public MqttClient(String serverURI, String clientId) throws MqttException { - this(serverURI,clientId, new MqttDefaultFilePersistence()); - } - - /** - * Create an MqttClient that can be used to communicate with an MQTT server. - *
- * The address of a server can be specified on the constructor. Alternatively - * a list containing one or more servers can be specified using the - * {@link MqttConnectOptions#setServerURIs(String[]) setServerURIs} method - * on MqttConnectOptions. - * - *
The serverURI parameter is typically used with the
- * the clientId parameter to form a key. The key
- * is used to store and reference messages while they are being delivered.
- * Hence the serverURI specified on the constructor must still be specified even if a list
- * of servers is specified on an MqttConnectOptions object.
- * The serverURI on the constructor must remain the same across
- * restarts of the client for delivery of messages to be maintained from a given
- * client to a given server or set of servers.
- *
- *
The address of the server to connect to is specified as a URI. Two types of
- * connection are supported tcp:// for a TCP connection and
- * ssl:// for a TCP connection secured by SSL/TLS.
- * For example:
tcp://localhost:1883ssl://localhost:8883
- * If the port is not specified, it will
- * default to 1883 for tcp://" URIs, and 8883 for ssl:// URIs.
- *
- * A client identifier clientId must be specified and be less that 65535 characters.
- * It must be unique across all clients connecting to the same
- * server. The clientId is used by the server to store data related to the client,
- * hence it is important that the clientId remain the same when connecting to a server
- * if durable subscriptions or reliable messaging are required.
- *
A convenience method is provided to generate a random client id that - * should satisfy this criteria - {@link #generateClientId()}. As the client identifier - * is used by the server to identify a client when it reconnects, the client must use the - * same identifier between connections if durable subscriptions or reliable - * delivery of messages is required. - *
- *- * In Java SE, SSL can be configured in one of several ways, which the - * client will use in the following order: - *
- *SSLSocketFactory - applications can
- * use {@link MqttConnectOptions#setSocketFactory(SocketFactory)} to supply
- * a factory with the appropriate SSL settings.In Java ME, the platform settings are used for SSL connections.
- *- * A persistence mechanism is used to enable reliable messaging. - * For messages sent at qualities of service (QoS) 1 or 2 to be reliably delivered, - * messages must be stored (on both the client and server) until the delivery of the message - * is complete. If messages are not safely stored when being delivered then - * a failure in the client or server can result in lost messages. A pluggable - * persistence mechanism is supported via the {@link MqttClientPersistence} - * interface. An implementer of this interface that safely stores messages - * must be specified in order for delivery of messages to be reliable. In - * addition {@link MqttConnectOptions#setCleanSession(boolean)} must be set - * to false. In the event that only QoS 0 messages are sent or received or - * cleanSession is set to true then a safe store is not needed. - *
- *An implementation of file-based persistence is provided in
- * class {@link MqttDefaultFilePersistence} which will work in all Java SE based
- * systems. If no persistence is needed, the persistence parameter
- * can be explicitly set to null.
- * The address of a server can be specified on the constructor. Alternatively - * a list containing one or more servers can be specified using the - * {@link MqttConnectOptions#setServerURIs(String[]) setServerURIs} method - * on MqttConnectOptions. - * - *
The serverURI parameter is typically used with the
- * the clientId parameter to form a key. The key
- * is used to store and reference messages while they are being delivered.
- * Hence the serverURI specified on the constructor must still be specified even if a list
- * of servers is specified on an MqttConnectOptions object.
- * The serverURI on the constructor must remain the same across
- * restarts of the client for delivery of messages to be maintained from a given
- * client to a given server or set of servers.
- *
- *
The address of the server to connect to is specified as a URI. Two types of
- * connection are supported tcp:// for a TCP connection and
- * ssl:// for a TCP connection secured by SSL/TLS.
- * For example:
- *
tcp://localhost:1883ssl://localhost:8883If the port is not specified, it will
- * default to 1883 for tcp://" URIs, and 8883 for ssl:// URIs.
- *
- * A client identifier clientId must be specified and be less that 65535 characters.
- * It must be unique across all clients connecting to the same
- * server. The clientId is used by the server to store data related to the client,
- * hence it is important that the clientId remain the same when connecting to a server
- * if durable subscriptions or reliable messaging are required.
- *
A convenience method is provided to generate a random client id that - * should satisfy this criteria - {@link #generateClientId()}. As the client identifier - * is used by the server to identify a client when it reconnects, the client must use the - * same identifier between connections if durable subscriptions or reliable - * delivery of messages is required. - *
- *- * In Java SE, SSL can be configured in one of several ways, which the - * client will use in the following order: - *
- *SSLSocketFactory - applications can
- * use {@link MqttConnectOptions#setSocketFactory(SocketFactory)} to supply
- * a factory with the appropriate SSL settings.In Java ME, the platform settings are used for SSL connections.
- *- * A persistence mechanism is used to enable reliable messaging. - * For messages sent at qualities of service (QoS) 1 or 2 to be reliably delivered, - * messages must be stored (on both the client and server) until the delivery of the message - * is complete. If messages are not safely stored when being delivered then - * a failure in the client or server can result in lost messages. A pluggable - * persistence mechanism is supported via the {@link MqttClientPersistence} - * interface. An implementer of this interface that safely stores messages - * must be specified in order for delivery of messages to be reliable. In - * addition {@link MqttConnectOptions#setCleanSession(boolean)} must be set - * to false. In the event that only QoS 0 messages are sent or received or - * cleanSession is set to true then a safe store is not needed. - *
- *An implementation of file-based persistence is provided in
- * class {@link MqttDefaultFilePersistence} which will work in all Java SE based
- * systems. If no persistence is needed, the persistence parameter
- * can be explicitly set to null.
- * Because the client is able to establish the TCP/IP connection to a none MQTT server and it will certainly fail to
- * send the disconnect packet.
- *
- * @param quiesceTimeout the amount of time in milliseconds to allow for existing work to finish before
- * disconnecting. A value of zero or less means the client will not quiesce.
- * @param disconnectTimeout the amount of time in milliseconds to allow send disconnect packet to server.
- * @param sendDisconnectPacket if true, will send the disconnect packet to the server
- * @throws MqttException if any unexpected error
- */
- public void disconnectForcibly(long quiesceTimeout, long disconnectTimeout, boolean sendDisconnectPacket) throws MqttException {
- aClient.disconnectForcibly(quiesceTimeout, disconnectTimeout, sendDisconnectPacket);
- }
-
- /*
- * @see IMqttClient#subscribe(String)
- */
- public void subscribe(String topicFilter) throws MqttException {
- this.subscribe(new String[] {topicFilter}, new int[] {1});
- }
-
- /*
- * @see IMqttClient#subscribe(String[])
- */
- public void subscribe(String[] topicFilters) throws MqttException {
- int[] qos = new int[topicFilters.length];
- for (int i=0; i
- * The default value is -1 which means the action will not timeout. - * In the event of a timeout the action carries on running in the - * background until it completes. The timeout is used on methods that - * block while the action is in progress. - *
- * @param timeToWaitInMillis before the action times out. A value or 0 or -1 will wait until - * the action finishes and not timeout. - * @throws IllegalArgumentException if timeToWaitInMillis is invalid - */ - public void setTimeToWait(long timeToWaitInMillis) throws IllegalArgumentException{ - if (timeToWaitInMillis < -1) { - throw new IllegalArgumentException(); - } - this.timeToWait = timeToWaitInMillis; - } - - /** - * Return the maximum time to wait for an action to complete. - * @return the time to wait - * @see MqttClient#setTimeToWait(long) - */ - public long getTimeToWait() { - return this.timeToWait; - } - - /* (non-Javadoc) - * @see org.eclipse.paho.client.mqttv3.IMqttClient#close() - */ - public void close() throws MqttException { - aClient.close(false); - } - - /* (non-Javadoc) - * @see org.eclipse.paho.client.mqttv3.IMqttClient#close() - */ - public void close(boolean force) throws MqttException { - aClient.close(force); - } - - - - /* (non-Javadoc) - * @see org.eclipse.paho.client.mqttv3.IMqttClient#getClientId() - */ - public String getClientId() { - return aClient.getClientId(); - } - - /* (non-Javadoc) - * @see org.eclipse.paho.client.mqttv3.IMqttClient#getPendingDeliveryTokens() - */ - public IMqttDeliveryToken[] getPendingDeliveryTokens() { - return aClient.getPendingDeliveryTokens(); - } - - /* (non-Javadoc) - * @see org.eclipse.paho.client.mqttv3.IMqttClient#getServerURI() - */ - public String getServerURI() { - return aClient.getServerURI(); - } - - /** - * Returns the currently connected Server URI - * Implemented due to: https://bugs.eclipse.org/bugs/show_bug.cgi?id=481097 - * - * Where getServerURI only returns the URI that was provided in - * MqttAsyncClient's constructor, getCurrentServerURI returns the URI of the - * Server that the client is currently connected to. This would be different in scenarios - * where multiple server URIs have been provided to the MqttConnectOptions. - * - * @return the currently connected server URI - */ - public String getCurrentServerURI(){ - return aClient.getCurrentServerURI(); - } - - /* (non-Javadoc) - * @see org.eclipse.paho.client.mqttv3.IMqttClient#getTopic(java.lang.String) - */ - public MqttTopic getTopic(String topic) { - return aClient.getTopic(topic); - } - - /* (non-Javadoc) - * @see org.eclipse.paho.client.mqttv3.IMqttClient#isConnected() - */ - public boolean isConnected() { - return aClient.isConnected(); - } - - /* (non-Javadoc) - * @see org.eclipse.paho.client.mqttv3.IMqttClient#setCallback(org.eclipse.paho.client.mqttv3.MqttCallback) - */ - public void setCallback(MqttCallback callback) { - aClient.setCallback(callback); - } - - /* (non-Javadoc) - * @see org.eclipse.paho.client.mqttv3.IMqttClient#setCallback(org.eclipse.paho.client.mqttv3.MqttCallback) - */ - public void setManualAcks(boolean manualAcks) { - aClient.setManualAcks(manualAcks); - } - - public void messageArrivedComplete(int messageId, int qos) throws MqttException { - aClient.messageArrivedComplete(messageId, qos); - } - - /** - * Returns a randomly generated client identifier based on the current user's login - * name and the system time. - *When cleanSession is set to false, an application must ensure it uses the - * same client identifier when it reconnects to the server to resume state and maintain - * assured message delivery.
- * @return a generated client identifier - * @see MqttConnectOptions#setCleanSession(boolean) - */ - public static String generateClientId() { - return MqttAsyncClient.generateClientId(); - } - - /** - * Will attempt to reconnect to the server after the client has lost connection. - * @throws MqttException if an error occurs attempting to reconnect - */ - public void reconnect() throws MqttException { - aClient.reconnect(); - } - - /** - * Return a debug object that can be used to help solve problems. - * @return the {@link Debug} Object. - */ - public Debug getDebug() { - return (aClient.getDebug()); - } - -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttClientPersistence.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttClientPersistence.java deleted file mode 100644 index 071846c..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttClientPersistence.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - */ -package org.eclipse.paho.client.mqttv3; - -import java.util.Enumeration; - -/** - * Represents a persistent data store, used to store outbound and inbound messages while they - * are in flight, enabling delivery to the QoS specified. You can specify an implementation - * of this interface using {@link MqttClient#MqttClient(String, String, MqttClientPersistence)}, - * which the {@link MqttClient} will use to persist QoS 1 and 2 messages. - *- * If the methods defined throw the MqttPersistenceException then the state of the data persisted - * should remain as prior to the method being called. For example, if {@link #put(String, MqttPersistable)} - * throws an exception at any point then the data will be assumed to not be in the persistent store. - * Similarly if {@link #remove(String)} throws an exception then the data will be - * assumed to still be held in the persistent store.
- *- * It is up to the persistence interface to log any exceptions or error information - * which may be required when diagnosing a persistence failure.
- */ -public interface MqttClientPersistence { - /** - * Initialise the persistent store. - * If a persistent store exists for this client ID then open it, otherwise - * create a new one. If the persistent store is already open then just return. - * An application may use the same client ID to connect to many different - * servers, so the client ID in conjunction with the - * connection will uniquely identify the persistence store required. - * - * @param clientId The client for which the persistent store should be opened. - * @param serverURI The connection string as specified when the MQTT client instance was created. - * @throws MqttPersistenceException if there was a problem opening the persistent store. - */ - public void open(String clientId, String serverURI) throws MqttPersistenceException; - - /** - * Close the persistent store that was previously opened. - * This will be called when a client application disconnects from the broker. - * @throws MqttPersistenceException if an error occurs closing the persistence store. - */ - public void close() throws MqttPersistenceException; - - /** - * Puts the specified data into the persistent store. - * @param key the key for the data, which will be used later to retrieve it. - * @param persistable the data to persist - * @throws MqttPersistenceException if there was a problem putting the data - * into the persistent store. - */ - public void put(String key, MqttPersistable persistable) throws MqttPersistenceException; - - /** - * Gets the specified data out of the persistent store. - * @param key the key for the data, which was used when originally saving it. - * @return the un-persisted data - * @throws MqttPersistenceException if there was a problem getting the data - * from the persistent store. - */ - public MqttPersistable get(String key) throws MqttPersistenceException; - - /** - * Remove the data for the specified key. - * @param key The key for the data to remove - * @throws MqttPersistenceException if there was a problem removing the data. - */ - public void remove(String key) throws MqttPersistenceException; - - /** - * Returns an Enumeration over the keys in this persistent data store. - * @return an enumeration of {@link String} objects. - * @throws MqttPersistenceException if there was a problem getting they keys - */ - public Enumeration keys() throws MqttPersistenceException; - - /** - * Clears persistence, so that it no longer contains any persisted data. - * @throws MqttPersistenceException if there was a problem clearing all data from the persistence store - */ - public void clear() throws MqttPersistenceException; - - /** - * Returns whether or not data is persisted using the specified key. - * @param key the key for data, which was used when originally saving it. - * @return True if the persistence store contains the key - * @throws MqttPersistenceException if there was a problem checking whether they key existed. - */ - public boolean containsKey(String key) throws MqttPersistenceException; -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttConnectOptions.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttConnectOptions.java deleted file mode 100644 index 2e16b7a..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttConnectOptions.java +++ /dev/null @@ -1,633 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2016 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - * Ian Craggs - MQTT 3.1.1 support - * James Sutton - Automatic Reconnect & Offline Buffering - */ -package org.eclipse.paho.client.mqttv3; - -import java.util.Properties; - -import javax.net.SocketFactory; -import javax.net.ssl.HostnameVerifier; - -import org.eclipse.paho.client.mqttv3.util.Debug; - -import java.net.URI; -import java.net.URISyntaxException; - -/** - * Holds the set of options that control how the client connects to a server. - */ -public class MqttConnectOptions { - /** - * The default keep alive interval in seconds if one is not specified - */ - public static final int KEEP_ALIVE_INTERVAL_DEFAULT = 60; - /** - * The default connection timeout in seconds if one is not specified - */ - public static final int CONNECTION_TIMEOUT_DEFAULT = 30; - /** - * The default max inflight if one is not specified - */ - public static final int MAX_INFLIGHT_DEFAULT = 10; - /** - * The default clean session setting if one is not specified - */ - public static final boolean CLEAN_SESSION_DEFAULT = true; - /** - * The default MqttVersion is 3.1.1 first, dropping back to 3.1 if that fails - */ - public static final int MQTT_VERSION_DEFAULT = 0; - /** - * Mqtt Version 3.1 - */ - public static final int MQTT_VERSION_3_1 = 3; - /** - * Mqtt Version 3.1.1 - */ - public static final int MQTT_VERSION_3_1_1 = 4; - - protected static final int URI_TYPE_TCP = 0; - protected static final int URI_TYPE_SSL = 1; - protected static final int URI_TYPE_LOCAL = 2; - protected static final int URI_TYPE_WS = 3; - protected static final int URI_TYPE_WSS = 4; - - private int keepAliveInterval = KEEP_ALIVE_INTERVAL_DEFAULT; - private int maxInflight = MAX_INFLIGHT_DEFAULT; - private String willDestination = null; - private MqttMessage willMessage = null; - private String userName; - private char[] password; - private SocketFactory socketFactory; - private Properties sslClientProps = null; - private HostnameVerifier sslHostnameVerifier = null; - private boolean cleanSession = CLEAN_SESSION_DEFAULT; - private int connectionTimeout = CONNECTION_TIMEOUT_DEFAULT; - private String[] serverURIs = null; - private int MqttVersion = MQTT_VERSION_DEFAULT; - private boolean automaticReconnect = false; - - /** - * Constructs a newMqttConnectOptions object using the
- * default values.
- *
- * The defaults are:
- * The default value is 60 seconds
- * - * @param keepAliveInterval the interval, measured in seconds, must be >= 0. - * @throws IllegalArgumentException if the keepAliveInterval was invalid - */ - public void setKeepAliveInterval(int keepAliveInterval)throws IllegalArgumentException { - if (keepAliveInterval <0 ) { - throw new IllegalArgumentException(); - } - this.keepAliveInterval = keepAliveInterval; - } - - /** - * Returns the "max inflight". - * The max inflight limits to how many messages we can send without receiving acknowledgments. - * @see #setMaxInflight(int) - * @return the max inflight - */ - public int getMaxInflight() { - return maxInflight; - } - - /** - * Sets the "max inflight". - * please increase this value in a high traffic environment. - *The default value is 10
- * @param maxInflight the number of maxInfligt messages - */ - public void setMaxInflight(int maxInflight) { - if (maxInflight < 0) { - throw new IllegalArgumentException(); - } - this.maxInflight = maxInflight; - } - - /** - * Returns the connection timeout value. - * @see #setConnectionTimeout(int) - * @return the connection timeout value. - */ - public int getConnectionTimeout() { - return connectionTimeout; - } - - /** - * Sets the connection timeout value. - * This value, measured in seconds, defines the maximum time interval - * the client will wait for the network connection to the MQTT server to be established. - * The default timeout is 30 seconds. - * A value of 0 disables timeout processing meaning the client will wait until the - * network connection is made successfully or fails. - * @param connectionTimeout the timeout value, measured in seconds. It must be >0; - */ - public void setConnectionTimeout(int connectionTimeout) { - if (connectionTimeout <0 ) { - throw new IllegalArgumentException(); - } - this.connectionTimeout = connectionTimeout; - } - - /** - * Returns the socket factory that will be used when connecting, or - *null if one has not been set.
- * @return The Socket Factory
- */
- public SocketFactory getSocketFactory() {
- return socketFactory;
- }
-
- /**
- * Sets the SocketFactory to use. This allows an application
- * to apply its own policies around the creation of network sockets. If
- * using an SSL connection, an SSLSocketFactory can be used
- * to supply application-specific security settings.
- * @param socketFactory the factory to use.
- */
- public void setSocketFactory(SocketFactory socketFactory) {
- this.socketFactory = socketFactory;
- }
-
- /**
- * Returns the topic to be used for last will and testament (LWT).
- * @return the MqttTopic to use, or null if LWT is not set.
- * @see #setWill(MqttTopic, byte[], int, boolean)
- */
- public String getWillDestination() {
- return willDestination;
- }
-
- /**
- * Returns the message to be sent as last will and testament (LWT).
- * The returned object is "read only". Calling any "setter" methods on
- * the returned object will result in an
- * IllegalStateException being thrown.
- * @return the message to use, or null if LWT is not set.
- */
- public MqttMessage getWillMessage() {
- return willMessage;
- }
-
- /**
- * Returns the SSL properties for the connection.
- * @return the properties for the SSL connection
- */
- public Properties getSSLProperties() {
- return sslClientProps;
- }
-
- /**
- * Sets the SSL properties for the connection.
- * Note that these - * properties are only valid if an implementation of the Java - * Secure Socket Extensions (JSSE) is available. These properties are - * not used if a SocketFactory has been set using - * {@link #setSocketFactory(SocketFactory)}. - * The following properties can be used:
- *com.ibm.micro.security.Password.obfuscate(char[] password).
- * This obfuscates the password using a simple and insecure XOR and Base64
- * encoding mechanism. Note that this is only a simple scrambler to
- * obfuscate clear-text passwords.com.ibm.micro.security.Password.obfuscate(char[] password).
- * This obfuscates the password using a simple and insecure XOR and Base64
- * encoding mechanism. Note that this is only a simple scrambler to
- * obfuscate clear-text passwords.- * There is no default HostnameVerifier - *
- * @param hostnameVerifier the {@link HostnameVerifier} - */ - public void setSSLHostnameVerifier(HostnameVerifier hostnameVerifier) { - this.sslHostnameVerifier = hostnameVerifier; - } - - /** - * Returns whether the client and server should remember state for the client across reconnects. - * @return the clean session flag - */ - public boolean isCleanSession() { - return this.cleanSession; - } - - /** - * Sets whether the client and server should remember state across restarts and reconnects. - *
- * Each serverURI specifies the address of a server that the client may
- * connect to. Two types of
- * connection are supported tcp:// for a TCP connection and
- * ssl:// for a TCP connection secured by SSL/TLS.
- * For example:
- *
tcp://localhost:1883ssl://localhost:8883tcp://" URIs, and 8883 for ssl:// URIs.
- * - * If serverURIs is set then it overrides the serverURI parameter passed in on the - * constructor of the MQTT client. - *
- * When an attempt to connect is initiated the client will start with the first - * serverURI in the list and work through - * the list until a connection is established with a server. If a connection cannot be made to - * any of the servers then the connect attempt fails. - *
- * Specifying a list of servers that a client may connect to has several uses: - *
Some MQTT servers support a high availability feature where two or more - * "equal" MQTT servers share state. An MQTT client can connect to any of the "equal" - * servers and be assured that messages are reliably delivered and durable subscriptions - * are maintained no matter which server the client connects to.
- *The cleansession flag must be set to false if durable subscriptions and/or reliable - * message delivery is required.
A set of servers may be specified that are not "equal" (as in the high availability - * option). As no state is shared across the servers reliable message delivery and - * durable subscriptions are not valid. The cleansession flag must be set to true if the - * hunt list mode is used
- * Used to track the the delivery progress of a message when a publish is - * executed in a non-blocking manner (run in the background)
- * - * @see MqttToken - */ -public class MqttDeliveryToken extends MqttToken implements IMqttDeliveryToken { - - - public MqttDeliveryToken() { - super(); - } - - public MqttDeliveryToken(String logContext) { - super(logContext); - } - - /** - * Returns the message associated with this token. - *Until the message has been delivered, the message being delivered will
- * be returned. Once the message has been delivered null will be
- * returned.
- * @return the message associated with this token or null if already delivered.
- * @throws MqttException if there was a problem completing retrieving the message
- */
- public MqttMessage getMessage() throws MqttException {
- return internalTok.getMessage();
- }
-
- protected void setMessage(MqttMessage msg) {
- internalTok.setMessage(msg);
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttException.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttException.java
deleted file mode 100644
index f9f88f4..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttException.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2016 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- * Ian Craggs - MQTT 3.1.1 support
- * James Sutton - Automatic Reconnect & Offline Buffering
- */
-package org.eclipse.paho.client.mqttv3;
-
-import org.eclipse.paho.client.mqttv3.internal.MessageCatalog;
-
-/**
- * Thrown if an error occurs communicating with the server.
- */
-public class MqttException extends Exception {
- private static final long serialVersionUID = 300L;
-
- /**
- * Client encountered an exception. Use the {@link #getCause()}
- * method to get the underlying reason.
- */
- public static final short REASON_CODE_CLIENT_EXCEPTION = 0x00;
-
- // CONNACK return codes
- /** The protocol version requested is not supported by the server. */
- public static final short REASON_CODE_INVALID_PROTOCOL_VERSION = 0x01;
- /** The server has rejected the supplied client ID */
- public static final short REASON_CODE_INVALID_CLIENT_ID = 0x02;
- /** The broker was not available to handle the request. */
- public static final short REASON_CODE_BROKER_UNAVAILABLE = 0x03;
- /** Authentication with the server has failed, due to a bad user name or password. */
- public static final short REASON_CODE_FAILED_AUTHENTICATION = 0x04;
- /** Not authorized to perform the requested operation */
- public static final short REASON_CODE_NOT_AUTHORIZED = 0x05;
-
- /** An unexpected error has occurred. */
- public static final short REASON_CODE_UNEXPECTED_ERROR = 0x06;
-
- /** Error from subscribe - returned from the server. */
- public static final short REASON_CODE_SUBSCRIBE_FAILED = 0x80;
-
- /**
- * Client timed out while waiting for a response from the server.
- * The server is no longer responding to keep-alive messages.
- */
- public static final short REASON_CODE_CLIENT_TIMEOUT = 32000;
-
- /**
- * Internal error, caused by no new message IDs being available.
- */
- public static final short REASON_CODE_NO_MESSAGE_IDS_AVAILABLE = 32001;
-
- /**
- * Client timed out while waiting to write messages to the server.
- */
- public static final short REASON_CODE_WRITE_TIMEOUT = 32002;
-
- /**
- * The client is already connected.
- */
- public static final short REASON_CODE_CLIENT_CONNECTED = 32100;
-
- /**
- * The client is already disconnected.
- */
- public static final short REASON_CODE_CLIENT_ALREADY_DISCONNECTED = 32101;
- /**
- * The client is currently disconnecting and cannot accept any new work.
- * This can occur when waiting on a token, and then disconnecting the client.
- * If the message delivery does not complete within the quiesce timeout
- * period, then the waiting token will be notified with an exception.
- */
- public static final short REASON_CODE_CLIENT_DISCONNECTING = 32102;
-
- /** Unable to connect to server */
- public static final short REASON_CODE_SERVER_CONNECT_ERROR = 32103;
-
- /**
- * The client is not connected to the server. The {@link MqttClient#connect()}
- * or {@link MqttClient#connect(MqttConnectOptions)} method must be called
- * first. It is also possible that the connection was lost - see
- * {@link MqttClient#setCallback(MqttCallback)} for a way to track lost
- * connections.
- */
- public static final short REASON_CODE_CLIENT_NOT_CONNECTED = 32104;
-
- /**
- * Server URI and supplied SocketFactory do not match.
- * URIs beginning tcp:// must use a javax.net.SocketFactory,
- * and URIs beginning ssl:// must use a javax.net.ssl.SSLSocketFactory.
- */
- public static final short REASON_CODE_SOCKET_FACTORY_MISMATCH = 32105;
-
- /**
- * SSL configuration error.
- */
- public static final short REASON_CODE_SSL_CONFIG_ERROR = 32106;
-
- /**
- * Thrown when an attempt to call {@link MqttClient#disconnect()} has been
- * made from within a method on {@link MqttCallback}. These methods are invoked
- * by the client's thread, and must not be used to control disconnection.
- *
- * @see MqttCallback#messageArrived(String, MqttMessage)
- */
- public static final short REASON_CODE_CLIENT_DISCONNECT_PROHIBITED = 32107;
-
- /**
- * Protocol error: the message was not recognized as a valid MQTT packet.
- * Possible reasons for this include connecting to a non-MQTT server, or
- * connecting to an SSL server port when the client isn't using SSL.
- */
- public static final short REASON_CODE_INVALID_MESSAGE = 32108;
-
- /**
- * The client has been unexpectedly disconnected from the server. The {@link #getCause() cause}
- * will provide more details.
- */
- public static final short REASON_CODE_CONNECTION_LOST = 32109;
-
- /**
- * A connect operation in already in progress, only one connect can happen
- * at a time.
- */
- public static final short REASON_CODE_CONNECT_IN_PROGRESS = 32110;
-
- /**
- * The client is closed - no operations are permitted on the client in this
- * state. New up a new client to continue.
- */
- public static final short REASON_CODE_CLIENT_CLOSED = 32111;
-
- /**
- * A request has been made to use a token that is already associated with
- * another action. If the action is complete the reset() can ve called on the
- * token to allow it to be reused.
- */
- public static final short REASON_CODE_TOKEN_INUSE = 32201;
-
- /**
- * A request has been made to send a message but the maximum number of inflight
- * messages has already been reached. Once one or more messages have been moved
- * then new messages can be sent.
- */
- public static final short REASON_CODE_MAX_INFLIGHT = 32202;
-
- /**
- * The Client has attempted to publish a message whilst in the 'resting' / offline
- * state with Disconnected Publishing enabled, however the buffer is full and
- * deleteOldestMessages is disabled, therefore no more messages can be published
- * until the client reconnects, or the application deletes buffered message
- * manually.
- */
- public static final short REASON_CODE_DISCONNECTED_BUFFER_FULL = 32203;
-
- private int reasonCode;
- private Throwable cause;
-
- /**
- * Constructs a new MqttException with the specified code
- * as the underlying reason.
- * @param reasonCode the reason code for the exception.
- */
- public MqttException(int reasonCode) {
- super();
- this.reasonCode = reasonCode;
- }
-
- /**
- * Constructs a new MqttException with the specified
- * Throwable as the underlying reason.
- * @param cause the underlying cause of the exception.
- */
- public MqttException(Throwable cause) {
- super();
- this.reasonCode = REASON_CODE_CLIENT_EXCEPTION;
- this.cause = cause;
- }
-
- /**
- * Constructs a new MqttException with the specified
- * Throwable as the underlying reason.
- * @param reason the reason code for the exception.
- * @param cause the underlying cause of the exception.
- */
- public MqttException(int reason, Throwable cause) {
- super();
- this.reasonCode = reason;
- this.cause = cause;
- }
-
-
- /**
- * Returns the reason code for this exception.
- * @return the code representing the reason for this exception.
- */
- public int getReasonCode() {
- return reasonCode;
- }
-
- /**
- * Returns the underlying cause of this exception, if available.
- * @return the Throwable that was the root cause of this exception,
- * which may be null.
- */
- public Throwable getCause() {
- return cause;
- }
-
- /**
- * Returns the detail message for this exception.
- * @return the detail message, which may be null.
- */
- public String getMessage() {
- return MessageCatalog.getMessage(reasonCode);
- }
-
- /**
- * Returns a String representation of this exception.
- * @return a String representation of this exception.
- */
- public String toString() {
- String result = getMessage() + " (" + reasonCode + ")";
- if (cause != null) {
- result = result + " - " + cause.toString();
- }
- return result;
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttMessage.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttMessage.java
deleted file mode 100644
index 06926e4..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttMessage.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- * Ian Craggs - ack control (bug 472172)
- */
-package org.eclipse.paho.client.mqttv3;
-
-/**
- * An MQTT message holds the application payload and options
- * specifying how the message is to be delivered
- * The message includes a "payload" (the body of the message)
- * represented as a byte[].
- */
-public class MqttMessage {
-
- private boolean mutable = true;
- private byte[] payload;
- private int qos = 1;
- private boolean retained = false;
- private boolean dup = false;
- private int messageId;
-
- /**
- * Utility method to validate the supplied QoS value.
- * @param qos The QoS Level
- * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2.
- */
- public static void validateQos(int qos) {
- if ((qos < 0) || (qos > 2)) {
- throw new IllegalArgumentException();
- }
- }
-
- /**
- * Constructs a message with an empty payload, and all other values
- * set to defaults.
- *
- * The defaults are:
- *
true if the message should be, or was, retained by
- * the server.
- * @see #setRetained(boolean)
- */
- public boolean isRetained() {
- return retained;
- }
-
- /**
- * Whether or not the publish message should be retained by the messaging engine.
- * Sending a message with retained set to true and with an empty
- * byte array as the payload e.g. new byte[0] will clear the
- * retained message from the server. The default value is false
- *
- * @param retained whether or not the messaging engine should retain the message.
- * @throws IllegalStateException if this message cannot be edited
- */
- public void setRetained(boolean retained) {
- checkMutable();
- this.retained = retained;
- }
-
- /**
- * Returns the quality of service for this message.
- * @return the quality of service to use, either 0, 1, or 2.
- * @see #setQos(int)
- */
- public int getQos() {
- return qos;
- }
-
- /**
- * Sets the quality of service for this message.
- * MqttConnectOptions.
- * If a persistence mechanism is not specified, the message will not be
- * delivered in the event of a client failure.
- * The message will be acknowledged across the network.
- * This is the default QoS.MqttConnectOptions.
- * If a persistence mechanism is not specified, the message will not be
- * delivered in the event of a client failure.true if the values can be changed,
- * false to prevent them from being changed.
- */
- protected void setMutable(boolean mutable) {
- this.mutable = mutable;
- }
-
- protected void checkMutable() throws IllegalStateException {
- if (!mutable) {
- throw new IllegalStateException();
- }
- }
-
- protected void setDuplicate(boolean dup) {
- this.dup = dup;
- }
-
- /**
- * Returns whether or not this message might be a duplicate of one which has
- * already been received. This will only be set on messages received from
- * the server.
- * @return true if the message might be a duplicate.
- */
- public boolean isDuplicate() {
- return this.dup;
- }
-
- /**
- * This is only to be used internally to provide the MQTT id of a message
- * received from the server. Has no effect when publishing messages.
- * @param messageId The Message ID
- */
- public void setId(int messageId) {
- this.messageId = messageId;
- }
-
- /**
- * Returns the MQTT id of the message. This is only applicable to messages
- * received from the server.
- * @return the MQTT id of the message
- */
- public int getId() {
- return this.messageId;
- }
-
-
-
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttPersistable.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttPersistable.java
deleted file mode 100644
index 95120a1..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttPersistable.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3;
-
-/**
- * Represents an object used to pass data to be persisted across the
- * {@link org.eclipse.paho.client.mqttv3.MqttClientPersistence MqttClientPersistence}
- * interface.
- * - * When data is passed across the interface the header and payload are - * separated, so that unnecessary message copies may be avoided. - * For example, if a 10 MB payload was published it would be inefficient - * to create a byte array a few bytes larger than 10 MB and copy the - * MQTT message header and payload into a contiguous byte array.
- *- * When the request to persist data is made a separate byte array and offset - * is passed for the header and payload. Only the data between - * offset and length need be persisted. - * So for example, a message to be persisted consists of a header byte - * array starting at offset 1 and length 4, plus a payload byte array - * starting at offset 30 and length 40000. There are three ways in which - * the persistence implementation may return data to the client on - * recovery:
- *MqttPersistenceException
- */
- public MqttPersistenceException() {
- super(REASON_CODE_CLIENT_EXCEPTION);
- }
-
- /**
- * Constructs a new MqttPersistenceException with the specified code
- * as the underlying reason.
- * @param reasonCode the reason code for the exception.
- */
- public MqttPersistenceException(int reasonCode) {
- super(reasonCode);
- }
- /**
- * Constructs a new MqttPersistenceException with the specified
- * Throwable as the underlying reason.
- * @param cause the underlying cause of the exception.
- */
- public MqttPersistenceException(Throwable cause) {
- super(cause);
- }
- /**
- * Constructs a new MqttPersistenceException with the specified
- * Throwable as the underlying reason.
- * @param reason the reason code for the exception.
- * @param cause the underlying cause of the exception.
- */
- public MqttPersistenceException(int reason, Throwable cause) {
- super(reason, cause);
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttPingSender.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttPingSender.java
deleted file mode 100644
index 27c090c..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttPingSender.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- */
-
-package org.eclipse.paho.client.mqttv3;
-
-import org.eclipse.paho.client.mqttv3.internal.ClientComms;
-
-/**
- * Represents an object used to send ping packet to MQTT broker
- * every keep alive interval.
- */
-public interface MqttPingSender {
-
- /**
- * Initial method. Pass interal state of current client in.
- * @param comms The core of the client, which holds the state information for pending and in-flight messages.
- */
- public void init(ClientComms comms);
-
- /**
- * Start ping sender. It will be called after connection is success.
- */
- public void start();
-
- /**
- * Stop ping sender. It is called if there is any errors or connection shutdowns.
- */
- public void stop();
-
- /**
- * Schedule next ping in certain delay.
- * @param delayInMilliseconds delay in milliseconds.
- */
- public void schedule(long delayInMilliseconds);
-
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttSecurityException.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttSecurityException.java
deleted file mode 100644
index a5791ce..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttSecurityException.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3;
-
-/**
- * Thrown when a client is not authorized to perform an operation, or
- * if there is a problem with the security configuration.
- */
-public class MqttSecurityException extends MqttException {
- private static final long serialVersionUID = 300L;
-
- /**
- * Constructs a new MqttSecurityException with the specified code
- * as the underlying reason.
- * @param reasonCode the reason code for the exception.
- */
- public MqttSecurityException(int reasonCode) {
- super(reasonCode);
- }
-
- /**
- * Constructs a new MqttSecurityException with the specified
- * Throwable as the underlying reason.
- * @param cause the underlying cause of the exception.
- */
- public MqttSecurityException(Throwable cause) {
- super(cause);
- }
- /**
- * Constructs a new MqttSecurityException with the specified
- * code and Throwable as the underlying reason.
- * @param reasonCode the reason code for the exception.
- * @param cause the underlying cause of the exception.
- */
- public MqttSecurityException(int reasonCode, Throwable cause) {
- super(reasonCode, cause);
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttToken.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttToken.java
deleted file mode 100644
index 3352835..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttToken.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributions:
- * Ian Craggs - MQTT 3.1.1 support
- */
-
-package org.eclipse.paho.client.mqttv3;
-
-import org.eclipse.paho.client.mqttv3.internal.Token;
-import org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage;
-
-/**
- * Provides a mechanism for tracking the completion of an asynchronous action.
- * - * A token that implements the ImqttToken interface is returned from all non-blocking - * method with the exception of publish. - *
- * - * @see IMqttToken - */ - -public class MqttToken implements IMqttToken { - /** - * A reference to the the class that provides most of the implementation of the - * MqttToken. MQTT application programs must not use the internal class. - */ - public Token internalTok = null; - - public MqttToken() { - } - - public MqttToken(String logContext) { - internalTok = new Token(logContext); - } - - public MqttException getException() { - return internalTok.getException(); - } - - public boolean isComplete() { - return internalTok.isComplete(); - } - - public void setActionCallback(IMqttActionListener listener) { - internalTok.setActionCallback(listener); - - } - public IMqttActionListener getActionCallback() { - return internalTok.getActionCallback(); - } - - public void waitForCompletion() throws MqttException { - internalTok.waitForCompletion(-1); - } - - public void waitForCompletion(long timeout) throws MqttException { - internalTok.waitForCompletion(timeout); - } - - public IMqttAsyncClient getClient() { - return internalTok.getClient(); - } - - public String[] getTopics() { - return internalTok.getTopics(); - } - - public Object getUserContext() { - return internalTok.getUserContext(); - } - - public void setUserContext(Object userContext) { - internalTok.setUserContext(userContext); - } - - public int getMessageId() { - return internalTok.getMessageID(); - } - - public int[] getGrantedQos() { - return internalTok.getGrantedQos(); - } - - public boolean getSessionPresent() { - return internalTok.getSessionPresent(); - } - - public MqttWireMessage getResponse() { - return internalTok.getResponse(); - } -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttTopic.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttTopic.java deleted file mode 100644 index 404e961..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/MqttTopic.java +++ /dev/null @@ -1,284 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - */ -package org.eclipse.paho.client.mqttv3; - -import java.io.UnsupportedEncodingException; - -import org.eclipse.paho.client.mqttv3.internal.ClientComms; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttPublish; -import org.eclipse.paho.client.mqttv3.util.Strings; - -/** - * Represents a topic destination, used for publish/subscribe messaging. - */ -public class MqttTopic { - - /** - * The forward slash (/) is used to separate each level within a topic tree - * and provide a hierarchical structure to the topic space. The use of the - * topic level separator is significant when the two wildcard characters are - * encountered in topics specified by subscribers. - */ - public static final String TOPIC_LEVEL_SEPARATOR = "/"; - - /** - * Multi-level wildcard The number sign (#) is a wildcard character that - * matches any number of levels within a topic. - */ - public static final String MULTI_LEVEL_WILDCARD = "#"; - - /** - * Single-level wildcard The plus sign (+) is a wildcard character that - * matches only one topic level. - */ - public static final String SINGLE_LEVEL_WILDCARD = "+"; - - /** - * Multi-level wildcard pattern(/#) - */ - public static final String MULTI_LEVEL_WILDCARD_PATTERN = TOPIC_LEVEL_SEPARATOR + MULTI_LEVEL_WILDCARD; - - /** - * Topic wildcards (#+) - */ - public static final String TOPIC_WILDCARDS = MULTI_LEVEL_WILDCARD + SINGLE_LEVEL_WILDCARD; - - //topic name and topic filter length range defined in the spec - private static final int MIN_TOPIC_LEN = 1; - private static final int MAX_TOPIC_LEN = 65535; - private static final char NUL = '\u0000'; - - private ClientComms comms; - private String name; - - /** - * @param name The Name of the topic - * @param comms The {@link ClientComms} - */ - public MqttTopic(String name, ClientComms comms) { - this.comms = comms; - this.name = name; - } - - /** - * Publishes a message on the topic. This is a convenience method, which will - * create a new {@link MqttMessage} object with a byte array payload and the - * specified QoS, and then publish it. All other values in the - * message will be set to the defaults. - - * @param payload the byte array to use as the payload - * @param qos the Quality of Service. Valid values are 0, 1 or 2. - * @param retained whether or not this message should be retained by the server. - * @return {@link MqttDeliveryToken} - * @throws MqttException If an error occurs publishing the message - * @throws MqttPersistenceException If an error occurs persisting the message - * @throws IllegalArgumentException if value of QoS is not 0, 1 or 2. - * @see #publish(MqttMessage) - * @see MqttMessage#setQos(int) - * @see MqttMessage#setRetained(boolean) - */ - public MqttDeliveryToken publish(byte[] payload, int qos, boolean retained) throws MqttException, MqttPersistenceException { - MqttMessage message = new MqttMessage(payload); - message.setQos(qos); - message.setRetained(retained); - return this.publish(message); - } - - /** - * Publishes the specified message to this topic, but does not wait for delivery - * of the message to complete. The returned {@link MqttDeliveryToken token} can be used - * to track the delivery status of the message. Once this method has - * returned cleanly, the message has been accepted for publication by the - * client. Message delivery will be completed in the background when a connection - * is available. - * - * @param message the message to publish - * @return an MqttDeliveryToken for tracking the delivery of the message - * @throws MqttException if an error occurs publishing the message - * @throws MqttPersistenceException if an error occurs persisting the message - */ - public MqttDeliveryToken publish(MqttMessage message) throws MqttException, MqttPersistenceException { - MqttDeliveryToken token = new MqttDeliveryToken(comms.getClient().getClientId()); - token.setMessage(message); - comms.sendNoWait(createPublish(message), token); - token.internalTok.waitUntilSent(); - return token; - } - - /** - * Returns the name of the queue or topic. - * - * @return the name of this destination. - */ - public String getName() { - return name; - } - - /** - * Create a PUBLISH packet from the specified message. - */ - private MqttPublish createPublish(MqttMessage message) { - return new MqttPublish(this.getName(), message); - } - - /** - * Returns a string representation of this topic. - * @return a string representation of this topic. - */ - public String toString() { - return getName(); - } - - /** - * Validate the topic name or topic filter - * - * @param topicString topic name or filter - * @param wildcardAllowed true if validate topic filter, false otherwise - * @throws IllegalArgumentException if the topic is invalid - */ - public static void validate(String topicString, boolean wildcardAllowed) - throws IllegalArgumentException{ - int topicLen = 0; - try { - topicLen = topicString.getBytes("UTF-8").length; - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException(e.getMessage()); - } - - // Spec: length check - // - All Topic Names and Topic Filters MUST be at least one character - // long - // - Topic Names and Topic Filters are UTF-8 encoded strings, they MUST - // NOT encode to more than 65535 bytes - if (topicLen < MIN_TOPIC_LEN || topicLen > MAX_TOPIC_LEN) { - throw new IllegalArgumentException(String.format("Invalid topic length, should be in range[%d, %d]!", - new Object[] { new Integer(MIN_TOPIC_LEN), new Integer(MAX_TOPIC_LEN) })); - } - - // ******************************************************************************* - // 1) This is a topic filter string that can contain wildcard characters - // ******************************************************************************* - if (wildcardAllowed) { - // Only # or + - if (Strings.equalsAny(topicString, new String[] { MULTI_LEVEL_WILDCARD, SINGLE_LEVEL_WILDCARD })) { - return; - } - - // 1) Check multi-level wildcard - // Rule: - // The multi-level wildcard can be specified only on its own or next - // to the topic level separator character. - - // - Can only contains one multi-level wildcard character - // - The multi-level wildcard must be the last character used within - // the topic tree - if (Strings.countMatches(topicString, MULTI_LEVEL_WILDCARD) > 1 - || (topicString.contains(MULTI_LEVEL_WILDCARD) && !topicString - .endsWith(MULTI_LEVEL_WILDCARD_PATTERN))) { - throw new IllegalArgumentException( - "Invalid usage of multi-level wildcard in topic string: " - + topicString); - } - - // 2) Check single-level wildcard - // Rule: - // The single-level wildcard can be used at any level in the topic - // tree, and in conjunction with the - // multilevel wildcard. It must be used next to the topic level - // separator, except when it is specified on - // its own. - validateSingleLevelWildcard(topicString); - - return; - } - - // ******************************************************************************* - // 2) This is a topic name string that MUST NOT contains any wildcard characters - // ******************************************************************************* - if (Strings.containsAny(topicString, TOPIC_WILDCARDS)) { - throw new IllegalArgumentException( - "The topic name MUST NOT contain any wildcard characters (#+)"); - } - } - - private static void validateSingleLevelWildcard(String topicString) { - char singleLevelWildcardChar = SINGLE_LEVEL_WILDCARD.charAt(0); - char topicLevelSeparatorChar = TOPIC_LEVEL_SEPARATOR.charAt(0); - - char[] chars = topicString.toCharArray(); - int length = chars.length; - char prev = NUL, next = NUL; - for (int i = 0; i < length; i++) { - prev = (i - 1 >= 0) ? chars[i - 1] : NUL; - next = (i + 1 < length) ? chars[i + 1] : NUL; - - if (chars[i] == singleLevelWildcardChar) { - // prev and next can be only '/' or none - if (prev != topicLevelSeparatorChar && prev != NUL || next != topicLevelSeparatorChar && next != NUL) { - throw new IllegalArgumentException(String.format( - "Invalid usage of single-level wildcard in topic string '%s'!", - new Object[] { topicString })); - - } - } - } - } - - /** - * Check the supplied topic name and filter match - * - * @param topicFilter topic filter: wildcards allowed - * @param topicName topic name: wildcards not allowed - * @return true if the topic matches the filter - * @throws IllegalArgumentException if the topic name or filter is invalid - */ - public static boolean isMatched(String topicFilter, String topicName) - throws IllegalArgumentException { - int curn = 0, - curf = 0; - int curn_end = topicName.length(); - int curf_end = topicFilter.length(); - - MqttTopic.validate(topicFilter, true); - MqttTopic.validate(topicName, false); - - if (topicFilter.equals(topicName)) { - return true; - } - - while (curf < curf_end && curn < curn_end) - { - if (topicName.charAt(curn) == '/' && topicFilter.charAt(curf) != '/') - break; - if (topicFilter.charAt(curf) != '+' && topicFilter.charAt(curf) != '#' && - topicFilter.charAt(curf) != topicName.charAt(curn)) - break; - if (topicFilter.charAt(curf) == '+') - { // skip until we meet the next separator, or end of string - int nextpos = curn + 1; - while (nextpos < curn_end && topicName.charAt(nextpos) != '/') - nextpos = ++curn + 1; - } - else if (topicFilter.charAt(curf) == '#') - curn = curn_end - 1; // skip until end of string - curf++; - curn++; - }; - - return (curn == curn_end) && (curf == curf_end); - } - -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/ScheduledExecutorPingSender.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/ScheduledExecutorPingSender.java deleted file mode 100644 index 511909c..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/ScheduledExecutorPingSender.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 IBM Corp. - * Copyright (c) 2017 BMW Car IT GmbH. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - */ - -package org.eclipse.paho.client.mqttv3; - -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -import org.eclipse.paho.client.mqttv3.internal.ClientComms; -import org.eclipse.paho.client.mqttv3.logging.Logger; -import org.eclipse.paho.client.mqttv3.logging.LoggerFactory; - -/** - * Default ping sender implementation - * - *This class implements the {@link IMqttPingSender} pinger interface - * allowing applications to send ping packet to server every keep alive interval. - *
- * - * @see MqttPingSender - */ -public class ScheduledExecutorPingSender implements MqttPingSender { - private static final String CLASS_NAME = ScheduledExecutorPingSender.class.getName(); - private static final Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME); - - private ClientComms comms; - private ScheduledExecutorService executorService; - private ScheduledFuture scheduledFuture; - private String clientid; - - public ScheduledExecutorPingSender(ScheduledExecutorService executorService) { - if (executorService == null) { - throw new IllegalArgumentException("ExecutorService cannot be null."); - } - this.executorService = executorService; - } - - public void init(ClientComms comms) { - if (comms == null) { - throw new IllegalArgumentException("ClientComms cannot be null."); - } - this.comms = comms; - clientid = comms.getClient().getClientId(); - } - - public void start() { - final String methodName = "start"; - - //@Trace 659=start timer for client:{0} - log.fine(CLASS_NAME, methodName, "659", new Object[]{ clientid }); - //Check ping after first keep alive interval. - schedule(comms.getKeepAlive()); - } - - public void stop() { - final String methodName = "stop"; - //@Trace 661=stop - log.fine(CLASS_NAME, methodName, "661", null); - if (scheduledFuture != null) { - scheduledFuture.cancel(true); - } - } - - public void schedule(long delayInMilliseconds) { - scheduledFuture = executorService.schedule(new PingRunnable(), delayInMilliseconds, TimeUnit.MILLISECONDS); - } - - private class PingRunnable implements Runnable { - private static final String methodName = "PingTask.run"; - - public void run() { - String originalThreadName = Thread.currentThread().getName(); - Thread.currentThread().setName("MQTT Ping: " + clientid); - //@Trace 660=Check schedule at {0} - log.fine(CLASS_NAME, methodName, "660", new Object[]{ new Long(System.currentTimeMillis()) }); - comms.checkForActivity(); - Thread.currentThread().setName(originalThreadName); - } - } -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/TimerPingSender.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/TimerPingSender.java deleted file mode 100644 index 4c93212..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/TimerPingSender.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - */ - -package org.eclipse.paho.client.mqttv3; - -import java.util.Timer; -import java.util.TimerTask; - -import org.eclipse.paho.client.mqttv3.internal.ClientComms; -import org.eclipse.paho.client.mqttv3.logging.Logger; -import org.eclipse.paho.client.mqttv3.logging.LoggerFactory; - -/** - * Default ping sender implementation - * - *This class implements the {@link MqttPingSender} pinger interface - * allowing applications to send ping packet to server every keep alive interval. - *
- * - * @see MqttPingSender - */ -public class TimerPingSender implements MqttPingSender { - private static final String CLASS_NAME = TimerPingSender.class.getName(); - private static final Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT,CLASS_NAME); - - private ClientComms comms; - private Timer timer; - - public void init(ClientComms comms) { - if (comms == null) { - throw new IllegalArgumentException("ClientComms cannot be null."); - } - this.comms = comms; - } - - public void start() { - final String methodName = "start"; - String clientid = comms.getClient().getClientId(); - - //@Trace 659=start timer for client:{0} - log.fine(CLASS_NAME, methodName, "659", new Object[]{clientid}); - - timer = new Timer("MQTT Ping: " + clientid); - //Check ping after first keep alive interval. - timer.schedule(new PingTask(), comms.getKeepAlive()); - } - - public void stop() { - final String methodName = "stop"; - //@Trace 661=stop - log.fine(CLASS_NAME, methodName, "661", null); - if(timer != null){ - timer.cancel(); - } - } - - public void schedule(long delayInMilliseconds) { - timer.schedule(new PingTask(), delayInMilliseconds); - } - - private class PingTask extends TimerTask { - private static final String methodName = "PingTask.run"; - - public void run() { - //@Trace 660=Check schedule at {0} - log.fine(CLASS_NAME, methodName, "660", new Object[]{new Long(System.currentTimeMillis())}); - comms.checkForActivity(); - } - } -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/ClientComms.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/ClientComms.java deleted file mode 100644 index 542d9df..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/ClientComms.java +++ /dev/null @@ -1,881 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2016 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - * Ian Craggs - per subscription message handlers (bug 466579) - * Ian Craggs - ack control (bug 472172) - * James Sutton - checkForActivity Token (bug 473928) - * James Sutton - Automatic Reconnect & Offline Buffering. - */ -package org.eclipse.paho.client.mqttv3.internal; - -import java.util.Enumeration; -import java.util.Properties; -import java.util.Vector; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.TimeUnit; - -import org.eclipse.paho.client.mqttv3.BufferedMessage; -import org.eclipse.paho.client.mqttv3.IMqttActionListener; -import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; -import org.eclipse.paho.client.mqttv3.IMqttMessageListener; -import org.eclipse.paho.client.mqttv3.MqttCallback; -import org.eclipse.paho.client.mqttv3.MqttCallbackExtended; -import org.eclipse.paho.client.mqttv3.MqttClientPersistence; -import org.eclipse.paho.client.mqttv3.MqttConnectOptions; -import org.eclipse.paho.client.mqttv3.MqttDeliveryToken; -import org.eclipse.paho.client.mqttv3.MqttException; -import org.eclipse.paho.client.mqttv3.MqttMessage; -import org.eclipse.paho.client.mqttv3.MqttPersistenceException; -import org.eclipse.paho.client.mqttv3.MqttPingSender; -import org.eclipse.paho.client.mqttv3.MqttToken; -import org.eclipse.paho.client.mqttv3.MqttTopic; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttConnack; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttConnect; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttDisconnect; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttPublish; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage; -import org.eclipse.paho.client.mqttv3.logging.Logger; -import org.eclipse.paho.client.mqttv3.logging.LoggerFactory; - -/** - * Handles client communications with the server. Sends and receives MQTT V3 - * messages. - */ -public class ClientComms { - public static String VERSION = "${project.version}"; - public static String BUILD_LEVEL = "L${build.level}"; - private static final String CLASS_NAME = ClientComms.class.getName(); - private static final Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT,CLASS_NAME); - - private static final byte CONNECTED = 0; - private static final byte CONNECTING = 1; - private static final byte DISCONNECTING = 2; - private static final byte DISCONNECTED = 3; - private static final byte CLOSED = 4; - - private IMqttAsyncClient client; - private int networkModuleIndex; - private NetworkModule[] networkModules; - private CommsReceiver receiver; - private CommsSender sender; - private CommsCallback callback; - private ClientState clientState; - private MqttConnectOptions conOptions; - private MqttClientPersistence persistence; - private MqttPingSender pingSender; - private CommsTokenStore tokenStore; - private boolean stoppingComms = false; - - private byte conState = DISCONNECTED; - private Object conLock = new Object(); // Used to synchronize connection state - private boolean closePending = false; - private boolean resting = false; - private DisconnectedMessageBuffer disconnectedMessageBuffer; - - private ExecutorService executorService; - - /** - * Creates a new ClientComms object, using the specified module to handle - * the network calls. - * @param client The {@link IMqttAsyncClient} - * @param persistence the {@link MqttClientPersistence} layer. - * @param pingSender the {@link MqttPingSender} - * @param executorService the {@link ExecutorService} - * @throws MqttException if an exception occurs whilst communicating with the server - */ - public ClientComms(IMqttAsyncClient client, MqttClientPersistence persistence, MqttPingSender pingSender, ExecutorService executorService) throws MqttException { - this.conState = DISCONNECTED; - this.client = client; - this.persistence = persistence; - this.pingSender = pingSender; - this.pingSender.init(this); - this.executorService = executorService; - - this.tokenStore = new CommsTokenStore(getClient().getClientId()); - this.callback = new CommsCallback(this); - this.clientState = new ClientState(persistence, tokenStore, this.callback, this, pingSender); - - callback.setClientState(clientState); - log.setResourceName(getClient().getClientId()); - } - - CommsReceiver getReceiver() { - return receiver; - } - - private void shutdownExecutorService() { - String methodName = "shutdownExecutorService"; - executorService.shutdown(); - try { - if (!executorService.awaitTermination(1, TimeUnit.SECONDS)) { - executorService.shutdownNow(); - if (!executorService.awaitTermination(1, TimeUnit.SECONDS)) { - log.fine(CLASS_NAME, methodName, "executorService did not terminate"); - } - } - } catch (InterruptedException ie) { - executorService.shutdownNow(); - Thread.currentThread().interrupt(); - } - } - - /** - * Sends a message to the server. Does not check if connected this validation must be done - * by invoking routines. - * @param message - * @param token - * @throws MqttException - */ - void internalSend(MqttWireMessage message, MqttToken token) throws MqttException { - final String methodName = "internalSend"; - //@TRACE 200=internalSend key={0} message={1} token={2} - log.fine(CLASS_NAME, methodName, "200", new Object[]{message.getKey(), message, token}); - - if (token.getClient() == null ) { - // Associate the client with the token - also marks it as in use. - token.internalTok.setClient(getClient()); - } else { - // Token is already in use - cannot reuse - //@TRACE 213=fail: token in use: key={0} message={1} token={2} - log.fine(CLASS_NAME, methodName, "213", new Object[]{message.getKey(), message, token}); - - throw new MqttException(MqttException.REASON_CODE_TOKEN_INUSE); - } - - try { - // Persist if needed and send the message - this.clientState.send(message, token); - } catch(MqttException e) { - if (message instanceof MqttPublish) { - this.clientState.undo((MqttPublish)message); - } - throw e; - } - } - - /** - * Sends a message to the broker if in connected state, but only waits for the message to be - * stored, before returning. - * @param message The {@link MqttWireMessage} to send - * @param token The {@link MqttToken} to send. - * @throws MqttException if an error occurs sending the message - */ - public void sendNoWait(MqttWireMessage message, MqttToken token) throws MqttException { - final String methodName = "sendNoWait"; - if (isConnected() || - (!isConnected() && message instanceof MqttConnect) || - (isDisconnecting() && message instanceof MqttDisconnect)) { - if(disconnectedMessageBuffer != null && disconnectedMessageBuffer.getMessageCount() != 0){ - //@TRACE 507=Client Connected, Offline Buffer available, but not empty. Adding message to buffer. message={0} - log.fine(CLASS_NAME, methodName, "507", new Object[] {message.getKey()}); - if(disconnectedMessageBuffer.isPersistBuffer()){ - this.clientState.persistBufferedMessage(message); - } - disconnectedMessageBuffer.putMessage(message, token); - } else { - this.internalSend(message, token); - } - } else if(disconnectedMessageBuffer != null) { - //@TRACE 508=Offline Buffer available. Adding message to buffer. message={0} - log.fine(CLASS_NAME, methodName, "508", new Object[] {message.getKey()}); - if(disconnectedMessageBuffer.isPersistBuffer()){ - this.clientState.persistBufferedMessage(message); - } - disconnectedMessageBuffer.putMessage(message, token); - } else { - //@TRACE 208=failed: not connected - log.fine(CLASS_NAME, methodName, "208"); - throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_CLIENT_NOT_CONNECTED); - } - } - - /** - * Close and tidy up. - * - * Call each main class and let it tidy up e.g. releasing the token - * store which normally survives a disconnect. - * @throws MqttException if not disconnected - */ - public void close(boolean force) throws MqttException { - final String methodName = "close"; - synchronized (conLock) { - if (!isClosed()) { - // Must be disconnected before close can take place or if we are being forced - if (!isDisconnected() || force) { - //@TRACE 224=failed: not disconnected - log.fine(CLASS_NAME, methodName, "224"); - - if (isConnecting()) { - throw new MqttException(MqttException.REASON_CODE_CONNECT_IN_PROGRESS); - } else if (isConnected()) { - throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_CLIENT_CONNECTED); - } else if (isDisconnecting()) { - closePending = true; - return; - } - } - - conState = CLOSED; - shutdownExecutorService(); - // ShutdownConnection has already cleaned most things - clientState.close(); - clientState = null; - callback = null; - persistence = null; - sender = null; - pingSender = null; - receiver = null; - networkModules = null; - conOptions = null; - tokenStore = null; - } - } - } - - /** - * Sends a connect message and waits for an ACK or NACK. - * Connecting is a special case which will also start up the - * network connection, receive thread, and keep alive thread. - * @param options The {@link MqttConnectOptions} for the connection - * @param token The {@link MqttToken} to track the connection - * @throws MqttException if an error occurs when connecting - */ - public void connect(MqttConnectOptions options, MqttToken token) throws MqttException { - final String methodName = "connect"; - synchronized (conLock) { - if (isDisconnected() && !closePending) { - //@TRACE 214=state=CONNECTING - log.fine(CLASS_NAME,methodName,"214"); - - conState = CONNECTING; - - conOptions = options; - - MqttConnect connect = new MqttConnect(client.getClientId(), - conOptions.getMqttVersion(), - conOptions.isCleanSession(), - conOptions.getKeepAliveInterval(), - conOptions.getUserName(), - conOptions.getPassword(), - conOptions.getWillMessage(), - conOptions.getWillDestination()); - - this.clientState.setKeepAliveSecs(conOptions.getKeepAliveInterval()); - this.clientState.setCleanSession(conOptions.isCleanSession()); - this.clientState.setMaxInflight(conOptions.getMaxInflight()); - - tokenStore.open(); - ConnectBG conbg = new ConnectBG(this, token, connect, executorService); - conbg.start(); - } - else { - // @TRACE 207=connect failed: not disconnected {0} - log.fine(CLASS_NAME,methodName,"207", new Object[] {new Byte(conState)}); - if (isClosed() || closePending) { - throw new MqttException(MqttException.REASON_CODE_CLIENT_CLOSED); - } else if (isConnecting()) { - throw new MqttException(MqttException.REASON_CODE_CONNECT_IN_PROGRESS); - } else if (isDisconnecting()) { - throw new MqttException(MqttException.REASON_CODE_CLIENT_DISCONNECTING); - } else { - throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_CLIENT_CONNECTED); - } - } - } - } - - public void connectComplete( MqttConnack cack, MqttException mex) throws MqttException { - final String methodName = "connectComplete"; - int rc = cack.getReturnCode(); - synchronized (conLock) { - if (rc == 0) { - // We've successfully connected - // @TRACE 215=state=CONNECTED - log.fine(CLASS_NAME,methodName,"215"); - - conState = CONNECTED; - return; - } - } - - // @TRACE 204=connect failed: rc={0} - log.fine(CLASS_NAME,methodName,"204", new Object[]{new Integer(rc)}); - throw mex; - } - - /** - * Shuts down the connection to the server. - * This may have been invoked as a result of a user calling disconnect or - * an abnormal disconnection. The method may be invoked multiple times - * in parallel as each thread when it receives an error uses this method - * to ensure that shutdown completes successfully. - * @param token the {@link MqttToken} To track closing the connection - * @param reason the {@link MqttException} thrown requiring the connection to be shut down. - */ - public void shutdownConnection(MqttToken token, MqttException reason) { - final String methodName = "shutdownConnection"; - boolean wasConnected; - MqttToken endToken = null; //Token to notify after disconnect completes - - // This method could concurrently be invoked from many places only allow it - // to run once. - synchronized(conLock) { - if (stoppingComms || closePending || isClosed()) { - return; - } - stoppingComms = true; - - //@TRACE 216=state=DISCONNECTING - log.fine(CLASS_NAME,methodName,"216"); - - wasConnected = (isConnected() || isDisconnecting()); - conState = DISCONNECTING; - } - - // Update the token with the reason for shutdown if it - // is not already complete. - if (token != null && !token.isComplete()) { - token.internalTok.setException(reason); - } - - // Stop the thread that is used to call the user back - // when actions complete - if (callback!= null) {callback.stop(); } - - // Stop the thread that handles inbound work from the network - if (receiver != null) {receiver.stop();} - - // Stop the network module, send and receive now not possible - try { - if (networkModules != null) { - NetworkModule networkModule = networkModules[networkModuleIndex]; - if (networkModule != null) { - networkModule.stop(); - } - } - } catch (Exception ioe) { - // Ignore as we are shutting down - } - - // Stop any new tokens being saved by app and throwing an exception if they do - tokenStore.quiesce(new MqttException(MqttException.REASON_CODE_CLIENT_DISCONNECTING)); - - // Notify any outstanding tokens with the exception of - // con or discon which may be returned and will be notified at - // the end - endToken = handleOldTokens(token, reason); - - try { - // Clean session handling and tidy up - clientState.disconnected(reason); - if (clientState.getCleanSession()) - callback.removeMessageListeners(); - }catch(Exception ex) { - // Ignore as we are shutting down - } - - if (sender != null) { sender.stop(); } - - if (pingSender != null){ - pingSender.stop(); - } - - try { - if(disconnectedMessageBuffer == null && persistence != null){ - persistence.close(); - } - - }catch(Exception ex) { - // Ignore as we are shutting down - } - // All disconnect logic has been completed allowing the - // client to be marked as disconnected. - synchronized(conLock) { - //@TRACE 217=state=DISCONNECTED - log.fine(CLASS_NAME,methodName,"217"); - - conState = DISCONNECTED; - stoppingComms = false; - } - - // Internal disconnect processing has completed. If there - // is a disconnect token or a connect in error notify - // it now. This is done at the end to allow a new connect - // to be processed and now throw a currently disconnecting error. - // any outstanding tokens and unblock any waiters - if (endToken != null & callback != null) { - callback.asyncOperationComplete(endToken); - } - - if (wasConnected && callback != null) { - // Let the user know client has disconnected either normally or abnormally - callback.connectionLost(reason); - } - - // While disconnecting, close may have been requested - try it now - synchronized(conLock) { - if (closePending) { - try { - close(true); - } catch (Exception e) { // ignore any errors as closing - } - } - } - } - - // Tidy up. There may be tokens outstanding as the client was - // not disconnected/quiseced cleanly! Work out what tokens still - // need to be notified and waiters unblocked. Store the - // disconnect or connect token to notify after disconnect is - // complete. - private MqttToken handleOldTokens(MqttToken token, MqttException reason) { - final String methodName = "handleOldTokens"; - //@TRACE 222=> - log.fine(CLASS_NAME,methodName,"222"); - - MqttToken tokToNotifyLater = null; - try { - // First the token that was related to the disconnect / shutdown may - // not be in the token table - temporarily add it if not - if (token != null) { - if (tokenStore.getToken(token.internalTok.getKey())==null) { - tokenStore.saveToken(token, token.internalTok.getKey()); - } - } - - Vector toksToNot = clientState.resolveOldTokens(reason); - Enumeration toksToNotE = toksToNot.elements(); - while(toksToNotE.hasMoreElements()) { - MqttToken tok = (MqttToken)toksToNotE.nextElement(); - - if (tok.internalTok.getKey().equals(MqttDisconnect.KEY) || - tok.internalTok.getKey().equals(MqttConnect.KEY)) { - // Its con or discon so remember and notify @ end of disc routine - tokToNotifyLater = tok; - } else { - // notify waiters and callbacks of outstanding tokens - // that a problem has occurred and disconnect is in - // progress - callback.asyncOperationComplete(tok); - } - } - }catch(Exception ex) { - // Ignore as we are shutting down - } - return tokToNotifyLater; - } - - public void disconnect(MqttDisconnect disconnect, long quiesceTimeout, MqttToken token) throws MqttException { - final String methodName = "disconnect"; - synchronized (conLock){ - if (isClosed()) { - //@TRACE 223=failed: in closed state - log.fine(CLASS_NAME,methodName,"223"); - throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_CLIENT_CLOSED); - } else if (isDisconnected()) { - //@TRACE 211=failed: already disconnected - log.fine(CLASS_NAME,methodName,"211"); - throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_CLIENT_ALREADY_DISCONNECTED); - } else if (isDisconnecting()) { - //@TRACE 219=failed: already disconnecting - log.fine(CLASS_NAME,methodName,"219"); - throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_CLIENT_DISCONNECTING); - } else if (Thread.currentThread() == callback.getThread()) { - //@TRACE 210=failed: called on callback thread - log.fine(CLASS_NAME,methodName,"210"); - // Not allowed to call disconnect() from the callback, as it will deadlock. - throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_CLIENT_DISCONNECT_PROHIBITED); - } - - //@TRACE 218=state=DISCONNECTING - log.fine(CLASS_NAME,methodName,"218"); - conState = DISCONNECTING; - DisconnectBG discbg = new DisconnectBG(disconnect,quiesceTimeout,token, executorService); - discbg.start(); - } - } - - public void disconnectForcibly(long quiesceTimeout, long disconnectTimeout) throws MqttException { - disconnectForcibly(quiesceTimeout, disconnectTimeout, true); - } - - /** - * Disconnect the connection and reset all the states. - * @param quiesceTimeout How long to wait whilst quiesing before messages are deleted. - * @param disconnectTimeout How long to wait whilst disconnecting - * @param sendDisconnectPacket If true, will send a disconnect packet - * @throws MqttException if an error occurs whilst disconnecting - */ - public void disconnectForcibly(long quiesceTimeout, long disconnectTimeout, boolean sendDisconnectPacket) throws MqttException { - // Allow current inbound and outbound work to complete - if (clientState != null) { - clientState.quiesce(quiesceTimeout); - } - MqttToken token = new MqttToken(client.getClientId()); - try { - // Send disconnect packet - if(sendDisconnectPacket) { - internalSend(new MqttDisconnect(), token); - - // Wait util the disconnect packet sent with timeout - token.waitForCompletion(disconnectTimeout); - } - } - catch (Exception ex) { - // ignore, probably means we failed to send the disconnect packet. - } - finally { - token.internalTok.markComplete(null, null); - shutdownConnection(token, null); - } - } - - public boolean isConnected() { - synchronized (conLock) { - return conState == CONNECTED; - } - } - - public boolean isConnecting() { - synchronized (conLock) { - return conState == CONNECTING; - } - } - - public boolean isDisconnected() { - synchronized (conLock) { - return conState == DISCONNECTED; - } - } - - public boolean isDisconnecting() { - synchronized (conLock) { - return conState == DISCONNECTING; - } - } - - public boolean isClosed() { - synchronized (conLock) { - return conState == CLOSED; - } - } - - public boolean isResting() { - synchronized (conLock) { - return resting; - } - } - - - public void setCallback(MqttCallback mqttCallback) { - this.callback.setCallback(mqttCallback); - } - - public void setReconnectCallback(MqttCallbackExtended callback){ - this.callback.setReconnectCallback(callback); - } - - public void setManualAcks(boolean manualAcks) { - this.callback.setManualAcks(manualAcks); - } - - public void messageArrivedComplete(int messageId, int qos) throws MqttException { - this.callback.messageArrivedComplete(messageId, qos); - } - - public void setMessageListener(String topicFilter, IMqttMessageListener messageListener) { - this.callback.setMessageListener(topicFilter, messageListener); - } - - public void removeMessageListener(String topicFilter) { - this.callback.removeMessageListener(topicFilter); - } - - protected MqttTopic getTopic(String topic) { - return new MqttTopic(topic, this); - } - public void setNetworkModuleIndex(int index) { - this.networkModuleIndex = index; - } - public int getNetworkModuleIndex() { - return networkModuleIndex; - } - public NetworkModule[] getNetworkModules() { - return networkModules; - } - public void setNetworkModules(NetworkModule[] networkModules) { - this.networkModules = networkModules; - } - public MqttDeliveryToken[] getPendingDeliveryTokens() { - return tokenStore.getOutstandingDelTokens(); - } - - protected void deliveryComplete(MqttPublish msg) throws MqttPersistenceException { - this.clientState.deliveryComplete(msg); - } - - protected void deliveryComplete(int messageId) throws MqttPersistenceException { - this.clientState.deliveryComplete(messageId); - } - - public IMqttAsyncClient getClient() { - return client; - } - - public long getKeepAlive() { - return this.clientState.getKeepAlive(); - } - - public ClientState getClientState() { - return clientState; - } - - public MqttConnectOptions getConOptions() { - return conOptions; - } - - public Properties getDebug() { - Properties props = new Properties(); - props.put("conState", new Integer(conState)); - props.put("serverURI", getClient().getServerURI()); - props.put("callback", callback); - props.put("stoppingComms", new Boolean(stoppingComms)); - return props; - } - - - - // Kick off the connect processing in the background so that it does not block. For instance - // the socket could take time to create. - private class ConnectBG implements Runnable { - ClientComms clientComms = null; - MqttToken conToken; - MqttConnect conPacket; - private String threadName; - - ConnectBG(ClientComms cc, MqttToken cToken, MqttConnect cPacket, ExecutorService executorService) { - clientComms = cc; - conToken = cToken; - conPacket = cPacket; - threadName = "MQTT Con: "+getClient().getClientId(); - } - - void start() { - executorService.execute(this); - } - - public void run() { - Thread.currentThread().setName(threadName); - final String methodName = "connectBG:run"; - MqttException mqttEx = null; - //@TRACE 220=> - log.fine(CLASS_NAME, methodName, "220"); - - try { - // Reset an exception on existing delivery tokens. - // This will have been set if disconnect occured before delivery was - // fully processed. - MqttDeliveryToken[] toks = tokenStore.getOutstandingDelTokens(); - for (int i=0; iThis class handles the connection of the AsyncClient to one of the available URLs.
- *The URLs are supplied as either the singleton when the client is created, or as a list in the connect options.
- *This class uses its own onSuccess and onFailure callbacks in preference to the user supplied callbacks.
- *An attempt is made to connect to each URL in the list until either a connection attempt succeeds or all the URLs have been tried
- *If a connection succeeds then the users token is notified and the users onSuccess callback is called.
- *If a connection fails then another URL in the list is attempted, otherwise the users token is notified - * and the users onFailure callback is called
- */ -public class ConnectActionListener implements IMqttActionListener { - - private MqttClientPersistence persistence; - private MqttAsyncClient client; - private ClientComms comms; - private MqttConnectOptions options; - private MqttToken userToken; - private Object userContext; - private IMqttActionListener userCallback; - private int originalMqttVersion; - private MqttCallbackExtended mqttCallbackExtended; - private boolean reconnect; - -/** - * @param persistence The {@link MqttClientPersistence} layer - * @param client the {@link MqttAsyncClient} - * @param comms {@link ClientComms} - * @param options the {@link MqttConnectOptions} - * @param userToken the {@link MqttToken} - * @param userContext the User Context Object - * @param userCallback the {@link IMqttActionListener} as the callback for the user - * @param reconnect If true, this is a reconnect attempt - */ - public ConnectActionListener( - MqttAsyncClient client, - MqttClientPersistence persistence, - ClientComms comms, - MqttConnectOptions options, - MqttToken userToken, - Object userContext, - IMqttActionListener userCallback, - boolean reconnect) { - this.persistence = persistence; - this.client = client; - this.comms = comms; - this.options = options; - this.userToken = userToken; - this.userContext = userContext; - this.userCallback = userCallback; - this.originalMqttVersion = options.getMqttVersion(); - this.reconnect = reconnect; - } - - /** - * If the connect succeeded then call the users onSuccess callback - * - * @param token the {@link IMqttToken} from the successful connection - */ - public void onSuccess(IMqttToken token) { - if (originalMqttVersion == MqttConnectOptions.MQTT_VERSION_DEFAULT) { - options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_DEFAULT); - } - userToken.internalTok.markComplete(token.getResponse(), null); - userToken.internalTok.notifyComplete(); - userToken.internalTok.setClient(this.client); // fix bug 469527 - maybe should be set elsewhere? - - comms.notifyConnect(); - - if (userCallback != null) { - userToken.setUserContext(userContext); - userCallback.onSuccess(userToken); - } - - if(mqttCallbackExtended != null){ - String serverURI = comms.getNetworkModules()[comms.getNetworkModuleIndex()].getServerURI(); - mqttCallbackExtended.connectComplete(reconnect, serverURI); - } - - - } - - /** - * The connect failed, so try the next URI on the list. - * If there are no more URIs, then fail the overall connect. - * - * @param token the {@link IMqttToken} from the failed connection attempt - * @param exception the {@link Throwable} exception from the failed connection attempt - */ - public void onFailure(IMqttToken token, Throwable exception) { - - int numberOfURIs = comms.getNetworkModules().length; - int index = comms.getNetworkModuleIndex(); - - if ((index + 1) < numberOfURIs || (originalMqttVersion == MqttConnectOptions.MQTT_VERSION_DEFAULT && options.getMqttVersion() == MqttConnectOptions.MQTT_VERSION_3_1_1)) { - - if (originalMqttVersion == MqttConnectOptions.MQTT_VERSION_DEFAULT) { - if (options.getMqttVersion() == MqttConnectOptions.MQTT_VERSION_3_1_1) { - options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1); - } - else { - options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1); - comms.setNetworkModuleIndex(index + 1); - } - } - else { - comms.setNetworkModuleIndex(index + 1); - } - try { - connect(); - } - catch (MqttPersistenceException e) { - onFailure(token, e); // try the next URI in the list - } - } - else { - if (originalMqttVersion == MqttConnectOptions.MQTT_VERSION_DEFAULT) { - options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_DEFAULT); - } - MqttException ex; - if (exception instanceof MqttException) { - ex = (MqttException) exception; - } - else { - ex = new MqttException(exception); - } - userToken.internalTok.markComplete(null, ex); - userToken.internalTok.notifyComplete(); - userToken.internalTok.setClient(this.client); // fix bug 469527 - maybe should be set elsewhere? - - if (userCallback != null) { - userToken.setUserContext(userContext); - userCallback.onFailure(userToken, exception); - } - } - } - - /** - * 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); - } - } - - /** - * Set the MqttCallbackExtened callback to receive connectComplete callbacks - * @param mqttCallbackExtended the {@link MqttCallbackExtended} to be called when the connection completes - */ - public void setMqttCallbackExtended(MqttCallbackExtended mqttCallbackExtended) { - this.mqttCallbackExtended = mqttCallbackExtended; - } - -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/DestinationProvider.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/DestinationProvider.java deleted file mode 100644 index 39a9059..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/DestinationProvider.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - */ -package org.eclipse.paho.client.mqttv3.internal; - -import org.eclipse.paho.client.mqttv3.MqttTopic; - -/** - * This interface exists to act as a common type for - * MqttClient and MqttMIDPClient so they can be passed to - * ClientComms without either client class need to know - * about the other. - * Specifically, this allows the MIDP client to work - * without the non-MIDP MqttClient/MqttConnectOptions - * classes being present. - */ -public interface DestinationProvider { - public MqttTopic getTopic(String topic); -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/DisconnectedMessageBuffer.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/DisconnectedMessageBuffer.java deleted file mode 100644 index 14425e4..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/DisconnectedMessageBuffer.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * James Sutton - Initial Contribution for Automatic Reconnect & Offline Buffering - */ -package org.eclipse.paho.client.mqttv3.internal; - -import java.util.ArrayList; - -import org.eclipse.paho.client.mqttv3.BufferedMessage; -import org.eclipse.paho.client.mqttv3.DisconnectedBufferOptions; -import org.eclipse.paho.client.mqttv3.MqttException; -import org.eclipse.paho.client.mqttv3.MqttToken; -import org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage; -import org.eclipse.paho.client.mqttv3.logging.Logger; -import org.eclipse.paho.client.mqttv3.logging.LoggerFactory; - -public class DisconnectedMessageBuffer implements Runnable { - - private static final String CLASS_NAME = "DisconnectedMessageBuffer"; - private static final Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME); - private DisconnectedBufferOptions bufferOpts; - private ArrayList buffer; - private Object bufLock = new Object(); // Used to synchronise the buffer - private IDisconnectedBufferCallback callback; - - public DisconnectedMessageBuffer(DisconnectedBufferOptions options){ - this.bufferOpts = options; - buffer = new ArrayList(); - } - - /** - * This will add a new message to the offline buffer, - * if the buffer is full and deleteOldestMessages is enabled - * then the 0th item in the buffer will be deleted and the - * new message will be added. If it is not enabled then an - * MqttException will be thrown. - * @param message the {@link MqttWireMessage} that will be buffered - * @param token the associated {@link MqttToken} - * @throws MqttException if the Buffer is full - */ - public void putMessage(MqttWireMessage message, MqttToken token) throws MqttException{ - BufferedMessage bufferedMessage = new BufferedMessage(message, token); - synchronized (bufLock) { - if(buffer.size() < bufferOpts.getBufferSize()){ - buffer.add(bufferedMessage); - } else if(bufferOpts.isDeleteOldestMessages() == true){ - buffer.remove(0); - buffer.add(bufferedMessage); - }else { - throw new MqttException(MqttException.REASON_CODE_DISCONNECTED_BUFFER_FULL); - } - } - } - - /** - * Retrieves a message from the buffer at the given index. - * @param messageIndex the index of the message to be retrieved in the buffer - * @return the {@link BufferedMessage} - */ - public BufferedMessage getMessage(int messageIndex){ - synchronized (bufLock) { - return((BufferedMessage) buffer.get(messageIndex)); - } - } - - - /** - * Removes a message from the buffer - * @param messageIndex the index of the message to be deleted in the buffer - */ - public void deleteMessage(int messageIndex){ - synchronized (bufLock) { - buffer.remove(messageIndex); - } - } - - /** - * Returns the number of messages currently in the buffer - * @return The count of messages in the buffer - */ - public int getMessageCount() { - synchronized (bufLock) { - return buffer.size(); - } - } - - /** - * Flushes the buffer of messages into an open connection - */ - public void run() { - final String methodName = "run"; - // @TRACE 516=Restoring all buffered messages. - log.fine(CLASS_NAME, methodName, "516"); - while(getMessageCount() > 0){ - try { - BufferedMessage bufferedMessage = getMessage(0); - callback.publishBufferedMessage(bufferedMessage); - // Publish was successful, remove message from buffer. - deleteMessage(0); - } catch (MqttException ex) { - // Error occurred attempting to publish buffered message likely because the client is not connected - // @TRACE 517=Error occured attempting to publish buffered message due to disconnect. - log.warning(CLASS_NAME, methodName, "517"); - break; - } - } - } - - public void setPublishCallback(IDisconnectedBufferCallback callback) { - this.callback = callback; - } - - public boolean isPersistBuffer(){ - return bufferOpts.isPersistBuffer(); - } - -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/ExceptionHelper.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/ExceptionHelper.java deleted file mode 100644 index 02b4c41..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/ExceptionHelper.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - */ -package org.eclipse.paho.client.mqttv3.internal; - -import org.eclipse.paho.client.mqttv3.MqttException; -import org.eclipse.paho.client.mqttv3.MqttSecurityException; - -/** - * Utility class to help create exceptions of the correct type. - */ -public class ExceptionHelper { - public static MqttException createMqttException(int reasonCode) { - if ((reasonCode == MqttException.REASON_CODE_FAILED_AUTHENTICATION) || - (reasonCode == MqttException.REASON_CODE_NOT_AUTHORIZED)) { - return new MqttSecurityException(reasonCode); - } - - return new MqttException(reasonCode); - } - - public static MqttException createMqttException(Throwable cause) { - if (cause.getClass().getName().equals("java.security.GeneralSecurityException")) { - return new MqttSecurityException(cause); - } - return new MqttException(cause); - } - - /** - * Returns whether or not the specified class is available to the current - * class loader. This is used to protect the code against using Java SE - * APIs on Java ME. - * @param className The name of the class - * @return If true, the class is available - */ - public static boolean isClassAvailable(String className) { - boolean result = false; - try { - Class.forName(className); - result = true; - } - catch (ClassNotFoundException ex) { - } - return result; - } - - // Utility classes should not have a public or default constructor. - private ExceptionHelper() { - } -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/FileLock.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/FileLock.java deleted file mode 100644 index ebad8bb..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/FileLock.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - */ -package org.eclipse.paho.client.mqttv3.internal; -/** - * FileLock - used to obtain a lock that can be used to prevent other MQTT clients - * using the same persistent store. If the lock is already held then an exception - * is thrown. - * - * Some Java runtimes such as JME MIDP do not support file locking or even - * the Java classes that support locking. The class is coded to both compile - * and work on all Java runtimes. In Java runtimes that do not support - * locking it will look as though a lock has been obtained but in reality - * no lock has been obtained. - */ -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.lang.reflect.Method; - -public class FileLock { - private File lockFile; - private RandomAccessFile file; - private Object fileLock; - - /** - * Creates an NIO FileLock on the specified file if on a suitable Java runtime. - * @param clientDir the a File of the directory to contain the lock file. - * @param lockFilename name of the the file to lock - * @throws Exception if the lock could not be obtained for any reason - */ - public FileLock(File clientDir, String lockFilename) throws Exception { - // Create a file to obtain a lock on. - lockFile = new File(clientDir,lockFilename); - if (ExceptionHelper.isClassAvailable("java.nio.channels.FileLock")) { - try { - this.file = new RandomAccessFile(lockFile,"rw"); - Method m = file.getClass().getMethod("getChannel",new Class[]{}); - Object channel = m.invoke(file,new Object[]{}); - m = channel.getClass().getMethod("tryLock",new Class[]{}); - this.fileLock = m.invoke(channel, new Object[]{}); - } catch(NoSuchMethodException nsme) { - this.fileLock = null; - } catch(IllegalArgumentException iae) { - this.fileLock = null; - } catch(IllegalAccessException iae) { - this.fileLock = null; - } - if (fileLock == null) { - // Lock not obtained - release(); - throw new Exception("Problem obtaining file lock"); - } - } - } - - /** - * Releases the lock. - */ - public void release() { - try { - if (fileLock != null) { - Method m = fileLock.getClass().getMethod("release",new Class[]{}); - m.invoke(fileLock, new Object[]{}); - fileLock = null; - } - } catch (Exception e) { - // Ignore exceptions - } - if (file != null) { - try { - file.close(); - } catch (IOException e) { - } - file = null; - } - - if (lockFile != null && lockFile.exists()) { - lockFile.delete(); - } - lockFile = null; - } - -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/IDisconnectedBufferCallback.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/IDisconnectedBufferCallback.java deleted file mode 100644 index f38df43..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/IDisconnectedBufferCallback.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * James Sutton - Initial Contribution for Automatic Reconnect & Offline Buffering - */ -package org.eclipse.paho.client.mqttv3.internal; - -import org.eclipse.paho.client.mqttv3.BufferedMessage; -import org.eclipse.paho.client.mqttv3.MqttException; - -public interface IDisconnectedBufferCallback { - - public void publishBufferedMessage(BufferedMessage bufferedMessage) throws MqttException; - -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/MessageCatalog.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/MessageCatalog.java deleted file mode 100644 index a0df46d..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/MessageCatalog.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - */ -package org.eclipse.paho.client.mqttv3.internal; - -/** - * Catalog of human readable error messages. - */ -public abstract class MessageCatalog { - private static MessageCatalog INSTANCE = null; - - public static final String getMessage(int id) { - if (INSTANCE == null) { - if (ExceptionHelper.isClassAvailable("java.util.ResourceBundle")) { - try { - // Hide this class reference behind reflection so that the class does not need to - // be present when compiled on midp - INSTANCE = (MessageCatalog)Class.forName("org.eclipse.paho.client.mqttv3.internal.ResourceBundleCatalog").newInstance(); - } catch (Exception e) { - return ""; - } - } else if (ExceptionHelper.isClassAvailable("org.eclipse.paho.client.mqttv3.internal.MIDPCatalog")){ - try { - INSTANCE = (MessageCatalog)Class.forName("org.eclipse.paho.client.mqttv3.internal.MIDPCatalog").newInstance(); - } catch (Exception e) { - return ""; - } - } - } - return INSTANCE.getLocalizedMessage(id); - } - - protected abstract String getLocalizedMessage(int id); -} diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/MqttPersistentData.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/MqttPersistentData.java deleted file mode 100644 index 8ab04c1..0000000 --- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/MqttPersistentData.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corp. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Eclipse Distribution License v1.0 which accompany this distribution. - * - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * and the Eclipse Distribution License is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * Contributors: - * Dave Locke - initial API and implementation and/or initial documentation - */ -package org.eclipse.paho.client.mqttv3.internal; - -import org.eclipse.paho.client.mqttv3.MqttPersistable; - -public class MqttPersistentData implements MqttPersistable { - // Message key - private String key = null; - - // Message header - private byte[] header = null; - private int hOffset = 0; - private int hLength = 0; - - // Message payload - private byte[] payload = null; - private int pOffset = 0; - private int pLength = 0; - - /** - * Construct a data object to pass across the MQTT client persistence interface. - * - * When this Object is passed to the persistence implementation the key is - * used by the client to identify the persisted data to which further - * update or deletion requests are targeted.- * The SSLSocketFactoryFactory is configured using IBM SSL properties, i.e. - * properties of the format "com.ibm.ssl.propertyName", e.g. - * "com.ibm.ssl.keyStore". The class supports multiple configurations, each - * configuration is identified using a name or configuration ID. The - * configuration ID with "null" is used as a default configuration. When a - * socket factory is being created for a given configuration, properties of that - * configuration are first picked. If a property is not defined there, then that - * property is looked up in the default configuration. Finally, if a property - * element is still not found, then the corresponding system property is - * inspected, i.e. javax.net.ssl.keyStore. If the system property is not set - * either, then the system's default value is used (if available) or an - * exception is thrown. - *
- * The SSLSocketFacotryFactory can be reconfigured at any time. A - * reconfiguration does not affect existing socket factories. - *
- * All properties share the same key space; i.e. the configuration ID is not - * part of the property keys. - *
- * The methods should be called in the following order: - *
CountingInputStream wrapping the supplied
- * input stream.
- * @param in The {@link InputStream}
- */
- public CountingInputStream(InputStream in) {
- this.in = in;
- this.counter = 0;
- }
-
- public int read() throws IOException {
- int i = in.read();
- if (i != -1) {
- counter++;
- }
- return i;
- }
-
- /**
- * @return the number of bytes read since the last reset.
- */
- public int getCounter() {
- return counter;
- }
-
- /**
- * Resets the counter to zero.
- */
- public void resetCounter() {
- counter = 0;
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttAck.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttAck.java
deleted file mode 100644
index ffc7f41..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttAck.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-
-/**
- * Abstract super-class of all acknowledgement messages.
- */
-public abstract class MqttAck extends MqttWireMessage {
- public MqttAck(byte type) {
- super(type);
- }
-
- protected byte getMessageInfo() {
- return 0;
- }
-
- /**
- * @return String representation of the wire message
- */
- public String toString() {
- return super.toString() + " msgId " + msgId;
- }
-}
\ No newline at end of file
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttConnack.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttConnack.java
deleted file mode 100644
index 3d21619..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttConnack.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- * Ian Craggs - MQTT 3.1.1 support
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-
-/**
- * An on-the-wire representation of an MQTT CONNACK.
- */
-public class MqttConnack extends MqttAck {
- public static final String KEY = "Con";
-
- private int returnCode;
- private boolean sessionPresent;
-
- public MqttConnack(byte info, byte[] variableHeader) throws IOException {
- super(MqttWireMessage.MESSAGE_TYPE_CONNACK);
- ByteArrayInputStream bais = new ByteArrayInputStream(variableHeader);
- DataInputStream dis = new DataInputStream(bais);
- sessionPresent = (dis.readUnsignedByte() & 0x01) == 0x01;
- returnCode = dis.readUnsignedByte();
- dis.close();
- }
-
- public int getReturnCode() {
- return returnCode;
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- // Not needed, as the client never encodes a CONNACK
- return new byte[0];
- }
-
- /**
- * Returns whether or not this message needs to include a message ID.
- */
- public boolean isMessageIdRequired() {
- return false;
- }
-
- public String getKey() {
- return KEY;
- }
-
- public String toString() {
- return super.toString() + " session present:" + sessionPresent + " return code: " + returnCode;
- }
-
- public boolean getSessionPresent() {
- return sessionPresent;
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttConnect.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttConnect.java
deleted file mode 100644
index 6dfadfd..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttConnect.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- * Ian Craggs - MQTT 3.1.1 support
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-import org.eclipse.paho.client.mqttv3.MqttMessage;
-
-/**
- * An on-the-wire representation of an MQTT CONNECT message.
- */
-public class MqttConnect extends MqttWireMessage {
-
- public static final String KEY = "Con";
-
- private String clientId;
- private boolean cleanSession;
- private MqttMessage willMessage;
- private String userName;
- private char[] password;
- private int keepAliveInterval;
- private String willDestination;
- private int MqttVersion;
-
- /**
- * Constructor for an on the wire MQTT connect message
- *
- * @param info The info byte
- * @param data the data byte array
- * @throws IOException thrown if an exception occurs when reading the input streams
- * @throws MqttException thrown if an exception occurs when decoding UTF-8
- */
- public MqttConnect(byte info, byte[] data) throws IOException, MqttException {
- super(MqttWireMessage.MESSAGE_TYPE_CONNECT);
- ByteArrayInputStream bais = new ByteArrayInputStream(data);
- DataInputStream dis = new DataInputStream(bais);
-
- String protocol_name = decodeUTF8(dis);
- int protocol_version = dis.readByte();
- byte connect_flags = dis.readByte();
- keepAliveInterval = dis.readUnsignedShort();
- clientId = decodeUTF8(dis);
- dis.close();
- }
-
- public MqttConnect(String clientId, int MqttVersion, boolean cleanSession, int keepAliveInterval, String userName, char[] password, MqttMessage willMessage, String willDestination) {
- super(MqttWireMessage.MESSAGE_TYPE_CONNECT);
- this.clientId = clientId;
- this.cleanSession = cleanSession;
- this.keepAliveInterval = keepAliveInterval;
- this.userName = userName;
- this.password = password;
- this.willMessage = willMessage;
- this.willDestination = willDestination;
- this.MqttVersion = MqttVersion;
- }
-
- public String toString() {
- String rc = super.toString();
- rc += " clientId " + clientId + " keepAliveInterval " + keepAliveInterval;
- return rc;
- }
-
- protected byte getMessageInfo() {
- return (byte) 0;
- }
-
- public boolean isCleanSession() {
- return cleanSession;
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream dos = new DataOutputStream(baos);
-
- if (MqttVersion == 3) {
- encodeUTF8(dos,"MQIsdp");
- }
- else if (MqttVersion == 4) {
- encodeUTF8(dos,"MQTT");
- }
- dos.write(MqttVersion);
-
- byte connectFlags = 0;
-
- if (cleanSession) {
- connectFlags |= 0x02;
- }
-
- if (willMessage != null ) {
- connectFlags |= 0x04;
- connectFlags |= (willMessage.getQos()<<3);
- if (willMessage.isRetained()) {
- connectFlags |= 0x20;
- }
- }
-
- if (userName != null) {
- connectFlags |= 0x80;
- if (password != null) {
- connectFlags |= 0x40;
- }
- }
- dos.write(connectFlags);
- dos.writeShort(keepAliveInterval);
- dos.flush();
- return baos.toByteArray();
- } catch(IOException ioe) {
- throw new MqttException(ioe);
- }
- }
-
- public byte[] getPayload() throws MqttException {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream dos = new DataOutputStream(baos);
- encodeUTF8(dos,clientId);
-
- if (willMessage != null) {
- encodeUTF8(dos,willDestination);
- dos.writeShort(willMessage.getPayload().length);
- dos.write(willMessage.getPayload());
- }
-
- if (userName != null) {
- encodeUTF8(dos,userName);
- if (password != null) {
- encodeUTF8(dos,new String(password));
- }
- }
- dos.flush();
- return baos.toByteArray();
- } catch (IOException ex) {
- throw new MqttException(ex);
- }
- }
-
- /**
- * Returns whether or not this message needs to include a message ID.
- */
- public boolean isMessageIdRequired() {
- return false;
- }
-
- public String getKey() {
- return KEY;
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttDisconnect.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttDisconnect.java
deleted file mode 100644
index 9aa618a..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttDisconnect.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-
-/**
- * An on-the-wire representation of an MQTT DISCONNECT message.
- */
-public class MqttDisconnect extends MqttWireMessage {
- public static final String KEY="Disc";
-
- public MqttDisconnect() {
- super(MqttWireMessage.MESSAGE_TYPE_DISCONNECT);
- }
-
- public MqttDisconnect(byte info, byte[] variableHeader) throws IOException {
- super(MqttWireMessage.MESSAGE_TYPE_DISCONNECT);
- }
-
- protected byte getMessageInfo() {
- return (byte) 0;
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- return new byte[0];
- }
-
- /**
- * Returns whether or not this message needs to include a message ID.
- */
- public boolean isMessageIdRequired() {
- return false;
- }
-
- public String getKey() {
- return KEY;
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttInputStream.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttInputStream.java
deleted file mode 100644
index 3a7b049..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttInputStream.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.SocketTimeoutException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-import org.eclipse.paho.client.mqttv3.internal.ClientState;
-import org.eclipse.paho.client.mqttv3.internal.ExceptionHelper;
-import org.eclipse.paho.client.mqttv3.logging.Logger;
-import org.eclipse.paho.client.mqttv3.logging.LoggerFactory;
-
-
-/**
- * An MqttInputStream lets applications read instances of
- * MqttWireMessage.
- */
-public class MqttInputStream extends InputStream {
- private static final String CLASS_NAME = MqttInputStream.class.getName();
- private static final Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME);
-
- private ClientState clientState = null;
- private DataInputStream in;
- private ByteArrayOutputStream bais;
- private long remLen;
- private long packetLen;
- private byte[] packet;
-
- public MqttInputStream(ClientState clientState, InputStream in) {
- this.clientState = clientState;
- this.in = new DataInputStream(in);
- this.bais = new ByteArrayOutputStream();
- this.remLen = -1;
- }
-
- public int read() throws IOException {
- return in.read();
- }
-
- public int available() throws IOException {
- return in.available();
- }
-
- public void close() throws IOException {
- in.close();
- }
-
- /**
- * Reads an MqttWireMessage from the stream.
- * If the message cannot be fully read within the socket read timeout,
- * a null message is returned and the method can be called again until
- * the message is fully read.
- * @return The {@link MqttWireMessage}
- * @throws IOException if an exception is thrown when reading from the stream
- * @throws MqttException if the message is invalid
- */
- public MqttWireMessage readMqttWireMessage() throws IOException, MqttException {
- final String methodName ="readMqttWireMessage";
-
- MqttWireMessage message = null;
- try {
- // read header
- if (remLen < 0) {
- // Assume we can read the whole header at once.
- // The header is very small so it's likely we
- // are able to read it fully or not at all.
- // This keeps the parser lean since we don't
- // need to cope with a partial header.
- // Should we lose synch with the stream,
- // the keepalive mechanism would kick in
- // closing the connection.
- bais.reset();
-
- byte first = in.readByte();
- clientState.notifyReceivedBytes(1);
-
- byte type = (byte) ((first >>> 4) & 0x0F);
- if ((type < MqttWireMessage.MESSAGE_TYPE_CONNECT) ||
- (type > MqttWireMessage.MESSAGE_TYPE_DISCONNECT)) {
- // Invalid MQTT message type...
- throw ExceptionHelper.createMqttException(MqttException.REASON_CODE_INVALID_MESSAGE);
- }
- remLen = MqttWireMessage.readMBI(in).getValue();
- bais.write(first);
- // bit silly, we decode it then encode it
- bais.write(MqttWireMessage.encodeMBI(remLen));
- packet = new byte[(int)(bais.size()+remLen)];
- packetLen = 0;
- }
-
- // read remaining packet
- if (remLen >= 0) {
- // the remaining packet can be read with timeouts
- readFully();
-
- // reset packet parsing state
- remLen = -1;
-
- byte[] header = bais.toByteArray();
- System.arraycopy(header,0,packet,0, header.length);
- message = MqttWireMessage.createWireMessage(packet);
- // @TRACE 501= received {0}
- log.fine(CLASS_NAME, methodName, "501",new Object[] {message});
- }
- } catch (SocketTimeoutException e) {
- // ignore socket read timeout
- }
-
- return message;
- }
-
- private void readFully() throws IOException {
- int off = bais.size() + (int) packetLen;
- int len = (int) (remLen - packetLen);
- if (len < 0)
- throw new IndexOutOfBoundsException();
- int n = 0;
- while (n < len) {
- int count = -1;
- try {
- count = in.read(packet, off + n, len - n);
- } catch (SocketTimeoutException e) {
- // remember the packet read so far
- packetLen += n;
- throw e;
- }
- clientState.notifyReceivedBytes(count);
-
- if (count < 0)
- throw new EOFException();
- n += count;
- }
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttOutputStream.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttOutputStream.java
deleted file mode 100644
index 95b9cea..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttOutputStream.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-import org.eclipse.paho.client.mqttv3.internal.ClientState;
-import org.eclipse.paho.client.mqttv3.logging.Logger;
-import org.eclipse.paho.client.mqttv3.logging.LoggerFactory;
-
-
-/**
- * An MqttOutputStream lets applications write instances of
- * MqttWireMessage.
- */
-public class MqttOutputStream extends OutputStream {
- private static final String CLASS_NAME = MqttOutputStream.class.getName();
- private static final Logger log = LoggerFactory.getLogger(LoggerFactory.MQTT_CLIENT_MSG_CAT, CLASS_NAME);
-
- private ClientState clientState = null;
- private BufferedOutputStream out;
-
- public MqttOutputStream(ClientState clientState, OutputStream out) {
- this.clientState = clientState;
- this.out = new BufferedOutputStream(out);
- }
-
- public void close() throws IOException {
- out.close();
- }
-
- public void flush() throws IOException {
- out.flush();
- }
-
- public void write(byte[] b) throws IOException {
- out.write(b);
- clientState.notifySentBytes(b.length);
- }
-
- public void write(byte[] b, int off, int len) throws IOException {
- out.write(b, off, len);
- clientState.notifySentBytes(len);
- }
-
- public void write(int b) throws IOException {
- out.write(b);
- }
-
- /**
- * Writes an MqttWireMessage to the stream.
- * @param message The {@link MqttWireMessage} to send
- * @throws IOException if an exception is thrown when writing to the output stream.
- * @throws MqttException if an exception is thrown when getting the header or payload
- */
- public void write(MqttWireMessage message) throws IOException, MqttException {
- final String methodName = "write";
- byte[] bytes = message.getHeader();
- byte[] pl = message.getPayload();
-// out.write(message.getHeader());
-// out.write(message.getPayload());
- out.write(bytes,0,bytes.length);
- clientState.notifySentBytes(bytes.length);
-
- int offset = 0;
- int chunckSize = 1024;
- while (offset < pl.length) {
- int length = Math.min(chunckSize, pl.length - offset);
- out.write(pl, offset, length);
- offset += chunckSize;
- clientState.notifySentBytes(length);
- }
-
- // @TRACE 529= sent {0}
- log.fine(CLASS_NAME, methodName, "529", new Object[]{message});
- }
-}
-
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPersistableWireMessage.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPersistableWireMessage.java
deleted file mode 100644
index c826d87..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPersistableWireMessage.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-import org.eclipse.paho.client.mqttv3.MqttPersistable;
-import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
-
-public abstract class MqttPersistableWireMessage extends MqttWireMessage
- implements MqttPersistable {
-
- public MqttPersistableWireMessage(byte type) {
- super(type);
- }
-
- public byte[] getHeaderBytes() throws MqttPersistenceException {
- try {
- return getHeader();
- }
- catch (MqttException ex) {
- throw new MqttPersistenceException(ex.getCause());
- }
- }
-
- public int getHeaderLength() throws MqttPersistenceException {
- return getHeaderBytes().length;
- }
-
- public int getHeaderOffset() throws MqttPersistenceException{
- return 0;
- }
-
-// public String getKey() throws MqttPersistenceException {
-// return new Integer(getMessageId()).toString();
-// }
-
- public byte[] getPayloadBytes() throws MqttPersistenceException {
- try {
- return getPayload();
- }
- catch (MqttException ex) {
- throw new MqttPersistenceException(ex.getCause());
- }
- }
-
- public int getPayloadLength() throws MqttPersistenceException {
- return 0;
- }
-
- public int getPayloadOffset() throws MqttPersistenceException {
- return 0;
- }
-
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPingReq.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPingReq.java
deleted file mode 100644
index e2472be..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPingReq.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-
-/**
- * An on-the-wire representation of an MQTT PINGREQ message.
- */
-public class MqttPingReq extends MqttWireMessage {
- public static final String KEY = "Ping";
-
- public MqttPingReq() {
- super(MqttWireMessage.MESSAGE_TYPE_PINGREQ);
- }
-
- public MqttPingReq(byte info, byte[] variableHeader) throws IOException {
- super(MqttWireMessage.MESSAGE_TYPE_PINGREQ);
- }
-
- /**
- * Returns false as message IDs are not required for MQTT
- * PINGREQ messages.
- */
- public boolean isMessageIdRequired() {
- return false;
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- return new byte[0];
- }
-
- protected byte getMessageInfo() {
- return 0;
- }
-
- public String getKey() {
- return KEY;
- }
-}
-
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPingResp.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPingResp.java
deleted file mode 100644
index 4f07fc9..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPingResp.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-
-
-/**
- * An on-the-wire representation of an MQTT PINGRESP.
- */
-public class MqttPingResp extends MqttAck {
- public static final String KEY = "Ping";
-
- public MqttPingResp(byte info, byte[] variableHeader) {
- super(MqttWireMessage.MESSAGE_TYPE_PINGRESP);
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- // Not needed, as the client never encodes a PINGRESP
- return new byte[0];
- }
-
- /**
- * Returns whether or not this message needs to include a message ID.
- */
- public boolean isMessageIdRequired() {
- return false;
- }
-
- public String getKey() {
- return KEY;
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubAck.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubAck.java
deleted file mode 100644
index de3ab5f..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubAck.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- * Ian Craggs - ack control (bug 472172)
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-
-
-
-/**
- * An on-the-wire representation of an MQTT PUBACK message.
- */
-public class MqttPubAck extends MqttAck {
- public MqttPubAck(byte info, byte[] data) throws IOException {
- super(MqttWireMessage.MESSAGE_TYPE_PUBACK);
- ByteArrayInputStream bais = new ByteArrayInputStream(data);
- DataInputStream dis = new DataInputStream(bais);
- msgId = dis.readUnsignedShort();
- dis.close();
- }
-
- public MqttPubAck(MqttPublish publish) {
- super(MqttWireMessage.MESSAGE_TYPE_PUBACK);
- msgId = publish.getMessageId();
- }
-
- public MqttPubAck(int messageId) {
- super(MqttWireMessage.MESSAGE_TYPE_PUBACK);
- msgId = messageId;
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- return encodeMessageId();
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubComp.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubComp.java
deleted file mode 100644
index 59c90b0..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubComp.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-
-
-
-/**
- * An on-the-wire representation of an MQTT PUBCOMP message.
- */
-public class MqttPubComp extends MqttAck {
- public MqttPubComp(byte info, byte[] data) throws IOException {
- super(MqttWireMessage.MESSAGE_TYPE_PUBCOMP);
- ByteArrayInputStream bais = new ByteArrayInputStream(data);
- DataInputStream dis = new DataInputStream(bais);
- msgId = dis.readUnsignedShort();
- dis.close();
- }
-
- public MqttPubComp(MqttPublish publish) {
- super(MqttWireMessage.MESSAGE_TYPE_PUBCOMP);
- this.msgId = publish.getMessageId();
- }
-
- public MqttPubComp(int msgId) {
- super(MqttWireMessage.MESSAGE_TYPE_PUBCOMP);
- this.msgId = msgId;
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- return encodeMessageId();
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubRec.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubRec.java
deleted file mode 100644
index f2dac68..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubRec.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-
-
-
-/**
- * An on-the-wire representation of an MQTT PUBREC message.
- */
-public class MqttPubRec extends MqttAck {
- public MqttPubRec(byte info, byte[] data) throws IOException {
- super(MqttWireMessage.MESSAGE_TYPE_PUBREC);
- ByteArrayInputStream bais = new ByteArrayInputStream(data);
- DataInputStream dis = new DataInputStream(bais);
- msgId = dis.readUnsignedShort();
- dis.close();
- }
-
- public MqttPubRec(MqttPublish publish) {
- super(MqttWireMessage.MESSAGE_TYPE_PUBREC);
- msgId = publish.getMessageId();
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- return encodeMessageId();
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubRel.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubRel.java
deleted file mode 100644
index 0db14ff..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPubRel.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-
-/**
- * An on-the-wire representation of an MQTT PUBREL message.
- */
-public class MqttPubRel extends MqttPersistableWireMessage {
-
- /**
- * Createa a pubrel message based on a pubrec
- * @param pubRec the {@link MqttPubRec}
- */
- public MqttPubRel(MqttPubRec pubRec) {
- super(MqttWireMessage.MESSAGE_TYPE_PUBREL);
- this.setMessageId(pubRec.getMessageId());
- }
-
- /**
- * Creates a pubrel based on a pubrel set of bytes read fro the network
- * @param info the info byte
- * @param data the byte array
- * @throws IOException if an exception occurs whilst reading from the input stream
- */
- public MqttPubRel(byte info, byte[] data) throws IOException {
- super(MqttWireMessage.MESSAGE_TYPE_PUBREL);
- ByteArrayInputStream bais = new ByteArrayInputStream(data);
- DataInputStream dis = new DataInputStream(bais);
- msgId = dis.readUnsignedShort();
- dis.close();
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- return encodeMessageId();
- }
-
- protected byte getMessageInfo() {
- return (byte)( 2 | (this.duplicate?8:0));
- }
-
- public String toString() {
- return super.toString() + " msgId " + msgId;
- }
-
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPublish.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPublish.java
deleted file mode 100644
index 9c8a278..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttPublish.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-import org.eclipse.paho.client.mqttv3.MqttMessage;
-
-/**
- * An on-the-wire representation of an MQTT SEND message.
- */
-public class MqttPublish extends MqttPersistableWireMessage {
-
- private MqttMessage message;
- private String topicName;
-
- private byte[] encodedPayload = null;
-
- public MqttPublish(String name, MqttMessage message) {
- super(MqttWireMessage.MESSAGE_TYPE_PUBLISH);
- topicName = name;
- this.message = message;
- }
-
- /**
- * Constructs a new MqttPublish object.
- * @param info the message info byte
- * @param data the variable header and payload bytes
- * @throws MqttException if an exception occurs creating the publish
- * @throws IOException if an exception occurs creating the publish
- */
- public MqttPublish(byte info, byte[] data) throws MqttException, IOException {
- super(MqttWireMessage.MESSAGE_TYPE_PUBLISH);
- message = new MqttReceivedMessage();
- message.setQos((info >> 1) & 0x03);
- if ((info & 0x01) == 0x01) {
- message.setRetained(true);
- }
- if ((info & 0x08) == 0x08) {
- ((MqttReceivedMessage) message).setDuplicate(true);
- }
-
- ByteArrayInputStream bais = new ByteArrayInputStream(data);
- CountingInputStream counter = new CountingInputStream(bais);
- DataInputStream dis = new DataInputStream(counter);
- topicName = decodeUTF8(dis);
- if (message.getQos() > 0) {
- msgId = dis.readUnsignedShort();
- }
- byte[] payload = new byte[data.length-counter.getCounter()];
- dis.readFully(payload);
- dis.close();
- message.setPayload(payload);
- }
-
- public String toString() {
-
- // Convert the first few bytes of the payload into a hex string
- StringBuffer hex = new StringBuffer();
- byte[] payload = message.getPayload();
- int limit = Math.min(payload.length, 20);
- for (int i = 0; i < limit; i++) {
- byte b = payload[i];
- String ch = Integer.toHexString(b);
- if (ch.length() == 1) {
- ch = "0" + ch;
- }
- hex.append(ch);
- }
-
- // It will not always be possible to convert the binary payload into
- // characters, but never-the-less we attempt to do this as it is often
- // useful
- String string = null;
- try {
- string = new String(payload, 0, limit, "UTF-8");
- } catch (Exception e) {
- string = "?";
- }
-
- StringBuffer sb = new StringBuffer();
- sb.append(super.toString());
- sb.append(" qos:").append(message.getQos());
- if (message.getQos() > 0) {
- sb.append(" msgId:").append(msgId);
- }
- sb.append(" retained:").append(message.isRetained());
- sb.append(" dup:").append(duplicate);
- sb.append(" topic:\"").append(topicName).append("\"");
- sb.append(" payload:[hex:").append(hex);
- sb.append(" utf8:\"").append(string).append("\"");
- sb.append(" length:").append(payload.length).append("]");
-
- return sb.toString();
- }
-
- protected byte getMessageInfo() {
- byte info = (byte) (message.getQos() << 1);
- if (message.isRetained()) {
- info |= 0x01;
- }
- if (message.isDuplicate() || duplicate ) {
- info |= 0x08;
- }
-
- return info;
- }
-
- public String getTopicName() {
- return topicName;
- }
-
- public MqttMessage getMessage() {
- return message;
- }
-
- protected static byte[] encodePayload(MqttMessage message) {
- return message.getPayload();
- }
-
- public byte[] getPayload() throws MqttException {
- if (encodedPayload == null) {
- encodedPayload = encodePayload(message);
- }
- return encodedPayload;
- }
-
- public int getPayloadLength() {
- int length = 0;
- try {
- length = getPayload().length;
- } catch(MqttException me) {
- }
- return length;
- }
-
- public void setMessageId(int msgId) {
- super.setMessageId(msgId);
- if (message instanceof MqttReceivedMessage) {
- ((MqttReceivedMessage)message).setMessageId(msgId);
- }
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream dos = new DataOutputStream(baos);
- encodeUTF8(dos, topicName);
- if (message.getQos() > 0) {
- dos.writeShort(msgId);
- }
- dos.flush();
- return baos.toByteArray();
- } catch (IOException ex) {
- throw new MqttException(ex);
- }
- }
-
- public boolean isMessageIdRequired() {
- // all publishes require a message ID as it's used as the key to the token store
- return true;
- }
-}
\ No newline at end of file
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttReceivedMessage.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttReceivedMessage.java
deleted file mode 100644
index d5290e0..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttReceivedMessage.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import org.eclipse.paho.client.mqttv3.MqttMessage;
-
-public class MqttReceivedMessage extends MqttMessage {
-
- public void setMessageId(int msgId) {
- super.setId(msgId);
- }
-
- public int getMessageId() {
- return super.getId();
- }
-
- // This method exists here to get around the protected visibility of the
- // super class method.
- public void setDuplicate(boolean value) {
- super.setDuplicate(value);
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttSuback.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttSuback.java
deleted file mode 100644
index cd74a43..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttSuback.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- * Ian Craggs - MQTT 3.1.1 support
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-
-
-/**
- * An on-the-wire representation of an MQTT SUBACK.
- */
-public class MqttSuback extends MqttAck {
- private int[] grantedQos;
-
- public MqttSuback(byte info, byte[] data) throws IOException {
- super(MqttWireMessage.MESSAGE_TYPE_SUBACK);
- ByteArrayInputStream bais = new ByteArrayInputStream(data);
- DataInputStream dis = new DataInputStream(bais);
- msgId = dis.readUnsignedShort();
- int index = 0;
- grantedQos = new int[data.length-2];
- int qos = dis.read();
- while (qos != -1) {
- grantedQos[index] = qos;
- index++;
- qos = dis.read();
- }
- dis.close();
- }
-
- protected byte[] getVariableHeader() throws MqttException {
- // Not needed, as the client never encodes a SUBACK
- return new byte[0];
- }
-
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append(super.toString()).append(" granted Qos");
- for (int i = 0; i < grantedQos.length; ++i) {
- sb.append(" ").append(grantedQos[i]);
- }
- return sb.toString();
- }
-
- public int[] getGrantedQos() {
- return grantedQos;
- }
-
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttSubscribe.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttSubscribe.java
deleted file mode 100644
index dcca4b8..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/internal/wire/MqttSubscribe.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.internal.wire;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.eclipse.paho.client.mqttv3.MqttException;
-import org.eclipse.paho.client.mqttv3.MqttMessage;
-
-
-/**
- * An on-the-wire representation of an MQTT SUBSCRIBE message.
- */
-public class MqttSubscribe extends MqttWireMessage {
- private String[] names;
- private int[] qos;
- private int count;
-
- /**
- * Constructor for an on the wire MQTT subscribe message
- *
- * @param info the info byte
- * @param data the data byte array
- * @throws IOException if an exception occurs whilst reading the input stream
- */
- public MqttSubscribe(byte info, byte[] data) throws IOException {
- super(MqttWireMessage.MESSAGE_TYPE_SUBSCRIBE);
- ByteArrayInputStream bais = new ByteArrayInputStream(data);
- DataInputStream dis = new DataInputStream(bais);
- msgId = dis.readUnsignedShort();
-
- count = 0;
- names = new String[10];
- qos = new int[10];
- boolean end = false;
- while (!end) {
- try {
- names[count] = decodeUTF8(dis);
- qos[count++] = dis.readByte();
- } catch (Exception e) {
- end = true;
- }
- }
- dis.close();
- }
-
- /**
- * Constructor for an on the wire MQTT subscribe message
- * @param names - one or more topics to subscribe to
- * @param qos - the max QoS that each each topic will be subscribed at
- */
- public MqttSubscribe(String[] names, int[] qos) {
- super(MqttWireMessage.MESSAGE_TYPE_SUBSCRIBE);
- this.names = names;
- this.qos = qos;
-
- if (names.length != qos.length) {
- throw new IllegalArgumentException();
- }
- this.count = names.length;
-
- for (int i=0;i- * Clients should use the the convenience methods such as severe() and fine() or - * one of the predefined level constants such as Logger.SEVERE and Logger.FINE - * with the appropriate log(int level...) or trace(int level...) methods. - *
- * The levels in descending order are:
- *- * In general SEVERE messages should describe events that are of - * considerable importance and which will prevent normal program execution. - * They should be reasonably intelligible to end users and to system - * administrators. - */ - public static final int SEVERE = 1; - /** - * WARNING is a message level indicating a potential problem. - *
- * In general WARNING messages should describe events that will be of - * interest to end users or system managers, or which indicate potential - * problems. - */ - public static final int WARNING = 2; - /** - * INFO is a message level for informational messages. - *
- * Typically INFO messages will be written to the console or its equivalent. - * So the INFO level should only be used for reasonably significant messages - * that will make sense to end users and system admins. - */ - public static final int INFO = 3; - /** - * CONFIG is a message level for static configuration messages. - *
- * CONFIG messages are intended to provide a variety of static configuration - * information, to assist in debugging problems that may be associated with - * particular configurations. For example, CONFIG message might include the - * CPU type, the graphics depth, the GUI look-and-feel, etc. - */ - public static final int CONFIG = 4; - /** - * FINE is a message level providing tracing information. - *
- * All of FINE, FINER, and FINEST are intended for relatively detailed - * tracing. The exact meaning of the three levels will vary between - * subsystems, but in general, FINEST should be used for the most voluminous - * detailed output, FINER for somewhat less detailed output, and FINE for - * the lowest volume (and most important) messages. - *
- * In general the FINE level should be used for information that will be - * broadly interesting to developers who do not have a specialized interest - * in the specific subsystem. - *
- * FINE messages might include things like minor (recoverable) failures.
- * Issues indicating potential performance problems are also worth logging
- * as FINE.
- */
- public static final int FINE = 5;
- /**
- * FINER indicates a fairly detailed tracing message. By default logging
- * calls for entering, returning, or throwing an exception are traced at
- * this level.
- */
- public static final int FINER = 6;
- /**
- * FINEST indicates a highly detailed tracing message.
- */
- public static final int FINEST = 7;
-
- public void initialise(ResourceBundle messageCatalog, String loggerID, String resourceName);
-
- /**
- * Set a name that can be used to provide context with each log record.
- * This overrides the value passed in on initialise
- * @param logContext The Log context name
- */
- public void setResourceName(String logContext);
-
- /**
- * Check if a message of the given level would actually be logged by this
- * logger. This check is based on the Loggers effective level, which may be
- * inherited from its parent.
- *
- * @param level
- * a message logging level.
- * @return true if the given message level is currently being logged.
- */
- public boolean isLoggable(int level);
-
- /**
- * Log a message, specifying source class and method, if the logger is
- * currently enabled for the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used.
- */
- public void severe(String sourceClass, String sourceMethod, String msg);
-
- /**
- * Log a message, specifying source class and method, with an array of
- * object arguments, if the logger is currently enabled for the given
- * message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used. The formatter uses java.text.MessageFormat
- * style formatting to format parameters, so for example a format
- * string "{0} {1}" would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- */
- public void severe(String sourceClass, String sourceMethod, String msg, Object[] inserts);
-
- /**
- * Log a message, specifying source class and method, with an array of
- * object arguments and a throwable, if the logger is currently enabled for
- * the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used. The formatter uses java.text.MessageFormat
- * style formatting to format parameters, so for example a format
- * string "{0} {1}" would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- * @param thrown
- * Throwable associated with log message.
- */
- public void severe(String sourceClass, String sourceMethod, String msg, Object[] inserts, Throwable thrown);
-
- /**
- * Log a message, specifying source class and method, if the logger is
- * currently enabled for the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used.
- */
- public void warning(String sourceClass, String sourceMethod, String msg);
-
- /**
- * Log a message, specifying source class and method, with an array of
- * object arguments, if the logger is currently enabled for the given
- * message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used. The formatter uses java.text.MessageFormat
- * style formatting to format parameters, so for example a format
- * string "{0} {1}" would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- */
- public void warning(String sourceClass, String sourceMethod, String msg, Object[] inserts);
-
- /**
- * Log a message, specifying source class and method, with an array of
- * object arguments and a throwable, if the logger is currently enabled for
- * the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used. The formatter uses java.text.MessageFormat
- * style formatting to format parameters, so for example a format
- * string "{0} {1}" would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- * @param thrown
- * Throwable associated with log message.
- */
- public void warning(String sourceClass, String sourceMethod, String msg, Object[] inserts, Throwable thrown);
-
- /**
- * Log a message, specifying source class and method, if the logger is
- * currently enabled for the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used.
- */
- public void info(String sourceClass, String sourceMethod, String msg);
-
- /**
- * Log a message, specifying source class and method, with an array of
- * object arguments, if the logger is currently enabled for the given
- * message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used. The formatter uses java.text.MessageFormat
- * style formatting to format parameters, so for example a format
- * string "{0} {1}" would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- */
- public void info(String sourceClass, String sourceMethod, String msg, Object[] inserts);
-
- /**
- * Log a message, specifying source class and method, with an array of
- * object arguments and a throwable, if the logger is currently enabled for
- * the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used. The formatter uses java.text.MessageFormat
- * style formatting to format parameters, so for example a format
- * string "{0} {1}" would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- * @param thrown
- * Throwable associated with log message.
- */
- public void info(String sourceClass, String sourceMethod, String msg, Object[] inserts, Throwable thrown);
-
- /**
- * Log a message, specifying source class and method, if the logger is
- * currently enabled for the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used.
- */
- public void config(String sourceClass, String sourceMethod, String msg);
-
- /**
- * Log a message, specifying source class and method, with an array of
- * object arguments, if the logger is currently enabled for the given
- * message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used. The formatter uses java.text.MessageFormat
- * style formatting to format parameters, so for example a format
- * string "{0} {1}" would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- */
- public void config(String sourceClass, String sourceMethod, String msg, Object[] inserts);
-
- /**
- * Log a message, specifying source class and method, with an array of
- * object arguments and a throwable, if the logger is currently enabled for
- * the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used. The formatter uses java.text.MessageFormat
- * style formatting to format parameters, so for example a format
- * string "{0} {1}" would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- * @param thrown
- * Throwable associated with log message.
- */
- public void config(String sourceClass, String sourceMethod, String msg, Object[] inserts, Throwable thrown);
-
- /**
- * Trace a message, specifying source class and method, if the logger is
- * currently enabled for the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message catalog for the message or the actual
- * message itself. During formatting, if the logger has a mapping
- * for the msg string, then the msg string is replaced by the
- * value. Otherwise the original msg string is used.
- */
- public void fine(String sourceClass, String sourceMethod, String msg);
-
- /**
- * Trace a message, specifying source class and method, with an array of
- * object arguments, if the logger is currently enabled for the given
- * message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message catalog for the message or the actual
- * message itself. During formatting, if the logger has a mapping
- * for the msg string, then the msg string is replaced by the
- * value. Otherwise the original msg string is used. The
- * formatter uses java.text.MessageFormat style formatting to
- * format parameters, so for example a format string "{0} {1}"
- * would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- */
- public void fine(String sourceClass, String sourceMethod, String msg, Object[] inserts);
-
- public void fine(String sourceClass, String sourceMethod, String msg, Object[] inserts, Throwable ex);
-
- /**
- * Trace a message, specifying source class and method, if the logger is
- * currently enabled for the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message catalog for the message or the actual
- * message itself. During formatting, if the logger has a mapping
- * for the msg string, then the msg string is replaced by the
- * value. Otherwise the original msg string is used.
- */
- public void finer(String sourceClass, String sourceMethod, String msg);
-
- /**
- * Trace a message, specifying source class and method, with an array of
- * object arguments, if the logger is currently enabled for the given
- * message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message catalog for the message or the actual
- * message itself. During formatting, if the logger has a mapping
- * for the msg string, then the msg string is replaced by the
- * value. Otherwise the original msg string is used. The
- * formatter uses java.text.MessageFormat style formatting to
- * format parameters, so for example a format string "{0} {1}"
- * would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- */
- public void finer(String sourceClass, String sourceMethod, String msg, Object[] inserts);
-
- public void finer(String sourceClass, String sourceMethod, String msg, Object[] inserts, Throwable ex);
-
- /**
- * Trace a message, specifying source class and method, if the logger is
- * currently enabled for the given message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message catalog for the message or the actual
- * message itself. During formatting, if the logger has a mapping
- * for the msg string, then the msg string is replaced by the
- * value. Otherwise the original msg string is used.
- */
- public void finest(String sourceClass, String sourceMethod, String msg);
-
- /**
- * Trace a message, specifying source class and method, with an array of
- * object arguments, if the logger is currently enabled for the given
- * message level.
- *
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message catalog for the message or the actual
- * message itself. During formatting, if the logger has a mapping
- * for the msg string, then the msg string is replaced by the
- * value. Otherwise the original msg string is used. The
- * formatter uses java.text.MessageFormat style formatting to
- * format parameters, so for example a format string "{0} {1}"
- * would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- */
- public void finest(String sourceClass, String sourceMethod, String msg, Object[] inserts);
-
- public void finest(String sourceClass, String sourceMethod, String msg, Object[] inserts, Throwable ex);
-
- /**
- * Log a message, specifying source class and method, with an array of
- * object arguments and a throwable, if the logger is currently enabled for
- * the given message level.
- *
- * @param level
- * One of the message level identifiers, e.g. SEVERE.
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used. The formatter uses java.text.MessageFormat
- * style formatting to format parameters, so for example a format
- * string "{0} {1}" would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message, may be null.
- * @param thrown
- * Throwable associated with log message.
- */
- public void log(int level, String sourceClass, String sourceMethod, String msg, Object[] inserts, Throwable thrown);
-
- /**
- * Log a trace message, specifying source class and method, with an array of
- * object arguments and a throwable, if the logger is currently enabled for
- * the given message level.
- *
- * @param level
- * One of the message level identifiers, e.g. SEVERE.
- * @param sourceClass
- * Name of class that issued the logging request.
- * @param sourceMethod
- * Name of method that issued the logging request.
- * @param msg
- * The key in the message catalog for the message or the actual
- * message itself. During formatting, if the logger has a mapping
- * for the msg string, then the msg string is replaced by the
- * value. Otherwise the original msg string is used. The
- * formatter uses java.text.MessageFormat style formatting to
- * format parameters, so for example a format string "{0} {1}"
- * would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message, may be null.
- * @param ex
- * Throwable associated with log message.
- */
- public void trace(int level, String sourceClass, String sourceMethod, String msg, Object[] inserts, Throwable ex);
-
- /**
- * Format a log message without causing it to be written to the log.
- *
- * @param msg
- * The key in the message localization catalog for the message or
- * the actual message itself. During formatting, if the logger
- * has a mapping for the msg string, then the msg string is
- * replaced by the localized value. Otherwise the original msg
- * string is used. The formatter uses java.text.MessageFormat
- * style formatting to format parameters, so for example a format
- * string "{0} {1}" would format two inserts into the message.
- * @param inserts
- * Array of parameters to the message.
- * @return The formatted message for the current locale.
- */
- public String formatMessage(String msg, Object[] inserts);
-
- public void dumpTrace();
-}
\ No newline at end of file
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/logging/LoggerFactory.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/logging/LoggerFactory.java
deleted file mode 100644
index 08ececb..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/logging/LoggerFactory.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.logging;
-
-import java.lang.reflect.Method;
-
-/**
- * LoggerFactory will create a logger instance ready for use by the caller.
- *
- * The default is to create a logger that utilises the Java's built in
- * logging facility java.util.logging (JSR47). It is possible to override
- * this for systems where JSR47 is not available or an alternative logging
- * facility is needed by using setLogger and passing the the class name of
- * a logger that implements {@link Logger}
- */
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-/**
- * A factory that returns a logger for use by the MQTT client.
- *
- * The default log and trace facility uses Java's build in log facility:-
- * java.util.logging. For systems where this is not available or where
- * an alternative logging framework is required the logging facility can be
- * replaced using {@link org.eclipse.paho.client.mqttv3.logging.LoggerFactory#setLogger(String)}
- * which takes an implementation of the {@link org.eclipse.paho.client.mqttv3.logging.Logger}
- * interface.
- */
-public class LoggerFactory {
- /**
- * Default message catalog.
- */
- public final static String MQTT_CLIENT_MSG_CAT = "org.eclipse.paho.client.mqttv3.internal.nls.logcat";
- private static final String CLASS_NAME = LoggerFactory.class.getName();
-
- private static String overrideloggerClassName = null;
- /**
- * Default logger that uses java.util.logging.
- */
- private static String jsr47LoggerClassName = JSR47Logger.class.getName();
-
- /**
- * Find or create a logger for a named package/class.
- * If a logger has already been created with the given name
- * it is returned. Otherwise a new logger is created. By default a logger
- * that uses java.util.logging will be returned.
- *
- * @param messageCatalogName the resource bundle containing the logging messages.
- * @param loggerID unique name to identify this logger.
- * @return a suitable Logger.
- */
- public static Logger getLogger(String messageCatalogName, String loggerID) {
- String loggerClassName = overrideloggerClassName;
- Logger logger = null;
-
- if (loggerClassName == null) {
- loggerClassName = jsr47LoggerClassName;
- }
-// logger = getJSR47Logger(ResourceBundle.getBundle(messageCatalogName), loggerID, null) ;
- logger = getLogger(loggerClassName, ResourceBundle.getBundle(messageCatalogName), loggerID, null) ;
-// }
-
- if (null == logger) {
- throw new MissingResourceException("Error locating the logging class", CLASS_NAME, loggerID);
- }
-
- return logger;
- }
-
-
- /**
- * Return an instance of a logger
- *
- * @param the class name of the load to load
- * @param messageCatalog the resource bundle containing messages
- * @param loggerID an identifier for the logger
- * @param resourceName a name or context to associate with this logger instance.
- * @return a ready for use logger
- */
- private static Logger getLogger(String loggerClassName, ResourceBundle messageCatalog, String loggerID, String resourceName) { //, FFDC ffdc) {
- Logger logger = null;
- Class logClass = null;
-
- try {
- logClass = Class.forName(loggerClassName);
- } catch (NoClassDefFoundError ncdfe) {
- return null;
- } catch (ClassNotFoundException cnfe) {
- return null;
- }
- if (null != logClass) {
- // Now instantiate the log
- try {
- logger = (Logger)logClass.newInstance();
- } catch (IllegalAccessException e) {
- return null;
- } catch (InstantiationException e) {
- return null;
- } catch (ExceptionInInitializerError e) {
- return null;
- } catch (SecurityException e) {
- return null;
- }
- logger.initialise(messageCatalog, loggerID, resourceName);
- }
-
- return logger;
- }
-
- /**
- * When run in JSR47, this allows access to the properties in the logging.properties
- * file.
- * If not run in JSR47, or the property isn't set, returns null.
- * @param name the property to return
- * @return the property value, or null if it isn't set or JSR47 isn't being used
- */
- public static String getLoggingProperty(String name) {
- String result = null;
- try {
- // Hide behind reflection as java.util.logging is guaranteed to be
- // available.
- Class logManagerClass = Class.forName("java.util.logging.LogManager");
- Method m1 = logManagerClass.getMethod("getLogManager", new Class[]{});
- Object logManagerInstance = m1.invoke(null, null);
- Method m2 = logManagerClass.getMethod("getProperty", new Class[]{String.class});
- result = (String)m2.invoke(logManagerInstance,new Object[]{name});
- } catch(Exception e) {
- // Any error, assume JSR47 isn't available and return null
- result = null;
- }
- return result;
- }
-
- /**
- * Set the class name of the logger that the LoggerFactory will load
- * If not set getLogger will attempt to create a logger
- * appropriate for the platform.
- * @param loggerClassName - Logger implementation class name to use.
- */
- public static void setLogger(String loggerClassName) {
- LoggerFactory.overrideloggerClassName = loggerClassName;
- }
-}
\ No newline at end of file
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/logging/SimpleLogFormatter.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/logging/SimpleLogFormatter.java
deleted file mode 100644
index 63deded..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/logging/SimpleLogFormatter.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- */
-
-package org.eclipse.paho.client.mqttv3.logging;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.text.MessageFormat;
-import java.util.Date;
-import java.util.logging.Formatter;
-import java.util.logging.LogRecord;
-
-/**
- * SimpleLogFormatter prints a single line
- * log record in human readable form.
- */
-public class SimpleLogFormatter extends Formatter {
-
- private static final String LS = System.getProperty("line.separator");
- /**
- * Constructs a The default log and trace facility uses Java's build in log facility:-
-java.util.logging. For systems where this is not available or where
-an alternative logging framework is required the logging facility can be
-replaced using {@link org.eclipse.paho.client.mqttv3.logging.LoggerFactory#setLogger(String)}
-which takes an implementation of the {@link org.eclipse.paho.client.mqttv3.logging.Logger}
-interface.
-
- A sample java.util.logging properties file - jsr47min.properties is provided that demonstrates
-how to run with a memory based trace facility that runs with minimal performance
-overhead. The memory buffer can be dumped when a log/trace record is written matching
-the MemoryHandlers trigger level or when the push method is invoked on the MemoryHandler.
-{@link org.eclipse.paho.client.mqttv3.util.Debug Debug} provides method to make it easy
-to dump the memory buffer as well as other useful debug info.
-
-
\ No newline at end of file
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/package.html b/EasyModbus/src/org/eclipse/paho/client/mqttv3/package.html
deleted file mode 100644
index 00ca45c..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/package.html
+++ /dev/null
@@ -1,136 +0,0 @@
-
-The MQ Telemetry Transport (MQTT) is a lightweight broker-based publish/subscribe
-messaging protocol designed to be open, simple, lightweight and easy to implement.
-These characteristics make it ideal for use in constrained environments, for example,
-but not limited to:
- Features of the protocol include:
- The basic means of operating the client is: The programming model and concepts like the protocol are small and easy to use. Key concepts
-to use when creating MQTT application include:
-
-An MQTT client needs a persistence mechanism to store messages while they
-are in the process of being delivered. This package contains several
-implementations of the interface. If a persistence class is not
-specified on the constructor to an MQTT client,
-{@link org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence MqttDefaultFilePersistence}
-is used by default.
-
-SimpleFormatter object.
- */
- public SimpleLogFormatter() {
- super();
- }
-
- /**
- * Format the logrecord as a single line with well defined columns.
- */
- public String format(LogRecord r) {
- StringBuffer sb = new StringBuffer();
- sb.append(r.getLevel().getName()).append("\t");
- sb.append(MessageFormat.format("{0, date, yy-MM-dd} {0, time, kk:mm:ss.SSSS} ",
- new Object[] { new Date(r.getMillis()) })+"\t");
- String cnm = r.getSourceClassName();
- String cn="";
- if (cnm != null) {
- int cnl = cnm.length();
- if (cnl>20) {
- cn = r.getSourceClassName().substring(cnl-19);
- } else {
- char sp[] = {' '};
- StringBuffer sb1= new StringBuffer().append(cnm);
- cn = sb1.append(sp,0, 1).toString();
- }
- }
- sb.append(cn).append("\t").append(" ");
- sb.append(left(r.getSourceMethodName(),23,' ')).append("\t");
- sb.append(r.getThreadID()).append("\t");
- sb.append(formatMessage(r)).append(LS);
- if (null != r.getThrown()) {
- sb.append("Throwable occurred: ");
- Throwable t = r.getThrown();
- PrintWriter pw = null;
- try {
- StringWriter sw = new StringWriter();
- pw = new PrintWriter(sw);
- t.printStackTrace(pw);
- sb.append(sw.toString());
- } finally {
- if (pw != null) {
- try {
- pw.close();
- } catch (Exception e) {
- // ignore
- }
- }
- }
- }
- return sb.toString();
- }
-
- /**
- * Left justify a string.
- *
- * @param s the string to justify
- * @param width the field width to justify within
- * @param fillChar the character to fill with
- *
- * @return the justified string.
- */
- public static String left(String s, int width, char fillChar) {
- if (s.length() >= width) {
- return s;
- }
- StringBuffer sb = new StringBuffer(width);
- sb.append(s);
- for (int i = width - s.length(); --i >= 0;) {
- sb.append(fillChar);
- }
- return sb.toString();
- }
-
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/logging/jsr47min.properties b/EasyModbus/src/org/eclipse/paho/client/mqttv3/logging/jsr47min.properties
deleted file mode 100644
index 0626551..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/logging/jsr47min.properties
+++ /dev/null
@@ -1,83 +0,0 @@
-# Properties file which configures the operation of the JDK logging facility.
-#
-# The configuration in this file is the suggesgted configuration
-# for collecting trace for helping debug problems related to the
-# Paho MQTT client. It configures trace to be continuosly collected
-# in memory with minimal impact on performance.
-#
-# When the push trigger (by default a Severe level message) or a
-# specific request is made to "push" the in memory trace then it
-# is "pushed" to the configured target handler. By default
-# this is the standard java.util.logging.FileHandler. The Paho Debug
-# class can be used to push the memory trace to its target
-#
-# To enable trace either:
-# - use this properties file as is and set the logging facility up
-# to use it by configuring the util logging system property e.g.
-#
-# >java -Djava.util.logging.config.file=
-
-
-
-
-
-
- The quality of service for message delivery is met even if the network connection
- breaks, or the client or the server stop while a message is being delivered
-
-
-
-connect to the server
-
- publish messages to the server
- specifying a topic as the destination on the serversubscribe to one more topics. The server will send any messages
- it receives on those topics to the client. The client will be informed when a message
- arrives via a callback
- disconnect from the server.
-
-
-
\ No newline at end of file
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/persist/MemoryPersistence.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/persist/MemoryPersistence.java
deleted file mode 100644
index c684ddf..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/persist/MemoryPersistence.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.persist;
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
-import org.eclipse.paho.client.mqttv3.MqttPersistable;
-import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
-
-/**
- * Persistence that uses memory
- *
- * In cases where reliability is not required across client or device
- * restarts memory this memory peristence can be used. In cases where
- * reliability is required like when clean session is set to false
- * then a non-volatile form of persistence should be used.
- *
- */
-public class MemoryPersistence implements MqttClientPersistence {
-
- private Hashtable data;
-
- /* (non-Javadoc)
- * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#close()
- */
- public void close() throws MqttPersistenceException {
- data.clear();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#keys()
- */
- public Enumeration keys() throws MqttPersistenceException {
- return data.keys();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#get(java.lang.String)
- */
- public MqttPersistable get(String key) throws MqttPersistenceException {
- return (MqttPersistable)data.get(key);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#open(java.lang.String, java.lang.String)
- */
- public void open(String clientId, String serverURI) throws MqttPersistenceException {
- this.data = new Hashtable();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#put(java.lang.String, org.eclipse.paho.client.mqttv3.MqttPersistable)
- */
- public void put(String key, MqttPersistable persistable) throws MqttPersistenceException {
- data.put(key, persistable);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#remove(java.lang.String)
- */
- public void remove(String key) throws MqttPersistenceException {
- data.remove(key);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#clear()
- */
- public void clear() throws MqttPersistenceException {
- data.clear();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.paho.client.mqttv3.MqttClientPersistence#containsKey(java.lang.String)
- */
- public boolean containsKey(String key) throws MqttPersistenceException {
- return data.containsKey(key);
- }
-}
diff --git a/EasyModbus/src/org/eclipse/paho/client/mqttv3/persist/MqttDefaultFilePersistence.java b/EasyModbus/src/org/eclipse/paho/client/mqttv3/persist/MqttDefaultFilePersistence.java
deleted file mode 100644
index 19d3d31..0000000
--- a/EasyModbus/src/org/eclipse/paho/client/mqttv3/persist/MqttDefaultFilePersistence.java
+++ /dev/null
@@ -1,306 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2014 IBM Corp.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- * Dave Locke - initial API and implementation and/or initial documentation
- */
-package org.eclipse.paho.client.mqttv3.persist;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.util.Enumeration;
-import java.util.Vector;
-
-import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
-import org.eclipse.paho.client.mqttv3.MqttPersistable;
-import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
-import org.eclipse.paho.client.mqttv3.internal.FileLock;
-import org.eclipse.paho.client.mqttv3.internal.MqttPersistentData;
-
-/**
- * An implementation of the {@link MqttClientPersistence} interface that provides
- * file based persistence.
- *
- * A directory is specified when the Persistence object is created. When the persistence
- * is then opened (see {@link #open(String, String)}), a sub-directory is made beneath the base
- * for this client ID and connection key. This allows one persistence base directory
- * to be shared by multiple clients.
- *
- * The sub-directory's name is created from a concatenation of the client ID and connection key
- * with any instance of '/', '\\', ':' or ' ' removed.
- */
-public class MqttDefaultFilePersistence implements MqttClientPersistence {
- private static final String MESSAGE_FILE_EXTENSION = ".msg";
- private static final String MESSAGE_BACKUP_FILE_EXTENSION = ".bup";
- private static final String LOCK_FILENAME = ".lck";
-
- private File dataDir;
- private File clientDir = null;
- private FileLock fileLock = null;
-
- //TODO
- private static FilenameFilter FILENAME_FILTER;
-
- private static FilenameFilter getFilenameFilter(){
- if(FILENAME_FILTER == null){
- FILENAME_FILTER = new PersistanceFileNameFilter(MESSAGE_FILE_EXTENSION);
- }
- return FILENAME_FILTER;
- }
-
- public MqttDefaultFilePersistence() { //throws MqttPersistenceException {
- this(System.getProperty("user.dir"));
- }
-
- /**
- * Create an file-based persistent data store within the specified directory.
- * @param directory the directory to use.
- */
- public MqttDefaultFilePersistence(String directory) { //throws MqttPersistenceException {
- dataDir = new File(directory);
- }
-
- public void open(String clientId, String theConnection) throws MqttPersistenceException {
-
- if (dataDir.exists() && !dataDir.isDirectory()) {
- throw new MqttPersistenceException();
- } else if (!dataDir.exists() ) {
- if (!dataDir.mkdirs()) {
- throw new MqttPersistenceException();
- }
- }
- if (!dataDir.canWrite()) {
- throw new MqttPersistenceException();
- }
-
-
- StringBuffer keyBuffer = new StringBuffer();
- for (int i=0;i
-
- If set to true:
-
-
-
-
-
-
-
-
- A client registers interest in these notifications by registering a
- {@link org.eclipse.paho.client.mqttv3.MqttCallback MqttCallback} on the client
-
-
-
-
-