Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 165944 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/tptp/platform/execution/client/core/IFileTransferManager.java (-3 / +8 lines)
Lines 21-41 Link Here
21
 *
21
 *
22
 */
22
 */
23
public interface IFileTransferManager {
23
public interface IFileTransferManager {
24
24
	public final static int FILE_TRANSFER_OK = 0;
25
	public final static int FILE_TRANSFER_ERROR = 1;
26
	public final static int FILE_NOT_FOUND = 2;
27
	public final static int FILE_READ_ERROR = 3;
28
	public final static int FILE_CREATE_ERROR = 4;
29
	
25
	/**
30
	/**
26
	 * Method to request Agent Controller to send the named file.
31
	 * Method to request Agent Controller to send the named file.
27
	 * @param localName - where to put it on the client side.
32
	 * @param localName - where to put it on the client side.
28
	 * @param remoteName - remote file name
33
	 * @param remoteName - remote file name
29
	 *
34
	 *
30
	 */
35
	 */
31
	public /*int*/ void getFile (String localName, String remoteName) throws IOException;
36
	public int getFile (String localName, String remoteName) throws IOException;
32
37
33
	/**
38
	/**
34
	 * Method to send a file to the Agent Controller machine.
39
	 * Method to send a file to the Agent Controller machine.
35
	 * @param localName - where to find the file.
40
	 * @param localName - where to find the file.
36
	 * @param remoteName -  where to put the file.
41
	 * @param remoteName -  where to put the file.
37
	 **/
42
	 **/
38
	public /*int*/ void putFile (String localName, String remoteName) throws IOException;
43
	public int putFile (String localName, String remoteName) throws IOException;
39
44
40
	/**
45
	/**
41
	 * Method to delete the named file
46
	 * Method to delete the named file
(-)src/org/eclipse/tptp/platform/execution/client/core/internal/FileDataProcessor.java (-35 / +48 lines)
Lines 19-40 Link Here
19
import java.io.FileOutputStream;
19
import java.io.FileOutputStream;
20
import java.net.InetAddress;
20
import java.net.InetAddress;
21
21
22
import org.eclipse.tptp.platform.execution.client.core.IFileTransferManager;
22
import org.eclipse.tptp.platform.execution.util.internal.Constants;
23
import org.eclipse.tptp.platform.execution.util.internal.Constants;
23
import org.eclipse.tptp.platform.execution.util.internal.DimeHeader;
24
import org.eclipse.tptp.platform.execution.util.internal.DimeHeader;
24
25
25
import java.io.IOException;
26
import java.io.IOException;
26
import java.util.Hashtable;
27
import java.util.HashMap;
27
28
28
public class FileDataProcessor implements IDataProcessorWithDime {
29
public class FileDataProcessor implements IDataProcessorWithDime {
29
	
30
	
30
	private FileDataMapper _fileNameMapper;
31
	private FileDataMapper _fileNameMapper;
31
	private Hashtable CompletedFilesHash;
32
	private HashMap CompletedFilesHash;
32
33
33
	public FileDataProcessor() {
34
	public FileDataProcessor() {
34
		super();
35
		super();
35
		// TODO Auto-generated constructor stub
36
		// TODO Auto-generated constructor stub
36
		_fileNameMapper = new FileDataMapper();
37
		_fileNameMapper = new FileDataMapper();
37
		CompletedFilesHash = new Hashtable();
38
		CompletedFilesHash = new HashMap();
38
	}
39
	}
39
	
40
	
40
	public void incomingData(byte[] buffer, int length, InetAddress peer)
41
	public void incomingData(byte[] buffer, int length, InetAddress peer)
Lines 47-60 Link Here
47
	 */
48
	 */
48
	public void incomingData(byte[] buffer, int length, InetAddress peer, byte[] dimeHeader)
49
	public void incomingData(byte[] buffer, int length, InetAddress peer, byte[] dimeHeader)
49
	{
50
	{
50
		int i;
51
		int rc;
52
		File fileHandle = null;
51
		File fileHandle = null;
53
		String fileName = null;
52
		String fileName = null;
54
		int dime_length = Constants.DIME_HEADER_LEN;
55
		DataOutputStream FileWriteStream = null;
53
		DataOutputStream FileWriteStream = null;
56
		DimeHeader dimeHeaderObj = DimeHeader.getDIMEHeader(dimeHeader);
54
		DimeHeader dimeHeaderObj = DimeHeader.getDIMEHeader(dimeHeader);
57
				
55
56
		int errorCode = getErrCodeFromHeader(dimeHeader, dimeHeaderObj);
57
58
		try
58
		try
59
		{
59
		{
60
			//System.out.println("The file handle to be written into - " + fileHandle);
60
			//System.out.println("The file handle to be written into - " + fileHandle);
Lines 64-74 Link Here
64
				//{
64
				//{
65
					
65
					
66
					fileName = getFileNameFromHeader(dimeHeader, dimeHeaderObj.getIDLength());
66
					fileName = getFileNameFromHeader(dimeHeader, dimeHeaderObj.getIDLength());
67
					if (fileName == null) System.out.println("Error - file name is null");
67
					if (fileName == null) { System.out.println("Error - file name is null"); return; }
68
					
68
					//System.out.println("File name is - " + fileName);
69
					//System.out.println("File name is - " + fileName);
69
					fileHandle = this._fileNameMapper.getProcessor(fileName);
70
					fileHandle = _fileNameMapper.getProcessor(fileName);
70
					//System.out.println("The file handle is - " + fileHandle);
71
					//System.out.println("The file handle is - " + fileHandle);
71
					if (fileHandle == null) {System.out.println("Invalid File Handle ");return;}
72
					if (fileHandle == null) {System.out.println("Invalid File Handle "); return; }
73
74
					if (errorCode != IFileTransferManager.FILE_TRANSFER_OK) {
75
						fileTransferCompleted (fileHandle, errorCode);
76
						return;
77
					}
78
					
72
					
79
					
73
					if (dimeHeaderObj.getMB())
80
					if (dimeHeaderObj.getMB())
74
					{
81
					{
Lines 87-93 Link Here
87
					/* Post the semaphore when we get to the last record */				
94
					/* Post the semaphore when we get to the last record */				
88
					if (dimeHeaderObj.getME()) {
95
					if (dimeHeaderObj.getME()) {
89
						//System.out.println("The File Transfer for file " + fileName + " is completed.");						;
96
						//System.out.println("The File Transfer for file " + fileName + " is completed.");						;
90
						CompletedFilesHash.put(fileHandle, new Boolean(true));
97
						fileTransferCompleted (fileHandle, IFileTransferManager.FILE_TRANSFER_OK);
91
					}
98
					}
92
				//}
99
				//}
93
			//}
100
			//}
Lines 99-104 Link Here
99
	
106
	
100
	}
107
	}
101
	
108
	
109
	private synchronized void fileTransferCompleted (File file, int errorCode) {
110
		if (file != null) {
111
			CompletedFilesHash.put(file, new Integer(errorCode));
112
			notifyAll ();
113
		}
114
	}
115
	
102
	/**
116
	/**
103
	 * Handle the data coming 
117
	 * Handle the data coming 
104
	 */
118
	 */
Lines 137-176 Link Here
137
	
151
	
138
	public void initializeFileTransfer(String fileName, File file)
152
	public void initializeFileTransfer(String fileName, File file)
139
	{
153
	{
140
		
154
		_fileNameMapper.addContext(fileName, file);
141
		this._fileNameMapper.addContext(fileName, file);
142
	}
155
	}
143
	
156
	
144
157
145
	public void waitForFileComplete(String fileName)
158
	public synchronized int waitForFileComplete(String fileName)
146
	{
159
	{
147
		File fileHandle = _fileNameMapper.getProcessor(fileName);
160
		File fileHandle = _fileNameMapper.getProcessor(fileName);
148
		boolean transferCompleted = false;
161
		if (fileHandle == null) return IFileTransferManager.FILE_TRANSFER_ERROR;
162
163
		Integer completed = null;
149
		
164
		
150
		try
165
		try {
151
		{
166
			while (true) {
152
			while (!transferCompleted)
167
				completed = (Integer) CompletedFilesHash.remove(fileHandle);
153
			{
168
				if (completed != null) {
154
				Boolean completed = (Boolean)CompletedFilesHash.get(fileHandle);
155
				if (completed != null && completed.booleanValue() == true)
156
				{
157
					CompletedFilesHash.remove(fileHandle);
158
					_fileNameMapper.removeContext(fileName);
169
					_fileNameMapper.removeContext(fileName);
159
					//System.out.println("The file transfer completed");
160
					break;
170
					break;
161
				}
171
				}
162
				else
172
				
163
				{
173
				wait();
164
					Thread.sleep(Constants.TIMEOUT_PERIOD);
165
					continue;
166
				}
167
			}			
174
			}			
168
		}
175
		}
169
		catch(InterruptedException exp)
176
		catch(InterruptedException exp)
170
		{
177
		{
171
			System.out.println("FileDataProcessor: Error waiting for file transfer complete " + exp);
178
			System.out.println("FileDataProcessor: Error waiting for file transfer complete " + exp);
172
		}
179
		}
173
		return;
180
		
181
		return completed.intValue();
174
	}
182
	}
175
	
183
	
176
	
184
	
Lines 179-190 Link Here
179
	 */
187
	 */
180
	public static String getFileNameFromHeader(byte[] buffer, int fileNameLength) 	
188
	public static String getFileNameFromHeader(byte[] buffer, int fileNameLength) 	
181
	{
189
	{
182
		byte[] fileName = new byte[fileNameLength-1];
190
		if (buffer == null || fileNameLength <= 1) return null;
183
		
191
		
184
		System.arraycopy(buffer,Constants.DIME_HEADER_LEN,fileName,0,fileNameLength-1);		
192
		return new String(buffer, Constants.DIME_HEADER_LEN, fileNameLength-1);
185
		//System.out.println(fileName);
193
	}
194
195
	public static int getErrCodeFromHeader(byte[] dime, DimeHeader dimeHeaderObj) 	
196
	{
197
		if (dimeHeaderObj.getOptionsLength() <= 0) return IFileTransferManager.FILE_TRANSFER_OK;
186
		
198
		
187
		return new String(fileName);
199
		int fileNameLen = dimeHeaderObj.getIDLength();
200
		
201
		return dime[Constants.DIME_HEADER_LEN + fileNameLen];
188
	}
202
	}
189
	
190
}
203
}
(-)src/org/eclipse/tptp/platform/execution/client/core/internal/FileTransferManagerImpl.java (-8 / +16 lines)
Lines 49-55 Link Here
49
	/* (non-Javadoc)
49
	/* (non-Javadoc)
50
	 * @see org.eclipse.tptp.platform.execution.core.IFileTransferManager#getFile(java.lang.String, java.lang.String)
50
	 * @see org.eclipse.tptp.platform.execution.core.IFileTransferManager#getFile(java.lang.String, java.lang.String)
51
	 */
51
	 */
52
	public void getFile(String localName, String remoteName) throws IOException
52
	public int getFile(String localName, String remoteName) throws IOException
53
	{
53
	{
54
		//System.out.println("getting '" + remoteName + "' to '" + localName + "'");
54
		//System.out.println("getting '" + remoteName + "' to '" + localName + "'");
55
	  
55
	  
Lines 73-88 Link Here
73
				boolean result = file.createNewFile();
73
				boolean result = file.createNewFile();
74
				if (!result) {
74
				if (!result) {
75
					//System.out.println("File creation failed!");
75
					//System.out.println("File creation failed!");
76
					return;
76
					return FILE_CREATE_ERROR;
77
				}
77
				}
78
			}
78
			}
79
			catch (IOException e) {
79
			catch (IOException e) {
80
				System.out.println("IOException on create " + e);
80
				System.out.println("IOException on create " + e);
81
				return;
81
				return FILE_CREATE_ERROR;
82
			}
82
			}
83
			
83
		if (!file.canWrite()) {
84
		if (!file.canWrite()) {
84
			System.out.println("Can't write to file!");
85
			System.out.println("Can't write to file!");
85
			return;
86
			return FILE_CREATE_ERROR;
86
		}
87
		}
87
		
88
		
88
		_fileDataProcessor.initializeFileTransfer(localName, file);
89
		_fileDataProcessor.initializeFileTransfer(localName, file);
Lines 103-109 Link Here
103
		catch(InactiveAgentException exp) {
104
		catch(InactiveAgentException exp) {
104
			System.out.println("Inactive Agent Exception" + exp);		  
105
			System.out.println("Inactive Agent Exception" + exp);		  
105
		}
106
		}
106
		_fileDataProcessor.waitForFileComplete(localName);
107
		
108
		return _fileDataProcessor.waitForFileComplete(localName);
107
	}
109
	}
108
	 
110
	 
109
	/* (non-Javadoc)
111
	/* (non-Javadoc)
Lines 129-141 Link Here
129
	/* (non-Javadoc)
131
	/* (non-Javadoc)
130
	 * @see org.eclipse.tptp.platform.execution.core.IFileTransferManager#putFile(java.lang.String, java.lang.String)
132
	 * @see org.eclipse.tptp.platform.execution.core.IFileTransferManager#putFile(java.lang.String, java.lang.String)
131
	 */
133
	 */
132
	public void putFile(String localName, String remoteName) throws IOException {
134
	public int putFile(String localName, String remoteName) throws IOException {
135
		File file = new File(localName);
136
		if (!file.exists()) return FILE_NOT_FOUND;
137
		if (!file.canRead()) return FILE_READ_ERROR;
138
		
133
		boolean _isComplete = false;
139
		boolean _isComplete = false;
134
140
135
		//Send the putFile command
141
		//Send the putFile command
136
		//System.out.println("Sending putFile() command");
142
		//System.out.println("Sending putFile() command");
137
		String putCmd = "<putFile iid=\"" + FILE_TRANSFER_AGENT + "\"><localFile>" +
143
		String putCmd = "<putFile iid=\"" + FILE_TRANSFER_AGENT + "\"><localFile>" +
138
						localName + "</localFile><remoteFile>" + remoteName + "</remoteFile></putFile>";
144
						localName + "</localFile><remoteFile>" + remoteName + "</remoteFile></putFile>";
145
		
139
		try {
146
		try {
140
			sendCommand(putCmd, new ICommandHandler() {
147
			sendCommand(putCmd, new ICommandHandler() {
141
				public void incomingCommand(INode node, ICommandElement command)
148
				public void incomingCommand(INode node, ICommandElement command)
Lines 149-155 Link Here
149
			System.out.println("Inactive Agent Exception" + exp);		  
156
			System.out.println("Inactive Agent Exception" + exp);		  
150
		}
157
		}
151
158
152
		File file = new File(localName);
153
		long fileLength = file.length();
159
		long fileLength = file.length();
154
		byte buffer[] = new byte[Constants.MAX_DATA_LENGTH];
160
		byte buffer[] = new byte[Constants.MAX_DATA_LENGTH];
155
		long byteCount = 0;
161
		long byteCount = 0;
Lines 206-212 Link Here
206
					// What gives? How did we read MORE than a buffer full??
212
					// What gives? How did we read MORE than a buffer full??
207
					// What do we do here? Bail? Send a DIME_MESSAGE_END packet?? of how much?
213
					// What do we do here? Bail? Send a DIME_MESSAGE_END packet?? of how much?
208
					//System.out.println("Should not have the case of reading more than asked for in putFile!");
214
					//System.out.println("Should not have the case of reading more than asked for in putFile!");
209
					return;
215
					return FILE_TRANSFER_ERROR;
210
				}
216
				}
211
				byteCount += ((bytesRead > 0) ? bytesRead : 0);
217
				byteCount += ((bytesRead > 0) ? bytesRead : 0);
212
			}
218
			}
Lines 218-223 Link Here
218
			//System.out.println("Did not send entire file correctly!");
224
			//System.out.println("Did not send entire file correctly!");
219
		}
225
		}
220
		inStream.close();
226
		inStream.close();
227
		
228
		return FILE_TRANSFER_OK;
221
	}
229
	}
222
	
230
	
223
	private void shipIt(int word0, String fileName, byte [] buffer, int dataLength) {
231
	private void shipIt(int word0, String fileName, byte [] buffer, int dataLength) {

Return to bug 165944