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 166596
Collapse All | Expand All

(-)src/org/eclipse/tptp/platform/execution/client/core/internal/ConsoleDataProcessor.java (-13 / +52 lines)
Lines 37-42 Link Here
37
	class ContextMap {
37
	class ContextMap {
38
		public long _pid=0;
38
		public long _pid=0;
39
		public IDataProcessor _processor=null;
39
		public IDataProcessor _processor=null;
40
		public IDataProcessor stderrProcessor=null;
40
		public boolean _dirty=false;
41
		public boolean _dirty=false;
41
	}
42
	}
42
43
Lines 45-50 Link Here
45
	}
46
	}
46
47
47
	public void addDataProcessor(long pid, IDataProcessor processor) {
48
	public void addDataProcessor(long pid, IDataProcessor processor) {
49
		addDataProcessor (pid, processor, null);
50
	}
51
	
52
	public void addDataProcessor(long pid, IDataProcessor processor, IDataProcessor stderrProcessor) {
48
		synchronized(_map) {
53
		synchronized(_map) {
49
			if(_maxMappingCount == _map.length) {
54
			if(_maxMappingCount == _map.length) {
50
				increaseContextmappingCapacity();
55
				increaseContextmappingCapacity();
Lines 57-62 Link Here
57
					_map[i]=new ContextMap();
62
					_map[i]=new ContextMap();
58
					_map[i]._pid=pid;
63
					_map[i]._pid=pid;
59
					_map[i]._processor=processor;
64
					_map[i]._processor=processor;
65
					_map[i].stderrProcessor=stderrProcessor;
60
					_map[i]._dirty=true;
66
					_map[i]._dirty=true;
61
					return;
67
					return;
62
				}
68
				}
Lines 64-69 Link Here
64
					_mappingCount++;
70
					_mappingCount++;
65
					_map[i]._pid=pid;
71
					_map[i]._pid=pid;
66
					_map[i]._processor=processor;
72
					_map[i]._processor=processor;
73
					_map[i].stderrProcessor=stderrProcessor;
67
					_map[i]._dirty=true;
74
					_map[i]._dirty=true;
68
					return;
75
					return;
69
				}
76
				}
Lines 72-77 Link Here
72
	}
79
	}
73
80
74
	public IDataProcessor getProcessor(long pid) {
81
	public IDataProcessor getProcessor(long pid) {
82
		return getProcessor (pid, IConsole.STDOUT);
83
	}
84
85
	public IDataProcessor getProcessor(long pid, int stream) {
75
		IDataProcessor ch=null;
86
		IDataProcessor ch=null;
76
		synchronized (_map) {
87
		synchronized (_map) {
77
			for(int i=_maxMappingCount-1; i>=0; i--) {
88
			for(int i=_maxMappingCount-1; i>=0; i--) {
Lines 80-86 Link Here
80
					break;
91
					break;
81
				}
92
				}
82
				if(_map[i]._pid==pid && _map[i]._dirty==true ) {
93
				if(_map[i]._pid==pid && _map[i]._dirty==true ) {
83
					ch=_map[i]._processor;
94
					if (stream == ConsoleImpl.STDOUT) {
95
						ch=_map[i]._processor;
96
					}
97
					else if (stream == ConsoleImpl.STDERR) {
98
						ch=_map[i].stderrProcessor;
99
					}
100
						
84
					break;
101
					break;
85
				}
102
				}
86
			}
103
			}
Lines 106-111 Link Here
106
					_mappingCount--;
123
					_mappingCount--;
107
					_map[i]._dirty=false;
124
					_map[i]._dirty=false;
108
					_map[i]._processor=null;
125
					_map[i]._processor=null;
126
					_map[i].stderrProcessor=null;
109
					break;
127
					break;
110
				}
128
				}
111
			}
129
			}
