7 #define LISTEN_PORT 2156
9 extern objstr_t *mainobjstore;
11 int classsize[]={sizeof(int),sizeof(char),sizeof(short), sizeof(void *)};
28 transrecord_t *record;
29 objheader_t *h1,*h2,*h3,*h4,*h5, *h6;
32 record = transStart();
33 printf("DEBUG -> Init done\n");
34 h1 = transRead(record, 1);
35 printf("oid = %d\tsize = %d\n", OID(h1),classsize[h1->type]);
36 h3 = transRead(record, 3);
37 printf("oid = %d\tsize = %d\n", OID(h3),classsize[h3->type]);
38 h4 = transRead(record, 4);
39 printf("oid = %d\tsize = %d\n", OID(h4),classsize[h4->type]);
40 h2 = transRead(record, 2);
41 printf("oid = %d\tsize = %d\n", OID(h2),classsize[h2->type]);
42 h4 = transRead(record, 4);
43 printf("oid = %d\tsize = %d\n", OID(h4),classsize[h4->type]);
44 h3 = transRead(record, 3);
45 printf("oid = %d\tsize = %d\n", OID(h3),classsize[h3->type]);
46 h5 = transRead(record, 5);
47 printf("oid = %d\tsize = %d\n", OID(h5),classsize[h5->type]);
52 transrecord_t *record;
53 objheader_t *h1,*h2,*h3,*h4,*h5, *h6;
56 record = transStart();
64 printf("DEBUG -> Init done\n");
65 h1 = transRead(record, 1);
66 lhashInsert(OID(h1), 1);
67 h2 = transRead(record, 2);
68 lhashInsert(OID(h2), 1);
69 h3 = transRead(record, 3);
70 lhashInsert(OID(h3), 1);
71 h4 = transRead(record, 4);
72 lhashInsert(OID(h4), 1);
73 h5 = transRead(record, 5);
74 lhashInsert(OID(h5), 1);
75 h6 = transRead(record, 6);
76 lhashInsert(OID(h6), 1);
83 //Read objects when objects are found in remote location
85 unsigned int val, mid;
86 transrecord_t *myTrans;
88 objheader_t *header, *h1, *h2;
89 pthread_t thread_Listen;
93 pthread_attr_init(&attr);
94 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
96 //Create and Insert Oid 20
97 size = sizeof(objheader_t) + classsize[2] ;
98 header = (objheader_t *) objstrAlloc(mainobjstore, size);
102 header->rcount = 0; //? not sure how to handle this yet
104 header->status |= NEW;
105 mhashInsert(OID(header), header);
106 mid = iptoMid("128.200.9.29");
107 lhashInsert(OID(header), mid);
109 //Create and Insert Oid 21
110 size = sizeof(objheader_t) + classsize[1] ;
111 header = (objheader_t *) objstrAlloc(mainobjstore, size);
115 header->rcount = 0; //? not sure how to handle this yet
117 header->status |= NEW;
118 mhashInsert(OID(header), header);
119 mid = iptoMid("128.200.9.29");
120 lhashInsert(OID(header), mid);
122 //Create and Insert Oid 22
123 size = sizeof(objheader_t) + classsize[3] ;
124 header = (objheader_t *) objstrAlloc(mainobjstore, size);
128 header->rcount = 0; //? not sure how to handle this yet
130 header->status |= NEW;
131 mhashInsert(OID(header), header);
132 mid = iptoMid("128.200.9.29");
133 lhashInsert(OID(header), mid);
135 //Inserting into lhashtable
136 mid = iptoMid("128.195.175.69"); //dw-1.eecs.uci.edu
137 lhashInsert(31, mid);
138 lhashInsert(32, mid);
140 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
141 //Inserting into lhashtable
147 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
149 //Check if machine demsky is up and running
150 checkServer(mid, "128.200.9.10");
151 mid = iptoMid("128.195.175.69");
152 //Check if machine dw-1 is up and running
153 checkServer(mid, "128.195.175.69");
156 myTrans = transStart();
159 if((h1 = transRead(myTrans, 1)) == NULL){
160 printf("Object not found\n");
163 if((h2 = transRead(myTrans, 2)) == NULL) {
164 printf("Object not found\n");
167 pthread_join(thread_Listen, NULL);
171 //Read objects that are both remote and local and are available on machines
174 unsigned int val, mid;
175 transrecord_t *myTrans;
177 objheader_t *header, *h1, *h2, *h3, *h4;
178 pthread_t thread_Listen;
182 pthread_attr_init(&attr);
183 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
185 //Create and Insert Oid 20
186 size = sizeof(objheader_t) + classsize[2] ;
187 header = (objheader_t *) objstrAlloc(mainobjstore, size);
191 header->rcount = 0; //? not sure how to handle this yet
193 header->status |= NEW;
194 mhashInsert(OID(header), header);
195 mid = iptoMid("128.200.9.29");
196 lhashInsert(OID(header), mid);
198 //Create and Insert Oid 21
199 size = sizeof(objheader_t) + classsize[1] ;
200 header = (objheader_t *) objstrAlloc(mainobjstore, size);
204 header->rcount = 0; //? not sure how to handle this yet
206 header->status |= NEW;
207 mhashInsert(OID(header), header);
208 mid = iptoMid("128.200.9.29");
209 lhashInsert(OID(header), mid);
211 //Create and Insert Oid 22
212 size = sizeof(objheader_t) + classsize[3] ;
213 header = (objheader_t *) objstrAlloc(mainobjstore, size);
217 header->rcount = 0; //? not sure how to handle this yet
219 header->status |= NEW;
220 mhashInsert(OID(header), header);
221 mid = iptoMid("128.200.9.29");
222 lhashInsert(OID(header), mid);
224 //Inserting into lhashtable
225 mid = iptoMid("128.195.175.69"); //dw-1.eecs.uci.edu
226 lhashInsert(31, mid);
227 lhashInsert(32, mid);
228 lhashInsert(33, mid);
230 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
231 //Inserting into lhashtable
237 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
239 //Check if machine demsky is up and running
240 checkServer(mid, "128.200.9.10");
241 mid = iptoMid("128.195.175.69");
242 //Check if machine dw-1 is up and running
243 checkServer(mid, "128.195.175.69");
246 myTrans = transStart();
248 //read object 1 (found on demksy)
249 if((h1 = transRead(myTrans, 1)) == NULL){
250 printf("Object not found\n");
252 //read object 2 (found on demsky)
253 if((h2 = transRead(myTrans, 2)) == NULL) {
254 printf("Object not found\n");
257 //read object 21 (found on local)
258 if((h3 = transRead(myTrans, 21)) == NULL) {
259 printf("Object not found\n");
262 //read object 32 (found on dw-1)
263 if((h4 = transRead(myTrans, 32)) == NULL) {
264 printf("Object not found\n");
267 pthread_join(thread_Listen, NULL);
273 //Read objects when objects are not found in any participant
275 transrecord_t *record;
279 record = transStart();
280 printf("DEBUG -> Init done\n");
282 if((h1 = transRead(record, 11)) == NULL){
283 printf("Object not found\n");
286 if((h2 = transRead(record, 12)) == NULL) {
287 printf("Object not found\n");
294 //Read objects when some objects are found and other objects not found in any participant
296 transrecord_t *record;
297 objheader_t *h1,*h2, *h3, *h4;
300 record = transStart();
301 printf("DEBUG -> Init done\n");
303 if((h1 = transRead(record, 1)) == NULL){
304 printf("Object not found\n");
307 if((h2 = transRead(record, 2)) == NULL) {
308 printf("Object not found\n");
311 if((h3 = transRead(record, 11)) == NULL) {
312 printf("Object not found\n");
315 if((h4 = transRead(record, 13)) == NULL) {
316 printf("Object not found\n");
318 if((h1 != NULL) && (h2 != NULL) && (h3 != NULL) && h4 !=NULL) {
321 printf("Cannot complete this transaction\n");
327 //Commit for transaction objects when the objs are part of other
328 //transactions running simultaneously
330 unsigned int val, mid;
331 transrecord_t *myTrans;
333 objheader_t *header, *h1, *h2, *h3, *h4, *h5, *h6;
334 pthread_t thread_Listen;
338 pthread_attr_init(&attr);
339 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
341 //Create and Insert Oid 20
342 size = sizeof(objheader_t) + classsize[2] ;
343 header = (objheader_t *) objstrAlloc(mainobjstore, size);
347 header->rcount = 0; //? not sure how to handle this yet
349 header->status |= NEW;
350 mhashInsert(OID(header), header);
351 mid = iptoMid("128.200.9.29");
352 lhashInsert(OID(header), mid);
354 //Create and Insert Oid 21
355 size = sizeof(objheader_t) + classsize[1] ;
356 header = (objheader_t *) objstrAlloc(mainobjstore, size);
360 header->rcount = 0; //? not sure how to handle this yet
362 header->status |= NEW;
363 mhashInsert(OID(header), header);
364 mid = iptoMid("128.200.9.29");
365 lhashInsert(OID(header), mid);
367 //Create and Insert Oid 22
368 size = sizeof(objheader_t) + classsize[3] ;
369 header = (objheader_t *) objstrAlloc(mainobjstore, size);
373 header->rcount = 0; //? not sure how to handle this yet
375 header->status |= NEW;
376 mhashInsert(OID(header), header);
377 mid = iptoMid("128.200.9.29");
378 lhashInsert(OID(header), mid);
380 //Inserting into lhashtable
381 mid = iptoMid("128.195.175.69"); //dw-1.eecs.uci.edu
382 lhashInsert(31, mid);
383 lhashInsert(32, mid);
384 lhashInsert(33, mid);
386 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
387 //Inserting into lhashtable
393 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
394 //Check if machine demsky is up and running
395 checkServer(mid, "128.200.9.10");
396 mid = iptoMid("128.195.175.69");
397 //Check if machine dw-1 is up and running
398 checkServer(mid, "128.195.175.69");
401 myTrans = transStart();
403 //read object 1 (found on demksy)
404 if((h1 = transRead(myTrans, 1)) == NULL){
405 printf("Object not found\n");
407 //read object 2 (found on demksy)
408 if((h2 = transRead(myTrans,2)) == NULL){
409 printf("Object not found\n");
411 //read object 22 (found locally )
412 if((h3 = transRead(myTrans, 22)) == NULL) {
413 printf("Object not found\n");
417 transCommit(myTrans);
419 pthread_join(thread_Listen, NULL);
423 unsigned int val, mid;
424 transrecord_t *myTrans;
426 objheader_t *header, *h1, *h2, *h3;
427 pthread_t thread_Listen;
431 pthread_attr_init(&attr);
432 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
434 //Create and Insert Oid 20
435 size = sizeof(objheader_t) + classsize[2] ;
436 header = (objheader_t *) objstrAlloc(mainobjstore, size);
440 header->rcount = 0; //? not sure how to handle this yet
442 header->status |= NEW;
443 mhashInsert(OID(header), header);
444 mid = iptoMid("128.200.9.29");
445 lhashInsert(OID(header), mid);
447 //Create and Insert Oid 21
448 size = sizeof(objheader_t) + classsize[1] ;
449 header = (objheader_t *) objstrAlloc(mainobjstore, size);
452 //read object 31 (found on dw-1)
453 if((h2 = transRead(myTrans, 31)) == NULL) {
454 printf("Object not found\n");
458 transCommit(myTrans);
460 pthread_join(thread_Listen, NULL);
464 unsigned int val, mid;
465 transrecord_t *myTrans;
467 objheader_t *header, *h1, *h2, *h3;
468 pthread_t thread_Listen;
472 pthread_attr_init(&attr);
473 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
475 //Create and Insert Oid 20
476 size = sizeof(objheader_t) + classsize[2] ;
477 header = (objheader_t *) objstrAlloc(mainobjstore, size);
481 header->rcount = 0; //? not sure how to handle this yet
483 header->status |= NEW;
484 mhashInsert(OID(header), header);
485 mid = iptoMid("128.200.9.29");
486 lhashInsert(OID(header), mid);
488 //Create and Insert Oid 21
489 size = sizeof(objheader_t) + classsize[1] ;
490 header = (objheader_t *) objstrAlloc(mainobjstore, size);
494 header->rcount = 0; //? not sure how to handle this yet
496 header->status |= NEW;
497 mhashInsert(OID(header), header);
498 mid = iptoMid("128.200.9.29");
499 lhashInsert(OID(header), mid);
501 //Create and Insert Oid 22
502 size = sizeof(objheader_t) + classsize[3] ;
503 header = (objheader_t *) objstrAlloc(mainobjstore, size);
507 header->rcount = 0; //? not sure how to handle this yet
509 header->status |= NEW;
510 mhashInsert(OID(header), header);
511 mid = iptoMid("128.200.9.29");
512 lhashInsert(OID(header), mid);
514 //Inserting into lhashtable
515 mid = iptoMid("128.195.175.69"); //dw-1.eecs.uci.edu
516 lhashInsert(31, mid);
517 lhashInsert(32, mid);
518 lhashInsert(33, mid);
520 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
521 //Inserting into lhashtable
527 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
529 //Check if machine demsky is up and running
530 checkServer(mid, "128.200.9.10");
531 mid = iptoMid("128.195.175.69");
532 //Check if machine dw-1 is up and running
533 checkServer(mid, "128.195.175.69");
536 myTrans = transStart();
538 //read object 1 (found on demksy)
539 if((h1 = transRead(myTrans, 1)) == NULL){
540 printf("Object not found\n");
542 //read object 31 (found on dw-1)
543 if((h2 = transRead(myTrans, 31)) == NULL) {
544 printf("Object not found\n");
547 //read object 22 (found locally)
548 if((h3 = transRead(myTrans, 22)) == NULL) {
549 printf("Object not found\n");
553 if((h1 != NULL) && (h2 != NULL) && (h3 != NULL))
554 transCommit(myTrans);
556 printf("Cannot complete this transaction \n");
558 pthread_join(thread_Listen, NULL);
561 //Commit transactions on local and remote objects that are NOT a part of
562 //any other transaction
564 unsigned int val, mid;
565 transrecord_t *myTrans;
567 objheader_t *header, *h1, *h2, *h3;
568 pthread_t thread_Listen;
572 pthread_attr_init(&attr);
573 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
575 //Create and Insert Oid 20
576 size = sizeof(objheader_t) + classsize[2] ;
577 header = (objheader_t *) objstrAlloc(mainobjstore, size);
581 header->rcount = 0; //? not sure how to handle this yet
583 header->status |= NEW;
584 mhashInsert(OID(header), header);
585 mid = iptoMid("128.200.9.29");
586 lhashInsert(OID(header), mid);
588 //Create and Insert Oid 21
589 size = sizeof(objheader_t) + classsize[1] ;
590 header = (objheader_t *) objstrAlloc(mainobjstore, size);
594 header->rcount = 0; //? not sure how to handle this yet
596 header->status |= NEW;
597 mhashInsert(OID(header), header);
598 mid = iptoMid("128.200.9.29");
599 lhashInsert(OID(header), mid);
601 //Create and Insert Oid 22
602 size = sizeof(objheader_t) + classsize[3] ;
603 header = (objheader_t *) objstrAlloc(mainobjstore, size);
607 header->rcount = 0; //? not sure how to handle this yet
609 header->status |= NEW;
610 mhashInsert(OID(header), header);
611 mid = iptoMid("128.200.9.29");
612 lhashInsert(OID(header), mid);
614 //Inserting into lhashtable
615 mid = iptoMid("128.195.175.69"); //dw-1.eecs.uci.edu
616 lhashInsert(31, mid);
617 lhashInsert(32, mid);
618 lhashInsert(33, mid);
620 mid = iptoMid("128.200.9.10"); //demsky.eecs.uci.edu
621 //Inserting into lhashtable
627 pthread_create(&thread_Listen, &attr, dstmListen, NULL);
629 //Check if machine demsky is up and running
630 checkServer(mid, "128.200.9.10");
631 mid = iptoMid("128.195.175.69");
632 //Check if machine dw-1 is up and running
633 checkServer(mid, "128.195.175.69");
636 myTrans = transStart();
638 //read object 3 (found on demksy)
639 if((h1 = transRead(myTrans, 3)) == NULL){
640 printf("Object not found\n");
642 //read object 32 (found on dw-1)
643 if((h2 = transRead(myTrans, 32)) == NULL) {
644 printf("Object not found\n");
647 //read object 22 (found locally)
648 if((h3 = transRead(myTrans, 22)) == NULL) {
649 printf("Object not found\n");
653 transCommit(myTrans);
655 pthread_join(thread_Listen, NULL);