|
| 1 | +create or replace package body ut_output_pipe_helper is |
| 2 | + |
| 3 | + |
| 4 | + type t_pipe_buffer is table of varchar2(4000); |
| 5 | + type t_outputs_buffer is table of t_pipe_buffer index by varchar2(128); |
| 6 | + |
| 7 | + g_outputs_buffer t_outputs_buffer; |
| 8 | + |
| 9 | + procedure send_from_buffer(a_output_id varchar2) is |
| 10 | + l_timeout_occured boolean; |
| 11 | + i integer; |
| 12 | + begin |
| 13 | + if g_outputs_buffer.exists(a_output_id) then |
| 14 | + i := g_outputs_buffer(a_output_id).first; |
| 15 | + while i is not null loop |
| 16 | + dbms_pipe.pack_message( g_outputs_buffer(a_output_id)(i) ); |
| 17 | + l_timeout_occured := dbms_pipe.send_message(a_output_id, 0) != 0; |
| 18 | + if l_timeout_occured then |
| 19 | + dbms_pipe.reset_buffer; |
| 20 | + return; |
| 21 | + end if; |
| 22 | + end loop; |
| 23 | + end if; |
| 24 | + end; |
| 25 | + |
| 26 | + --sends a message to a named pipe |
| 27 | + --and if sending fails it writes the message to the end of the buffer for pipe |
| 28 | + procedure send(a_output_id varchar2, a_text varchar2) is |
| 29 | + l_timeout_occured boolean; |
| 30 | + begin |
| 31 | + send_from_buffer(a_output_id); |
| 32 | + dbms_pipe.pack_message( a_text ); |
| 33 | + l_timeout_occured := dbms_pipe.send_message(a_output_id, 0) != 0; |
| 34 | + if l_timeout_occured then |
| 35 | + dbms_pipe.reset_buffer; |
| 36 | + buffer(a_output_id, a_text); |
| 37 | + end if; |
| 38 | + end; |
| 39 | + |
| 40 | + --writes the message to the end of the buffer for pipe |
| 41 | + procedure buffer(a_output_id varchar2, a_text varchar2) is |
| 42 | + begin |
| 43 | + if not g_outputs_buffer.exists(a_output_id) then |
| 44 | + g_outputs_buffer(a_output_id) := t_pipe_buffer(); |
| 45 | + end if; |
| 46 | + g_outputs_buffer(a_output_id).extend; |
| 47 | + g_outputs_buffer(a_output_id)(g_outputs_buffer(a_output_id).last) := a_text; |
| 48 | + end; |
| 49 | + |
| 50 | + --registers a close request and tries to close a pipe |
| 51 | + --by first sending out all messages remaining in the buffers |
| 52 | + --the procedure holds infomrmation about closure requests |
| 53 | + --so that if close is not possble as buffer was not yet flusehd |
| 54 | + --it will proceed to other close requests |
| 55 | + --scenario with failure: |
| 56 | + -- two buffers used: output_1, output_2 |
| 57 | + -- call is made to close output_1 |
| 58 | + -- register the close request |
| 59 | + -- send all messaged from output_1 buffer |
| 60 | + -- if buffer not empty and timeout |
| 61 | + -- go to output_2 |
| 62 | + -- if output_2 is still open, return |
| 63 | + -- so the outout_1 close request is in a pending state |
| 64 | + -- next a call should be made from framework to close output_2 |
| 65 | + -- register the close request |
| 66 | + -- send all messaged from output_2 buffer |
| 67 | + -- if buffer not empty and timeout |
| 68 | + -- go to output_1 |
| 69 | + -- if output_1 has a pending close |
| 70 | + -- try to send from output_1 buffer |
| 71 | + -- if timeout -> raise |
| 72 | + --scenario with success: |
| 73 | + -- two buffers used: output_1, output_2 |
| 74 | + procedure request_close(a_output_id varchar2, a_text varchar2) is |
| 75 | + begin |
| 76 | + null; |
| 77 | + end; |
| 78 | + |
| 79 | +end; |
| 80 | +/ |
0 commit comments