1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 14:15:23 +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
* 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) [302996] [dstore] null checks and performance issue with shell output
*******************************************************************************/
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();
}
@ -1092,7 +1093,7 @@ public class CommandMinerThread extends MinerThread
// clean up the associated environment
List projectEnvReference = _subject.getAssociated("inhabits"); //$NON-NLS-1$
if (projectEnvReference != null)
if (projectEnvReference != null && projectEnvReference.size() > 0)
{
DataElement env = (DataElement)projectEnvReference.get(0);
DataElement envParent = env.getParent();

View file

@ -19,6 +19,7 @@
* 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[
* 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;
@ -159,15 +160,18 @@ public class OutputHandler extends Handler {
}
}
private int checkAvailable() {
private int checkAvailable(){
return checkAvailable(100);
}
private int checkAvailable(int time) {
try
{
int available = _reader.available();
// if there's none, wait a bit and return true to continue
if (available <= 0) {
sleep(1500);
if (available <= 0){
sleep(time);
available = _reader.available();
}
return available;
@ -192,7 +196,7 @@ public class OutputHandler extends Handler {
int lookahead = 0;
// re-determine available if none available now
if (available == 0) {
if (available == 0) {
try {
lookahead = _reader.read();
}
@ -200,7 +204,6 @@ public class OutputHandler extends Handler {
// pipe closed
return null;
}
if (lookahead == -1) {
return null;
} else {
@ -260,25 +263,43 @@ public class OutputHandler extends Handler {
int index = 0;
while (tokenizer.hasMoreTokens()) {
output[index] = tokenizer.nextToken();
index++;
}
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
byte[] lastBytes = new byte[MAX_OFFSET];
int lastIndex = 0;
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)
{
while (!_endOfStream && lastIndex < MAX_OFFSET)
{
available = _reader.available();
if (available == 0)
{
String suffix = new String(lastBytes, 0, lastIndex, encoding);
@ -296,26 +317,22 @@ public class OutputHandler extends Handler {
else
{
lastBytes[lastIndex] = (byte)c;
// 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)
{
if (lastBytes[lastIndex] == '\r' || lastBytes[lastIndex] == '\n'){
// 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);
return output;
}
lastIndex++;
available = checkAvailable();
}
}
}
}
return output;
}
} catch (Exception e) {
@ -327,7 +344,6 @@ public class OutputHandler extends Handler {
}
return output;
}
public synchronized void waitForInput() {
try {
Thread.sleep(100);