1 /*
2 	ZillionServer.h
3 	Tue Aug 27 17:00:11 CEST 2002
4  */
5 
6 #import <Foundation/Foundation.h>
7 #import	"ZillionClientServer.h"
8 #import "ZillionClient.h"
9 
10 #define	ZILLION_SERVER_NAME	@"zillion"
11 
12 @protocol ZillionClientProtocol;
13 @protocol ZillionServerProtocol;
14 @protocol ZillionJobProtocol;
15 
16 @protocol ZillionServerProtocol <NSObject>
17 
18 /*
19 	managing masters
20  */
21 - (void)setMasterServer:(id <ZillionServerProtocol>)masterServer;
22 - (id <ZillionServerProtocol>)masterServer;
23 - (void)terminate;
24 
25 /*
26 	managing clients
27  */
28 - (void)registerClient:(id <ZillionClientProtocol>)someClient;
29 - (void)deregisterClient:(id <ZillionClientProtocol>)someClient;
30 
31 
32 /*
33 	managing jobs
34  */
35 
36 - (NSString *)dispatchJob:(bycopy NSData *)bundle;
37 - (bycopy NSString *)loadAndRegisterJob:(NSData *)bundle;
38 
39 - (void)registerJob:(NSData *)jobBundle withId:(NSString *)jobId;
40 
41 - (NSData *)packedJobBundleForJobId:(NSString *)jobId;
42 /*
43 	forward outcome to the client to let it store relevant stuff
44 	if outcome cannot be submitted as a linge chunk at the end of the job unit
45 	someStoreHint can be used to
46  */
47 - (void)submitOutcome:(NSData *)outcome ofJob:(NSString *)jobId forSeedId:(NSData *)seedId
48 	storeHints:(NSDictionary *)someStoreHint;
49 
50 - (void)jobUnitDidEndForJobId:(NSString *)jobId seedId:(NSData *)seedId
51 	timePenalty:(NSTimeInterval)penalty;
52 
53 /*
54 	bringing the jobs into action
55  */
56 
57 // sender is a dummy argument to make it amenable to performSelector:
58 - (void)scheduleJobs:sender;
59 - (NSData *)nextSeedIdForJobId:(NSString *)jobId;
60 
61 /*
62 	storing results
63  */
64 - (void)setOutcome:(bycopy NSData *)outcome forSeedId:(bycopy NSData *)seedId
65 	andJobId:(bycopy NSString *)jobId;
66 - (NSMutableDictionary *)outcomeDictionaryForJobId:(bycopy NSString *)jobId;
67 
68 @end
69 
70 #define	ZillionClientKey	@"client"
71 #define	ZillionSeedKey		@"seed"
72 #define	ZillionJobKey		@"job"
73 
74 @protocol ZillionJobProtocol <NSObject>
75 
76 + (NSString *)jobId;
77 + (NSData *)dataRepresentationOfSeed:seed;
78 + seedObjectFromDataRepresentation:(NSData *)seed;
79 - initWithBundle:(NSBundle *)someBundle;
80 
81 - (NSEnumerator *)seedEnumeratorWithSeed:(NSData *)seed;
82 
83 
84 /*
85 	The specification of the jobs entails the following keys (with ovious meanings)
86 	ZillionClientKey
87 	ZillionSeedKey
88  */
89 - (void)startJobUnitWithSeed:aSeed andClient:(id <ZillionClientProtocol>)aClient;
90 
91 /*
92 	The job class must not store any information in global variables since the class
93 	may be deallocated at any time. Instead the information can be stored in the server
94 	via -setOutcome:forSeedId:andJobId:
95  */
96 + (void)saveOutcome:(NSData *)outcome forSeedId:(NSData *)seedId
97 	storeHints:(NSDictionary *)someStoreHint usingServer:(id <ZillionServerProtocol>)aServer;
98 + (void)sealJobOutcomesUsingServer:(id <ZillionServerProtocol>)aServer;
99 
100 @end
101 
102 @interface ZillionServer : ZillionClientServer <ZillionServerProtocol>
103 {
104 
105 	NSMutableDictionary	*proxyServers;
106 	unsigned			proxyServerIdCounter;
107 
108 	NSMutableDictionary	*clients;
109 	NSMutableDictionary	*dispatchedSeeds;
110 	NSMutableDictionary	*outcomes;
111 
112 	BOOL	_serverToGoDown;
113 	BOOL	_respawnStatus;
114 	BOOL	_reschedulingIsMarked;
115 }
116 
117 - initWithRespawnStatus:(BOOL)respawnStatus;
118 - (BOOL)serverToGoDown;
119 
120 - (id <ZillionJobProtocol>)jobInstance:(NSString *)jobId;
121 
122 @end
123