Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 60260 Details for
Bug 165944
FileTransferManager getFile/putFile methods hang.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Execution patch
execution.txt (text/plain), 10.96 KB, created by
Igor Alelekov
on 2007-03-05 08:08:56 EST
(
hide
)
Description:
Execution patch
Filename:
MIME Type:
Creator:
Igor Alelekov
Created:
2007-03-05 08:08:56 EST
Size:
10.96 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.tptp.platform.execution >Index: src/org/eclipse/tptp/platform/execution/client/core/IFileTransferManager.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/client/core/IFileTransferManager.java,v >retrieving revision 1.1 >diff -u -r1.1 IFileTransferManager.java >--- src/org/eclipse/tptp/platform/execution/client/core/IFileTransferManager.java 29 Sep 2005 21:34:38 -0000 1.1 >+++ src/org/eclipse/tptp/platform/execution/client/core/IFileTransferManager.java 5 Mar 2007 12:59:34 -0000 >@@ -21,21 +21,26 @@ > * > */ > public interface IFileTransferManager { >- >+ public final static int FILE_TRANSFER_OK = 0; >+ public final static int FILE_TRANSFER_ERROR = 1; >+ public final static int FILE_NOT_FOUND = 2; >+ public final static int FILE_READ_ERROR = 3; >+ public final static int FILE_CREATE_ERROR = 4; >+ > /** > * Method to request Agent Controller to send the named file. > * @param localName - where to put it on the client side. > * @param remoteName - remote file name > * > */ >- public /*int*/ void getFile (String localName, String remoteName) throws IOException; >+ public int getFile (String localName, String remoteName) throws IOException; > > /** > * Method to send a file to the Agent Controller machine. > * @param localName - where to find the file. > * @param remoteName - where to put the file. > **/ >- public /*int*/ void putFile (String localName, String remoteName) throws IOException; >+ public int putFile (String localName, String remoteName) throws IOException; > > /** > * Method to delete the named file >Index: src/org/eclipse/tptp/platform/execution/client/core/internal/FileDataProcessor.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/client/core/internal/FileDataProcessor.java,v >retrieving revision 1.3 >diff -u -r1.3 FileDataProcessor.java >--- src/org/eclipse/tptp/platform/execution/client/core/internal/FileDataProcessor.java 30 Oct 2006 21:44:24 -0000 1.3 >+++ src/org/eclipse/tptp/platform/execution/client/core/internal/FileDataProcessor.java 5 Mar 2007 12:59:34 -0000 >@@ -19,22 +19,23 @@ > import java.io.FileOutputStream; > import java.net.InetAddress; > >+import org.eclipse.tptp.platform.execution.client.core.IFileTransferManager; > import org.eclipse.tptp.platform.execution.util.internal.Constants; > import org.eclipse.tptp.platform.execution.util.internal.DimeHeader; > > import java.io.IOException; >-import java.util.Hashtable; >+import java.util.HashMap; > > public class FileDataProcessor implements IDataProcessorWithDime { > > private FileDataMapper _fileNameMapper; >- private Hashtable CompletedFilesHash; >+ private HashMap CompletedFilesHash; > > public FileDataProcessor() { > super(); > // TODO Auto-generated constructor stub > _fileNameMapper = new FileDataMapper(); >- CompletedFilesHash = new Hashtable(); >+ CompletedFilesHash = new HashMap(); > } > > public void incomingData(byte[] buffer, int length, InetAddress peer) >@@ -47,14 +48,13 @@ > */ > public void incomingData(byte[] buffer, int length, InetAddress peer, byte[] dimeHeader) > { >- int i; >- int rc; > File fileHandle = null; > String fileName = null; >- int dime_length = Constants.DIME_HEADER_LEN; > DataOutputStream FileWriteStream = null; > DimeHeader dimeHeaderObj = DimeHeader.getDIMEHeader(dimeHeader); >- >+ >+ int errorCode = getErrCodeFromHeader(dimeHeader, dimeHeaderObj); >+ > try > { > //System.out.println("The file handle to be written into - " + fileHandle); >@@ -64,11 +64,18 @@ > //{ > > fileName = getFileNameFromHeader(dimeHeader, dimeHeaderObj.getIDLength()); >- if (fileName == null) System.out.println("Error - file name is null"); >+ if (fileName == null) { System.out.println("Error - file name is null"); return; } >+ > //System.out.println("File name is - " + fileName); >- fileHandle = this._fileNameMapper.getProcessor(fileName); >+ fileHandle = _fileNameMapper.getProcessor(fileName); > //System.out.println("The file handle is - " + fileHandle); >- if (fileHandle == null) {System.out.println("Invalid File Handle ");return;} >+ if (fileHandle == null) {System.out.println("Invalid File Handle "); return; } >+ >+ if (errorCode != IFileTransferManager.FILE_TRANSFER_OK) { >+ fileTransferCompleted (fileHandle, errorCode); >+ return; >+ } >+ > > if (dimeHeaderObj.getMB()) > { >@@ -87,7 +94,7 @@ > /* Post the semaphore when we get to the last record */ > if (dimeHeaderObj.getME()) { > //System.out.println("The File Transfer for file " + fileName + " is completed."); ; >- CompletedFilesHash.put(fileHandle, new Boolean(true)); >+ fileTransferCompleted (fileHandle, IFileTransferManager.FILE_TRANSFER_OK); > } > //} > //} >@@ -99,6 +106,13 @@ > > } > >+ private synchronized void fileTransferCompleted (File file, int errorCode) { >+ if (file != null) { >+ CompletedFilesHash.put(file, new Integer(errorCode)); >+ notifyAll (); >+ } >+ } >+ > /** > * Handle the data coming > */ >@@ -137,40 +151,34 @@ > > public void initializeFileTransfer(String fileName, File file) > { >- >- this._fileNameMapper.addContext(fileName, file); >+ _fileNameMapper.addContext(fileName, file); > } > > >- public void waitForFileComplete(String fileName) >+ public synchronized int waitForFileComplete(String fileName) > { > File fileHandle = _fileNameMapper.getProcessor(fileName); >- boolean transferCompleted = false; >+ if (fileHandle == null) return IFileTransferManager.FILE_TRANSFER_ERROR; >+ >+ Integer completed = null; > >- try >- { >- while (!transferCompleted) >- { >- Boolean completed = (Boolean)CompletedFilesHash.get(fileHandle); >- if (completed != null && completed.booleanValue() == true) >- { >- CompletedFilesHash.remove(fileHandle); >+ try { >+ while (true) { >+ completed = (Integer) CompletedFilesHash.remove(fileHandle); >+ if (completed != null) { > _fileNameMapper.removeContext(fileName); >- //System.out.println("The file transfer completed"); > break; > } >- else >- { >- Thread.sleep(Constants.TIMEOUT_PERIOD); >- continue; >- } >+ >+ wait(); > } > } > catch(InterruptedException exp) > { > System.out.println("FileDataProcessor: Error waiting for file transfer complete " + exp); > } >- return; >+ >+ return completed.intValue(); > } > > >@@ -179,12 +187,17 @@ > */ > public static String getFileNameFromHeader(byte[] buffer, int fileNameLength) > { >- byte[] fileName = new byte[fileNameLength-1]; >+ if (buffer == null || fileNameLength <= 1) return null; > >- System.arraycopy(buffer,Constants.DIME_HEADER_LEN,fileName,0,fileNameLength-1); >- //System.out.println(fileName); >+ return new String(buffer, Constants.DIME_HEADER_LEN, fileNameLength-1); >+ } >+ >+ public static int getErrCodeFromHeader(byte[] dime, DimeHeader dimeHeaderObj) >+ { >+ if (dimeHeaderObj.getOptionsLength() <= 0) return IFileTransferManager.FILE_TRANSFER_OK; > >- return new String(fileName); >+ int fileNameLen = dimeHeaderObj.getIDLength(); >+ >+ return dime[Constants.DIME_HEADER_LEN + fileNameLen]; > } >- > } >Index: src/org/eclipse/tptp/platform/execution/client/core/internal/FileTransferManagerImpl.java >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.execution/src/org/eclipse/tptp/platform/execution/client/core/internal/FileTransferManagerImpl.java,v >retrieving revision 1.3 >diff -u -r1.3 FileTransferManagerImpl.java >--- src/org/eclipse/tptp/platform/execution/client/core/internal/FileTransferManagerImpl.java 28 Jul 2006 22:17:38 -0000 1.3 >+++ src/org/eclipse/tptp/platform/execution/client/core/internal/FileTransferManagerImpl.java 5 Mar 2007 12:59:34 -0000 >@@ -49,7 +49,7 @@ > /* (non-Javadoc) > * @see org.eclipse.tptp.platform.execution.core.IFileTransferManager#getFile(java.lang.String, java.lang.String) > */ >- public void getFile(String localName, String remoteName) throws IOException >+ public int getFile(String localName, String remoteName) throws IOException > { > //System.out.println("getting '" + remoteName + "' to '" + localName + "'"); > >@@ -73,16 +73,17 @@ > boolean result = file.createNewFile(); > if (!result) { > //System.out.println("File creation failed!"); >- return; >+ return FILE_CREATE_ERROR; > } > } > catch (IOException e) { > System.out.println("IOException on create " + e); >- return; >+ return FILE_CREATE_ERROR; > } >+ > if (!file.canWrite()) { > System.out.println("Can't write to file!"); >- return; >+ return FILE_CREATE_ERROR; > } > > _fileDataProcessor.initializeFileTransfer(localName, file); >@@ -103,7 +104,8 @@ > catch(InactiveAgentException exp) { > System.out.println("Inactive Agent Exception" + exp); > } >- _fileDataProcessor.waitForFileComplete(localName); >+ >+ return _fileDataProcessor.waitForFileComplete(localName); > } > > /* (non-Javadoc) >@@ -129,13 +131,18 @@ > /* (non-Javadoc) > * @see org.eclipse.tptp.platform.execution.core.IFileTransferManager#putFile(java.lang.String, java.lang.String) > */ >- public void putFile(String localName, String remoteName) throws IOException { >+ public int putFile(String localName, String remoteName) throws IOException { >+ File file = new File(localName); >+ if (!file.exists()) return FILE_NOT_FOUND; >+ if (!file.canRead()) return FILE_READ_ERROR; >+ > boolean _isComplete = false; > > //Send the putFile command > //System.out.println("Sending putFile() command"); > String putCmd = "<putFile iid=\"" + FILE_TRANSFER_AGENT + "\"><localFile>" + > localName + "</localFile><remoteFile>" + remoteName + "</remoteFile></putFile>"; >+ > try { > sendCommand(putCmd, new ICommandHandler() { > public void incomingCommand(INode node, ICommandElement command) >@@ -149,7 +156,6 @@ > System.out.println("Inactive Agent Exception" + exp); > } > >- File file = new File(localName); > long fileLength = file.length(); > byte buffer[] = new byte[Constants.MAX_DATA_LENGTH]; > long byteCount = 0; >@@ -206,7 +212,7 @@ > // What gives? How did we read MORE than a buffer full?? > // What do we do here? Bail? Send a DIME_MESSAGE_END packet?? of how much? > //System.out.println("Should not have the case of reading more than asked for in putFile!"); >- return; >+ return FILE_TRANSFER_ERROR; > } > byteCount += ((bytesRead > 0) ? bytesRead : 0); > } >@@ -218,6 +224,8 @@ > //System.out.println("Did not send entire file correctly!"); > } > inStream.close(); >+ >+ return FILE_TRANSFER_OK; > } > > private void shipIt(int word0, String fileName, byte [] buffer, int dataLength) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 165944
:
60259
| 60260