BLADE Tutorial
Overview
The API for BLADE consists of the following two classes:
- The Blade class encapsulates an instance of the broker. An
instance of BLADE is created simply by instantiating this class. The only
public method exported by Blade is Start. This method is invoked
to get the broker instance running.
- The BladeParams class is used to pass customization options
to the constructor of Blade. Each data member of this class corresponds to
an option for the broker. The data members can be modified by public methods
of the class.
Example
The following program shows how a broker can be started so that it listens
to port 9999 and sends notifications:
#include
"Blade.h"
int
main()
{
//set the parameters to blade
BladeParams params;
params.SetPort(9999);
params.SetNotify(true);
//create the blade object
Blade *blade = new Blade(params);
//start the broker
blade->Start();
//even though the call to Start returns, the components
//of the broker are executing in separate threads. the broker
//can only keep going if we do not terminate here.
while(true) {}
return 0;
}
Notice that the program includes the header file Blade.h where
the two classes are declared. If we save this program to a file blade.cpp
then we can compile it on Linux as follows:
$ g++
-DBLADE_OS_LINUX blade.cpp -lblade -lspear -pthread
Obviously the blade and spear libraries must be in the same
directory as blade.cpp or appropriate command line options must be
passed to g++ so that the linker can find these libraries. On Windows we
can do the compilation as follows
:
$ cl
-DBLADE_OS_WIN32 blade.cpp libblade.lib libspear.lib -link -NODEFAULTLIB:LIBC.lib
Once again we have assumed that the libraries are in the current directory.
Otherwise appropriate linker options must be supplied.
BLADE Query Language
The query language supported
by BLADE is like a boolean fragment of XQL. Its grammar is given by
the following BNF:
query
:= atomic_query
| '(' query ')'
| '$not$' atomic_query
| atomic_query '$and$' atomic_query
| atomic_query '$or$' atomic_query
atomic_query
:= var int_rel_op int_const
| var dbl_rel_op dbl_const
| var str_rel_op str_const
var := a collection of characters not beginning with a single
or double quote, '$', digit, '=', '<', '>', '!', '+', '-', '.', '(',
')' or whitespace and not containing a single or double quote, '$', '=',
'<', '>', '!', '+', '-', '.', '(', ')' or whitespace.
int_rel_op := '=' | '!=' | '<' | '<=' | '>' |
'>=' | '$eq$' | '$ne$' | '$lt$' | '$le$' | '$gt$' | '$ge$'
dbl_rel_op := '=' | '!=' | '<' | '<=' | '>' |
'>=' | '$eq$' | '$ne$' | '$lt$' | '$le$' | '$gt$' | '$ge$'
str_rel_op := '=' | '!=' | '$eq$' | '$ne$' | '$supstr$' | '$substr$'
| '$prefix$' | '$suffix$' | '$starts$' | '$ends$'
int_const := a standard integer constant.
dbl_const := a standard double constant. exponential notation,
e.g. 5e-10, 0.7E+2 etc. is allowed.
str_const := a sequence of characters delimited by single or
double quotes e.g. 'foo', "bar". single and double quotes appearing in
the constant must be escaped with a backslash.
Most of the relational operators
have the usual meaning. The string operators $supstr$, $substr$, $prefix$,
$suffix$, $starts$ and $ends$ have the following connotations:
- (X $supstr$ Y) iff X is a superstring
of Y.
- (X $substr$ Y) iff X is a substring
of Y.
- (X $prefix$ Y) iff X is a
prefix of Y.
- (X $suffix$ Y) iff X is a suffix
of Y.
- (X $starts$ Y) iff X begins with
Y.
- (X $ends$ Y) iff X ends with Y.
API of BladeParams class
We now document the public methods of the BladeParams
class. First we describe the modifier methods.
Modifier methods
- void SetMatchSem(const string m) -
This sets the matching semantics of the broker. Currently the only semantics
supported is the default semantics described in our
paper
. So the only argument accepted by this method is "default". Since
the broker supports only one matching semantics this method has no utility
at present. It is kept for future use when the broker would be capable
of supporting multiple matching semantics.
- void SetDefaultInt(const int d) -
This sets the default value of integer attributes used by the broker. The
default value is needed by the default matching semantics used by
the broker. Normally the broker uses a default integer value of 10.
- void SetDefaultDbl(const double d)
- This sets the default value of double attributes used by the broker.
The default value is needed by the default matching semantics used
by the broker. Normally the broker uses a default double value of 10.0.
- void SetDefaultStr(const string d)
- This sets the default value of string attributes used by the broker.
The default value is needed by the default matching semantics used
by the broker. Normally the broker uses a default string value of "default".
- void SetSubUpdateInterval(const int s)
- This sets the number of seconds between successive subscription updates
by the broker. The default value is 15.
- void SetMinSubUpdate(const int m)
- This sets the minimum number of pending subscriptions that must be present
for the broker to do a subscription update. The default value is 0.
- void SetMinUnsubUpdate(const int m)
- This sets the minimum number of pending subscriptions that must be present
for the broker to do a subscription update. The default value is 0.
- void SetNotify(const bool n) - This
sets the flag that controls notification generation by the broker. The broker
generates notifications iff the flag is true. The default value is
false.
- void SetPort(const unsigned short p)
- This sets the port at which the broker accepts client connections. The
default value is 0.
- void SetBacklog(const int b) - This
sets the backlog on the server socket opened by the broker. The default
value is 10.
- void SetMaxPubQLen(const int m) -
This sets the capacity of the publication queue. The default value is
10,000.
- void SetMaxSubQLen(const int m) -
This sets the capacity of the subscription queue. The default value is
250,000.
- void SetMaxUnsubQLen(const int m)
- This sets the capacity of the unsubscription queue. The default value
is 200.
- void SetMaxNotQLen(const int m) -
This sets the capacity of the main notification queue. The default value
is 500.
- void SetMaxNotTQLen(const int m) -
This sets the capacity of the queues of the worker notification threads.
The default value is 100.
- void SetCurrSubFile(const string s)
- This sets the name of the file used to store the set of current subscriptions.
Actually two files are used to attain a degree of fault tolerance. However
their names are derived from the supplied filename as follows: if the supplied
filename is "foo" then the two files used are called "foo-1"
and "foo-2". The default value is "curr_subs.spear".
- void SetNotThreadNum(const int n)
- This sets the number of worker notifier threads. The default value is
5.
Accessor Methods
For each of the modifier methods described above there
is a corresponding accessor method that returns the current value of the
option. These are mentioned below:
- string GetMatchSem() const
- int GetDefaultInt() const
- double GetDefaultDbl() const
- string GetDefaultStr() const
- int GetSubUpdateInterval() const
- int GetMinSubUpdate() const
- int GetMinUnsubUpdate() const
- bool GetNotify() const
- unsigned short GetPort() const
- int GetBacklog() const
- int GetMaxPubQLen() const
- int GetMaxSubQLen() const
- int GetMaxUnsubQLen() const
- int GetMaxNotQLen() const
- int GetMaxNotTQLen() const
- string GetCurrSubFile() const
- int GetNotThreadNum() const
If you wish to program in Java take a peek at the
JBLADE tutorial
. If you wish to write a client the
SHAFT tutorial
might be helpful.