1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-05 07:15:39 +02:00

merge from IBM rse to allow for user-configured idle time shutdown

This commit is contained in:
David McKnight 2007-10-23 16:18:44 +00:00
parent 486bc7245d
commit 3004ae191a
2 changed files with 92 additions and 1 deletions

View file

@ -111,6 +111,8 @@ public final class DataStore
private boolean _logTimes; private boolean _logTimes;
private int _timeout; private int _timeout;
private int _serverIdleShutdownTimeout = 0;
private HashMap _hashMap; private HashMap _hashMap;
private HashMap _objDescriptorMap; private HashMap _objDescriptorMap;
private HashMap _cmdDescriptorMap; private HashMap _cmdDescriptorMap;
@ -466,6 +468,14 @@ public final class DataStore
return _timeout; return _timeout;
} }
/**
* Gets the time the server may remain idle before shutting down
* @return the idle time before shutdown
*/
public int getServerIdleShutdownTimeout()
{
return _serverIdleShutdownTimeout;
}
/** /**
* Sets an attribute of the <code>DataStore</code> * Sets an attribute of the <code>DataStore</code>
@ -3475,6 +3485,20 @@ public final class DataStore
_dataStoreSchema = new DataStoreSchema(this); _dataStoreSchema = new DataStoreSchema(this);
if (!isVirtual())
{
// get the time the server can remain idle before automatically shutting down
// if the idle is 0 or not set then it is considered indefinite.
// The server is considered idle for the period of which no commands are
// received in server command handler
String serverIdleShutdownTimeout = System.getProperty("DSTORE_IDLE_SHUTDOWN_TIMEOUT");
if (serverIdleShutdownTimeout != null)
{
_serverIdleShutdownTimeout = Integer.parseInt(serverIdleShutdownTimeout);
}
}
String tracingProperty = System.getProperty("DSTORE_TRACING_ON"); //$NON-NLS-1$ String tracingProperty = System.getProperty("DSTORE_TRACING_ON"); //$NON-NLS-1$
if (tracingProperty != null && tracingProperty.equals("true")) //$NON-NLS-1$ if (tracingProperty != null && tracingProperty.equals("true")) //$NON-NLS-1$
{ {

View file

@ -39,10 +39,55 @@ import org.eclipse.dstore.core.model.IDataStoreConstants;
*/ */
public class ServerCommandHandler extends CommandHandler public class ServerCommandHandler extends CommandHandler
{ {
public class ServerIdleThread extends Thread
{
private long _timeout;
private boolean _serverTimedOut = false;
public ServerIdleThread(long timeout)
{
_timeout = timeout;
}
public void run()
{
while (!_serverTimedOut)
{
waitForTimeout();
}
if (_serverTimedOut)
{
_dataStore.getCommandHandler().finish();
_dataStore.getUpdateHandler().finish();
_dataStore.finish();
System.out.println(ServerReturnCodes.RC_FINISHED);
System.exit(0);
}
}
protected synchronized void waitForTimeout()
{
try
{
wait(_timeout);
}
catch (InterruptedException e)
{
// whenver a new command comes through we interrupt this
// if we do timeout then it's time to shutdown the server
return;
}
System.out.println("server timed out!");
_serverTimedOut = true;
}
}
private ArrayList _loaders; private ArrayList _loaders;
private MinerLoader _minerLoader; private MinerLoader _minerLoader;
private ServerIdleThread _serverIdleThread;
/** /**
* Constructor * Constructor
@ -494,5 +539,27 @@ public class ServerCommandHandler extends CommandHandler
} }
/**
* Overridden so that ServerIdleThread knows when new commands are received
*/
public void addCommand(DataElement command, boolean immediate)
{
super.addCommand(command, immediate);
int serverIdleShutdownTimeout = _dataStore.getServerIdleShutdownTimeout();
if (serverIdleShutdownTimeout > 0)
{
if (_serverIdleThread != null)
{
// new command so restart timeout
_serverIdleThread.interrupt();
}
else
{
_serverIdleThread = new ServerIdleThread(serverIdleShutdownTimeout);
_serverIdleThread.start();
}
}
}
} }