Scalable program architecture
So far, we have only created programs that handle one call.
Now, we will create multi-threaded, multi-call
programs that can fully utilise the capabilities of the Diva adapters.
Multi-call programs
It is possible to create multi-call programs using the Component API with AsyncMode = True
(non-blocking mode) and SignalEvents = True using the same programming techniques we have used
for single-call programs. However, programs like this have limited practical scalability because you have to
code duplicate set of event handlers for each call object. This is the only way to create multi-call programs
in Visual Basic 6, principally because this environment does not provide sufficient support for
multi-threading applications.
Fully-scalable programs using Visual C# and Visual Basic 2005
Visual C# and Visual Basic 2005 do support multi-threading and
allow us to implement fully-scalable multi-call programs in a very convenient and
efficient way using a call-handler class, without mandating the use of non-blocking mode and events and
without having to create duplicate code for each call object.
The technique described here allows us to scale-up the blocking-mode programming techniques
demonstrated on the previous pages of this course to handle 100 or more calls, right up to the limits
imposed by the Diva adapters.
Before we start to describe how to create scalable programs,
there are several pre-requisite topics that we need to introduce or review:
-
Non-blocking (asynchronous) mode - what do we mean by 'blocking' and 'non-blocking'?
-
Events - how do events work in the Component API?
-
Creating more than one DivaCall using the DivaInstance method
CreateCall
-
Using
Listen
rather than
WaitForCall
to prepare DivaCall objects to receive a call
-
Listen is a non-blocking method and
returns immediately
- Listen must be used with
SignalEvents
= True
-
In Visual Basic, the DivaCall must be declared using the parameter 'WithEvents'
- An
OnIncomingCall
handler must be coded to handle the event that is raised when an incoming call is detected
-
Creating the 'call-handler' class
-
The InitializeCall method of the call-handler class is called by the main program to create
the DivaCall and start answering calls on an incoming call channel
-
The TerminateCall method of the call-handler class is called by the main program to 'shut down'
an incoming call channel
These topics are covered in detail on the following pages.