|
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)); |