Skip to content
Permalink
Browse files
Add Duration APIs to specify timeouts.
- FTP] Add FTPClient.getControlKeepAliveReplyTimeoutDuration().
- FTP] Add FTPClient.setControlKeepAliveReplyTimeout(Duration).
- FTP] Add FTPClient.getControlKeepAliveTimeoutDuration().
- FTP] Add FTPClient.setControlKeepAliveTimeout(Duration).
  • Loading branch information
garydgregory committed Feb 20, 2021
1 parent 09f128a commit 866e2c03f90a16135d8184e023e39ed88b33334d
Showing 5 changed files with 173 additions and 45 deletions.
@@ -66,10 +66,22 @@ The <action> type attribute can be add,update,fix,remove.
<release version="3.9.0" date="2021-MM-DD" description="Maintenance and bug fix release (Java 8).">
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">
Add FTPClient.mdtmInstant(String).
[FTP] Add FTPClient.mdtmInstant(String).
</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">
Add MLSxEntryParser.parseGmtInstant(String).
[FTP] Add MLSxEntryParser.parseGmtInstant(String).
</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">
[FTP] Add FTPClient.getControlKeepAliveReplyTimeoutDuration().
</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">
[FTP] Add FTPClient.setControlKeepAliveReplyTimeout(Duration).
</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">
[FTP] Add FTPClient.getControlKeepAliveTimeoutDuration().
</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">
[FTP] Add FTPClient.setControlKeepAliveTimeout(Duration).
</action>
</release>
<release version="3.8.0" date="2021-02-13" description="Maintenance and bug fix release (Java 7).">
@@ -81,14 +93,14 @@ The <action> type attribute can be add,update,fix,remove.
Add and use SocketClient.applySocketAttributes().
</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">
Add FTPClient.hasFeature(FTPCmd).
[FTP] Add FTPClient.hasFeature(FTPCmd).
</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">
Add FTPClient.mdtmCalendar(String).
[FTP] Add FTPClient.mdtmCalendar(String).
</action>
<!-- FIX -->
<action type="fix" dev="ggregory" due-to="Gary Gregory">
Fix concurrent counting of chunks in IMAPExportMbox.
[IMAP] Fix concurrent counting of chunks in IMAPExportMbox.
</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">
Fix possible if rare NPEs in tests.
@@ -25,6 +25,7 @@
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.Duration;
import java.util.Arrays;

import org.apache.commons.net.PrintCommandListener;
@@ -298,10 +299,10 @@ else if (args[base].equals("-#")) {
ftp.setCopyStreamListener(createListener());
}
if (keepAliveTimeoutSeconds >= 0) {
ftp.setControlKeepAliveTimeout(keepAliveTimeoutSeconds);
ftp.setControlKeepAliveTimeout(Duration.ofSeconds(keepAliveTimeoutSeconds));
}
if (controlKeepAliveReplyTimeoutMillis >= 0) {
ftp.setControlKeepAliveReplyTimeout(controlKeepAliveReplyTimeoutMillis);
ftp.setControlKeepAliveReplyTimeout(Duration.ofMillis(controlKeepAliveReplyTimeoutMillis));
}
if (encoding != null) {
ftp.setControlEncoding(encoding);
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.commons.net.ftp;

import java.time.Duration;

/** Temporary until Commons Lang 3.12.0. */
class DurationUtils {

/**
* Tests whether the given Duration is positive (&gt;0).
*
* @param duration the value to test
* @return whether the given Duration is positive (&gt;0).
*/
static boolean isPositive(final Duration duration) {
return duration != null && !duration.isNegative() && !duration.isZero();
}

static int toMillisInt(final Duration duration) {
final long millis = duration.toMillis();
return millis > 0 ? (int) Math.min(millis, Integer.MAX_VALUE) : (int) Math.max(millis, Integer.MIN_VALUE);
}

static Duration zeroIfNull(final Duration controlIdle) {
return controlIdle == null ? Duration.ZERO : controlIdle;
}
}

0 comments on commit 866e2c0

Please sign in to comment.