1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

[224906] [dstore] changes for getting properties and doing exit due to single-process capability

This commit is contained in:
David McKnight 2008-03-31 14:46:38 +00:00
parent 85233305ba
commit 962e46cef7
12 changed files with 90 additions and 500 deletions

View file

@ -13,6 +13,7 @@
*
* Contributors:
* Noriaki Takatsu (IBM) [220126] [dstore][api][breaking] Single process server for multiple clients
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
*******************************************************************************/
package org.eclipse.dstore.core.miners;
@ -29,6 +30,7 @@ import org.eclipse.dstore.core.model.DataStoreSchema;
import org.eclipse.dstore.core.model.Handler;
import org.eclipse.dstore.core.model.IExternalLoader;
import org.eclipse.dstore.core.model.ISchemaExtender;
import org.eclipse.dstore.core.server.SystemServiceManager;
/**
* Miner is the abstact base class of all DataStore extensions).
@ -303,6 +305,8 @@ implements ISchemaExtender
er.printStackTrace();
_dataStore.trace(er);
_dataStore.finish();
if (SystemServiceManager.getInstance() == null)
System.exit(-1);
}
}

View file

@ -11,7 +11,7 @@
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
********************************************************************************/
package org.eclipse.dstore.core.model;
@ -98,21 +98,6 @@ public class ByteStreamHandler implements IByteStreamHandler
byteConverter.setContext(file);
byte[] convertedBytes = byteConverter.convertClientBytesToHostBytes(buffer, 0, size);
fileStream.write(convertedBytes, 0, convertedBytes.length);
/*
String bufferString = new String(buffer, 0, size, DE.ENCODING_UTF_8);
// hack for zOS
String theOS = System.getProperty("os.name");
if (theOS.toLowerCase().startsWith("z"))
{
bufferString = bufferString.replace('\r', ' ');
}
OutputStreamWriter writer = new OutputStreamWriter(fileStream);
writer.write(bufferString, 0, size);
writer.flush();
*/
}
fileStream.close();

View file

@ -18,6 +18,7 @@
* David McKnight (IBM) [220123][dstore] Configurable timeout on irresponsiveness
* David McKnight (IBM) - [222168][dstore] Buffer in DataElement is not sent
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
*******************************************************************************/
package org.eclipse.dstore.core.model;
@ -3515,9 +3516,16 @@ public final class DataStore
{
if (_userPreferencesDirectory == null) {
String clientUserID;
if (_client != null){
_userPreferencesDirectory = _client.getProperty("user.home"); //$NON-NLS-1$
clientUserID = _client.getProperty("client.username"); //$NON-NLS-1$
}
else {
_userPreferencesDirectory = System.getProperty("user.home"); //$NON-NLS-1$
clientUserID = System.getProperty("client.username"); //$NON-NLS-1$
}
String clientUserID = System.getProperty("client.username"); //$NON-NLS-1$
if (clientUserID == null || clientUserID.equals("")) //$NON-NLS-1$
{
clientUserID = ""; //$NON-NLS-1$

View file

@ -13,6 +13,7 @@
*
* Contributors:
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
*******************************************************************************/
package org.eclipse.dstore.core.server;
@ -65,6 +66,7 @@ public class Server implements Runnable
{
// version is bad
System.err.println(ServerReturnCodes.RC_JRE_VERSION_ERROR);
if (SystemServiceManager.getInstance() == null)
System.exit(-1);
}
}
@ -72,6 +74,7 @@ public class Server implements Runnable
{
// version is bad
System.err.println(ServerReturnCodes.RC_JRE_VERSION_ERROR);
if (SystemServiceManager.getInstance() == null)
System.exit(-1);
}

View file

@ -15,6 +15,7 @@
* David McKnight (IBM) [220123][dstore] Configurable timeout on irresponsiveness
* David McKnight (IBM) [220892][dstore] Backward compatibility: Server and Daemon should support old clients
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
*******************************************************************************/
package org.eclipse.dstore.internal.core.server;
@ -39,6 +40,7 @@ import org.eclipse.dstore.core.model.DataElement;
import org.eclipse.dstore.core.model.DataStore;
import org.eclipse.dstore.core.model.DataStoreAttributes;
import org.eclipse.dstore.core.model.ISSLProperties;
import org.eclipse.dstore.core.server.SystemServiceManager;
import org.eclipse.dstore.internal.core.util.ExternalLoader;
import org.eclipse.dstore.internal.core.util.Sender;
import org.eclipse.dstore.internal.core.util.ssl.DStoreSSLContext;
@ -182,7 +184,9 @@ public class ConnectionEstablisher
_updateHandler.finish();
_dataStore.finish();
System.out.println(ServerReturnCodes.RC_FINISHED);
//System.exit(0);
if (SystemServiceManager.getInstance() == null)
System.exit(0);
}
}