Lines 128-160 Link Here
128
	{
146
	{
129
		if(buffer.length < pid_length)
147
		if(buffer.length < pid_length)
130
		{	return -1;}
148
		{	return -1;}
131
		byte[] pbyte = new byte[pid_length-1];
149
//		byte[] pbyte = new byte[pid_length-1];
132
		System.arraycopy(buffer,Constants.DIME_HEADER_LEN,pbyte,0,pid_length-1);
150
//		System.arraycopy(buffer,Constants.DIME_HEADER_LEN,pbyte,0,pid_length-1);
133
		//Now that you have the Console part of the Header containing the PID - it also contains the 
151
		//Now that you have the Console part of the Header containing the PID - it also contains the 
134
		//prefix in this case TPTP_STDOUT: prefix = 'O' ;
152
		//prefix in this case TPTP_STDOUT: prefix = 'O' ;
135
		
153
		
136
		return Long.parseLong((new String(pbyte)).substring(1),10);
154
//		return Long.parseLong((new String(pbyte)).substring(1),10);
155
		return Long.parseLong(new String(buffer, Constants.DIME_HEADER_LEN+1, pid_length-2),10);
156
	}
157
158
	public static int getTPTPConsoleStream(byte[] buffer) {
159
		int stream = -1;
160
		if (buffer != null && buffer.length > Constants.DIME_HEADER_LEN) {
161
			switch ((char) buffer[Constants.DIME_HEADER_LEN]) {
162
			case Constants.DIME_TPTP_STDOUT:  
163
				stream = ConsoleImpl.STDOUT;
164
				break;
165
			case Constants.DIME_TPTP_STDERR:  
166
				stream = ConsoleImpl.STDERR;
167
				break;
168
			}
169
		}
170
		
171
		return stream;
137
	}
172
	}
173
	
138
	/**
174
	/**
139
	 * Get the Data
175
	 * Get the Data
140
	 */
176
	 */
141
	public static String getTPTPConsoleData(byte[] buffer, int length) 
177
	public static String getTPTPConsoleData(byte[] buffer, int length) 
142
	{
178
	{
143
		byte[] data = new byte[length];
179
		return new String(buffer, 0, length);
144
		System.arraycopy(buffer,0,data,0,length);
145
		return new String(data);
146
	}
180
	}
181
	
147
	public void incomingData(byte[] buffer, int length, InetAddress peer, byte[] dimeHeader)
182
	public void incomingData(byte[] buffer, int length, InetAddress peer, byte[] dimeHeader)
148
	{
183
	{
149
		int dime_length = Constants.DIME_HEADER_LEN;
150
		DimeHeader dimeHeaderObj = DimeHeader.getDIMEHeader(dimeHeader);
184
		DimeHeader dimeHeaderObj = DimeHeader.getDIMEHeader(dimeHeader);
151
		long pid = getTPTPConsoleProcessId(dimeHeader, dimeHeaderObj.getIDLength());
185
		long pid = getTPTPConsoleProcessId(dimeHeader, dimeHeaderObj.getIDLength());
186
		int stream = getTPTPConsoleStream(dimeHeader);
187
	
188
		IDataProcessor cp = getProcessor(pid, stream);
189
		if (cp == null && stream != IConsole.STDOUT) cp = getProcessor(pid, IConsole.STDOUT);  
152
		
190
		
153
		IDataProcessor cp = this.getProcessor(pid);
191
		if (cp != null) { 
154
		String cdata = getTPTPConsoleData(buffer, length);
192
//			cp.incomingData(buffer, length, peer);
155
		//The following to be looked up following the API change
193
			cp.incomingData(getTPTPConsoleData(buffer,length).getBytes(), length, peer);
156
		cp.incomingData(getTPTPConsoleData(buffer,length).getBytes(), length, peer);
194
		}
157
	}
195
}
196
	
158
	public void incomingData(char[] buffer, int length, InetAddress peer, char[] dimeHeader)
197
	public void incomingData(char[] buffer, int length, InetAddress peer, char[] dimeHeader)
