FileTransferAgent - strange behaviour [message #116203] |
Tue, 23 October 2007 08:38  |
Eclipse User |
|
|
|
Hi everybody,
my problem concerns file transfer and delete operations in TPTP using
standart FileTransferAgent. I'm using TPTP 4.3.1 and AC 4.3.1 runnig java
1.5.0_12. I also tried AC 4.4.0.3 with the same results.
I've got sample code like this one:
INode node = NodeFactory.createNode("localhost");
ConnectionInfo cInfo = new ConnectionInfo();
cInfo.setHostName("localhost");
cInfo.setPort(port);
IAgentController ac = node.connect(cInfo);
IFileTransferManager fileTransferMgr = ac.getFileTransferManager();
fileTransferMgr.putFile(localFilePath, remoteFilePath);
fileTransferMgr.putFile(otherLocalFilePath, otherRemoteFilePath);
Thread.sleep(1000);
fileTransferMgr.deleteFile(remoteFilePath);
Thread.sleep(1000);
fileTransferMgr.deleteFile(otherRemoteFilePath);
Thread.sleep(1000);
After some experimenting with the code I added Thread.sleep(1000)
statements to get this running properly. Without this sleeps one or both
files were not deleted.
My problem is that I don't understand why it doesn't work without sleeping
the thread because I didn't find any info in docs or in examples about it.
Sometimes file transfer hangs up too and it seems to me that it could have
similar reasons.
Can you please provide me some explanation of this strange behaviour?
Thanks in advance.
Jiri Bjalek
|
|
|
|
|
|
|
|
|
|
|
|
Re: FileTransferAgent - strange behaviour [message #116896 is a reply to message #116883] |
Thu, 01 November 2007 05:52   |
Eclipse User |
|
|
|
Hi again,
I have yet another sample code which works bad for me. This sample is
based on code I've found in
http://www.eclipse.org/tptp/home/documents/resources/AC_Assi sted_File_Transfer.html
in chapter '3.2 Sample file transfer code'.
This time I experimented with C++ code instead of Java.
/*********************************************************** ********************
* Copyright (c) 2005 Intel Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* Contributors:
*
* Kevin P O'Leary, Intel - Sample of FileTransfer Client
*
* $Id: MyFileTransferClient.cpp,v 1.8 2005/11/07 18:51:18 koleary Exp $
*
*
************************************************************ *******************/
#include <iostream>
using namespace std;
#include "tptp/client/NodeFactory.h"
#include "tptp/client/FileTransfer.h"
using namespace TPTP::Client;
int main(int argc, char* argv[])
{
char* hostName = "localhost";
int portNum = 10006;
INode* TargetNode = 0;
AgentController* ACProxy = 0;
// Create a Node object for the target system of choice.
TargetNode = NodeFactory::createNode(hostName);
if (!TargetNode)
{
cout<<"ERROR: Failed to create the Node object."<<endl;
cout<<"Press any key to exit..."<<endl;
getchar();
return -1;
}
// Establish a connection with an Agent Controller on the
// target system. The port number specified must match
// that defined in the configuration file for the desired
// Agent Controller.
ACProxy = TargetNode->connect(portNum);
if (!ACProxy)
{
cout<<"ERROR: Unable to connect to the Agent Controller running on
"<<hostName<<" at port number "<<portNum<<endl;
cout<<"Press any key to exit..."<<endl;
getchar();
return -1;
}
cout<<endl<<"Connected to the Agent Controller on \""<<hostName<<"\" at
port number "<<portNum<<endl;
//End of generic connect to AgentController code.
//Start of FileTransferAgent specific code.
// Create a client-side representative of a FileTransfer object from which
// a MyFileTransferAgent is derived, specifying the name of the desired
agent
// as it has been installed in the agents directory.
FileTransfer* MyFileTransferAgent = new
FileTransfer("org.eclipse.tptp.FileTransferAgent");
// Get a handle to the actual FileTransferAgent, storing it in the
MyFileTransferAgent
// object. If the call is successful, the FileTransferAgent is running
and
// ready to respond to requests.
// Note that the Agent Controller manages the life of an agent, so it
will start
// one running if needed.
// We request controller access to the agent since we want to perform
// actions like getFile and putFile. However, the FileTransferAgent is
not checking
// access levels on incoming requests at this time (TBD).
if (-1 == ACProxy->getAgent(MyFileTransferAgent, TPTP_CONTROLLER_ACCESS))
{
cout<<"ERROR: Unable to get agent
org.eclipse.tptp.FileTransferAgent"<<endl;
cout<<"Press any key to exit..."<<endl;
getchar();
return -1;
}
cout<<endl<<"The FileTransferAgent Agent ID:
"<<MyFileTransferAgent->getAgentID()<<endl;
//These next variables encode the file paths for the transfered files.
#ifdef _WIN32
char *remoteFile = "C:\\tmp\\oi\\big_simple.txt"; //This is the
source file for getFile and putFile.
//char *localFile = "C:\\tmp\\big_local.txt"; //This is the
destination file for getFile and putFile.
char *localFile = "C:\\tmp\\oi1.txt"; //This is the
destination file for getFile and putFile.
char *remoteFile2 = "C:\\tmp\\oi\\big_simple2.txt"; //This is
the source file for getFile and putFile.
//char *localFile2 = "C:\\tmp\\big_local2.txt"; //This is the
destination file for getFile and putFile.
char *localFile2 = "C:\\tmp\\oi2.txt"; //This is the
destination file for getFile and putFile.
//Deleted by deleteFile operation.
#else
//other platform than win32 not used
#endif
tptp_int32 res;
for (int iter=0; iter<100000; iter++) {
cout << "Kolo: " << iter << endl;
cout << "putFile1 " << endl;
res = MyFileTransferAgent->putFile(localFile, remoteFile);
cout << "putFile2? " << res << endl;
cout << "putFile3 " << endl;
res = MyFileTransferAgent->putFile(localFile2, remoteFile2);
cout << "putFile4? " << res << endl;
cout << "deleteFile1 " << endl;
res = MyFileTransferAgent->deleteFile(remoteFile);
cout << "deleteFile2? " << res << endl;
cout << "deleteFile3 " << endl;
res = MyFileTransferAgent->deleteFile(remoteFile2);
cout << "deleteFile4? " << res << endl;
}
//Put the file specified in remoteFile to localFile.
//MyFileTransferAgent->putFile(remoteFile, localFile);
// Wait for data to finish coming over channel.
// Note: A protocol for recognizing end of data is TBD.
Sleep(2000);
// Release resources allocated by the Agent Controller
MyFileTransferAgent->destroyDataConnection();
MyFileTransferAgent->releaseAgent();
ACProxy->disconnect();
// Release client side resources
delete MyFileTransferAgent;
ACProxy->destroy();
NodeFactory::deleteNode(TargetNode);
cout << "This is the end :)" << endl;
return 0;
}
------------------------------------------------------------ --------------
Both files localFile and localFile2 have 16B in my case and after about
50000 iterations remote files are not replaced but the content is
appended. Transfered file has several kB instead of just 16B and the
content repeats several times.
Regards,
Jiri
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.28051 seconds