Skip to content

Commit dd7970d

Browse files
committed
Completing the move to Java 1.7
Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
1 parent eedd866 commit dd7970d

8 files changed

Lines changed: 78 additions & 92 deletions

File tree

org.eclipse.paho.client.mqttv3/src/main/java-templates/org/eclipse/paho/client/mqttv3/internal/ClientComms.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,4 +862,8 @@ public void publishBufferedMessage(BufferedMessage bufferedMessage) throws MqttE
862862
}
863863
}
864864

865+
public int getActualInFlight() {
866+
return this.clientState.getActualInFlight();
867+
}
868+
865869
}

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/MqttAsyncClient.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
* <p>This class implements the non-blocking {@link IMqttAsyncClient} client interface
6464
* allowing applications to initiate MQTT actions and then carry on working while the
6565
* MQTT action completes on a background thread.
66-
* This implementation is compatible with all Java SE runtimes from 1.4.2 and up.
66+
* This implementation is compatible with all Java SE runtimes from 1.7 and up.
6767
* </p>
6868
* <p>An application can connect to an MQTT server using:</p>
6969
* <ul>
@@ -480,7 +480,6 @@ private NetworkModule createNetworkModule(String address, MqttConnectOptions opt
480480
try {
481481
uri = new URI(address);
482482
} catch (URISyntaxException e) {
483-
// throw new IllegalArgumentException("Malformed URI: " + address, e); // Cannot use for Java 1.4.2
484483
throw new IllegalArgumentException("Malformed URI: " + address + ", " + e.getMessage());
485484
}
486485

@@ -1084,8 +1083,7 @@ public void messageArrivedComplete(int messageId, int qos) throws MqttException
10841083
*/
10851084
public static String generateClientId() {
10861085
//length of nanoTime = 15, so total length = 19 < 65535(defined in spec)
1087-
//return CLIENT_ID_PREFIX + System.nanoTime(); // Cannot use for Java 1.4.2
1088-
return CLIENT_ID_PREFIX + (System.currentTimeMillis() * 1000000);
1086+
return CLIENT_ID_PREFIX + System.nanoTime();
10891087

10901088
}
10911089

@@ -1227,8 +1225,7 @@ private void startReconnectCycle(){
12271225
String methodName = "startReconnectCycle";
12281226
//@Trace 503=Start reconnect timer for client: {0}, delay: {1}
12291227
log.fine(CLASS_NAME, methodName, "503", new Object[]{this.clientId, new Long(reconnectDelay)});
1230-
//reconnectTimer = new Timer("MQTT Reconnect: " + clientId); // Cannot use for Java 1.4.2
1231-
reconnectTimer = new Timer();
1228+
reconnectTimer = new Timer("MQTT Reconnect: " + clientId);
12321229
reconnectTimer.schedule(new ReconnectTask(), reconnectDelay);
12331230
}
12341231

@@ -1307,7 +1304,7 @@ public MqttMessage getBufferedMessage(int bufferIndex){
13071304
public void deleteBufferedMessage(int bufferIndex){
13081305
this.comms.deleteBufferedMessage(bufferIndex);
13091306
}
1310-
1307+
13111308
/**
13121309
* Returns the current number of outgoing in-flight messages
13131310
* being sent by the client. Note that this number cannot be

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/MqttClient.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v1.0
6-
* and Eclipse Distribution License v1.0 which accompany this distribution.
6+
* and Eclipse Distribution License v1.0 which accompany this distribution.
77
*
8-
* The Eclipse Public License is available at
8+
* The Eclipse Public License is available at
99
* http://www.eclipse.org/legal/epl-v10.html
10-
* and the Eclipse Distribution License is available at
10+
* and the Eclipse Distribution License is available at
1111
* http://www.eclipse.org/org/documents/edl-v10.php.
1212
*
1313
* Contributors:
@@ -32,14 +32,14 @@
3232
*
3333
* <p>This class implements the blocking {@link IMqttClient} client interface where all
3434
* actions block until they have completed (or timed out).
35-
* This implementation is compatible with all Java SE runtimes from 1.4.2 and up.
35+
* This implementation is compatible with all Java SE runtimes from 1.7 and up.
3636
* </p>
3737
* <p>An application can connect to an MQTT server using:</p>
3838
* <ul>
3939
* <li>A plain TCP socket
4040
* <li>An secure SSL/TLS socket
4141
* </ul>
42-
*
42+
*
4343
* <p>To enable messages to be delivered even across network and client restarts
4444
* messages need to be safely stored until the message has been delivered at the requested
4545
* quality of service. A pluggable persistence mechanism is provided to store the messages.
@@ -331,7 +331,7 @@ public void connect() throws MqttSecurityException, MqttException {
331331
public void connect(MqttConnectOptions options) throws MqttSecurityException, MqttException {
332332
aClient.connect(options, null, null).waitForCompletion(getTimeToWait());
333333
}
334-
334+
335335
/*
336336
* @see IMqttClient#connect(MqttConnectOptions)
337337
*/
@@ -357,7 +357,7 @@ public void disconnect(long quiesceTimeout) throws MqttException {
357357

358358
/*
359359
* (non-Javadoc)
360-
*
360+
*
361361
* @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#disconnectForcibly()
362362
*/
363363
public void disconnectForcibly() throws MqttException {
@@ -366,7 +366,7 @@ public void disconnectForcibly() throws MqttException {
366366

367367
/*
368368
* (non-Javadoc)
369-
*
369+
*
370370
* @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#disconnectForcibly(long)
371371
*/
372372
public void disconnectForcibly(long disconnectTimeout) throws MqttException {
@@ -375,7 +375,7 @@ public void disconnectForcibly(long disconnectTimeout) throws MqttException {
375375

376376
/*
377377
* (non-Javadoc)
378-
*
378+
*
379379
* @see org.eclipse.paho.client.mqttv3.IMqttAsyncClient#disconnectForcibly(long, long)
380380
*/
381381
public void disconnectForcibly(long quiesceTimeout, long disconnectTimeout) throws MqttException {
@@ -387,7 +387,7 @@ public void disconnectForcibly(long quiesceTimeout, long disconnectTimeout) thro
387387
* <p>
388388
* Because the client is able to establish the TCP/IP connection to a none MQTT server and it will certainly fail to
389389
* send the disconnect packet.
390-
*
390+
*
391391
* @param quiesceTimeout the amount of time in milliseconds to allow for existing work to finish before
392392
* disconnecting. A value of zero or less means the client will not quiesce.
393393
* @param disconnectTimeout the amount of time in milliseconds to allow send disconnect packet to server.
@@ -437,14 +437,14 @@ public void subscribe(String[] topicFilters, int[] qos) throws MqttException {
437437
throw new MqttException(MqttException.REASON_CODE_SUBSCRIBE_FAILED);
438438
}
439439
}
440-
440+
441441
/* (non-Javadoc)
442442
* @see org.eclipse.paho.client.mqttv3.IMqttClient#subscribe(java.lang.String, int, java.lang.Object, org.eclipse.paho.client.mqttv3.IMqttActionListener)
443443
*/
444444
public void subscribe(String topicFilter, IMqttMessageListener messageListener) throws MqttException {
445445
this.subscribe(new String[] {topicFilter}, new int[] {1}, new IMqttMessageListener[] {messageListener});
446446
}
447-
447+
448448
/* (non-Javadoc)
449449
* @see org.eclipse.paho.client.mqttv3.IMqttClient#subscribe(java.lang.String, int, java.lang.Object, org.eclipse.paho.client.mqttv3.IMqttActionListener)
450450
*/
@@ -463,23 +463,23 @@ public void subscribe(String topicFilter, int qos, IMqttMessageListener messageL
463463
this.subscribe(new String[] {topicFilter}, new int[] {qos}, new IMqttMessageListener[] {messageListener});
464464
}
465465

466-
467-
public void subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) throws MqttException {
466+
467+
public void subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) throws MqttException {
468468
this.subscribe(topicFilters, qos);
469-
469+
470470
// add message handlers to the list for this client
471471
for (int i = 0; i < topicFilters.length; ++i) {
472472
aClient.comms.setMessageListener(topicFilters[i], messageListeners[i]);
473473
}
474474
}
475-
475+
476476
/*
477477
* @see IMqttClient#subscribeWithResponse(String)
478478
*/
479479
public IMqttToken subscribeWithResponse(String topicFilter) throws MqttException {
480480
return this.subscribeWithResponse(new String[] {topicFilter}, new int[] {1});
481481
}
482-
482+
483483
/*
484484
* @see IMqttClient#subscribeWithResponse(String, IMqttMessageListener)
485485
*/
@@ -540,7 +540,7 @@ public IMqttToken subscribeWithResponse(String[] topicFilters, int[] qos) throws
540540
public IMqttToken subscribeWithResponse(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners)
541541
throws MqttException {
542542
IMqttToken tok = this.subscribeWithResponse(topicFilters, qos);
543-
543+
544544
// add message handlers to the list for this client
545545
for (int i = 0; i < topicFilters.length; ++i) {
546546
aClient.comms.setMessageListener(topicFilters[i], messageListeners[i]);
@@ -645,16 +645,16 @@ public IMqttDeliveryToken[] getPendingDeliveryTokens() {
645645
public String getServerURI() {
646646
return aClient.getServerURI();
647647
}
648-
648+
649649
/**
650650
* Returns the currently connected Server URI
651651
* Implemented due to: https://bugs.eclipse.org/bugs/show_bug.cgi?id=481097
652-
*
652+
*
653653
* Where getServerURI only returns the URI that was provided in
654654
* MqttAsyncClient's constructor, getCurrentServerURI returns the URI of the
655655
* Server that the client is currently connected to. This would be different in scenarios
656656
* where multiple server URIs have been provided to the MqttConnectOptions.
657-
*
657+
*
658658
* @return the currently connected server URI
659659
*/
660660
public String getCurrentServerURI(){
@@ -681,14 +681,14 @@ public boolean isConnected() {
681681
public void setCallback(MqttCallback callback) {
682682
aClient.setCallback(callback);
683683
}
684-
684+
685685
/* (non-Javadoc)
686686
* @see org.eclipse.paho.client.mqttv3.IMqttClient#setCallback(org.eclipse.paho.client.mqttv3.MqttCallback)
687687
*/
688688
public void setManualAcks(boolean manualAcks) {
689689
aClient.setManualAcks(manualAcks);
690690
}
691-
691+
692692
public void messageArrivedComplete(int messageId, int qos) throws MqttException {
693693
aClient.messageArrivedComplete(messageId, qos);
694694
}
@@ -705,7 +705,7 @@ public void messageArrivedComplete(int messageId, int qos) throws MqttException
705705
public static String generateClientId() {
706706
return MqttAsyncClient.generateClientId();
707707
}
708-
708+
709709
/**
710710
* Will attempt to reconnect to the server after the client has lost connection.
711711
* @throws MqttException if an error occurs attempting to reconnect
@@ -721,5 +721,5 @@ public void reconnect() throws MqttException {
721721
public Debug getDebug() {
722722
return (aClient.getDebug());
723723
}
724-
724+
725725
}

0 commit comments

Comments
 (0)