159
	{
198
	{
160
		System.out.println(" Incomming Data Buffer -- DO NOTHING  "+new String(buffer));
199
		System.out.println(" Incomming Data Buffer -- DO NOTHING  "+new String(buffer));
(-)src/org/eclipse/tptp/platform/execution/client/core/internal/ConsoleImpl.java (+31 lines)
Lines 39-44 Link Here
39
	protected ServerSocket _sock = null; /* 9707 */
39
	protected ServerSocket _sock = null; /* 9707 */
40
	//DataProcessor used by both TPTP 3.x and 4.x
40
	//DataProcessor used by both TPTP 3.x and 4.x
41
	protected IDataProcessor _processor=null;
41
	protected IDataProcessor _processor=null;
42
	protected IDataProcessor stderrProcessor=null;
42
	protected long _ip=0;
43
	protected long _ip=0;
43
	protected long _port=0;
44
	protected long _port=0;
44
	private boolean _started=false;
45
	private boolean _started=false;
Lines 99-104 Link Here
99
		this._processor=processor;
100
		this._processor=processor;
100
	}
101
	}
101
102
103
	public void setDataProcessor(IDataProcessor processor, int stream) {
104
		switch (stream) {
105
		case STDOUT:
106
			this._processor = processor;
107
			break;
108
		case STDERR:
109
			this.stderrProcessor = processor;
110
			break;
111
		}
112
	}
113
102
	/* (non-Javadoc)
114
	/* (non-Javadoc)
103
	 * @see org.eclipse.tptp.platform.execution.core.IConsole#getDataProcessor()
115
	 * @see org.eclipse.tptp.platform.execution.core.IConsole#getDataProcessor()
104
	 */
116
	 */
Lines 106-111 Link Here
106
	{
118
	{
107
		return _processor;
119
		return _processor;
108
	}
120
	}
121
	
122
	public IDataProcessor getDataProcessor(int stream) {
123
		IDataProcessor dp;
124
		
125
		switch (stream) {
126
		case STDOUT:
127
			dp = _processor;
128
			break;
129
		case STDERR:
130
			dp = stderrProcessor;
131
			break;
132
		default:
133
			dp = null;
134
			break;
135
		}
136
		
137
		return dp;
138
	}
139
	
109
	public void setAC(IAgentController ac)
140
	public void setAC(IAgentController ac)
110
	{
141
	{
111
		this._ac = ac;
142
		this._ac = ac;
(-)src/org/eclipse/tptp/platform/execution/client/core/internal/ProcessImpl.java (-1 / +1 lines)
Lines 621-627 Link Here
621
 				{
621
 				{
622
 					((AgentController)this._ac).addDataListener(this._consoleDataConnectID, (IDataProcessor)consoleMap);
622
 					((AgentController)this._ac).addDataListener(this._consoleDataConnectID, (IDataProcessor)consoleMap);
623
 					this._console.setProcessID(_processId);
623
 					this._console.setProcessID(_processId);
624
 					consoleMap.addDataProcessor(_processId,_console.getDataProcessor());
624
 					consoleMap.addDataProcessor(_processId,_console.getDataProcessor(IConsole.STDOUT), _console.getDataProcessor(IConsole.STDERR));
625
 				}
625
 				}
626
 				if(Constants.TPTP_DEBUG) System.out.println("Process launch response "+ commandStr);
626
 				if(Constants.TPTP_DEBUG) System.out.println("Process launch response "+ commandStr);
627
 				String contextID = (String)ParseObj.getHashTable().get("ctxt");
627
 				String contextID = (String)ParseObj.getHashTable().get("ctxt");
(-)src/org/eclipse/tptp/platform/execution/samples/TPTPProcess.java (-9 / +21 lines)
Lines 38-44 Link Here
38
    	//Connect to the host where the Agent Controller is running
38
    	//Connect to the host where the Agent Controller is running
39
	    //See the Getting started guide for TPTP 4.0 
39
	    //See the Getting started guide for TPTP 4.0 
40
		String localhost = "127.0.0.1";
40
		String localhost = "127.0.0.1";
41
		int port = 10002;
41
		int port = 10006;
42
42
43
		// Get the Command Line Parameters
43
		// Get the Command Line Parameters
44
		if (args.length > 0)
44
		if (args.length > 0)
Lines 102-109 Link Here
102
				//For the same process object created - create a console 
102
				//For the same process object created - create a console 
103
				//and set the data processor required for the console.
103
				//and set the data processor required for the console.
104
				IConsole console = proc.getConsole();
104
				IConsole console = proc.getConsole();
105
				IDataProcessor dp = new ClientDataProcessor();
105
				IDataProcessor dp = new ClientDataProcessor("stdin");
106
				console.setDataProcessor(dp);
106
				console.setDataProcessor(dp, IConsole.STDOUT);
107
				IDataProcessor edp = new ClientDataProcessor("stderr");
108
				console.setDataProcessor(edp, IConsole.STDERR);
107
				//Launch the process. At this point the process object information 
109
				//Launch the process. At this point the process object information 
108
				//is sent to the Agent Controller that in turn hands it over to the process 
110
				//is sent to the Agent Controller that in turn hands it over to the process 
109
				//controller agent to launch the process.
111
				//controller agent to launch the process.
Lines 112-117 Link Here
112
					public void processExited(IProcess process) 
114
					public void processExited(IProcess process) 
113
					{
115
					{
114
						System.out.println("Process exited.");
116
						System.out.println("Process exited.");
117
						synchronized(proc){
118
							proc.notify();
119
						}
115
					}
120
					}
116
121
117
					public void processLaunched(IProcess process) 
122
					public void processLaunched(IProcess process) 
Lines 159-173 Link Here
159
		}		
164
		}		
