allow control of launch order

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@38129 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2014-10-23 09:46:04 +00:00
parent 09f146a0b6
commit 6ca03f0ab5
3 changed files with 105 additions and 5 deletions

View file

@ -1,3 +1,11 @@
2014-10-23 Richard Frith-Macdonald <rfm@gnu.org>
* EcCommand.m:
* Control.plist:
Add LaunchOrder config to control the order in which services are
handled by the Command server. By default we now do them in
lexicographic order rather than leaving the order undefined.
2014-09-16 Richard Frith-Macdonald <rfm@gnu.org> 2014-09-16 Richard Frith-Macdonald <rfm@gnu.org>
* EcCommand.m: Simplify handling of loss of process and configuration * EcCommand.m: Simplify handling of loss of process and configuration

View file

@ -8,6 +8,10 @@
/* Common section for all processes on any/all hosts. /* Common section for all processes on any/all hosts.
*/ */
}; };
Feep = {
/* Section for the process Feep on any/all hosts.
*/
};
Foo = { Foo = {
/* Section for the process Foo on any/all hosts. /* Section for the process Foo on any/all hosts.
*/ */
@ -20,6 +24,10 @@
/* Common section for any/all processses on localhost. /* Common section for any/all processses on localhost.
*/ */
}; };
Bar = {
/* Section for process Bar on localhost
*/
};
Foo = { Foo = {
/* Section for process Foo on localhost /* Section for process Foo on localhost
*/ */
@ -29,12 +37,31 @@
*/ */
Launch = { Launch = {
Foo = { Foo = {
Prog = "/usr/GNUstep/Local/Tools/Foo"; // Path to binary Prog = "/usr/GNUstep/Local/Tools/Foo"; // Full path to binary
Home = "~xxx/Test"; // Directory to run in Home = "~xxx/Test"; // Directory to run in
Args = ("-Debug", "YES"); // Args to launch with Args = ("-Debug", "YES"); // Args to launch with
Auto = NO; // Auto-launch? Auto = NO; // Auto-launch?
}; };
Bar = {
Prog = "Bar"; // RName of binary
Home = "~xxx/Test"; // Directory to run in
Args = ("-Debug", "YES"); // Args to launch with
Auto = YES; // Auto-launch?
};
Feep = {
Prog = "Feep"; // RName of binary
Home = "~xxx/Test"; // Directory to run in
Auto = YES; // Auto-launch?
};
}; };
/* Specify launch order ... Feep first, Bar second
* Processes not listed here are launched in lexicographical order
* after any processes which are listed.
*/
LaunchOrder = (
Feep, // Launch Feep first
Bar // Launch Bar second
);
}; };
}; };
} }

View file

