Download DBMS_PIPE

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Intersession Communication
Oracle Database PL/SQL 10g Programming
Chapter 11
Intersession Communication



2006
Intersession Communication Definition
DBMS_PIPE Built-in Package
DBMS_ALERT Built-in Package
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 2
Intersession Communication
DBMS_PIPE

Interactive intersession communication is:





2006
The process of sending messages from one
open session in the database to another.
The process works by accessing a messaging
buffer, known as a pipe.
Pipes are FIFO (First-in and last-out) queues.
The pipes can be local, private, and public.
The process uses the DBMS_PIPE built-in
package to send and receive messages.
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 3
Intersession Communication
DBMS_PIPE: Local Buffer
Local Buffer
Write to
Local Buffer
2006
Read from
Local Buffer
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 4
Intersession Communication
DBMS_PIPE: Local Buffer Write
DECLARE
message
VARCHAR2(30);
success
INTEGER;
BEGIN
message := DBMS_PIPE.UNIQUE_SESSION_NAME;
DBMS_PIPE.RESET_BUFFER;
DBMS_PIPE.PACK_MESSAGE(message);
DBMS_OUTPUT.PUT_LINE('Message ['||message||'] ');
END;
/
2006
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 5
Intersession Communication
DBMS_PIPE: Local Buffer Read
DECLARE
message
VARCHAR2(30);
success
INTEGER;
BEGIN
DBMS_PIPE.UNPACK_MESSAGE(message);
DBMS_OUTPUT.PUT_LINE('Message ['||message||'] ');
END;
/
2006
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 6
Intersession Communication
DBMS_PIPE: SGA Named
Pipe
Named Pipe
2006
Local Buffer
Local Buffer
Write to
Local Buffer
Read from
Local Buffer
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 7
Intersession Communication
DBMS_PIPE: Create a Pipe
DECLARE
message_pipe
VARCHAR2(30) := 'PLSQL$MESSAGE_INBOX';
success_size
INTEGER
:= 2000;
retval
INTEGER;
'||message||'
BEGIN
retval := DBMS_PIPE.CREATE_PIPE();
IF (retval = 0) THEN
DBMS_OUTPUT.PUT_LINE('Message ['||message||'] ');
END IF;
END;
/
2006
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 8
Intersession Communication
DBMS_PIPE: Write to a Pipe
DECLARE
flag INTEGER;
BEGIN
DBMS_PIPE.PURGE('PLSQL$MESSAGE_INBOX');
DBMS_PIPE.PACK_MESSAGE('MESSAGE');
DBMS_PIPE.SEND_MESSAGE('PLSQL$MESSAGE_INBOX');
END;
/
2006
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 9
Intersession Communication
DBMS_PIPE: Read from a
Pipe
DECLARE
message VARCHAR2(4000);
flag INTEGER;
BEGIN
DBMS_PIPE.RESET_BUFFER;'||message||'
-- Force immediate read of pipe.
flag := DBMS_PIPE.RECEIVE_MESSAGE('PLSQL$MESSAGE_INBOX',0);
DBMS_PIPE.UNPACK_MESSAGE('MESSAGE');
DBMS_PIPE.SEND_MESSAGE('PLSQL$MESSAGE_INBOX');
END;
/
2006
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 10
Intersession Communication
DBMS_ALERT

Event-driven intersession communication is:




DBMS_ALERT built-in sends messages through a pipe:
The transaction-based DBMS_ALERT lets a database
trigger send an alert message to an implicit public
pipe.
DBMS_ALERT uses a publish-and-subscribe pattern
where multiple sessions can register interest in an
alert.
Subscribers, those who register:


2006
Wait on the event for a polling interval.
Read ONLY the last message received by the pipe because it
is a single element queue.
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 11
Intersession Communication
DBMS_ALERT: Publish on Event
CREATE OR REPLACE TRIGGER signal_message
AFTER INSERT
OF message_id, message
ON messages
'||message||'
FOR EACH ROW
BEGIN
IF :old.message_id IS NULL THEN
DBMS_ALERT.SIGNAL('EVENT_MESSAGE_QUEUE',:message);
END IF;
END;
/
2006
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 12
Intersession Communication
DBMS_ALERT: Subscribe
BEGIN
-- Subscribe to an alert event.
DBMS_ALERT.REGISTER('EVENT_MESSAGE_QUEUE');
END;
/
2006
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 13
Intersession Communication
DBMS_ALERT: Catch
DECLARE
message VARCHAR2(4000);
flag INTEGER;
BEGIN
'||message||'
DBMS_ALERT.WAITONE('EVENT_MESSAGE_QUEUE'
,message,status,30);
END;
/
2006
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 14
Summary





2006
Database Trigger Concepts
DDL Triggers
DML Triggers
Instead-of Triggers
System or Database Event Triggers
Oracle Database PL/SQL 10g Programming
(Chapter 11)
Page 15
Related documents