160
	}
165
	}
161
}
166
}
162
class ClientDataProcessor implements IDataProcessor 
167
class ClientDataProcessor implements IDataProcessor {
163
{
168
	private String mark;
164
	public void incomingData(byte[] buffer, int length, java.net.InetAddress peer)
169
	
165
	{
170
	public ClientDataProcessor (String mark) {
166
		System.out.println("Console Output "+ new String(buffer));
171
		this.mark = mark;
172
		if (mark != null) this.mark += ": ";
173
	}
174
	
175
	public void incomingData(byte[] buffer, int length, java.net.InetAddress peer) {
176
		if (mark != null) System.out.print(mark);
177
		System.out.println(new String(buffer, 0, length));
167
	}
178
	}
168
	
179
	
169
	public void incomingData(char[] buffer, int length, java.net.InetAddress peer){
180
	public void incomingData(char[] buffer, int length, java.net.InetAddress peer){
170
		System.out.println("Console Output "+ new String(buffer));	
181
		if (mark != null) System.out.print(mark);
182
		System.out.println(new String(buffer, 0, length));
171
	}
183
	}
172
	
184
	
173
	public void invalidDataType(byte[] data, int length, java.net.InetAddress peer){}
185
	public void invalidDataType(byte[] data, int length, java.net.InetAddress peer){}
(-)src/org/eclipse/tptp/platform/execution/client/core/IConsole.java (+16 lines)
Lines 23-28 Link Here
23
 */
23
 */
24
24
25
public interface IConsole {
25
public interface IConsole {
26
	public final static int STDIN = 0;
27
	public final static int STDOUT = 1;
28
	public final static int STDERR = 2;
26
29
27
	/**
30
	/**
28
	 * Set the Data Processor for reading the Console data.	
31
	 * Set the Data Processor for reading the Console data.	
Lines 30-35 Link Here
30
	 */
33
	 */
31
	public void setDataProcessor(IDataProcessor processor) ;
34
	public void setDataProcessor(IDataProcessor processor) ;
32
35
36
	/**
37
	 * Set the Data Processor for reading the Console data.	
38
	 * @param processor org.eclipse.hyades.internal.execution.local.common.DataProcessor
39
	 * @param stream
40
	 */
41
	public void setDataProcessor(IDataProcessor processor, int stream) ;
42
33
43
34
	/**
44
	/**
35
	 * Get the Data Processor of the Console
45
	 * Get the Data Processor of the Console
Lines 37-42 Link Here
37
	public IDataProcessor getDataProcessor() ;
47
	public IDataProcessor getDataProcessor() ;
38
48
39
	/**
49
	/**
50
	 * Get the Data Processor of the Console for the stream
51
	 * @param stream
52
	 */
53
	public IDataProcessor getDataProcessor(int stream) ;
54
55
	/**
40
	 * Write to the Console.
56
	 * Write to the Console.
41
	 * @param data java.lang.String
57
	 * @param data java.lang.String
42
	 */
58
	 */

Return to bug 166596