CS 342: Object-Oriented Software Development Lab An Introduction to ACE David L. Levine Christopher D. Gill Department of Computer Science Washington University, St. Louis levine,cdgill @cs.wustl.edu http://classes.cec.wustl.edu/ cs342/ CS 342: OO Software Development Lab OO Patterns Introduction to ACE What is ACE? – OO middleware framework that implements many core design patterns for concurrent communication software – Targeted for developers of high-performance and real-time communication services and applications – Simplifies and speeds development via reuse Why Use Frameworks? Why Use ACE? Why Use Communication Middleware? How do we use ACE? The ADAPTIVE Communication Environment (ACE) Sources for more information Copyright c 1997-2000 Dept. of Computer Science, Washington University 1 CS 342: OO Software Development Lab OO Patterns Why Use Frameworks? APPLICATION APPLICATION SPECIFIC SPECIFIC LOGIC LOGIC USER USER INTERFACE INTERFACE (A) CLASS LIBRARY ARCHITECTURE NETWORKING MATH ADTS DATA BASE MATH (B) FRAMEWORK ARCHITECTURE ADTS INVOKES INVOKES EVENT LOOP APPLICATION SPECIFIC LOGIC CALL BACKS NETWORKING USER INTERFACE DATABASE EVENT LOOP Proven solutions – Components Self-contained, ready-to-use ADTs – Frameworks Reusable, semi-complete applications – Patterns Problem/solution pairs in a context – Architecture Families of related patterns and components Copyright c 1997-2000 Dept. of Computer Science, Washington University 2 CS 342: OO Software Development Lab OO Patterns Why Use ACE? Good example of a framework Provides many implementations of patterns Open-source It’s taking over the world ;-) Copyright c 1997-2000 Dept. of Computer Science, Washington University 3
14
Embed
CS 342: Object-Oriented Software Development Lab An ...levine/courses/cs342/patterns/ACE-intro_4.pdf · An Introduction to ACE ... CS 342: OO Software Development Lab OO Patterns
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
CS 342: Object-Oriented Software Development Lab
An Introduction to ACE
David L. LevineChristopher D. Gill
Department of Computer ScienceWashington University, St. Louis
woes– Mechanisms do not scale ! Win32 TLS– Steep learning curve ! Win32 Named Pipes– Non-portable ! socket bugs– Inefficient ! i.e., tedious for humans
� GUI frameworks are inadequate for communication software
– Inefficient ! excessive use of virtual methods– Lack of features ! minimal threading and synchronization
mechanisms, no network services
Copyright c 1997-2000 Dept. of Computer Science, Washington University 4
CS 342: OO Software Development Lab OO Patterns
How Do We Use ACE?
� The Makefile takes care of most details, with two exceptions:– You must use GNU gmake instead of Sun make with this Makefile.– In order to run your ACE application, you must set your
LD_LIBRARY_PATHenvironment variable to find the ACE library– For Sun CC:% pkgadd sc% setenv LD_LIBRARY_PATH \
˜/ACE_wrappers/build/SunOS5_sunc++:$LD_LIBRARY_PATH% make
– For egcs:% pkgadd egcs% setenv LD_LIBRARY_PATH \
˜/ACE_wrappers/build/SunOS5_egcs:$LD_LIBRARY_PATH% make egcs=1
Copyright c 1997-2000 Dept. of Computer Science, Washington University 5
CS 342: OO Software Development Lab OO Patterns
The ADAPTIVE Communication Environment (ACE)
PROCESSES//THREADSTHREADS
DYNAMICDYNAMIC
LINKINGLINKING
MEMORYMEMORY
MAPPINGMAPPING
SELECTSELECT//IO COMPIO COMP
SYSTEMSYSTEM
VV IPCIPCSTREAMSTREAM
PIPESPIPES
NAMEDNAMED
PIPESPIPES
CAPISS
SOCKETSSOCKETS//TLITLI
COMMUNICATIONCOMMUNICATION
SUBSYSTEMSUBSYSTEM
VIRTUAL MEMORYVIRTUAL MEMORY
SUBSYSTEMSUBSYSTEM
GENERAL POSIX AND WIN32 SERVICES
PROCESSPROCESS//THREADTHREAD
SUBSYSTEMSUBSYSTEM
FRAMEWORKS ACCEPTORACCEPTOR CONNECTORCONNECTOR
SELF-CONTAINED
DISTRIBUTED
SERVICE
COMPONENTS
NAMENAME
SERVERSERVER
TOKENTOKEN
SERVERSERVER
LOGGINGLOGGING
SERVERSERVER
GATEWAYGATEWAY
SERVERSERVER
SOCKSOCK__SAPSAP//TLITLI__SAPSAP
FIFOFIFO
SAPSAP
LOGLOG
MSGMSG
SERVICESERVICE
HANDLERHANDLER
TIMETIME
SERVERSERVER
C++WRAPPER
FACADES
SPIPESPIPE
SAPSAP
CORBACORBA
HANDLERHANDLER
SYSVSYSVWRAPPERSWRAPPERS
SHAREDSHARED
MALLOCMALLOC
THE ACE ORBTHE ACE ORB
((TAOTAO))
JAWS ADAPTIVEJAWS ADAPTIVE
WEB SERVERWEB SERVER
MIDDLEWARE
APPLICATIONS
REACTORREACTOR//PROACTORPROACTOR
PROCESSPROCESS//THREADTHREAD
MANAGERSMANAGERS
STREAMSSTREAMS
SERVICESERVICE
CONFIGCONFIG--URATORURATOR
SYNCHSYNCH
WRAPPERSWRAPPERS
MEMMEM
MAPMAP
OS ADAPTATION LAYER
http://www.cs.wustl.edu/�schmidt/ACE.html
� ACE Overview
– A concurrent OOnetworkingframework
– Available in C++and Java
– Ported toVxWorks, POSIX,and Win32
� Related work
– x-Kernel– SysV STREAMS
Copyright c 1997-2000 Dept. of Computer Science, Washington University 6
� The adjacentcode containsmany subtle,common bugs
Copyright c 1997-2000 Dept. of Computer Science, Washington University 15
CS 342: OO Software Development Lab OO Patterns
Problem with Sockets: Steep Learning Curve
Many socket/TLI API functions have complex semantics, e.g.:
� Multiple protocol families and address families
– e.g., TCP, UNIX domain, OSI, XNS, etc.
� Infrequently used features, e.g.:
– Broadcasting/multicasting– Passing open file handles– Urgent data delivery and reception– Asynch I/O, non-blocking I/O, I/O-based and timer-based event
multiplexing
Copyright c 1997-2000 Dept. of Computer Science, Washington University 16
CS 342: OO Software Development Lab OO Patterns
Problem with Sockets: Poorly Structured
sock
et()
bin
d()
con
nec
t()
list
en()
acce
pt(
)re
ad()
wri
te()
read
v()
wri
tev()
recv
()se
nd
()re
cvfr
om
()se
nd
to()
recv
msg
()se
ndm
sg()
sets
ock
op
t()
get
sock
opt(
)get
pee
rnam
e()
get
sock
nam
e()
get
host
bynam
e()
get
serv
bynam
e()
� Limitations
– Socket API is linear rather than hierarchical– There is no consistency among names...– Non-portable
Copyright c 1997-2000 Dept. of Computer Science, Washington University 17
CS 342: OO Software Development Lab OO Patterns
Problem with Sockets: Portability
� Having multiple “standards,” i.e., sockets and TLI, makes portabilitydifficult, e.g.,
– May require conditional compilation– In addition, related functions are not included in POSIX standards
� e.g., select , WaitForMultipleObjects , and poll
� Portability between UNIX and Win32 Sockets is problematic, e.g.:
– Header files– Error numbers– Handle vs. descriptor types– Shutdown semantics– I/O controls and socket options
Copyright c 1997-2000 Dept. of Computer Science, Washington University 18
CS 342: OO Software Development Lab OO Patterns
The ACE C++ IPC Wrapper Solution
IPC_SAP
A
SOCK_SAP TLI_SAP FIFO_SAPSPIPE_SAP
SOCKET
API
TRANSPORT
LAYER
INTERFACE API
STREAM PIPE
API
NAMED PIPE
API
� ACE provides C++ “wrapper facades” that encapsulate IPCprogramming interfaces like sockets and TLI
– This is an example of the Wrapper Facade Pattern
Copyright c 1997-2000 Dept. of Computer Science, Washington University 19
CS 342: OO Software Development Lab OO Patterns
Intent and Structure of the Wrapper Facade Pattern
1: method_k()
2: function_k()
clientclient
FunctionsFunctions
function_1()...function_n()
WrapperWrapperFacadeFacade
method_1()...method_m()
� Intent
– Encapsulates low-level,stand-alone systemmechanisms withintype-safe, modular, andportable class interfaces
// Local address of server (note use of traits).ACCEPTOR::PEER_ADDR my_addr (port);// Initialize the passive mode server.ACCEPTOR acceptor (my_addr);// Data transfer object (note use of traits).ACCEPTOR::PEER_STREAM stream;// Accept a new connection.acceptor.accept (stream);
for (;;) {char buf[BUFSIZ];ssize_t n = stream.recv (buf, sizeof buf);stream.send_n (buf, n);
}}
Copyright c 1997-2000 Dept. of Computer Science, Washington University 26
CS 342: OO Software Development Lab OO Patterns
Socket vs. ACE C++ Socket Wrapper Example� The following slides illustrate differences between using the Socket
interface vs. the ACE C++ Socket wrappers
� The example is a simple client/server “network pipe” application thatbehaves as follows:
1. Starts an iterative daemon at a well-known server port2. Client connects to the server and transmits its standard input to
the server3. The server prints this data to its standard output
� The server portion of the “network pipe” application may actually runeither locally or remotely...
Copyright c 1997-2000 Dept. of Computer Science, Washington University 27
CS 342: OO Software Development Lab OO Patterns
Network Pipe with Sockets
SERVERSERVERCLIENTCLIENT
socket()bind() (optional)
connect()
send()/recv()
socket()bind()listen()accept()
send()/recv()
2: ACTIVE
ROLE
3: SERVICE
PROCESSINGclose()
close()
NETWORK
1: PASSIVE
ROLE
Copyright c 1997-2000 Dept. of Computer Science, Washington University 28
CS 342: OO Software Development Lab OO Patterns
Network Pipe with ACE C++ Socket Wrappers
SERVERSERVERCLIENTCLIENT
SOCK_ConnectorSOCK_Stream
send()/recv()
SOCK_AcceptorSOCK_Stream
send()/recv()
2: ACTIVE
ROLE
3: SERVICE
PROCESSINGclose()
close()
NETWORK
1: PASSIVE
ROLE
Copyright c 1997-2000 Dept. of Computer Science, Washington University 29
}// Close new endpoint (listening// endpoint stays open).new_stream.close ();
}
Copyright c 1997-2000 Dept. of Computer Science, Washington University
CS
342:O
OS
oftware
Developm
entLabO
OP
atterns
AC
EC
++W
rapperD
esignP
rinciples�
Enforce
typesafetyatcom
pile-time
�
Allow
controlledviolations
oftypesafety
�
Sim
plifyfor
thecom
mon
case
�
Replace
one-dimensionalinterfaces
with
hierarchicalclasscategories
�
Enhance
portabilityw
ithparam
eterizedtypes
�
Inlineperform
ancecriticalm
ethods
�
Define
auxiliaryclasses
tohide
error-pronedetails
Copyright
c
1997-2000D
ept.ofC
omputer
Science,W
ashingtonU
niversity39
CS 342: OO Software Development Lab OO Patterns
Enforce Typesafety at Compile-Time
Sockets cannot detect certain errors at compile-time, e.g.,
int s_sd = socket (PF_INET, SOCK_STREAM, 0);// ...bind (s_sd, ...); // Bind address.listen (s_sd); // Make a passive-mode socket.
// Error not detected until run-time.read (s_sd, buf, sizeof buf);
ACE enforces type-safety at compile-time via factories, e.g.:
SOCK_Acceptor acceptor (port);
// Error: recv() not a method of SOCK_Acceptor.acceptor.recv (buf, sizeof buf);
Copyright c 1997-2000 Dept. of Computer Science, Washington University 40
CS 342: OO Software Development Lab OO Patterns
Allow Controlled Violations of Typesafety
Make it easy to use the C++ Socket wrappers correctly, hard to use itincorrectly, but not impossible to use it in ways the class designers didnot anticipate
� e.g., it may be necessary to retrieve the underlying socket handle: