1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-14 12:35:22 +02:00

[302996] [dstore] null checks and performance issue with shell output

This commit is contained in:
David McKnight 2010-02-16 21:37:02 +00:00
parent abb0845a5d
commit a32a34db40
2 changed files with 38 additions and 21 deletions

View file

@ -27,6 +27,7 @@
* Peter Wang (IBM) [299422] [dstore] OutputHandler.readLines() not compatible with servers that return max 1024bytes available to be read * Peter Wang (IBM) [299422] [dstore] OutputHandler.readLines() not compatible with servers that return max 1024bytes available to be read
* David McKnight (IBM) [302174] [dstore] shell init command can potentially get called too late * David McKnight (IBM) [302174] [dstore] shell init command can potentially get called too late
* David McKnight (IBM) [302724] problems with environment variable substitution * David McKnight (IBM) [302724] problems with environment variable substitution
* David McKnight (IBM) [302996] [dstore] null checks and performance issue with shell output
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.command; package org.eclipse.rse.internal.dstore.universal.miners.command;
@ -1028,7 +1029,7 @@ public class CommandMinerThread extends MinerThread
{ {
} }
if (_stdOutputHandler.isAlive()) if (_stdOutputHandler.isAlive() && _theProcess != null)
{ {
_theProcess.destroy(); _theProcess.destroy();
} }
@ -1092,7 +1093,7 @@ public class CommandMinerThread extends MinerThread
// clean up the associated environment // clean up the associated environment
List projectEnvReference = _subject.getAssociated("inhabits"); //$NON-NLS-1$ List projectEnvReference = _subject.getAssociated("inhabits"); //$NON-NLS-1$
if (projectEnvReference != null) if (projectEnvReference != null && projectEnvReference.size() > 0)
{ {
DataElement env = (DataElement)projectEnvReference.get(0); DataElement env = (DataElement)projectEnvReference.get(0);
DataElement envParent = env.getParent(); DataElement envParent = env.getParent();

View file

@ -19,6 +19,7 @@
* David McKnight (IBM) - [286671] Dstore shell service interprets < and > sequences * David McKnight (IBM) - [286671] Dstore shell service interprets < and > sequences
* David McKnight (IBM) [287305] [dstore] Need to set proper uid for commands when using SecuredThread and single server for multiple clients[ * David McKnight (IBM) [287305] [dstore] Need to set proper uid for commands when using SecuredThread and single server for multiple clients[
* Peter Wang (IBM) [299422] [dstore] OutputHandler.readLines() not compatible with servers that return max 1024bytes available to be read * Peter Wang (IBM) [299422] [dstore] OutputHandler.readLines() not compatible with servers that return max 1024bytes available to be read
* David McKnight (IBM) [302996] [dstore] null checks and performance issue with shell output
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.command; package org.eclipse.rse.internal.dstore.universal.miners.command;
@ -159,15 +160,18 @@ public class OutputHandler extends Handler {
} }
} }
private int checkAvailable(){
return checkAvailable(100);
}
private int checkAvailable() { private int checkAvailable(int time) {
try try
{ {
int available = _reader.available(); int available = _reader.available();
// if there's none, wait a bit and return true to continue // if there's none, wait a bit and return true to continue
if (available <= 0) { if (available <= 0){
sleep(1500); sleep(time);
available = _reader.available(); available = _reader.available();
} }
return available; return available;
@ -200,7 +204,6 @@ public class OutputHandler extends Handler {
// pipe closed // pipe closed
return null; return null;
} }
if (lookahead == -1) { if (lookahead == -1) {
return null; return null;
} else { } else {
@ -260,25 +263,43 @@ public class OutputHandler extends Handler {
int index = 0; int index = 0;
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
output[index] = tokenizer.nextToken(); output[index] = tokenizer.nextToken();
index++; index++;
} }
String lastLine = output[index - 1]; String lastLine = output[index - 1];
boolean endLine = fullOutput.endsWith("\n") || fullOutput.endsWith("\r") || fullOutput.endsWith(">");
if (!_endOfStream && (!fullOutput.endsWith("\n") && !fullOutput.endsWith("\r"))) //$NON-NLS-1$ //$NON-NLS-2$ if (!_endOfStream && !endLine)
{ {
// our last line may be cut off // our last line may be cut off
byte[] lastBytes = new byte[MAX_OFFSET]; byte[] lastBytes = new byte[MAX_OFFSET];
int lastIndex = 0; int lastIndex = 0;
available = checkAvailable(); available = checkAvailable();
if (available == 0){
try {
lookahead = _reader.read();
}
catch (IOException e){
// pipe closed
// allow to fall through
}
if (lookahead == -1) {
// allow to fall through
} else {
available = _reader.available() + 1;
}
}
if (available > 0) if (available > 0)
{ {
while (!_endOfStream && lastIndex < MAX_OFFSET) while (!_endOfStream && lastIndex < MAX_OFFSET)
{ {
available = _reader.available();
if (available == 0) if (available == 0)
{ {
String suffix = new String(lastBytes, 0, lastIndex, encoding); String suffix = new String(lastBytes, 0, lastIndex, encoding);
@ -296,19 +317,15 @@ public class OutputHandler extends Handler {
else else
{ {
lastBytes[lastIndex] = (byte)c; lastBytes[lastIndex] = (byte)c;
if (lastBytes[lastIndex] == '\r' || lastBytes[lastIndex] == '\n'){
// check for end of line
String suffix = new String(lastBytes, 0, lastIndex + 1, encoding);
int rBreak = suffix.indexOf("\r"); //$NON-NLS-1$
int nBreak = suffix.indexOf("\n"); //$NON-NLS-1$
if (nBreak != -1 || rBreak != -1)
{
// we've hit the end of line; // we've hit the end of line;
String suffix = new String(lastBytes, 0, lastIndex + 1, encoding);
output[index - 1] = lastLine + suffix.substring(0, suffix.length() - 1); output[index - 1] = lastLine + suffix.substring(0, suffix.length() - 1);
return output; return output;
} }
lastIndex++; lastIndex++;
available = checkAvailable();
} }
} }
@ -327,7 +344,6 @@ public class OutputHandler extends Handler {
} }
return output; return output;
} }
public synchronized void waitForInput() { public synchronized void waitForInput() {
try { try {
Thread.sleep(100); Thread.sleep(100);