-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocs_customadaptors.html
129 lines (114 loc) · 8.81 KB
/
docs_customadaptors.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<html><head>
<title>DBToaster - Custom Adaptors</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="http://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css">
</head> <body>
<a name="pagetop"></a>
<div class="overallpage">
<div class="pagebody">
<div class="logobox">
<a href="index.html" ><img src="dbtoaster-logo.gif" width="214"
height="100" alt="DBToaster"/></a> </div>
<div class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">About <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="index.html" >Welcome to dbtoaster.org</a></li>
<li><a href="home_about.html" >Is DBToaster right for you?</a></li>
<li><a href="home_performance.html" >Performance</a></li>
<li><a href="home_features.html" >Features</a></li>
<li><a href="home_features.html#roadmap" ><small><i class="fa fa-caret-square-o-right"></i> Roadmap</small></a></li>
<li><a href="home_people.html" >The Team</a></li>
<li><a href="home_research.html" >For Researchers</a></li>
</ul>
</li>
<li class="dropdown">
<!--?php if(!isset($now_building_distro)) { ?-->
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Downloads <b class="caret"></b></a>
<!--?php } else { ?-->
<!--a href="#" class="dropdown-toggle" data-toggle="dropdown">License <b class="caret"></b></a-->
<!--?php } ?-->
<ul class="dropdown-menu">
<!--?php if(!isset($now_building_distro)) { ?-->
<li><a href="download.html" >Downloads</a></li>
<!--?php } ?-->
<li><a href="download.html#license" >License</a></li>
<li><a href="download.html#changelog" >Changelog</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Documentation <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="docs.html" >Installation</a></li>
<li><a href="docs_start.html" >Getting Started</a></li>
<li><a href="docs_architecture.html" >Architecture</a></li>
<li><a href="docs_compiler.html" >Command-Line Reference</a></li>
<li><a href="docs_compiler.html#options" ><small><i class="fa fa-caret-square-o-right"></i> Command-Line Options</small></a></li>
<li><a href="docs_compiler.html#languages" ><small><i class="fa fa-caret-square-o-right"></i> Supported Languages</small></a></li>
<li><a href="docs_compiler.html#opt_flags" ><small><i class="fa fa-caret-square-o-right"></i> Optimization Flags</small></a></li>
<li><a href="docs_sql.html" >DBToaster SQL Reference</a></li>
<li><a href="docs_stdlib.html" >DBToaster StdLib Reference</a></li>
<li><a href="docs_adaptors.html" >DBToaster Adaptors Reference</a></li>
<li><a href="docs_cpp.html" >C++ Code Generation</a></li>
<li><a href="docs_scala.html" >Scala Code Generation</a></li>
<li><a href="docs_java.html" >DBToaster in Java Programs</a></li>
<li><a href="docs_customadaptors.html" >Custom Adaptors</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contact <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="home_contact.html#inquiries" >Inquiries</a></li>
<li><a href="home_contact.html#mailing" >Mailing List</a></li>
<li><a href="bugs.html" >Bug Reports</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="contentwrapper">
<div class="content">
<div class="doc_chain_link"> < <span class="doc_chain_link_prev"><a href="docs_java.html" >DBToaster in Java Programs</a></span></div> <div class="titlebox">Custom Adaptors</div><p>DBToaster allows users to build custom adaptors for processing input streams. Such adaptors can build their own events and feed them into the query engine by calling the generated trigger functions.</p>
<p>The incremental view-maintenance (IVM) programs generated by DBToaster would be a component of your application, and in any real-world application, you will need to write your own adaptors for providing the IVM program with your data stream, as well as the operations on the data (either insert, delete, or update). Update operations in DBToaser are considered as a sequence of delete and insert operations, so it will make it even easier for you, to write your own custom data adaptors.</p>
<p>Based on the choice of your target language, either C++ or Scala, you need to write the data adaptor the same language.</p>
<h3>1. Custom Scala Adaptors</h3><p>For writing your data adaptor in Scala, you should consider that the generated code for Scala consists of a class and an object with the same name. The generated object contains a default main method for quickly testing the program. Although, as you want to write your own data adaptor, you can simply ignore this generated object, and you will only need the generated class.</p>
<p>By having a look at the generated class code, you might have noticed that it is a descendant of Akka Actor class, which makes it an actor. If you are already familiar with Akka Actor, you know that each actor has a receive method that accepts a request and tries to handle that request. The generated code for each IVM program will try to handle several events in the receive method:
<ul>
<li>StreamInit: which is an event that is meant to occur only once in the beginning of the execution.</li>
<li>TupleEvent: that you will normally see the pattern matching for several kinds of this event. Actually, this is the main event that should occur on every database operation on the database tables.</li>
<li>GetSnapshot: that is a request for sending back the current view result.</li>
<li>EndOfStream: which is an event that is meant to occur only once in the end of the execution.</li>
</ul>
</p>
<p>As you might have already guessed, you only have to create these events in your custom adaptor and pass them to this generated Akka Actor to handle your request.</p>
<h3>2. Custom C++ Adaptors</h3>
<p>Writing a custom adaptor in C++ is semantically almost the same as Scala, but implementation-wise is different. For C++, the main file for quick testing of your generated IVM programs is not generated and you can find it in the latest distribution tarball (under examples/code/main.cpp).</p>
<p>In this sample main.cpp file, in addition to the main function, there are two custom programs (named CustomProgram_1 and CustomProgram_2) which extend the Program class.</p>
<p>If you look into one of the generated IVM programs in C++, you will notice that a class named Program is generated. So, the two custom programs (named CustomProgram_1 and CustomProgram_2) that you have already seen in main.cpp are extending the generated Program class, and they provide a custom way of handling input to the program, and you can write your adaptor in the same way.</p>
<p>See <a href="docs_cpp.html" >C++ Code Generation</a> and <a href="docs_scala.html" >Scala Code Generation</a> for more information on some details about code generation.</p> <div class="doc_chain_link"> < <span class="doc_chain_link_prev"><a href="docs_java.html" >DBToaster in Java Programs</a></span></div> </div><!-- /content -->
</div><!-- /contentwrapper -->
</div><!-- /pagebody -->
<div class="footer">
<hr/>
<p>Copyright (c) 2009-2014, The DBToaster Consortium. All rights reserved.</p>
</div>
</div><!-- /overallpage -->
<div id="pageEndElem" style="padding: 0 20px;"></div>
<script type="text/javascript" src="js/jquery-2.0.3.min.js"> </script>
<script type="text/javascript" src="js/bootstrap.min.js"> </script>
</body>
</html>