View file

@ -12,7 +12,7 @@
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
*******************************************************************************/
package org.eclipse.dstore.internal.core.server;
@ -31,6 +31,7 @@ import org.eclipse.dstore.core.model.DataStoreAttributes;
import org.eclipse.dstore.core.model.DataStoreResources;
import org.eclipse.dstore.core.model.DataStoreSchema;
import org.eclipse.dstore.core.model.IDataStoreConstants;
import org.eclipse.dstore.core.server.SystemServiceManager;
/**
* The ServerCommandHandler is reponsible for maintaining
@ -62,6 +63,9 @@ public class ServerCommandHandler extends CommandHandler
_dataStore.getUpdateHandler().finish();
_dataStore.finish();
System.out.println(ServerReturnCodes.RC_FINISHED);
// only exit if there's no service manager
if (SystemServiceManager.getInstance() == null)
System.exit(0);
}
}

View file

@ -15,6 +15,7 @@
* David McKnight (IBM) [220123][dstore] Configurable timeout on irresponsiveness
* David McKnight (IBM) [221601][dstore] xmlparser needs to be able to handle very large attributes
* David McKnight (IBM) [222163][dstore] Special characters from old server are not restored
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
*******************************************************************************/
package org.eclipse.dstore.internal.core.util;

View file

