[Home] [Help]
PACKAGE BODY: APPS.WF_ERROR_QH
Source
1 package body WF_ERROR_QH as
2 /* $Header: wferrqhb.pls 120.2 2006/02/16 05:49:22 nravindr ship $ */
3 ------------------------------------------------------------------------------
4 PROCEDURE dequeue(p_agent_guid in raw,
5 p_event out nocopy wf_event_t)
6 is
7 x_queue_name varchar2(80);
8 x_agent_name varchar2(30);
9 x_dequeue_options dbms_aq.dequeue_options_t;
10 x_message_properties dbms_aq.message_properties_t;
11 x_msgid RAW(16);
12 no_messages exception;
13 pragma exception_init (no_messages, -25228);
14
15 snap_too_old exception;
16 pragma exception_init(snap_too_old, -1555);
17 begin
18 select upper(queue_name), upper(name)
19 into x_queue_name, x_agent_name
20 from wf_agents
21 where guid = p_agent_guid;
22
23 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
24 wf_log_pkg.string(wf_log_pkg.level_procedure,
25 'wf.plsql.WF_ERROR_QH.dequeue.Begin',
26 'Dequeuing '||x_queue_name||' on '||x_agent_name);
27 end if;
28
29
30 -- Set correlation Id for dequeue if only available
31 if (wf_event.g_correlation is not null) then
32 -- Seeded agent with this queue handler
33 if (x_agent_name like 'WF_%') then
34 if (wf_event.account_name is null) then
35 wf_event.SetAccountName;
36 end if;
37 x_dequeue_options.correlation := wf_event.account_name || ':' || wf_event.g_correlation;
38 else
39 x_dequeue_options.correlation := wf_event.g_correlation;
40 end if;
41 end if;
42
43 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
44 if (wf_event.g_correlation is not null) then
45 wf_log_pkg.string(wf_log_pkg.level_procedure,
46 'wf.plsql.WF_ERROR_QH.dequeue.corrid',
47 'Dequeuing with Correlation ' || x_dequeue_options.correlation);
48 else
49 wf_log_pkg.string(wf_log_pkg.level_procedure,
50 'wf.plsql.WF_ERROR_QH.dequeue.corrid',
51 'Dequeuing with No Correlation');
52 end if;
53 end if;
54
55 x_dequeue_options.consumer_name := x_agent_name;
56 --x_dequeue_options.wait := DBMS_AQ.NO_WAIT;
57 x_dequeue_options.navigation := wf_event.navigation;
58 x_dequeue_options.wait := 1;
59 BEGIN
60 DBMS_AQ.DEQUEUE(queue_name => x_queue_name,
61 dequeue_options => x_dequeue_options,
62 message_properties => x_message_properties, /* OUT */
63 payload => p_event, /* OUT */
64 msgid => x_msgid); /* OUT */
65 wf_event.navigation := dbms_aq.next_message;
66 EXCEPTION
67 when no_messages then
68
69 if (wf_log_pkg.level_event >= fnd_log.g_current_runtime_level) then
70 wf_log_pkg.string(wf_log_pkg.level_event,
71 'wf.plsql.WF_ERROR_QH.dequeue.queue_empty',
72 'No more messages in dequeue.');
73 end if;
74
75 wf_event.navigation := dbms_aq.first_message;
76 p_event := NULL;
77 return;
78 --Capture the snapshot too old error
79 when snap_too_old then
80 --Workaround for AQ when receiving ORA-01555 using NEXT_MESSAGE as
81 --navigation. We will try to set to FIRST_MESSAGE and dequeue to
82 --silently handle this exception.
83 if (wf_event.navigation = dbms_aq.FIRST_MESSAGE) then
84 raise;
85 else
86 wf_event.navigation := dbms_aq.FIRST_MESSAGE;
87 x_dequeue_options.navigation := wf_event.navigation;
88 dbms_aq.dequeue(queue_name => x_queue_name,
89 dequeue_options => x_dequeue_options,
90 message_properties => x_message_properties, -- out
91 payload => p_event, -- out
92 msgid => x_msgid); -- out
93
94 --Set the navigation now to the next message
95 wf_event.navigation := dbms_aq.next_message;
96 end if;
97 when others then
98 wf_event.navigation := dbms_aq.FIRST_MESSAGE;
99 raise;
100 END;
101 exception
102 when others then
103 Wf_Core.Context('Wf_Error_QH', 'Dequeue', x_queue_name,
104 'SQL err is '||substr(sqlerrm,1,200));
105 raise;
106 end dequeue;
107 ------------------------------------------------------------------------------
108 -- Bug 5034154
109 -- Added as a wrapper over the existing dequeue
110 -- calls existing dequeue with two parameters ignoring p_wait
111 PROCEDURE dequeue(p_agent_guid in raw,
112 p_event out nocopy wf_event_t,
113 p_wait in binary_integer)
114 is
115 begin
116 dequeue(p_agent_guid, p_event);
117 end dequeue;
118 ------------------------------------------------------------------------------
119 PROCEDURE enqueue(p_event in wf_event_t,
120 p_out_agent_override in wf_agent_t )
121 is
122 x_out_agent_name varchar2(30);
123 x_out_system_name varchar2(30);
124 x_out_queue varchar2(80);
125 x_enqueue_options dbms_aq.enqueue_options_t;
126 x_message_properties dbms_aq.message_properties_t;
127 x_msgid RAW(16);
128 x_name varchar2(30);
129 x_address varchar2(1024);
130 x_protocol varchar2(30);
131 x_protocol_num number := 0;
132 begin
133
134 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
135 wf_log_pkg.string(wf_log_pkg.level_procedure,
136 'wf.plsql.WF_ERROR_QH.enqueue.Begin',
137 'Entered Enqueue ');
138 end if;
139
140 -- Determine the out queue --
141
142 x_out_agent_name := p_out_agent_override.GetName();
143 x_out_system_name := p_out_agent_override.GetSystem();
144
145 select agt.queue_name into x_out_queue
146 from wf_agents agt,
147 wf_systems sys
148 where agt.name = x_out_agent_name
149 and sys.name = x_out_system_name
150 and sys.guid = agt.system_guid;
151
152 if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
153 wf_log_pkg.string(wf_log_pkg.level_statement,
154 'wf.plsql.WF_ERROR_QH.enqueue.Enqueuing',
155 'Enqueuing on Queue: '||x_out_queue);
156 end if;
157
158 x_protocol_num := 0;
159 x_message_properties.recipient_list(1) := sys.aq$_agent(x_out_agent_name,
160 null,
161 x_protocol_num);
162
163 if (x_out_agent_name like 'WF_%') then
164 if wf_event.account_name is null then
165 wf_event.SetAccountName;
166 end if;
167 --<rwunderl:2867245>
168 --Append the event name to the correlation id
169 x_message_properties.correlation := wf_event.account_name||
170 ':'||p_event.event_name;
171 end if;
172
173 if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
174 wf_log_pkg.string(wf_log_pkg.level_statement,
175 'wf.plsql.WF_ERROR_QH.enqueue.dbms_qa',
176 'calling dbms_aq.enqueue');
177 end if;
178
179 DBMS_AQ.ENQUEUE(
180 queue_name => x_out_queue,
181 enqueue_options => x_enqueue_options,
182 message_properties => x_message_properties,
183 payload => p_event,
184 msgid => x_msgid); /* OUT*/
185
186 if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
187 wf_log_pkg.string(wf_log_pkg.level_statement,
188 'wf.plsql.WF_ERROR_QH.enqueue.done',
189 'finished calling dbms_aq.enqueue');
190 end if;
191
192 exception
193 when others then
194 Wf_Core.Context('Wf_Error_QH', 'Enqueue', x_out_queue
195 );
196 raise;
197 end enqueue;
198 ------------------------------------------------------------------------------
199 end WF_ERROR_QH;