3.
Intro
Proactor?
Making things work
In detail...
Verdict
Dictionary deﬁnition
proactive
adjective
(of a person, policy or action) creating or controlling a situation by
causing something to happen rather than responding to it after it
has happened: be proactive in identifying and preventing potential
problems
Ant´nio Sousa
o The Proactor Pattern

4.
Intro
Proactor?
Making things work
In detail...
Verdict
My deﬁnition
proactor
pattern
allows an eﬃcient use of the asynchronous mechanisms provided
by operating systems in event-driven applications, by integrating
the demultiplexing of completion events and the dispatching of
their event handlers;
Ant´nio Sousa
o The Proactor Pattern

5.
Intro
Proactor?
Making things work
In detail...
Verdict
A little background
Asynchronous I/O
Operations run in the background and do not block user
applications (libaio, linux kernel 2.6, Windows NT)
Completion events
When an asynchronous I/O operation ﬁnishes a completion
event is generated saying that the operation is completed (or
not)
Event handlers
The application-speciﬁc component that processes the results
of the asynchronous operations
Ant´nio Sousa
o The Proactor Pattern

8.
Intro
Proactor?
Making things work
In detail...
Verdict
Participants
Completion event queue
Buﬀer where the asynchronous operation processor queues the
completion events associated with a speciﬁc handle
Completion Dispatcher (Proactor)
Makes use of the asynchronous event demultiplexer to dequeue
completion event and then dispatches them to the correspondent
hook method of the completion handler
Initiator
Any entity in the application that invokes an asynchronous
operation
Ant´nio Sousa
o The Proactor Pattern

19.
Intro
JAVA!
Making things work
Some code
Verdict
java.nio.*
Features
The NIO APIs include the following features:
Buﬀers for data of primitive types
Character-set encoders and decoders
A pattern-matching facility based on Perl-style regular
expressions
Channels, a new primitive I/O abstraction
A ﬁle interface that supports locks and memory mapping
A multiplexed, non-blocking I/O facility for writing scalable
servers
source: http://java.sun.com/j2se/1.4.2/docs/guide/nio/
Ant´nio Sousa
o The Proactor Pattern

20.
Intro
JAVA!
Making things work
Some code
Verdict
java.nio.*
Features
The NIO APIs include the following features:
Buﬀers for data of primitive types
Character-set encoders and decoders
A pattern-matching facility based on Perl-style regular
expressions
Channels, a new primitive I/O abstraction
A ﬁle interface that supports locks and memory mapping
A multiplexed, non-blocking I/O facility for writing scalable
servers
source: http://java.sun.com/j2se/1.4.2/docs/guide/nio/
Ant´nio Sousa
o The Proactor Pattern

21.
Intro
JAVA!
Making things work
Some code
Verdict
This sounds interesting!
java.nio.channels
Deﬁnes channels, which represent connections to entities that are
capable of performing I/O operations, such as ﬁles and sockets;
deﬁnes selectors, for multiplexed, non-blocking I/O operations.
SocketChannel Selector SelectionKey
A selectable A multiplexor of A token
channel for SelectableChan- representing the
stream-oriented nel registration of a
connecting objects. SelectableChan-
sockets. nel with a
Selector.
Ant´nio Sousa
o The Proactor Pattern

37.
Intro
Consequences
Making things work
Finale
Verdict
Related patterns
Asynchronous completion token
Usually used in conjunction with the Proactor pattern. For every
asynch op invoked, an ACT is created and returned to the caller
when the operation ﬁnishes
Observer
All dependents are updated automatically when a change occurs;
in the Proactor handlers are informed automatically when events
occur
Reactor
Considered an asynchronous version of the Reactor Pattern
Ant´nio Sousa
o The Proactor Pattern

38.
Intro
Consequences
Making things work
Finale
Verdict
Related patterns
Active Object
Decouples method execution from invocation; in Proactor Pattern
the asynchronous processor performs operation on behalf of the
initiators
Chain of Responsability
Decouples event handlers from event sources; initiators and
completion handlers in Proactor (although in CoR the source has
no knowledge about which handler will be executed)
Leader/Followers and Half-Sync/Half-Async
Demultiplex and process various types of events synchronously
Ant´nio Sousa
o The Proactor Pattern