@ -15,6 +15,7 @@
* {Name} (company) - description of contribution.
* David McKnight (IBM) - [196624] dstore miner IDs should be String constants rather than dynamic lookup
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
*******************************************************************************/
package org.eclipse.rse.dstore.universal.miners;
@ -95,8 +96,15 @@ public class EnvironmentMiner extends Miner
*/
DataElement systemInfo = _dataStore.createObject(_minerData, "dstore.structureNode", "systemInfo"); //$NON-NLS-1$ //$NON-NLS-2$
if (_dataStore.getClient() != null){
_dataStore.createObject(systemInfo, "system.property", "user.home", _dataStore.getClient().getProperty("user.home")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
_dataStore.createObject(systemInfo, "system.property", "temp.dir", _dataStore.getClient().getProperty("java.io.tmpdir")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
else {
_dataStore.createObject(systemInfo, "system.property", "user.home", System.getProperty("user.home")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
_dataStore.createObject(systemInfo, "system.property", "temp.dir", System.getProperty("java.io.tmpdir")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
_dataStore.createObject(systemInfo, "system.property", "os.name", System.getProperty("os.name")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
_dataStore.createObject(systemInfo, "system.property", "os.version", System.getProperty("os.version")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@ -253,7 +261,13 @@ public class EnvironmentMiner extends Miner
{
String userPreferencesDirectory = _dataStore.getClient().getProperty("user.home"); //$NON-NLS-1$
String clientUserID = System.getProperty("client.username"); //$NON-NLS-1$
String clientUserID = null;
if (_dataStore.getClient() != null){
clientUserID = _dataStore.getClient().getProperty("client.username"); //$NON-NLS-1$
}
else {
clientUserID = System.getProperty("client.username"); //$NON-NLS-1$
}
if (clientUserID == null || clientUserID.equals("")) //$NON-NLS-1$
{
clientUserID = ""; //$NON-NLS-1$

View file

@ -31,6 +31,7 @@
* David McKnight (IBM) - [209593] [api] add support for "file permissions" and "owner" properties for unix files
* Johnson Ma (Wind River) - [195402] Add tar.gz archive support
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
*******************************************************************************/
package org.eclipse.rse.dstore.universal.miners;
@ -903,7 +904,12 @@ public class UniversalFileSystemMiner extends Miner {
// . translates to home dir
if (filterValue.equals(".")) //$NON-NLS-1$
{
if (_dataStore.getClient() != null){
filterValue = _dataStore.getClient().getProperty("user.home"); //$NON-NLS-1$
}
else {
filterValue = System.getProperty("user.home"); //$NON-NLS-1$
}
subject.setAttribute(DE.A_VALUE, filterValue);
}
if (!isVirtual)
@ -1769,7 +1775,12 @@ public class UniversalFileSystemMiner extends Miner {
// . translates to home dir
if (filterValue.equals(".")) //$NON-NLS-1$
{
if (_dataStore.getClient() != null){
filterValue = _dataStore.getClient().getProperty("user.home"); //$NON-NLS-1$
}
else {
filterValue = System.getProperty("user.home"); //$NON-NLS-1$
}
subject.setAttribute(DE.A_VALUE, filterValue);
}
if (!isVirtual)

View file

@ -14,6 +14,7 @@
* Contributors:
* David McKnight (IBM) - [196624] dstore miner IDs should be String constants rather than dynamic lookup
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
*******************************************************************************/
package org.eclipse.rse.dstore.universal.miners;
@ -145,10 +146,13 @@ public class UniversalProcessMiner extends Miner
* Get the username
*/
protected DataElement handleQueryUserName(DataElement subject, DataElement status) {
if (_dataStore.getClient() != null){
subject.setAttribute(DE.A_VALUE, _dataStore.getClient().getProperty("user.name")); //$NON-NLS-1$
}
else {
subject.setAttribute(DE.A_VALUE, System.getProperty("user.name")); //$NON-NLS-1$
}
String encoding = System.getProperty("user.name"); //$NON-NLS-1$
subject.setAttribute(DE.A_VALUE, encoding);
_dataStore.refresh(subject);
status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$

View file

@ -16,6 +16,7 @@
* David McKnight (IBM) - [202822] updating cleanup
* David McKnight (IBM) - [196624] dstore miner IDs should be String constants rather than dynamic lookup
* Noriaki Takatsu (IBM) - [220126] [dstore][api][breaking] Single process server for multiple clients
* David McKnight (IBM) [224906] [dstore] changes for getting properties and doing exit due to single-process capability
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.command;
@ -63,7 +64,6 @@ public class CommandMinerThread extends MinerThread
private Patterns _patterns;
private Process _theProcess;
private ProcessTracker _processTracker;
private DataElement _subject;
private String _cwdStr;
@ -113,7 +113,13 @@ public class CommandMinerThread extends MinerThread
try
{
String userHome = System.getProperty("user.home");//$NON-NLS-1$
String userHome = null;
if (_dataStore.getClient() != null){
userHome = _dataStore.getClient().getProperty("user.home");//$NON-NLS-1$
}
else {
userHome = System.getProperty("user.home");//$NON-NLS-1$
}
_cwdStr = theElement.getSource();
if (_cwdStr == null || _cwdStr.length() == 0)
@ -190,7 +196,7 @@ public class CommandMinerThread extends MinerThread
{
if (var.startsWith("HOME")) //$NON-NLS-1$
{
env[i] = "HOME=" + _dataStore.getClient().getProperty("user.home"); //$NON-NLS-1$
env[i] = "HOME=" + _dataStore.getClient().getProperty("user.home"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
@ -547,19 +553,6 @@ public class CommandMinerThread extends MinerThread
public void sendBreak()
{
if (!_isWindows)
{
if (_processTracker != null)
{
_processTracker.killLastest();
}
}
}
public void sendInput(String input)
{
@ -575,7 +568,6 @@ public class CommandMinerThread extends MinerThread
// pty executable handles the break now
if (input.equals("#break") && !_isTTY) //$NON-NLS-1$
{
sendBreak();
return;
}
else if (input.equals("#enter")) //$NON-NLS-1$
@ -1108,7 +1100,14 @@ public class CommandMinerThread extends MinerThread
int tildaIndex = fileName.indexOf("~"); //$NON-NLS-1$
if (tildaIndex == 0)
{
String userHome = System.getProperty("user.home"); //$NON-NLS-1$
String userHome = null;
if (_dataStore.getClient() != null){
userHome = _dataStore.getClient().getProperty("user.home"); //$NON-NLS-1$
}
else {
userHome = System.getProperty("user.home"); //$NON-NLS-1$
}
fileName = userHome + fileName.substring(1);
}

View file

@ -1,447 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* {Name} (company) - description of contribution.
*******************************************************************************/
package org.eclipse.rse.internal.dstore.universal.miners.command;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.eclipse.dstore.core.model.Handler;
public class ProcessTracker extends Handler
{
private class ProcessDescriptor
{
private String _pid;
private String _cmd;
public ProcessDescriptor(String pid, String cmd)
{
_pid = pid;
_cmd = cmd;
}
public String getPID()
{
return _pid;
}
public String getCMD()
{
return _cmd;
}
public String toString()
{
String result = getPID() + " " + getCMD(); //$NON-NLS-1$
if (ProcessDescriptor.this == _newestProcess)
{
result += " *"; //$NON-NLS-1$
}
return result;
}
public boolean hasCMD(String cmdname)
{
StringTokenizer tokenizer = new StringTokenizer(_cmd, "/"); //$NON-NLS-1$
while (tokenizer.hasMoreTokens())
{
String token = tokenizer.nextToken();
if (!tokenizer.hasMoreElements())
{
if (token.equals(cmdname))
{
return true;
}
}
}
return false;
}
public boolean equals(Object obj)
{
if (obj instanceof ProcessDescriptor)
{
ProcessDescriptor des = (ProcessDescriptor) obj;
if (des.getPID().equals(_pid))
{
return true;
}
}
return false;
}
}
private Process _psShell;
private BufferedReader _psReader;
private BufferedWriter _psWriter;
private boolean _updateFlag;
private ProcessDescriptor _newestProcess;
private String _psCommand;
private boolean _isEnabled;
private List _currentProcesses = new ArrayList();
public ProcessTracker()
{
super();
init();
}
private String getFormatOptions(String theOS)
{
String formatOptions = ""; //$NON-NLS-1$
if (theOS.startsWith("z")) //$NON-NLS-1$
{
formatOptions = "-o pid,comm"; //$NON-NLS-1$
}
else if (theOS.startsWith("linux")) //$NON-NLS-1$
{
formatOptions = "--format pid,ucomm"; //$NON-NLS-1$
}
else if (theOS.startsWith("aix")) //$NON-NLS-1$
{
formatOptions = "-F pid,ucomm"; //$NON-NLS-1$
}
return formatOptions;
}
private void init()
{
String userID = System.getProperty("user.name"); //$NON-NLS-1$
String userOptions = "-u " + userID; //$NON-NLS-1$
String theOS = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
String formatOptions = getFormatOptions(theOS);
if (formatOptions.length() == 0)
{
_isEnabled = false;
}
else
{
_isEnabled = true;
}
if (_isEnabled)
{
_psCommand = "ps " + userOptions + " " + formatOptions; //$NON-NLS-1$ //$NON-NLS-2$
try
{
if (_psShell == null)
{
_psShell = Runtime.getRuntime().exec("sh"); //$NON-NLS-1$
String specialEncoding = System.getProperty("dstore.stdin.encoding"); //$NON-NLS-1$
if (specialEncoding != null)
{
_psReader = new BufferedReader(new InputStreamReader(_psShell.getInputStream(), specialEncoding));
try
{
_psWriter = new BufferedWriter(new OutputStreamWriter(_psShell.getOutputStream(), specialEncoding));
}
catch (UnsupportedEncodingException e)
{
_psWriter = new BufferedWriter(new OutputStreamWriter(_psShell.getOutputStream()));
}
}
else
{
_psReader = new BufferedReader(new InputStreamReader(_psShell.getInputStream()));
_psWriter = new BufferedWriter(new OutputStreamWriter(_psShell.getOutputStream()));
}
}
}
catch (Exception e)
{
}
}
}
private static String readLine(BufferedReader reader)
{
StringBuffer theLine = new StringBuffer();
int ch;
boolean done = false;
while (!done)
{
try
{
synchronized (reader)
{
if (!reader.ready())
{
return theLine.toString();
}
ch = reader.read();
switch (ch)
{
case -1 :
if (theLine.length() == 0) //End of Reader
return null;
done = true;
break;
case 65535 :
if (theLine.length() == 0)
return null;
done = true;
break;
case 10 :
done = true; //Newline
break;
case 13 :
done = true;
break; //Carriage Return
default :
char tch = (char) ch;
if (!Character.isISOControl(tch))
{
theLine.append(tch); //Any other character
}
else
{
// ignore next char too
if (reader.ready())
reader.read();
}
break;
//Any other character
}
//Check to see if the BufferedReader is still ready which means there are more characters
//in the Buffer...If not, then we assume it is waiting for input.
if (!reader.ready())
{
done = true;
}
}
}
catch (IOException e)
{
return null;
}
}
return theLine.toString();
}
private void getCurrentProcesses()
{
try
{
_psWriter.write(_psCommand);
_psWriter.write("\n"); //$NON-NLS-1$
_psWriter.flush();
// skip first line
String line = _psReader.readLine();
ArrayList newPIDs = new ArrayList();
line = readLine(_psReader);
while (line != null && line.length() > 0)
{
line = line.trim();
int firstBlank = line.indexOf(' ');
if (firstBlank != -1)
{
String pid = line.substring(0, firstBlank);
String cmd = line.substring(firstBlank + 1, line.length());
ProcessDescriptor descriptor = new ProcessDescriptor(pid, cmd);
if (!descriptor.hasCMD("ps")) //$NON-NLS-1$
{
newPIDs.add(descriptor);
}
}
line = readLine(_psReader);
}
updateProcesses(newPIDs);
}
catch (Exception e)
{
e.printStackTrace();
}
//listProcesses();
}
public void finish()
{
_updateFlag = false;
if (_isEnabled)
{
endTrackerProcess();
}
super.finish();
}
private void updateProcesses(ArrayList newPIDs)
{
boolean firstRun = _currentProcesses.size() == 0;
// remove finished pids
for (int c = _currentProcesses.size() - 1; c >= 0; c--)
{
ProcessDescriptor p = (ProcessDescriptor) _currentProcesses.get(c);
if (newPIDs.contains(p))
{
newPIDs.remove(p);
}
else
{
_currentProcesses.remove(p);
}
}
// add new pids
for (int i = 0; i < newPIDs.size(); i++)
{
ProcessDescriptor p = (ProcessDescriptor) newPIDs.get(i);
_currentProcesses.add(p);
if (!firstRun)
{
_newestProcess = p;
}
}
}
public void endTrackerProcess()
{
if (_isEnabled)
{
try
{
_psWriter.write("exit"); //$NON-NLS-1$
_psWriter.write("\n"); //$NON-NLS-1$
_psWriter.flush();
_psReader.close();
_psWriter.close();
_psShell.waitFor();
}
catch (Exception e)
{
}
}
}
public ProcessDescriptor getNewestProcess()
{
return _newestProcess;
}
private ProcessDescriptor findLast(String cmd)
{
if (_newestProcess != null && _newestProcess.hasCMD(cmd))
{
return _newestProcess;
}
for (int i = _currentProcesses.size() - 1; i > 0; i--)
{
ProcessDescriptor descriptor = (ProcessDescriptor) _currentProcesses.get(i);
if (descriptor.hasCMD(cmd))
{
return descriptor;
}
}
return null;
}
public void killCommand(String cmd)
{
ProcessDescriptor descriptor = findLast(cmd);
if (descriptor != null)
{
kill(descriptor);
}
}
public void killLastest()
{
if (_newestProcess != null)
{
kill(_newestProcess);
}
}
private void kill(ProcessDescriptor descriptor)
{
if (_isEnabled)
{
try
{
_psWriter.write("kill " + descriptor.getPID()); //$NON-NLS-1$
_psWriter.write("\n"); //$NON-NLS-1$
_psWriter.flush();
_psReader.reset();
}
catch (Exception e)
{
}
doUpdate();
}
}
public void handle()
{
if (!_isEnabled)
{
finish();
}
if (_updateFlag)
{
try
{
Thread.sleep(100);
}
catch (Exception e)
{
}
getCurrentProcesses();
_updateFlag = false;
}
}
public void doUpdate()
{
if (_isEnabled)
_updateFlag = true;
else
_updateFlag = false;
}
public synchronized void waitForInput()
{
try
{
Thread.sleep(100);
}
catch (Exception e)
{
}
}
}