DBA Data[Home] [Help]

PACKAGE BODY: APPS.FNDCP_TMSRV

Source


1 package body FNDCP_TMSRV as
2 /* $Header: AFCPTMSB.pls 120.5 2005/09/17 02:07:04 pferguso ship $ */
3 
4 
5 --
6 -- Private variables
7 --
8 P_CONC_QUEUE_ID   number := null;
9 P_REQUEST_ID      number := 0;
10 P_TRANSPORT_TYPE  varchar2(240) := 'QUEUE';
11 
12 
13 --
14 --   debug_info
15 -- Purpose
16 --   If the debug flag is set, then write to
17 --   the debug table.
18 -- Arguments
19 --   IN:
20 --    function_name - Name of the calling function
21 --    action_name   - Name of the current action being logged
22 --    message_text  - Any relevent info.
23 --    s_type        - Source Type ('C'- Client Send, 'M' - Manager Receive
24 --                                  'S' - Server Send, 'U' - Client Receive)
25 -- Notes
26 --   none.
27 --
28 procedure debug_info(function_name in varchar2,
29                      action_name   in varchar2,
30                      message_text  in varchar2,
31                      s_type        in varchar2 default 'M') is
32 
33 PRAGMA AUTONOMOUS_TRANSACTION;
34 begin
35 
36        insert into fnd_concurrent_debug_info
37         (
38           session_id, user_id, login_id,
39           time, function, action, message,
40           resp_appl_id, responsibility_id,
41           security_group_id, transaction_id,
42           concurrent_queue_id, time_in_number,
43           source_type
44         )
45       select
46           userenv('SESSIONID'), fnd_global.user_id, fnd_global.login_id,
47           sysdate, function_name, action_name, substr(message_text, 1, 480),
48           fnd_global.resp_appl_id, fnd_global.resp_id,
49           fnd_global.security_group_id, P_REQUEST_ID, P_CONC_QUEUE_ID,
50           dbms_utility.get_time, s_type
51         from sys.dual;
52 
53       commit;
54 end;
55 
56 
57 --
58 -- Returns the oracle id, oracle username and the encrypted password
59 -- for the TM (qapid, qid) to connect.
60 --
61 
62 procedure get_oracle_account (e_code in out nocopy number,
63                   qapid  in     number,
64                   qid    in     number,
65                   oid    in out nocopy number,
66                   ouname in out nocopy varchar2,
67                   opass  in out nocopy varchar2) is
68 
69 begin
70   e_code := E_SUCCESS;
71 
72   select fou.oracle_id,
73      fou.oracle_username,
74      fou.encrypted_oracle_password
75     into oid,
76      ouname,
77      opass
78     from fnd_oracle_userid fou,
79      fnd_data_group_units fdu,
80      fnd_concurrent_queues fcq
81    where fcq.application_id = qapid
82      and fcq.concurrent_queue_id = qid
83      and fcq.processor_application_id = fdu.application_id
84      and fcq.data_group_id = fdu.data_group_id
85      and fdu.oracle_id = fou.oracle_id;
86 
87 exception
88   when no_data_found then
89     e_code := E_OTHER;
90     fnd_message.set_name ('FND', 'CONC-Failed to get oracle name');
91   when others then
92     e_code := E_OTHER;
93     fnd_message.set_name ('FND', 'CP-Generic oracle error');
94     fnd_message.set_token ('ERROR', substr (sqlerrm, 1, 30), FALSE);
95     fnd_message.set_token ('ROUTINE', 'get_oracle_account', FALSE);
96 end get_oracle_account;
97 
98 
99 
100 procedure initialize (e_code in out nocopy number,
101                       qid    in     number,
102                       pid    in     number) is
103 begin
104 
105 
106   P_CONC_QUEUE_ID := qid;
107   for counter in 1..20 loop
108      P_RETURN_VALS(counter) := null;
109   end loop;
110 
111   FND_PROFILE.GET('CONC_TM_TRANSPORT_TYPE', P_TRANSPORT_TYPE);
112   if P_TRANSPORT_TYPE is null then
113      P_TRANSPORT_TYPE := 'QUEUE';
114   end if;
115 
116   if P_TRANSPORT_TYPE = 'PIPE' then
117      fnd_cp_tmsrv_pipe.initialize(e_code, qid, pid);
118   else
119      fnd_cp_tmsrv_queue.initialize(e_code, qid, pid);
120   end if;
121 
122 end initialize;
123 
124 
125 procedure read_message(e_code  in out nocopy number,
126                    timeout in     number,
127                    pktyp   in out nocopy varchar2,
128                    enddate in out nocopy varchar2,
129                    reqid   in out nocopy number,
130                    return_id in out nocopy varchar2,
131                    nlslang in out nocopy varchar2,
132                    nls_num_chars in out nocopy varchar2,
133                    nls_date_lang in out nocopy varchar2,
134                    secgrpid in out nocopy number,
135                    usrid   in out nocopy number,
136                    rspapid in out nocopy number,
137                    rspid   in out nocopy number,
138                    logid   in out nocopy number,
139                    apsname in out nocopy varchar2,
140                    program in out nocopy varchar2,
141                    numargs in out nocopy number,
142                    org_type in out nocopy varchar2,
143                    org_id  in out nocopy number,
144                    arg_1   in out nocopy varchar2,
145                    arg_2   in out nocopy varchar2,
146                    arg_3   in out nocopy varchar2,
147                    arg_4   in out nocopy varchar2,
148                    arg_5   in out nocopy varchar2,
149                    arg_6   in out nocopy varchar2,
150                    arg_7   in out nocopy varchar2,
151                    arg_8   in out nocopy varchar2,
152                    arg_9   in out nocopy varchar2,
153                    arg_10  in out nocopy varchar2,
154                    arg_11  in out nocopy varchar2,
155                    arg_12  in out nocopy varchar2,
156                    arg_13  in out nocopy varchar2,
157                    arg_14  in out nocopy varchar2,
158                    arg_15  in out nocopy varchar2,
159                    arg_16  in out nocopy varchar2,
160                    arg_17  in out nocopy varchar2,
161                    arg_18  in out nocopy varchar2,
162                    arg_19  in out nocopy varchar2,
163                    arg_20  in out nocopy varchar2) is
164 begin
165 
166    if P_TRANSPORT_TYPE = 'PIPE' then
167       fnd_cp_tmsrv_pipe.read_message(e_code, timeout, pktyp, enddate,
168                                      reqid, return_id, nlslang, nls_num_chars,
169                                      nls_date_lang, secgrpid, usrid, rspapid,
170                                      rspid, logid, apsname, program,
171                                      numargs, org_type, org_id,
172                                      arg_1, arg_2, arg_3, arg_4,
173                                      arg_5, arg_6, arg_7, arg_8,
174                                      arg_9, arg_10, arg_11, arg_12,
175                                      arg_13, arg_14,  arg_15,  arg_16,
176                                      arg_17, arg_18, arg_19, arg_20);
177 
178    else
179       fnd_cp_tmsrv_queue.read_message(e_code, timeout, pktyp, enddate,
180                                      reqid, return_id, nlslang, nls_num_chars,
181                                      nls_date_lang, secgrpid, usrid, rspapid,
182                                      rspid, logid, apsname, program,
183                                      numargs, org_type, org_id,
184                                      arg_1, arg_2, arg_3, arg_4,
185                                      arg_5, arg_6, arg_7, arg_8,
186                                      arg_9, arg_10, arg_11, arg_12,
187                                      arg_13, arg_14,  arg_15,  arg_16,
188                                      arg_17, arg_18, arg_19, arg_20);
189 
190    end if;
191 
192    -- Save the current transaction id
193    if e_code = E_SUCCESS then
194      P_REQUEST_ID := reqid;
195    end if;
196 
197 end read_message;
198 
199 
200 
201 procedure write_message (e_code  in out nocopy number,
202                          return_id  in     varchar2,
203                          pktyp      in     varchar2,
204                          reqid      in     number,
205                          outcome    in     varchar2,
206                          message    in     varchar2) is
207 
208 begin
209 
210 
211    if P_TRANSPORT_TYPE = 'PIPE' then
212       fnd_cp_tmsrv_pipe.write_message(e_code, return_id, pktyp, reqid, outcome, message);
213    else
214       fnd_cp_tmsrv_queue.write_message(e_code, return_id, pktyp, reqid, outcome, message);
215    end if;
216 
217 end write_message;
218 
219 
220 
221 --
222 -- This routine is called from a transaction program to put a return
223 -- to be sent back to the client.  This can be called at most, MAXVALS
224 -- times ane the values are stored in a table and written to the queue
225 -- when the TP completes.
226 --
227 
228 procedure put_value (e_code in out nocopy number,
229                      retval in     varchar2) is
230 
231 begin
232   e_code := E_SUCCESS;
233 
234   -- Make sure put_values is called at most MAXVALS times
235   if (P_RETVALCOUNT >= MAXVALS) then
236     e_code := E_MAXVALS;
237     return;
238   end if;
239 
240   P_RETVALCOUNT := P_RETVALCOUNT + 1;
241   P_RETURN_VALS (P_RETVALCOUNT) := retval;
242 
243   if ( P_DEBUG <> DBG_OFF ) then
244      debug_info('FNDCP_TMSRV.put_value',
245                 'Set return entry #' || to_char(P_RETVALCOUNT),
246                 retval, 'M');
247 
248   end if;
249 
250 
251   return;
252 end put_value;
253 
254 
255 
256 --
257 -- Monitor self (TM) to see if need to exit.
258 -- Exit if max procs is 0 or less than running, or current node is
259 -- different from the target when target is not null (PCP).
260 -- Read in sleep seconds and manager debug flag a new.
261 --
262 
263 procedure monitor_self (e_code in out nocopy number,
264             qapid  in     number,
265             qid    in     number,
266             cnode  in     varchar2,
267             slpsec in out nocopy number,
268             mgrdbg in out nocopy varchar2) is
269 
270   max_procs    number;
271   run_procs    number;
272   tnode        varchar2(30);    -- Target node
273 
274  begin
275   e_code := E_SUCCESS;
276 
277   select max_processes,
278      running_processes,
279      target_node,
280      sleep_seconds,
281      diagnostic_level
282     into max_procs,
283      run_procs,
284      tnode,
285      slpsec,
286      mgrdbg
287     from fnd_concurrent_queues
288    where application_id = qapid
289      and concurrent_queue_id = qid;
290 
291   if ((max_procs = 0) or
292       (max_procs < run_procs) or            -- Deactivate
293       ((tnode is not null) and (cnode <> tnode))) then    -- Migrate
294     e_code := E_EXIT;                    -- Exit
295   end if;
296 
297   exception
298     when others then
299       e_code := E_OTHER;
300       fnd_message.set_name ('FND', 'CP-Generic oracle error');
301       fnd_message.set_token ('ERROR', substr (sqlerrm, 1, 30), FALSE);
302       fnd_message.set_token ('ROUTINE', 'monitor_self', FALSE);
303 end monitor_self;
304 
305 
306 --
307 -- Use this routine to stop a TM when it's running online.
308 --
309 procedure stop_tm (qid in number) is
310 begin
311   null;
312 end stop_tm;
313 
314 
315 --
316 -- Not used.
317 --
318 procedure debug (dbg_level in number) is
319 begin
320   P_DEBUG := dbg_level;
321 end;
322 
323 
324 --
325 -- Not used.
326 --
327 function debug return number is
328 begin
329   return P_DEBUG;
330 end;
331 
332 
333 
334 
335 --
336 -- Monitor self (TM) to see if need to exit.
337 -- Exit if max procs is 0 or less than running, or current node is
338 -- different from the target when target is not null (PCP).
339 -- Read in sleep seconds and manager debug flag a new.
340 -- This version also check the process status
341 
342 procedure monitor_self2 (e_code in out nocopy number,
343                         qapid  in     number,
344                         qid    in     number,
345                         cnode  in     varchar2,
346                         slpsec in out nocopy number,
347                         mgrdbg in out nocopy varchar2,
348                         procid in     number) is
349 
350 scode varchar2(1);
351 
352 begin
353 
354     monitor_self(e_code, qapid, qid, cnode, slpsec, mgrdbg);
355 
356     begin
357       if (e_code = E_SUCCESS) then
358         select PROCESS_STATUS_CODE
359          into scode
360          from fnd_concurrent_processes
361          where CONCURRENT_PROCESS_ID = procid;
362 
363         if scode = 'D' then
364           e_code := E_EXIT;
365         end if;
366       end if;
367 
368     exception when others then null;
369     end;
370 
371 end;
372 
373 
374 end FNDCP_TMSRV;