Gradle P4Java java.net.SocketTimeoutException: 读取超时
Gradle P4Java java.net.SocketTimeoutException: Read timed out
我在 build.gradle 文件中使用 P4Java 库来同步驻留在远程 Perforce 存储库中的大型 zip 文件 (>200MB),但我在同步过程中遇到 "java.net.SocketTimeoutException: Read timed out" 错误或者(主要是)在删除为同步操作创建的临时客户端期间。我指的是 http://razgulyaev.blogspot.in/2011/08/p4-java-api-how-to-work-with-temporary.html 使用 P4Java API.
与临时客户端一起工作
我尝试按照 http://answers.perforce.com/articles/KB/8044 中的建议将套接字读取超时从默认的 30 秒增加,并且还通过引入睡眠,但这两种方法都没有解决问题。在执行同步或删除操作之前使用 getServerInfo() 探测服务器以验证连接会导致连接检查成功。有人可以指出我应该在哪里寻找答案吗?
谢谢。
提供代码片段:
void perforceSync(String srcPath, String destPath, String server) {
// Generating the file(s) to sync-up
String[] pathUnderDepot = [
srcPath + "*"
]
// Increasing timeout from default 30 sec to 60 sec
Properties defaultProps = new Properties()
defaultProps.put(PropertyDefs.PROG_NAME_KEY, "CustomBuildApp")
defaultProps.put(PropertyDefs.PROG_VERSION_KEY, "tv_1.0")
defaultProps.put(RpcPropertyDefs.RPC_SOCKET_SO_TIMEOUT_NICK, "60000")
// Instantiating the server
IOptionsServer p4Server = ServerFactory.getOptionsServer("p4java://" + server, defaultProps)
p4Server.connect()
// Authorizing
p4Server.setUserName("perforceUserName")
p4Server.login("perforcePassword")
// Just check if connected successfully
IServerInfo serverInfo = p4Server.getServerInfo()
println 'Server info: ' + serverInfo.getServerLicense()
// Creating new client
IClient tempClient = new Client()
// Setting up the name and the root folder
tempClient.setName("tempClient" + UUID.randomUUID().toString().replace("-", ""))
tempClient.setRoot(destPath)
tempClient.setServer(p4Server)
// Setting the client as the current one for the server
p4Server.setCurrentClient(tempClient)
// Creating Client View entry
ClientViewMapping tempMappingEntry = new ClientViewMapping()
// Setting up the mapping properties
tempMappingEntry.setLeft(srcPath + "...")
tempMappingEntry.setRight("//" + tempClient.getName() + "/...")
tempMappingEntry.setType(EntryType.INCLUDE)
// Creating Client view
ClientView tempClientView = new ClientView()
// Attaching client view entry to client view
tempClientView.addEntry(tempMappingEntry)
tempClient.setClientView(tempClientView)
// Registering the new client on the server
println p4Server.createClient(tempClient)
// Surrounding the underlying block with try as we want some action
// (namely client removing) to be performed in any way
try {
// Forming the FileSpec collection to be synced-up
List<IFileSpec> fileSpecsSet = FileSpecBuilder.makeFileSpecList(pathUnderDepot)
// Syncing up the client
println "Syncing..."
tempClient.sync(FileSpecBuilder.getValidFileSpecs(fileSpecsSet), true, false, false, false)
}
catch (Exception e) {
println "Sync failed. Trying again..."
sleep(60 * 1000)
tempClient.sync(FileSpecBuilder.getValidFileSpecs(fileSpecsSet), true, false, false, false)
}
finally {
println "Done syncing."
try {
p4Server.connect()
IServerInfo serverInfo2 = p4Server.getServerInfo()
println '\nServer info: ' + serverInfo2.getServerLicense()
// Removing the temporary client from the server
println p4Server.deleteClient(tempClient.getName(), false)
}
catch(Exception e) {
println 'Ignoring exception caught while deleting tempClient!'
/*sleep(60 * 1000)
p4Server.connect()
IServerInfo serverInfo3 = p4Server.getServerInfo()
println '\nServer info: ' + serverInfo3.getServerLicense()
sleep(60 * 1000)
println p4Server.deleteClient(tempClient.getName(), false)*/
}
}
}
我在删除 tempClient 时观察到的一件不寻常的事情是它实际上是在删除客户端但仍然抛出 "java.net.SocketTimeoutException: Read timed out" 这就是为什么我最终评论了第二个 catch 块中的第二次删除尝试。
您使用的是哪个版本的 P4Java?你用最新的 P4Java 试过这个吗?从 2013.2 版本开始,有处理 RPC 套接字的值得注意的修复,如发行说明中所示:
http://www.perforce.com/perforce/doc.current/user/p4javanotes.txt
您可以尝试使用以下代码来增加超时和实例化服务器的一些变体:
a] 你试过在它自己的参数中传递 props 吗?例如:
Properties prop = new Properties();
prop.setProperty(RpcPropertyDefs.RPC_SOCKET_SO_TIMEOUT_NICK, "300000");
UsageOptions uop = new UsageOptions(prop);
server = ServerFactory.getOptionsServer(ServerFactory.DEFAULT_PROTOCOL_NAME + "://" + serverPort, prop, uop);
或类似以下内容:
IOptionsServer p4Server = ServerFactory.getOptionsServer("p4java://" + server, defaultProps)
您也可以将超时设置为“0”,使其不超时。
b]
props.put(RpcPropertyDefs.RPC_SOCKET_SO_TIMEOUT_NICK, "60000");
props.put(RpcPropertyDefs.RPC_SOCKET_POOL_SIZE_NICK, "5");
c]
Properties props = System.getProperties();
props.put(RpcPropertyDefs.RPC_SOCKET_SO_TIMEOUT_NICK, "60000");
IOptionsServer server =
ServerFactory.getOptionsServer("p4java://perforce:1666", props, null);
d] 如果您有 Eclipse 用户使用我们的 P4Eclipse 插件,可以在自定义 P4Java 属性下的插件首选项(Team->Perforce->Advanced)中设置 属性。
"sockSoTimeout":“3000000”
参考文献
Class RpcPropertyDefs
http://perforce.com/perforce/doc.current/manuals/p4java-javadoc/com/perforce/p4java/impl/mapbased/rpc/RpcPropertyDefs.html
P4Eclipse 或 P4Java:SocketTimeoutException:读取超时
http://answers.perforce.com/articles/KB/8044
我在 build.gradle 文件中使用 P4Java 库来同步驻留在远程 Perforce 存储库中的大型 zip 文件 (>200MB),但我在同步过程中遇到 "java.net.SocketTimeoutException: Read timed out" 错误或者(主要是)在删除为同步操作创建的临时客户端期间。我指的是 http://razgulyaev.blogspot.in/2011/08/p4-java-api-how-to-work-with-temporary.html 使用 P4Java API.
与临时客户端一起工作我尝试按照 http://answers.perforce.com/articles/KB/8044 中的建议将套接字读取超时从默认的 30 秒增加,并且还通过引入睡眠,但这两种方法都没有解决问题。在执行同步或删除操作之前使用 getServerInfo() 探测服务器以验证连接会导致连接检查成功。有人可以指出我应该在哪里寻找答案吗?
谢谢。
提供代码片段:
void perforceSync(String srcPath, String destPath, String server) {
// Generating the file(s) to sync-up
String[] pathUnderDepot = [
srcPath + "*"
]
// Increasing timeout from default 30 sec to 60 sec
Properties defaultProps = new Properties()
defaultProps.put(PropertyDefs.PROG_NAME_KEY, "CustomBuildApp")
defaultProps.put(PropertyDefs.PROG_VERSION_KEY, "tv_1.0")
defaultProps.put(RpcPropertyDefs.RPC_SOCKET_SO_TIMEOUT_NICK, "60000")
// Instantiating the server
IOptionsServer p4Server = ServerFactory.getOptionsServer("p4java://" + server, defaultProps)
p4Server.connect()
// Authorizing
p4Server.setUserName("perforceUserName")
p4Server.login("perforcePassword")
// Just check if connected successfully
IServerInfo serverInfo = p4Server.getServerInfo()
println 'Server info: ' + serverInfo.getServerLicense()
// Creating new client
IClient tempClient = new Client()
// Setting up the name and the root folder
tempClient.setName("tempClient" + UUID.randomUUID().toString().replace("-", ""))
tempClient.setRoot(destPath)
tempClient.setServer(p4Server)
// Setting the client as the current one for the server
p4Server.setCurrentClient(tempClient)
// Creating Client View entry
ClientViewMapping tempMappingEntry = new ClientViewMapping()
// Setting up the mapping properties
tempMappingEntry.setLeft(srcPath + "...")
tempMappingEntry.setRight("//" + tempClient.getName() + "/...")
tempMappingEntry.setType(EntryType.INCLUDE)
// Creating Client view
ClientView tempClientView = new ClientView()
// Attaching client view entry to client view
tempClientView.addEntry(tempMappingEntry)
tempClient.setClientView(tempClientView)
// Registering the new client on the server
println p4Server.createClient(tempClient)
// Surrounding the underlying block with try as we want some action
// (namely client removing) to be performed in any way
try {
// Forming the FileSpec collection to be synced-up
List<IFileSpec> fileSpecsSet = FileSpecBuilder.makeFileSpecList(pathUnderDepot)
// Syncing up the client
println "Syncing..."
tempClient.sync(FileSpecBuilder.getValidFileSpecs(fileSpecsSet), true, false, false, false)
}
catch (Exception e) {
println "Sync failed. Trying again..."
sleep(60 * 1000)
tempClient.sync(FileSpecBuilder.getValidFileSpecs(fileSpecsSet), true, false, false, false)
}
finally {
println "Done syncing."
try {
p4Server.connect()
IServerInfo serverInfo2 = p4Server.getServerInfo()
println '\nServer info: ' + serverInfo2.getServerLicense()
// Removing the temporary client from the server
println p4Server.deleteClient(tempClient.getName(), false)
}
catch(Exception e) {
println 'Ignoring exception caught while deleting tempClient!'
/*sleep(60 * 1000)
p4Server.connect()
IServerInfo serverInfo3 = p4Server.getServerInfo()
println '\nServer info: ' + serverInfo3.getServerLicense()
sleep(60 * 1000)
println p4Server.deleteClient(tempClient.getName(), false)*/
}
}
}
我在删除 tempClient 时观察到的一件不寻常的事情是它实际上是在删除客户端但仍然抛出 "java.net.SocketTimeoutException: Read timed out" 这就是为什么我最终评论了第二个 catch 块中的第二次删除尝试。
您使用的是哪个版本的 P4Java?你用最新的 P4Java 试过这个吗?从 2013.2 版本开始,有处理 RPC 套接字的值得注意的修复,如发行说明中所示:
http://www.perforce.com/perforce/doc.current/user/p4javanotes.txt
您可以尝试使用以下代码来增加超时和实例化服务器的一些变体:
a] 你试过在它自己的参数中传递 props 吗?例如:
Properties prop = new Properties();
prop.setProperty(RpcPropertyDefs.RPC_SOCKET_SO_TIMEOUT_NICK, "300000");
UsageOptions uop = new UsageOptions(prop);
server = ServerFactory.getOptionsServer(ServerFactory.DEFAULT_PROTOCOL_NAME + "://" + serverPort, prop, uop);
或类似以下内容:
IOptionsServer p4Server = ServerFactory.getOptionsServer("p4java://" + server, defaultProps)
您也可以将超时设置为“0”,使其不超时。
b]
props.put(RpcPropertyDefs.RPC_SOCKET_SO_TIMEOUT_NICK, "60000");
props.put(RpcPropertyDefs.RPC_SOCKET_POOL_SIZE_NICK, "5");
c]
Properties props = System.getProperties();
props.put(RpcPropertyDefs.RPC_SOCKET_SO_TIMEOUT_NICK, "60000");
IOptionsServer server =
ServerFactory.getOptionsServer("p4java://perforce:1666", props, null);
d] 如果您有 Eclipse 用户使用我们的 P4Eclipse 插件,可以在自定义 P4Java 属性下的插件首选项(Team->Perforce->Advanced)中设置 属性。
"sockSoTimeout":“3000000”
参考文献
Class RpcPropertyDefs http://perforce.com/perforce/doc.current/manuals/p4java-javadoc/com/perforce/p4java/impl/mapbased/rpc/RpcPropertyDefs.html
P4Eclipse 或 P4Java:SocketTimeoutException:读取超时 http://answers.perforce.com/articles/KB/8044