@ -126,6 +126,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
NSString *logname; NSString *logname;
NSMutableDictionary *config; NSMutableDictionary *config;
NSDictionary *launchInfo; NSDictionary *launchInfo;
NSArray *launchOrder;
NSDictionary *environment; NSDictionary *environment;
NSMutableDictionary *launches; NSMutableDictionary *launches;
NSMutableSet *launching; NSMutableSet *launching;
@ -306,9 +307,11 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
d = [config objectForKey: [self cmdName]]; d = [config objectForKey: [self cmdName]];
DESTROY(launchInfo); DESTROY(launchInfo);
DESTROY(launchOrder);
DESTROY(environment); DESTROY(environment);
if ([d isKindOfClass: [NSDictionary class]] == YES) if ([d isKindOfClass: [NSDictionary class]] == YES)
{ {
id o;
NSMutableDictionary *m; NSMutableDictionary *m;
NSString *k; NSString *k;
NSString *err = nil; NSString *err = nil;
@ -446,6 +449,67 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
} }
} }
RETAIN(launchInfo); RETAIN(launchInfo);
o = [d objectForKey: @"LaunchOrder"];
if (NO == [o isKindOfClass: [NSArray class]])
{
if (nil != o)
{
NSLog(@"bad 'LaunchOrder' config (not an array) ignored");
}
/* The default launch order is alphabetical by server name.
*/
o = [[launchInfo allKeys] sortedArrayUsingSelector:
@selector(compare:)];
launchOrder = RETAIN(o);
}
else
{
NSMutableArray *m;
NSEnumerator *e;
NSString *k;
NSUInteger c;
m = AUTORELEASE([o mutableCopy]);
c = [m count];
while (c-- > 0)
{
o = [m objectAtIndex: c];
if (NO == [o isKindOfClass: [NSString class]])
{
NSLog(@"bad 'LaunchOrder' item ('%@' at %u) ignored"
@" (not a server name)", o, (unsigned)c);
[m removeObjectAtIndex: c];
}
else if ([m indexOfObject: o] != c)
{
NSLog(@"bad 'LaunchOrder' item ('%@' at %u) ignored"
@" (repeat of earlier item)", o, (unsigned)c);
[m removeObjectAtIndex: c];
}
else if (nil == [launchInfo objectForKey: o])
{
NSLog(@"bad 'LaunchOrder' item ('%@' at %u) ignored"
@" (not in 'Launch' dictionary)", o, (unsigned)c);
[m removeObjectAtIndex: c];
}
}
/* Any missing servers are launched after others
* they are in lexicographic order.
*/
o = [[launchInfo allKeys] sortedArrayUsingSelector:
@selector(compare:)];
e = [o objectEnumerator];
while (nil != (k = [e nextObject]))
{
if (NO == [m containsObject: k])
{
[m addObject: k];
}
}
launchOrder = [m copy];
}
environment = [d objectForKey: @"Environment"]; environment = [d objectForKey: @"Environment"];
if ([environment isKindOfClass: [NSDictionary class]] == NO) if ([environment isKindOfClass: [NSDictionary class]] == NO)
{ {
@ -774,7 +838,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
NSString *nam = [cmd objectAtIndex: 1]; NSString *nam = [cmd objectAtIndex: 1];
BOOL found = NO; BOOL found = NO;
enumerator = [launchInfo keyEnumerator]; enumerator = [launchOrder objectEnumerator];
if ([nam caseInsensitiveCompare: @"all"] == NSOrderedSame) if ([nam caseInsensitiveCompare: @"all"] == NSOrderedSame)
{ {
NSMutableArray *names = [NSMutableArray array]; NSMutableArray *names = [NSMutableArray array];
@ -1058,7 +1122,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
NSEnumerator *enumerator; NSEnumerator *enumerator;
NSString *key; NSString *key;
enumerator = [launchInfo keyEnumerator]; enumerator = [launchOrder objectEnumerator];
while ((key = [enumerator nextObject]) != nil) while ((key = [enumerator nextObject]) != nil)
{ {
if (comp(wd, key) >= 0) if (comp(wd, key) >= 0)
@ -1424,6 +1488,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
RELEASE(host); RELEASE(host);
RELEASE(clients); RELEASE(clients);
RELEASE(launchInfo); RELEASE(launchInfo);
RELEASE(launchOrder);
RELEASE(environment); RELEASE(environment);
RELEASE(lastUnanswered); RELEASE(lastUnanswered);
[super dealloc]; [super dealloc];
@ -1625,7 +1690,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
NSDate *firstDate = nil; NSDate *firstDate = nil;
NSDate *now = [NSDate date]; NSDate *now = [NSDate date];
enumerator = [launchInfo keyEnumerator]; enumerator = [launchOrder objectEnumerator];
while ((key = [enumerator nextObject]) != nil) while ((key = [enumerator nextObject]) != nil)
{ {
EcClientI *r = [self findIn: clients byName: key]; EcClientI *r = [self findIn: clients byName: key];
@ -1880,7 +1945,7 @@ static NSString* cmdWord(NSArray* a, unsigned int pos)
NSEnumerator *enumerator; NSEnumerator *enumerator;
NSString *key; NSString *key;
enumerator = [launchInfo keyEnumerator]; enumerator = [launchOrder objectEnumerator];
while ((key = [enumerator nextObject]) != nil) while ((key = [enumerator nextObject]) != nil)
{ {
[launches setObject: [NSDate distantFuture] forKey: key]; [launches setObject: [NSDate distantFuture] forKey: key];