In SFTPEngine / Requester, move from using TimeUnit.SECONDS to TimeUnit.MILLISECONDS, and start using some more explicit naming

This commit is contained in:
Shikhar Bhushan
2013-02-23 16:26:37 -05:00
parent 1ced1d4fdc
commit 9539ff6b7a
5 changed files with 14 additions and 14 deletions

View File

@@ -35,7 +35,7 @@ public class RemoteDirectory
loop:
for (; ; ) {
final Response res = requester.request(newRequest(PacketType.READDIR))
.retrieve(requester.getTimeout(), TimeUnit.SECONDS);
.retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS);
switch (res.getType()) {
case NAME:

View File

@@ -40,7 +40,7 @@ public class RemoteFile
public FileAttributes fetchAttributes()
throws IOException {
return requester.request(newRequest(PacketType.FSTAT))
.retrieve(requester.getTimeout(), TimeUnit.SECONDS)
.retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS)
.ensurePacketTypeIs(PacketType.ATTRS)
.readFileAttributes();
}
@@ -59,7 +59,7 @@ public class RemoteFile
throws IOException {
final Response res = requester.request(
newRequest(PacketType.READ).putUInt64(fileOffset).putUInt32(len)
).retrieve(requester.getTimeout(), TimeUnit.SECONDS);
).retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS);
switch (res.getType()) {
case DATA:
int recvLen = res.readUInt32AsInt();
@@ -81,13 +81,13 @@ public class RemoteFile
.putUInt64(fileOffset)
.putUInt32(len - off)
.putRawBytes(data, off, len)
).retrieve(requester.getTimeout(), TimeUnit.SECONDS).ensureStatusPacketIsOK();
).retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS).ensureStatusPacketIsOK();
}
public void setAttributes(FileAttributes attrs)
throws IOException {
requester.request(newRequest(PacketType.FSETSTAT).putFileAttributes(attrs))
.retrieve(requester.getTimeout(), TimeUnit.SECONDS).ensureStatusPacketIsOK();
.retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS).ensureStatusPacketIsOK();
}
public int getOutgoingPacketOverhead() {

View File

@@ -51,7 +51,7 @@ public abstract class RemoteResource
throws IOException {
log.debug("Closing `{}`", this);
requester.request(newRequest(PacketType.CLOSE))
.retrieve(requester.getTimeout(), TimeUnit.SECONDS)
.retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS)
.ensureStatusPacketIsOK();
}

View File

@@ -28,6 +28,6 @@ public interface Requester {
Promise<Response, SFTPException> request(Request req)
throws IOException;
int getTimeout();
int getTimeoutMs();
}

View File

@@ -35,12 +35,12 @@ public class SFTPEngine
implements Requester, Closeable {
public static final int MAX_SUPPORTED_VERSION = 3;
public static final int DEFAULT_TIMEOUT = 30;
public static final int DEFAULT_TIMEOUT_MS = 30 * 1000; // way too long, but it was the original default
/** Logger */
protected final Logger log = LoggerFactory.getLogger(getClass());
protected volatile int timeout = DEFAULT_TIMEOUT;
protected volatile int timeoutMs = DEFAULT_TIMEOUT_MS;
protected final PathHelper pathHelper;
@@ -127,7 +127,7 @@ public class SFTPEngine
private Response doRequest(Request req)
throws IOException {
return request(req).retrieve(getTimeout(), TimeUnit.SECONDS);
return request(req).retrieve(getTimeoutMs(), TimeUnit.MILLISECONDS);
}
public RemoteFile open(String path, Set<OpenMode> modes, FileAttributes fa)
@@ -233,12 +233,12 @@ public class SFTPEngine
));
}
public void setTimeout(int timeout) {
this.timeout = timeout;
public void setTimeoutMs(int timeoutMs) {
this.timeoutMs = timeoutMs;
}
public int getTimeout() {
return timeout;
public int getTimeoutMs() {
return timeoutMs;
}
@Override