This repository has been archived by the owner on May 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
PRC_Objects.nugg
5380 lines (4720 loc) · 302 KB
/
PRC_Objects.nugg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<nugget name="PRC_OBJECTS">
<CLAS CLSNAME="ZCX_PRC_EXCESSIVE_DELAY" VERSION="1" LANGU="E" DESCRIPT="The process failed already during execution, check error tra" CATEGORY="40" EXPOSURE="2" STATE="1" RELEASE="0" CLSFINAL="X" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 " REFCLSNAME="ZCX_PRC_PROCESS_EXCEPTION">
<localImplementation>*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations</localImplementation>
<localTypes>*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section</localTypes>
<localMacros>*"* use this source file for any macro definitions you need
*"* in the implementation part of the class</localMacros>
<inheritance CLSNAME="ZCX_PRC_EXCESSIVE_DELAY" REFCLSNAME="ZCX_PRC_PROCESS_EXCEPTION" VERSION="1" STATE="1"/>
</CLAS>
<CLAS CLSNAME="ZCL_PRC_BG_BATCH_JOB" VERSION="1" LANGU="E" DESCRIPT="Runs as a Background Job(e.g. a job is submitted internally)" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 ">
<implementing CLSNAME="ZCL_PRC_BG_BATCH_JOB" REFCLSNAME="IF_SERIALIZABLE_OBJECT" VERSION="1" EXPOSURE="2" STATE="1" RELTYPE="1" EDITORDER="1 "/>
<localImplementation>*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations
class lcl_processor definition.
public section.
methods:
constructor
importing ir_process type ref to zcl_prc_bg_batch_job,
dispatch
importing iv_uname type sy-uname default sy-uname
raising zcx_prc_process_exception zcx_prc_wait_timout_exception.
protected section.
private section.
data: mr_process type ref to zcl_prc_bg_batch_job.
methods:
serialize returning value(rv_process) type zprce_data.
endclass. "lcl_processor DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_processor IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_processor implementation.
method constructor.
mr_process = ir_process.
endmethod. "constructor
method serialize.
call transformation id_indent
source obj = mr_process
result xml rv_process.
endmethod. "serialize
method dispatch.
data: ls_bg type zprcd_bg_batch.
"... Set the guid
mr_process->mv_guid = cl_system_uuid=>create_uuid_x16_static( ).
convert
date mr_process->mr_schedule->date( )
time mr_process->mr_schedule->time( )
into time stamp data(lv_start_time) time zone sy-zonlo.
"... Get the serialized data
ls_bg-data = serialize( ).
ls_bg-guid = mr_process->mv_guid.
get time stamp field ls_bg-time.
ls_bg-start_time = lv_start_time.
"... The program will use this table entry
modify zprcd_bg_batch from ls_bg.
"... Commit
commit work.
endmethod. "dispatch
endclass. "lcl_processor IMPLEMENTATION</localImplementation>
<localTypes>*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section
class lcl_processor definition deferred.
class zcl_prc_bg_batch_job definition local friends lcl_processor.</localTypes>
<localMacros>*"* use this source file for any macro definitions you need
*"* in the implementation part of the class</localMacros>
<attribute CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="MR_RUNNABLE" VERSION="1" LANGU="E" DESCRIPT="Runnable Interface" EXPOSURE="2" STATE="1" EDITORDER="1 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="3" TYPE="ZIF_PRC_RUNNABLE" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="MR_SCHEDULE" VERSION="1" LANGU="E" DESCRIPT="Used to add scheduling" EXPOSURE="0" STATE="1" EDITORDER="4 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="3" TYPE="ZCL_PRC_JOB_SCHEDULE" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="MV_DELAY" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="2 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="STRING" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="MV_GROUP" VERSION="1" LANGU="E" EXPOSURE="1" STATE="1" EDITORDER="5 " ATTDECLTYP="0" ATTVALUE="' '" ATTEXPVIRT="0" TYPTYPE="1" TYPE="STRING" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="MV_GUID" VERSION="1" LANGU="E" DESCRIPT="16 Byte UUID in 16 Bytes (Raw Format)" EXPOSURE="0" STATE="1" EDITORDER="3 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="SYSUUID_X16" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<method CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="CONSTRUCTOR" VERSION="1" LANGU="E" DESCRIPT="CONSTRUCTOR" EXPOSURE="2" STATE="1" EDITORDER="1 " DISPID="0 " MTDTYPE="2" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="CONSTRUCTOR" SCONAME="IR_RUNNABLE" VERSION="1" LANGU="E" DESCRIPT="Runnable Interface" CMPTYPE="1" MTDTYPE="2" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZIF_PRC_RUNNABLE"/>
<parameter CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="CONSTRUCTOR" SCONAME="IV_DELAY" VERSION="1" LANGU="E" DESCRIPT="Seconds, yes as a char e.g. '2' or '0.2' dont ask" CMPTYPE="1" MTDTYPE="2" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING" PAROPTIONL="X"/>
<source>method CONSTRUCTOR.
mr_runnable = ir_runnable.
mv_delay = iv_delay.
endmethod. "CONSTRUCTOR</source>
</method>
<method CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="START" VERSION="1" LANGU="E" DESCRIPT="Start the process" EXPOSURE="2" STATE="1" EDITORDER="2 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="START" SCONAME="SCHEDULE" VERSION="1" LANGU="E" DESCRIPT="Used to add scheduling" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZCL_PRC_JOB_SCHEDULE" PAROPTIONL="X"/>
<exception CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="START" SCONAME="ZCX_PRC_PROCESS_EXCEPTION" VERSION="1" LANGU="E" MTDTYPE="0" EDITORDER="1 "/>
<exception CLSNAME="ZCL_PRC_BG_BATCH_JOB" CMPNAME="START" SCONAME="ZCX_PRC_WAIT_TIMOUT_EXCEPTION" VERSION="1" LANGU="E" MTDTYPE="0" EDITORDER="2 "/>
<source>method START.
data: lr_processor type ref to lcl_processor.
mr_schedule = schedule.
create object lr_processor
exporting
ir_process = me.
lr_processor->dispatch( ).
endmethod. "START</source>
</method>
</CLAS>
<CLAS CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" VERSION="1" LANGU="E" DESCRIPT="PRC Completion Monitor" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" CLSFINAL="X" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 ">
<localImplementation>*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations
class lcl_processor definition.
public section.
methods:
constructor
importing
ir_callable type ref to zif_prc_callable
iv_delay type string optional
iv_timeout type i optional,
dispatch
raising zcx_prc_process_exception zcx_prc_wait_timout_exception.
protected section.
private section.
data: mr_callable type ref to zif_prc_callable,
mv_delay type string,
mv_timeout type i.
methods:
serialize returning value(rv_callable) type zprce_data.
methods:
initialize_group returning value(rv_group) type rzlli_apcl.
methods:
get_wp_id returning value(rv_wpid) type char8.
endclass. "lcl_processor DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_processor IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_processor implementation.
method constructor.
mr_callable = ir_callable.
mv_delay = iv_delay.
mv_timeout = iv_timeout.
endmethod. "constructor
method serialize.
call transformation id_indent
source obj = mr_callable
result xml rv_callable.
endmethod. "serialize
method dispatch.
data: lv_group type rzlli_apcl value ' ',
lv_data type zprce_data,
lv_time type t.
get time field lv_time.
do. "... Timeout checked at end
try.
if zcl_prc_future_executor=>get_wp_avail( ) ne 0.
"... Set the process ID
mr_callable->mv_cpid = zcl_prc_future_executor=>register_pid( ).
mr_callable->mv_guid = cl_system_uuid=>create_uuid_x16_static( ).
mr_callable->mv_wpid = get_wp_id( ).
"... Get the serialized data
lv_data = serialize( ).
call function 'Z_PRC_RUN_FUTURE_TASK' starting new task mr_callable->mv_cpid
destination 'NONE'
exporting
iv_callable = lv_data
iv_delay = mv_delay
exceptions
system_failure = 1
communication_failure = 2
resource_failure = 3.
case sy-subrc.
when 0.
exit. "... Exit the do loop to complete the method
when 3.
"... Do nothing because we are waiting
when others.
"... Explode in other cases
raise exception type zcx_prc_system_failure.
endcase.
endif.
catch zcx_prc_no_processes_avail.
"... No process available, occurs under very high load
"... Let the retry occur
endtry.
get time. "... Init the system time to be sure
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt mv_timeout.
"... Wait time is over
raise exception type zcx_prc_wait_timout_exception.
endif.
enddo.
endmethod. "dispatch
method initialize_group.
data: lv_available type i,
lv_time type t,
lv_initial type abap_bool value abap_true,
lv_max type i.
get time field lv_time.
do. "... Timeout checked at end
"... IF unsure do intialisation
if lv_initial eq abap_true.
"... Prepare for launch, we need the number of available processes
call function 'SPBT_INITIALIZE'
exporting
group_name = rv_group "... name of group
importing
max_pbt_wps = lv_max "... number of dialog processes avail
free_pbt_wps = lv_available "... number available
exceptions
invalid_group_name = 1 "... Incorrect group name; RFC group not defined.
* "... See transaction RZ12
internal_error = 2 "... Server error
pbt_env_already_initialized = 3 "... Apparently this FM can only be called once
currently_no_resources_avail = 4 "... No processes available / workload too high
no_pbt_resources_found = 5 "... No servers in workgrp with 2 or more processes defined
cant_init_different_pbt_groups = 6 "... Another grp is already initialised
others = 7. "... Who knows?
else.
"... We are certain initialisation is done lets check resources
call function 'SPBT_GET_CURR_RESOURCE_INFO'
importing
max_pbt_wps = lv_max
free_pbt_wps = lv_available
exceptions
internal_error = 1
pbt_env_not_initialized_yet = 2
others = 3. "... Thanks SAP for making 3 other! thats really not
* very helpful for my case statement
endif.
case sy-subrc.
when 3. "... Either initial failed or getting resources failed
if lv_initial eq abap_true.
lv_initial = abap_false.
mv_timeout = mv_timeout + 1. "... A second was wasted so add it back on
continue.
else.
"... Resource grab failed
raise exception type zcx_prc_process_exception.
endif.
when 4 or 0.
"... Not enough available processes
if lv_available eq 0 or zcl_prc_future_executor=>get_wp_avail( ) eq 0.
"... Do nothing we will continue the loop
else.
"... Theres at least 1 process free so lets exit the do loop and move on
exit.
endif.
when others.
raise exception type zcx_prc_process_exception.
endcase.
get time. "... Init the system time to be sure
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt mv_timeout.
"... Wait time is over
raise exception type zcx_prc_wait_timout_exception.
endif.
enddo.
endmethod.
method get_wp_id.
"...get the originating work process ID
call function 'TH_GET_OWN_WP_NO'
importing
wp_pid = rv_wpid.
endmethod. "get work process id
endclass. "lcl_processor IMPLEMENTATION</localImplementation>
<localTypes>*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section
class lcl_processor definition deferred.
class ZCL_prc_future_executor definition local friends lcl_processor.</localTypes>
<localMacros>*"* use this source file for any macro definitions you need
*"* in the implementation part of the class</localMacros>
<typeUsage CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" TYPEGROUP="ABAP" VERSION="1" TPUTYPE="0" IMPLICIT="X"/>
<forwardDeclaration>ABAP</forwardDeclaration>
<typeClasDef CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" TYPEGROUP="ZCL_PRC_EXECUTOR_ACCESS" VERSION="1" TPUTYPE="1" EXPLICIT="X" IMPLICIT="X"/>
<attribute CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="MV_TIMEOUT" VERSION="1" LANGU="E" DESCRIPT="Timeout in seconds" EXPOSURE="0" STATE="1" EDITORDER="1 " ATTDECLTYP="0" ATTVALUE="299" ATTEXPVIRT="0" TYPTYPE="1" TYPE="I" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="ATTACH_WP" VERSION="1" LANGU="E" EXPOSURE="2" STATE="1" EDITORDER="5 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="ATTACH_WP" SCONAME="IV_PID" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CHAR8"/>
<source>method ATTACH_WP.
data: lr_area type ref to zcl_prc_executor_area,
lr_executor type ref to zcl_prc_executor_access,
lr_exc type ref to cx_shm_attach_error,
lv_time type t.
get time field lv_time.
do.
try.
lr_area = zcl_prc_executor_area=>attach_for_update( 'ZCL_PRC_EXECUTOR_AREA' ).
exit. "... Exit Do
catch cx_shm_exclusive_lock_active
cx_shm_version_limit_exceeded
cx_shm_change_lock_active
cx_shm_read_lock_active
cx_shm_no_active_version into lr_exc.
get time.
"... 1hr Retry(pretty extreme)
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt 3600.
raise exception type zcx_prc_wait_timout_exception.
endif.
endtry.
enddo.
"... Check for previous success
check lr_area is not initial and lr_area->root is not initial.
lr_executor = lr_area->root.
lr_executor->attach_wp( iv_pid ).
lr_area->detach_commit( ).
endmethod.</source>
</method>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="CONSTRUCTOR" VERSION="1" LANGU="E" DESCRIPT="CONSTRUCTOR" EXPOSURE="2" STATE="1" EDITORDER="1 " DISPID="0 " MTDTYPE="2" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="CONSTRUCTOR" SCONAME="IV_MAXPROCESSES" VERSION="1" LANGU="E" DESCRIPT="Maximum work processes to use" CMPTYPE="1" MTDTYPE="2" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="I" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="CONSTRUCTOR" SCONAME="IV_TIMEOUT" VERSION="1" LANGU="E" DESCRIPT="Timeout in seconds when attempting to access shared memory" CMPTYPE="1" MTDTYPE="2" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="I" PARVALUE="43200"/>
<source>method constructor.
mv_timeout = iv_timeout.
if iv_maxprocesses is not initial.
max_work_processes( iv_maxprocesses ).
else.
max_work_processes( zcl_prc_wp_manager=>get_max_work_processes( ) ).
endif.
endmethod. "CONSTRUCTOR</source>
</method>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="DEREGISTER_PID" VERSION="1" LANGU="E" DESCRIPT="Public for FM module access ONLY" EXPOSURE="2" STATE="1" EDITORDER="4 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="DEREGISTER_PID" SCONAME="IV_PID" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CHAR8"/>
<source>method DEREGISTER_PID.
data: lr_area type ref to zcl_prc_executor_area,
lr_executor type ref to zcl_prc_executor_access,
lr_exc type ref to cx_shm_attach_error,
lv_time type t.
get time field lv_time.
do.
try.
lr_area = zcl_prc_executor_area=>attach_for_update( 'ZCL_PRC_EXECUTOR_AREA' ).
exit. "... Exit Do
catch cx_shm_exclusive_lock_active
cx_shm_version_limit_exceeded
cx_shm_change_lock_active
cx_shm_read_lock_active
cx_shm_no_active_version into lr_exc.
get time.
"... 1hr Retry(pretty extreme)
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt 3600.
raise exception type zcx_prc_wait_timout_exception.
endif.
endtry.
enddo.
"... Check for previous success
check lr_area is not initial and lr_area->root is not initial.
lr_executor = lr_area->root.
lr_executor->deregister_pid( iv_pid ).
lr_area->detach_commit( ).
endmethod. "DEREGISTER_PID</source>
</method>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="GARBAGE_COLLECT" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="6 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="GARBAGE_COLLECT" SCONAME="IV_BYPASS_LONGCHK" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="ABAP_BOOL" PARVALUE="ABAP_FALSE"/>
<source>method GARBAGE_COLLECT.
data: lr_area type ref to zcl_prc_executor_area,
lr_executor type ref to zcl_prc_executor_access,
lr_exc type ref to cx_shm_attach_error,
lv_time type t.
get time field lv_time.
do.
try.
lr_area = zcl_prc_executor_area=>attach_for_update( 'ZCL_PRC_EXECUTOR_AREA' ).
exit. "... Exit Do
catch cx_shm_exclusive_lock_active
cx_shm_version_limit_exceeded
cx_shm_change_lock_active
cx_shm_read_lock_active
cx_shm_no_active_version into lr_exc.
get time.
"... 1hr Retry(pretty extreme)
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt 3600.
raise exception type zcx_prc_wait_timout_exception.
endif.
endtry.
enddo.
"... Check for previous success
check lr_area is not initial and lr_area->root is not initial.
lr_executor = lr_area->root.
lr_executor->garbage_collect( iv_bypass_longchk ).
lr_area->detach_commit( ).
endmethod.</source>
</method>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="GET_WP_AVAIL" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="5 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="GET_WP_AVAIL" SCONAME="RV_WP_AVAIL" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="I"/>
<source>method GET_WP_AVAIL.
data: lr_area type ref to zcl_prc_executor_area,
lr_executor type ref to zcl_prc_executor_access,
lr_exc type ref to cx_shm_attach_error,
rv_cleaned type abap_bool,
lv_time type t.
"... Do any GC first
garbage_collect( ).
get time field lv_time.
do.
try.
lr_area = zcl_prc_executor_area=>attach_for_read( 'ZCL_PRC_EXECUTOR_AREA' ).
exit. "... Exit Do
catch cx_shm_inconsistent. "... When inconsistent all we need to do is reset this
zcl_prc_executor_area=>free_area( ). "... If this fails we have a real problem
catch cx_shm_exclusive_lock_active
cx_shm_version_limit_exceeded
cx_shm_change_lock_active
cx_shm_read_lock_active
cx_shm_no_active_version into lr_exc.
get time.
"... 1hr Retry(pretty extreme)
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt 3600.
raise exception type zcx_prc_wait_timout_exception.
endif.
endtry.
enddo.
"... Check for previous success
check lr_area is not initial and lr_area->root is not initial.
lr_executor = lr_area->root.
rv_wp_avail = lr_executor->get_wp_avail( ).
lr_area->detach( ).
case rv_wp_avail.
when -1. "... Not initialised
"... Initialise the work processes to default, can return that value here
rv_wp_avail = zcl_prc_wp_manager=>get_max_work_processes( ).
max_work_processes( rv_wp_avail ).
endcase.
endmethod. "GET_WP_AVAIL</source>
</method>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="HAS_PROCESSES" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="4 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="HAS_PROCESSES" SCONAME="RV_RESULT" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="ABAP_BOOL"/>
<source>method HAS_PROCESSES.
data: lr_area type ref to zcl_prc_executor_area,
lr_executor type ref to zcl_prc_executor_access,
lr_exc type ref to cx_shm_attach_error,
lv_time type t.
"... Do any GC first(probably not used for completion?)
garbage_collect( abap_true ).
get time field lv_time.
do.
try.
lr_area = zcl_prc_executor_area=>attach_for_read( 'ZCL_PRC_EXECUTOR_AREA' ).
exit. "... Exit Do
catch cx_shm_exclusive_lock_active
cx_shm_version_limit_exceeded
cx_shm_change_lock_active
cx_shm_read_lock_active
cx_shm_no_active_version into lr_exc.
get time.
"... 1hr Retry(pretty extreme)
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt 3600.
raise exception type zcx_prc_wait_timout_exception.
endif.
endtry.
enddo.
"... Check for previous success
check lr_area is not initial and lr_area->root is not initial.
lr_executor = lr_area->root.
rv_result = lr_executor->has_processes( ).
lr_area->detach( ).
endmethod. "HAS_PROCESSES</source>
</method>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="MAX_WORK_PROCESSES" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="1 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="MAX_WORK_PROCESSES" SCONAME="IV_NUM" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="I"/>
<source>method MAX_WORK_PROCESSES.
data: lr_area type ref to zcl_prc_executor_area,
lr_executor type ref to zcl_prc_executor_access,
lr_exc type ref to cx_shm_attach_error,
lv_time type t.
get time field lv_time.
do.
try.
lr_area = zcl_prc_executor_area=>attach_for_update( 'ZCL_PRC_EXECUTOR_AREA' ).
exit. "... Exit Do
catch cx_shm_inconsistent. "... When inconsistent all we need to do is reset this
zcl_prc_executor_area=>free_area( ). "... If this fails we have a real problem
catch cx_shm_exclusive_lock_active
cx_shm_version_limit_exceeded
cx_shm_change_lock_active
cx_shm_read_lock_active
cx_shm_no_active_version into lr_exc.
get time.
"... 1hr Retry(pretty extreme)
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt 3600.
raise exception type zcx_prc_wait_timout_exception.
endif.
endtry.
enddo.
"... Check for previous success
check lr_area is not initial and lr_area->root is not initial.
lr_executor = lr_area->root.
lr_executor->number_of_processes( iv_num ).
lr_area->detach_commit( ).
endmethod. "MAX_WORK_PROCESSES</source>
</method>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="PID_EXISTS" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="3 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="PID_EXISTS" SCONAME="IV_PID" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CHAR8"/>
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="PID_EXISTS" SCONAME="RV_EXISTS" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="ABAP_BOOL"/>
<source>method PID_EXISTS.
data: lr_area type ref to zcl_prc_executor_area,
lr_executor type ref to zcl_prc_executor_access,
lr_exc type ref to cx_shm_attach_error,
lv_time type t.
get time field lv_time.
do.
try.
lr_area = zcl_prc_executor_area=>attach_for_read( 'ZCL_PRC_EXECUTOR_AREA' ).
exit. "... Exit Do
catch cx_shm_exclusive_lock_active
cx_shm_version_limit_exceeded
cx_shm_change_lock_active
cx_shm_read_lock_active
cx_shm_no_active_version into lr_exc.
get time.
"... 1hr Retry(pretty extreme)
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt 3600.
raise exception type zcx_prc_wait_timout_exception.
endif.
endtry.
enddo.
"... Check for previous success
check lr_area is not initial and lr_area->root is not initial.
lr_executor = lr_area->root.
rv_exists = lr_executor->pid_exists( iv_pid ).
lr_area->detach( ).
endmethod. "PID_EXISTS</source>
</method>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="REGISTER_PID" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="2 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="REGISTER_PID" SCONAME="RV_PID" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="CHAR8"/>
<exception CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="REGISTER_PID" SCONAME="ZCX_PRC_NO_PROCESSES_AVAIL" VERSION="1" LANGU="E" DESCRIPT="Raised when no proceses available for user" MTDTYPE="0" EDITORDER="1 "/>
<source>method REGISTER_PID.
data: lr_area type ref to zcl_prc_executor_area,
lr_executor type ref to zcl_prc_executor_access,
lr_exc type ref to cx_shm_attach_error,
lv_time type t.
get time field lv_time.
do.
try.
lr_area = zcl_prc_executor_area=>attach_for_update( 'ZCL_PRC_EXECUTOR_AREA' ).
exit. "... Exit Do
catch cx_shm_exclusive_lock_active
cx_shm_version_limit_exceeded
cx_shm_change_lock_active
cx_shm_read_lock_active
cx_shm_no_active_version into lr_exc.
get time.
"... 1hr Retry(pretty extreme)
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt 3600.
raise exception type zcx_prc_wait_timout_exception.
endif.
endtry.
enddo.
"... Check for previous success
check lr_area is not initial and lr_area->root is not initial.
lr_executor = lr_area->root.
rv_pid = lr_executor->register_pid( ).
lr_area->detach_commit( ).
endmethod. "REGISTER_PID</source>
</method>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="SET_RESULT" VERSION="1" LANGU="E" EXPOSURE="2" STATE="1" EDITORDER="3 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="1" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="SET_RESULT" SCONAME="IV_PID" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CHAR8"/>
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="SET_RESULT" SCONAME="IV_GUID" VERSION="1" LANGU="E" DESCRIPT="16 Byte UUID in 16 Bytes (Raw Format)" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="SYSUUID_X16"/>
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="SET_RESULT" SCONAME="IR_RESULT" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="3 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="ANY"/>
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="SET_RESULT" SCONAME="IV_WPID" VERSION="1" LANGU="E" DESCRIPT="Character field, 8 characters long" CMPTYPE="1" MTDTYPE="0" EDITORDER="4 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CHAR8"/>
<exception CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="SET_RESULT" SCONAME="ZCX_PRC_NON_SERIALIZABLE" VERSION="1" LANGU="E" DESCRIPT="A Result object ref was used that cant be serialized" MTDTYPE="0" EDITORDER="1 "/>
<source>method SET_RESULT.
data: lr_area type ref to zcl_prc_executor_area,
lr_executor type ref to zcl_prc_executor_access,
lr_exc type ref to cx_shm_attach_error,
lv_data type zprce_data,
lv_time type t.
"... First thing to do is try to serialize the input
try.
lv_data = zcl_prc_serialization_util=>serialize_result( ir_result ).
catch zcx_prc_non_serializable.
raise exception type zcx_prc_non_serializable.
endtry.
get time field lv_time.
do.
try.
lr_area = zcl_prc_executor_area=>attach_for_update( 'ZCL_PRC_EXECUTOR_AREA' ).
exit. "... Exit Do
catch cx_shm_exclusive_lock_active
cx_shm_version_limit_exceeded
cx_shm_change_lock_active
cx_shm_read_lock_active
cx_shm_no_active_version into lr_exc.
get time.
"... 1hr Retry(pretty extreme)
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt 3600.
raise exception type zcx_prc_wait_timout_exception.
endif.
endtry.
enddo.
"... Check for previous success
check lr_area is not initial and lr_area->root is not initial.
lr_executor = lr_area->root.
lr_executor->set_result( iv_pid = iv_pid
iv_guid = iv_guid
iv_wpid = iv_wpid
iv_result = lv_data ).
lr_area->detach_commit( ).
endmethod. "SET_RESULT</source>
</method>
<method CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="SUBMIT" VERSION="1" LANGU="E" DESCRIPT="Submit a Callable Completion Process" EXPOSURE="2" STATE="1" EDITORDER="2 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="SUBMIT" SCONAME="IR_CALLABLE" VERSION="1" LANGU="E" DESCRIPT="Callback interface for definition of callback" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZIF_PRC_CALLABLE"/>
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="SUBMIT" SCONAME="IV_DELAY" VERSION="1" LANGU="E" DESCRIPT="Seconds, yes as a char e.g. '2' or '0.2' dont ask" CMPTYPE="1" MTDTYPE="0" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING" PAROPTIONL="X"/>
<parameter CLSNAME="ZCL_PRC_FUTURE_EXECUTOR" CMPNAME="SUBMIT" SCONAME="RR_PROCESS" VERSION="1" LANGU="E" DESCRIPT="Process" CMPTYPE="1" MTDTYPE="0" EDITORDER="3 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="3" TYPE="ZCL_PRC_FUTURE_TASK"/>
<source>method submit.
data: lr_processor type ref to lcl_processor,
lv_pid type char8.
data: lv_p type p decimals 2.
lv_p = iv_delay.
if lv_p gt 45.
raise exception type zcx_prc_excessive_delay.
endif.
create object lr_processor
exporting
ir_callable = ir_callable
iv_delay = iv_delay
iv_timeout = mv_timeout.
lr_processor->dispatch( ).
create object rr_process
exporting
ir_callable = ir_callable.
endmethod. "submit</source>
</method>
</CLAS>
<CLAS CLSNAME="ZCL_PRC_MANAGED_TASK" VERSION="1" LANGU="E" DESCRIPT="Runs as new task with shared memory management" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 ">
<implementing CLSNAME="ZCL_PRC_MANAGED_TASK" REFCLSNAME="IF_SERIALIZABLE_OBJECT" VERSION="1" EXPOSURE="2" STATE="1" RELTYPE="1" EDITORDER="1 "/>
<localImplementation>*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations
class lcl_processor definition.
public section.
methods:
constructor importing ir_process type ref to zcl_prc_managed_task,
dispatch raising zcx_prc_process_exception zcx_prc_wait_timout_exception.
protected section.
private section.
data: mr_process type ref to zcl_prc_managed_task.
methods:
serialize returning value(rv_process) type zprce_data.
methods:
initialize_group returning value(rv_group) type rzlli_apcl.
endclass. "lcl_processor DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_processor IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_processor implementation.
method constructor.
mr_process = ir_process.
endmethod. "constructor
method serialize.
call transformation id_indent
source obj = mr_process
result xml rv_process.
endmethod. "serialize
method dispatch.
data: lv_data type zprce_data,
lv_time type t,
lv_group type rzlli_apcl.
get time field lv_time.
do. "... Timeout checked at end
try.
if zcl_prc_monitor=>get_wp_avail( ) ne 0.
"... Set the process ID
mr_process->set_pid( zcl_prc_monitor=>register_pid( ) ).
"... Get the serialized data
lv_data = serialize( ).
call function 'Z_PRC_RUN_MANAGED_TASK' starting new task mr_process->mv_pid
destination 'NONE'
exporting
iv_process = lv_data
iv_delay = mr_process->mv_delay
exceptions
system_failure = 1
communication_failure = 2
resource_failure = 3.
case sy-subrc.
when 0.
exit. "... Exit the do loop to complete the method
when 3.
"... Do nothing because we are waiting
when others.
"... Explode in other cases
raise exception type zcx_prc_system_failure.
endcase.
endif.
catch zcx_prc_no_processes_avail.
"... No process available, occurs under very high load
"... Let the retry occur
endtry.
get time. "... Init the system time to be sure
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt mr_process->mv_timeout.
"... Wait time is over
raise exception type zcx_prc_wait_timout_exception.
endif.
enddo.
endmethod. "dispatch
method initialize_group.
data: lv_available type i,
lv_time type t,
lv_initial type abap_bool value abap_true,
lv_max type i.
get time field lv_time.
do. "... Timeout checked at end
"... IF unsure do intialisation
if lv_initial eq abap_true.
"... Prepare for launch, we need the number of available processes
call function 'SPBT_INITIALIZE'
exporting
group_name = rv_group "... name of group
importing
max_pbt_wps = lv_max "... number of dialog processes avail
free_pbt_wps = lv_available "... number available
exceptions
invalid_group_name = 1 "... Incorrect group name; RFC group not defined.
"... See transaction RZ12
internal_error = 2 "... Server error
pbt_env_already_initialized = 3 "... Apparently this FM can only be called once
currently_no_resources_avail = 4 "... No processes available / workload too high
no_pbt_resources_found = 5 "... No servers in workgrp with 2 or more processes defined
cant_init_different_pbt_groups = 6 "... Another grp is already initialised
others = 7. "... Who knows?
else.
"... We are certain initialisation is done lets check resources
call function 'SPBT_GET_CURR_RESOURCE_INFO'
importing
max_pbt_wps = lv_max
free_pbt_wps = lv_available
exceptions
internal_error = 1
pbt_env_not_initialized_yet = 2
others = 3. "... Thanks SAP for making 3 other! thats really not
* very helpful for my case statement
endif.
case sy-subrc.
when 3. "... Either initial failed or getting resources failed
if lv_initial eq abap_true.
lv_initial = abap_false.
mr_process->mv_timeout = mr_process->mv_timeout + 1. "... A second was wasted so add it back on
continue.
else.
"... Resource grab failed
raise exception type zcx_prc_process_exception.
endif.
when 4 or 0.
"... Not enough available processes
if lv_available eq 0 or zcl_prc_monitor=>get_wp_avail( ) eq 0.
"... Do nothing we will continue the loop
else.
"... Theres at least 1 process free so lets exit the do loop and move on
exit.
endif.
when others.
raise exception type zcx_prc_process_exception.
endcase.
get time. "... Init the system time to be sure
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt mr_process->mv_timeout.
"... Wait time is over
raise exception type zcx_prc_wait_timout_exception.
endif.
enddo.
endmethod.
endclass. "lcl_processor IMPLEMENTATION</localImplementation>
<localTypes>*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section
class lcl_processor definition deferred.
class ZCL_PRC_MANAGED_TASK definition local friends lcl_processor.</localTypes>
<localMacros>*"* use this source file for any macro definitions you need
*"* in the implementation part of the class</localMacros>
<attribute CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="MR_RUNNABLE" VERSION="1" LANGU="E" DESCRIPT="Runnable Interface" EXPOSURE="2" STATE="1" EDITORDER="1 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="3" TYPE="ZIF_PRC_RUNNABLE" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="MV_DELAY" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="3 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="STRING" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="MV_PID" VERSION="1" LANGU="E" DESCRIPT="Process ID" EXPOSURE="0" STATE="1" EDITORDER="1 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="CHAR8" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="MV_TIMEOUT" VERSION="1" LANGU="E" DESCRIPT="Timeout in seconds" EXPOSURE="0" STATE="1" EDITORDER="2 " ATTDECLTYP="0" ATTVALUE="299" ATTEXPVIRT="0" TYPTYPE="1" TYPE="I" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<method CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="CONSTRUCTOR" VERSION="1" LANGU="E" DESCRIPT="CONSTRUCTOR" EXPOSURE="2" STATE="1" EDITORDER="1 " DISPID="0 " MTDTYPE="2" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="CONSTRUCTOR" SCONAME="IR_RUNNABLE" VERSION="1" LANGU="E" DESCRIPT="Runnable Interface" CMPTYPE="1" MTDTYPE="2" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZIF_PRC_RUNNABLE"/>
<parameter CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="CONSTRUCTOR" SCONAME="IV_DELAY" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="2" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING" PAROPTIONL="X"/>
<source>method CONSTRUCTOR.
data: lv_p type p decimals 2.
lv_p = iv_delay.
if lv_p gt 45.
raise exception type zcx_prc_excessive_delay.
endif.
mr_runnable = ir_runnable.
mv_delay = iv_delay.
endmethod. "CONSTRUCTOR</source>
</method>
<method CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="GET_PID" VERSION="1" LANGU="E" DESCRIPT="Get the process ID" EXPOSURE="2" STATE="1" EDITORDER="3 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="GET_PID" SCONAME="RV_PID" VERSION="1" LANGU="E" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="3" PARPASSTYP="0" TYPTYPE="1" TYPE="CHAR8"/>
<source>method GET_PID.
rv_pid = mv_pid.
endmethod. "GET_PID</source>
</method>
<method CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="SET_PID" VERSION="1" LANGU="E" DESCRIPT="Set the process ID (used in FM now)" EXPOSURE="2" STATE="1" EDITORDER="4 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="SET_PID" SCONAME="IV_PID" VERSION="1" LANGU="E" DESCRIPT="Character field, 8 characters long" CMPTYPE="1" MTDTYPE="0" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="CHAR8"/>
<source>method SET_PID.
mv_pid = iv_pid.
endmethod.</source>
</method>
<method CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="START" VERSION="1" LANGU="E" DESCRIPT="Start the process" EXPOSURE="2" STATE="1" EDITORDER="2 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<exception CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="START" SCONAME="ZCX_PRC_PROCESS_EXCEPTION" VERSION="1" LANGU="E" MTDTYPE="0" EDITORDER="1 "/>
<exception CLSNAME="ZCL_PRC_MANAGED_TASK" CMPNAME="START" SCONAME="ZCX_PRC_WAIT_TIMOUT_EXCEPTION" VERSION="1" LANGU="E" MTDTYPE="0" EDITORDER="2 "/>
<source>method START.
data: lr_processor type ref to lcl_processor.
create object lr_processor
exporting
ir_process = me.
lr_processor->dispatch( ).
endmethod. "START</source>
</method>
</CLAS>
<CLAS CLSNAME="ZCL_PRC_ISOLATED_TASK" VERSION="1" LANGU="E" DESCRIPT="Runs as an isolated Background Task(its still a DIA WP)" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 ">
<implementing CLSNAME="ZCL_PRC_ISOLATED_TASK" REFCLSNAME="IF_SERIALIZABLE_OBJECT" VERSION="1" EXPOSURE="2" STATE="1" RELTYPE="1" EDITORDER="1 "/>
<localImplementation>*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations
class lcl_processor definition.
public section.
methods:
constructor importing ir_process type ref to zcl_prc_isolated_task,
dispatch raising zcx_prc_process_exception zcx_prc_wait_timout_exception.
protected section.
private section.
data: mr_process type ref to zcl_prc_isolated_task.
methods:
serialize returning value(rv_process) type zprce_data.
endclass. "lcl_processor DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_processor IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_processor implementation.
method constructor.
mr_process = ir_process.
endmethod. "constructor
method serialize.
call transformation id_indent
source obj = mr_process
result xml rv_process.
endmethod. "serialize
method dispatch.
data: lv_data type zprce_data,
lv_time type t.
get time field lv_time.
do.
"... Get the serialized data
lv_data = serialize( ).
call function 'Z_PRC_RUN_ISOLATED_TASK' starting new task '' destination in group default
exporting
iv_process = lv_data
iv_delay = mr_process->mv_delay
exceptions
system_failure = 1
communication_failure = 2
resource_failure = 3.
case sy-subrc.
when 0.
exit. "... Exit the do loop to complete the method
when 3.
"... Do nothing because we are waiting
when others.
"... Explode in other cases
raise exception type zcx_prc_system_failure.
endcase.
get time. "... Init the system time to be sure
if ( ( sy-uzeit - lv_time ) mod 86400 ) gt mr_process->mv_timeout.
"... Wait time is over
raise exception type zcx_prc_wait_timout_exception.
endif.
enddo.
endmethod. "dispatch
endclass. "lcl_processor IMPLEMENTATION</localImplementation>
<localTypes>*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section
class lcl_processor definition deferred.
class ZCL_PRC_ISOLATED_TASK definition local friends lcl_processor.</localTypes>
<localMacros>*"* use this source file for any macro definitions you need
*"* in the implementation part of the class</localMacros>
<attribute CLSNAME="ZCL_PRC_ISOLATED_TASK" CMPNAME="MR_RUNNABLE" VERSION="1" LANGU="E" DESCRIPT="Runnable Interface" EXPOSURE="2" STATE="1" EDITORDER="1 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="3" TYPE="ZIF_PRC_RUNNABLE" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_PRC_ISOLATED_TASK" CMPNAME="MV_DELAY" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="3 " ATTDECLTYP="0" ATTEXPVIRT="0" TYPTYPE="1" TYPE="STRING" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_PRC_ISOLATED_TASK" CMPNAME="MV_TIMEOUT" VERSION="1" LANGU="E" DESCRIPT="Timeout in seconds" EXPOSURE="0" STATE="1" EDITORDER="2 " ATTDECLTYP="0" ATTVALUE="299" ATTEXPVIRT="0" TYPTYPE="1" TYPE="I" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<method CLSNAME="ZCL_PRC_ISOLATED_TASK" CMPNAME="CONSTRUCTOR" VERSION="1" LANGU="E" DESCRIPT="CONSTRUCTOR" EXPOSURE="2" STATE="1" EDITORDER="1 " DISPID="0 " MTDTYPE="2" MTDDECLTYP="0" BCMTDCAT="00" BCMTDSYN="0">
<parameter CLSNAME="ZCL_PRC_ISOLATED_TASK" CMPNAME="CONSTRUCTOR" SCONAME="IR_RUNNABLE" VERSION="1" LANGU="E" DESCRIPT="Runnable Interface" CMPTYPE="1" MTDTYPE="2" EDITORDER="1 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="3" TYPE="ZIF_PRC_RUNNABLE"/>
<parameter CLSNAME="ZCL_PRC_ISOLATED_TASK" CMPNAME="CONSTRUCTOR" SCONAME="IV_DELAY" VERSION="1" LANGU="E" DESCRIPT="Seconds, yes as a char e.g. '2' or '0.2' dont ask" CMPTYPE="1" MTDTYPE="2" EDITORDER="2 " DISPID="0 " PARDECLTYP="0" PARPASSTYP="1" TYPTYPE="1" TYPE="STRING" PAROPTIONL="X"/>
<source>method constructor.
data: lv_p type p decimals 2.
lv_p = iv_delay.
if lv_p gt 45.
raise exception type zcx_prc_excessive_delay.
endif.
mr_runnable = ir_runnable.
mv_delay = iv_delay.
endmethod. "CONSTRUCTOR</source>
</method>
<method CLSNAME="ZCL_PRC_ISOLATED_TASK" CMPNAME="START" VERSION="1" LANGU="E" DESCRIPT="Start the process" EXPOSURE="2" STATE="1" EDITORDER="2 " DISPID="0 " MTDTYPE="0" MTDDECLTYP="0" MTDNEWEXC="X" BCMTDCAT="00" BCMTDSYN="0">
<exception CLSNAME="ZCL_PRC_ISOLATED_TASK" CMPNAME="START" SCONAME="ZCX_PRC_PROCESS_EXCEPTION" VERSION="1" LANGU="E" MTDTYPE="0" EDITORDER="1 "/>
<exception CLSNAME="ZCL_PRC_ISOLATED_TASK" CMPNAME="START" SCONAME="ZCX_PRC_WAIT_TIMOUT_EXCEPTION" VERSION="1" LANGU="E" MTDTYPE="0" EDITORDER="2 "/>
<source>method START.
data: lr_processor type ref to lcl_processor.
create object lr_processor
exporting
ir_process = me.
lr_processor->dispatch( ).
endmethod. "START</source>
</method>
</CLAS>
<CLAS CLSNAME="ZCX_PRC_SYSTEM_FAILURE" VERSION="1" LANGU="E" DESCRIPT="System Fail" CATEGORY="40" EXPOSURE="2" STATE="1" RELEASE="0" CLSFINAL="X" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 " REFCLSNAME="CX_STATIC_CHECK">
<localImplementation>*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations</localImplementation>
<localTypes>*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section</localTypes>
<localMacros>*"* use this source file for any macro definitions you need
*"* in the implementation part of the class</localMacros>
<inheritance CLSNAME="ZCX_PRC_SYSTEM_FAILURE" REFCLSNAME="CX_STATIC_CHECK" VERSION="1" STATE="1"/>
</CLAS>
<CLAS CLSNAME="ZCL_PRC_WP_MANAGER" VERSION="1" LANGU="E" DESCRIPT="Gets work process related details" CATEGORY="00" EXPOSURE="2" STATE="1" RELEASE="0" CLSFINAL="X" CLSCCINCL="X" FIXPT="X" UNICODE="X" CLSBCCAT="00" DURATION_TYPE="0 " RISK_LEVEL="0 ">
<localImplementation>*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations</localImplementation>
<localTypes>*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section</localTypes>
<localMacros>*"* use this source file for any macro definitions you need
*"* in the implementation part of the class</localMacros>
<attribute CLSNAME="ZCL_PRC_WP_MANAGER" CMPNAME="CO_DEFAULT_MAX" VERSION="1" LANGU="E" EXPOSURE="2" STATE="1" EDITORDER="1 " ATTDECLTYP="2" ATTVALUE="10" ATTEXPVIRT="0" TYPTYPE="1" TYPE="I" SRCROW1="0 " SRCCOLUMN1="0 " SRCROW2="0 " SRCCOLUMN2="0 " TYPESRC_LENG="0 "/>
<attribute CLSNAME="ZCL_PRC_WP_MANAGER" CMPNAME="MT_USERS" VERSION="1" LANGU="E" EXPOSURE="0" STATE="1" EDITORDER="1 " ATTDECLTYP="1" ATTEXPVIRT="0" TYPTYPE="4" SRCROW1="2 " SRCCOLUMN1="16 " SRCROW2="2 " SRCCOLUMN2="86 " TYPESRC_LENG="73 " TYPESRC="mt_users type hashed table of zprcc_wp_config with unique key user_name
"/>
<method CLSNAME="ZCL_PRC_WP_MANAGER" CMPNAME="CLASS_CONSTRUCTOR" VERSION="1" LANGU="E" DESCRIPT="CLASS_CONSTRUCTOR" EXPOSURE="2" STATE="1" EDITORDER="1 " DISPID="0 " MTDTYPE="2" MTDDECLTYP="1" BCMTDCAT="00" BCMTDSYN="0">
<source>method class_constructor.
select * from zprcc_wp_config into table mt_users.