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: loop:
for (; ; ) { for (; ; ) {
final Response res = requester.request(newRequest(PacketType.READDIR)) final Response res = requester.request(newRequest(PacketType.READDIR))
.retrieve(requester.getTimeout(), TimeUnit.SECONDS); .retrieve(requester.getTimeoutMs(), TimeUnit.MILLISECONDS);
switch (res.getType()) { switch (res.getType()) {
case NAME: case NAME:

View File

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

View File

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

View File

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

View File

@@ -35,12 +35,12 @@ public class SFTPEngine
implements Requester, Closeable { implements Requester, Closeable {
public static final int MAX_SUPPORTED_VERSION = 3; 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 */ /** Logger */
protected final Logger log = LoggerFactory.getLogger(getClass()); protected final Logger log = LoggerFactory.getLogger(getClass());
protected volatile int timeout = DEFAULT_TIMEOUT; protected volatile int timeoutMs = DEFAULT_TIMEOUT_MS;
protected final PathHelper pathHelper; protected final PathHelper pathHelper;
@@ -127,7 +127,7 @@ public class SFTPEngine
private Response doRequest(Request req) private Response doRequest(Request req)
throws IOException { 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) public RemoteFile open(String path, Set<OpenMode> modes, FileAttributes fa)
@@ -233,12 +233,12 @@ public class SFTPEngine
)); ));
} }
public void setTimeout(int timeout) { public void setTimeoutMs(int timeoutMs) {
this.timeout = timeout; this.timeoutMs = timeoutMs;
} }
public int getTimeout() { public int getTimeoutMs() {
return timeout; return timeoutMs;
} }
@Override @Override