-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime.html
381 lines (366 loc) · 22.7 KB
/
runtime.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="Scala library to describe event sourced entities using tagless-final algebras, running with built-in implementations for Akka.">
<meta property="og:title" content="Endless4s">
<meta property="og:description" content="Scala library to describe event sourced entities using tagless-final algebras, running with built-in implementations for Akka.">
<meta property="og:image" content="https://endless4s.github.io/logo-open-graph.png">
<meta name="generator" content="Paradox, paradox-material-theme=0.7.0, mkdocs-material=3.0.3">
<meta name="lang:clipboard.copy" content="Copy to clipboard">
<meta name="lang:clipboard.copied" content="Copied to clipboard">
<meta name="lang:search.language" content="">
<meta name="lang:search.pipeline.stopwords" content="true">
<meta name="lang:search.pipeline.trimmer" content="true">
<meta name="lang:search.result.none" content="No matching documents">
<meta name="lang:search.result.one" content="1 matching document">
<meta name="lang:search.result.other" content="# matching documents">
<meta name="lang:search.tokenizer" content="[\s\-]+">
<meta name="description" content="Scala library to describe event sourced entities using tagless-final algebras, running with built-in implementations for Akka.">
<link rel="shortcut icon" href="favicon.png">
<title>Pekko and Akka runtimes · </title>
<link rel="stylesheet" href="assets/stylesheets/application.451f80e5.css">
<link rel="stylesheet" href="assets/stylesheets/application-palette.22915126.css">
<meta name="theme-color" content="#546e7a" />
<link rel="stylesheet" href="lib/material__tabs/dist/mdc.tabs.min.css">
<link rel="stylesheet" href="lib/prettify/prettify.css">
<script src="assets/javascripts/modernizr.1aa3b519.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Overpass:300,400,400i,700|Overpass+Mono">
<style>
body,input{font-family:"Overpass","Helvetica Neue",Helvetica,Arial,sans-serif}
code,kbd,pre{font-family:"Overpass Mono","Courier New",Courier,monospace}
</style>
<link rel="stylesheet" href="assets/fonts/font-awesome.css">
<link rel="stylesheet" href="assets/fonts/material-icons.css">
<link rel="stylesheet" href="assets/stylesheets/paradox-material-theme.css">
</head>
<body
data-md-color-primary="blue-grey"
data-md-color-accent="red"
>
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
<header class="md-header" data-md-component="header">
<nav class="md-header-nav md-grid">
<div class="md-flex">
<div class="md-flex__cell md-flex__cell--shrink">
<a href="index.html" title="" class="md-header-nav__button md-logo">
<img src="logo-symbol-only.svg" width="24" height="24">
</a>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
</div>
<div class="md-flex__cell md-flex__cell--stretch">
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
<span class="md-header-nav__topic">
</span>
<span class="md-header-nav__topic">
Pekko and Akka runtimes
</span>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
<label class="md-icon md-search__icon" for="__search"></label>
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1"></button>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" data-md-scrollfix>
<div class="md-search-result" data-md-component="result">
<div class="md-search-result__meta">
Type to start searching
</div>
<ol class="md-search-result__list"></ol>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<div class="md-header-nav__source">
<a href="https://github.com/endless4s/endless"
title="Go to repository"
class="md-source"
data-md-source="github">
<div class="md-source__icon">
<i class="fa fa-github"></i>
</div>
<div class="md-source__repository">
endless4s/endless
</div>
</a>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container">
<main class="md-main">
<div class="md-main__inner md-grid" data-md-component="container">
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary" data-md-level="0" style="visibility: hidden">
<label class="md-nav__title md-nav__title--site" for="drawer">
<a href="index.html" title="" class="md-nav__button md-logo">
<span class="md-nav__button md-logo">
<img src="logo-symbol-only.svg" width="24" height="24">
</a>
<a href="index.html" title="">
</a>
</label>
<div class="md-nav__source">
<a href="https://github.com/endless4s/endless"
title="Go to repository"
class="md-source"
data-md-source="github">
<div class="md-source__icon">
<i class="fa fa-github"></i>
</div>
<div class="md-source__repository">
endless4s/endless
</div>
</a>
</div>
<ul>
<li><a href="getting-started.html" class="page">Getting Started</a></li>
<li><a href="nutshell.html" class="page">In a nutshell</a></li>
<li><a href="abstractions.html" class="page">Abstractions</a>
<ul>
<li><a href="sharding.html" class="page">Sharding</a></li>
<li><a href="entity.html" class="page">Entity</a></li>
<li><a href="durable-entity.html" class="page">Durable entity</a></li>
<li><a href="applier.html" class="page">EventApplier</a></li>
<li><a href="protocol.html" class="page">CommandProtocol</a></li>
<li><a href="sender.html" class="page">CommandSender</a></li>
<li><a href="side-effect.html" class="page">Side-effect</a></li>
<li><a href="effector.html" class="page">Effector</a></li>
<li><a href="name.html" class="page">EntityNameProvider</a></li>
<li><a href="id.html" class="page">EntityIDCodec</a></li>
<li><a href="deployer.html" class="page">Deployer</a></li>
</ul></li>
<li><a href="runtime.html" class="active page">Pekko and Akka runtimes</a></li>
<li><a href="example.html" class="page">Example app</a></li>
<li><a href="transactions.html" class="page">Transactions</a></li>
<li><a href="reference.html" class="page">Reference</a></li>
<li><a href="inspiration.html" class="page">Inspiration</a></li>
</ul>
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="__toc">Table of contents</label>
<ul>
<li><a href="runtime.html#pekko-and-akka-runtimes" class="header">Pekko and Akka runtimes</a>
<ul>
<li><a href="runtime.html#how-to-initiate-the-distributed-cluster" class="header">How to initiate the distributed cluster</a></li>
<li><a href="runtime.html#internals" class="header">Internals</a></li>
</ul></li>
</ul>
</nav>
</nav>
<ul style="display: none">
<li class="md-nav__item md-version" id="project.version">
<label class="md-nav__link" for="__version">
<i class="md-icon" title="Version">label_outline</i> 0.31.0
</label>
</li>
</ul>
</div>
</div>
</div>
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--secondary">
<label class="md-nav__title" for="__toc">Table of contents</label>
<ul>
<li><a href="runtime.html#pekko-and-akka-runtimes" class="header">Pekko and Akka runtimes</a>
<ul>
<li><a href="runtime.html#how-to-initiate-the-distributed-cluster" class="header">How to initiate the distributed cluster</a></li>
<li><a href="runtime.html#internals" class="header">Internals</a></li>
</ul></li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content">
<article class="md-content__inner md-typeset">
<div class="md-content__searchable">
<h1><a href="#pekko-and-akka-runtimes" name="pekko-and-akka-runtimes" class="anchor"><span class="anchor-link"></span></a>Pekko and Akka runtimes</h1>
<p>Once required interpreters and typeclass instances have been defined, deploying an entity with Pekko or Akka boils down to a single call to <a href="api/core/endless/core/entity/Deployer.html" title="endless.core.entity.Deployer"><code>deployRepository</code></a>. This requires an actor system and the cluster sharding extension in implicit scope, bundled in the type <a href="api/pekko-runtime/endless/runtime/pekko/deploy/PekkoCluster.html" title="endless.runtime.pekko.deploy.PekkoCluster"><code>PekkoCluster</code></a> (or <a href="api/akka-runtime/endless/runtime/akka/deploy/AkkaCluster.html" title="endless.runtime.akka.deploy.AkkaCluster"><code>AkkaCluster</code></a>). The recommended pattern is to use the built-in <a href="api/akka-runtime/endless/runtime/akka/deploy/AkkaCluster$$managedResource.html" title="endless.runtime.akka.deploy.AkkaCluster.managedResource"><code>managedResource</code></a> helper method to obtain an instance of this class, which wraps actor system creation and shutdown with a <a href="https://typelevel.org/cats-effect/docs/std/resource" title="Resource" target="_blank" rel="noopener noreferrer">Resource</a>. </p>
<h2><a href="#how-to-initiate-the-distributed-cluster" name="how-to-initiate-the-distributed-cluster" class="anchor"><span class="anchor-link"></span></a>How to initiate the distributed cluster</h2>
<p>The entrypoint is available by importing <code>endless.runtime.pekko.syntax.deploy.*</code> or <code>endless.runtime.akka.syntax.deploy.*</code> and calling <code>deployRepository</code> with the required parameters. </p>
<p>This function ties everything together and delivers a cats effect <a href="https://typelevel.org/cats-effect/docs/std/resource" title="Resource" target="_blank" rel="noopener noreferrer">Resource</a> with an instance of <a href="endless.runtime.pekko.deploy.DeployedPekkoRepository">DeployedPekkoRepository</a> in context <code>F</code> bundling the <code>RepositoryAlg</code> instance together with the ref to the shard region actor returned by the call to Pekko’s <a href="https://doc.akka.io/docs/akka/current/typed/cluster-sharding.html#basic-example" title="ClusterSharding.init" target="_blank" rel="noopener noreferrer">ClusterSharding.init</a>.</p>
<p>The following snippet is the scaffolding for the library’s sample application (in its Pekko form), a simple API to manage vehicles and bookings:</p>
<pre class="prettyprint"><button class="snippet-button copy-snippet" title="Copy snippet to clipboard">copy</button><a class="snippet-button go-to-source" href="https://github.com/endless4s/endless/tree/v0.31.0/example/src/main/scala/endless/example/app/pekko/PekkoApp.scala#L62-L128" target="_blank" title="Go to snippet source">source</a><code class="language-scala">Resource
.eval(Slf4jLogger.create[IO])
.flatMap { implicit logger: Logger[IO] =>
PekkoCluster.managedResource[IO](actorSystem).flatMap {
implicit cluster: PekkoCluster[IO] =>
implicit val eventSourcingDeploymentParameters
: PekkoDeploymentParameters[IO, Booking, BookingEvent] =
PekkoDeploymentParameters[IO, Booking, BookingEvent](
customizeBehavior = (_, behavior) =>
behavior.eventAdapter(
new EventAdapter[
BookingEvent,
endless.example.proto.booking.events.BookingEvent
] {
def toJournal(
e: BookingEvent
): endless.example.proto.booking.events.BookingEvent =
eventAdapter.toJournal(e)
def manifest(event: BookingEvent): String = event.getClass.getName
def fromJournal(
p: endless.example.proto.booking.events.BookingEvent,
manifest: String
): EventSeq[BookingEvent] = EventSeq.single(eventAdapter.fromJournal(p))
}
)
)
implicit val durableDeploymentParameters
: PekkoDurableDeploymentParameters[IO, Vehicle] =
PekkoDurableDeploymentParameters[IO, Vehicle](
customizeBehavior = (_, behavior) =>
behavior.snapshotAdapter(new SnapshotAdapter[Option[Vehicle]] {
def toJournal(state: Option[Vehicle]): Any = stateAdapter.toJournal(state)
def fromJournal(from: Any): Option[Vehicle] = stateAdapter.fromJournal(from)
})
)
Resource
.both(
deployRepository[
IO,
BookingID,
Booking,
BookingEvent,
BookingAlg,
BookingsAlg
](
RepositoryInterpreter.lift(ShardedBookings(_)),
BehaviorInterpreter.lift(BookingEntityBehavior(_)),
SideEffectInterpreter.lift { case (_, _) => new BookingSideEffect() }
),
deployDurableRepository[IO, VehicleID, Vehicle, VehicleAlg, VehiclesAlg](
RepositoryInterpreter.lift(ShardedVehicles(_)),
DurableBehaviorInterpreter.lift(VehicleEntityBehavior(_)),
SideEffectInterpreter.lift { case (_, _) => new VehicleSideEffect() }
)
)
.flatMap { case (bookingDeployment, vehicleDeployment) =>
HttpServer(
port,
bookingDeployment.repository,
vehicleDeployment.repository,
cluster.isMemberUp
)
}
}
}</code></pre>
<p><code>deployRepository</code> is parameterized with the context <code>F</code> and the various involved types: <code>S</code> for entity state, <code>E</code> for events, <code>ID</code> for entity ID and <code>Alg</code> & <code>RepositoryAlg</code> for entity and repository algebras respectively (both higher-kinded type constructors).</p>
<p>In order to bridge Pekko/Akka’s implicit asynchronicity with the side-effect free context <code>F</code> used for algebras, it requires <a href="https://typelevel.org/cats-effect/docs/typeclasses/async" title="Async" target="_blank" rel="noopener noreferrer">Async</a> from <code>F</code>. This makes it possible to use the <a href="https://typelevel.org/cats-effect/docs/std/dispatcher" title="Dispatcher" target="_blank" rel="noopener noreferrer">Dispatcher</a> mechanism for running the command handling monadic chain synchronously from within the actor thread.</p>
<p><code>Logger</code> from <a href="https://github.com/typelevel/log4cats" title="`log4cats`" target="_blank" rel="noopener noreferrer"><code>log4cats</code></a> is also required as the library supports basic logging capabilities.</p><div class="callout warning "><div class="callout-title">Important</div>
<p><code>deployRepository</code> needs to be called upon application startup, before joining the cluster as the <code>ClusterSharding</code> extension needs to know about the various entity types beforehand.</p></div><div class="callout note "><div class="callout-title">Durable entity</div>
<p>The equivalent method for durable entities is <a href="api/core/endless/core/entity/DurableDeployer.html" title="endless.core.entity.DurableDeployer"><code>deployDurableRepository</code></a>.</p></div>
<h2><a href="#internals" name="internals" class="anchor"><span class="anchor-link"></span></a>Internals</h2>
<h3><a href="#protocol" name="protocol" class="anchor"><span class="anchor-link"></span></a>Protocol</h3>
<p>Thanks to the <a href="protocol.html">CommandProtocol</a> instance, entity algebra calls can be “materialized” into concrete commands and replies. These types are encoded to a binary payload, which is transported within an internal protobuf envelope <a href="https://github.com/endless4s/endless/tree/v0.31.0/runtime/src/main/protobuf/command.proto">command.proto</a>.</p>
<p><a href="/runtime/src/main/scala/endless/runtime/pekko/ShardingCommandSender.scala">ShardingCommandSender</a> takes care of delivering the commands to the right entity and returning the reply simply by using Pekko/Akka’s <code>ask</code>.</p>
<h3><a href="#deployer" name="deployer" class="anchor"><span class="anchor-link"></span></a>Deployer</h3>
<p>Internally, <a href="https://github.com/endless4s/endless/tree/v0.31.0/runtime/src/main/scala/endless/runtime/pekko/PekkoDeployer.scala">deployRepository</a> uses <a href="https://pekko.apache.org/docs/pekko/current/typed/persistence.html#example-and-core-api" title="EventSourcedBehavior" target="_blank" rel="noopener noreferrer">EventSourcedBehavior</a> DSL to configure the entity in the following way (for <a href="https://github.com/endless4s/endless/tree/v0.31.0/runtime/src/main/scala/endless/runtime/pekko/DurablePekkoDeployer.scala">deployDurableRepository</a>, this is <a href="https://pekko.apache.org/docs/pekko/current/typed/durable-state/persistence.html#cluster-sharding-and-durablestatebehavior">DurableStateBehavior</a>):</p>
<h4><a href="#command-handler" name="command-handler" class="anchor"><span class="anchor-link"></span></a>Command handler</h4>
<ol>
<li>use <a href="protocol.html">CommandProtocol.server</a> to decode the command and invoke the corresponding algebra logic, interpreted internally with <a href="api/core/endless/core/interpret/EntityT.html" title="endless.core.interpret.EntityT"><code>EntityT</code></a>. Interpretation of the monadic chain occurs, leading to one or more events and a return value.</li>
<li>hand in produced events to Pekko/Akka’s <code>Effect.persist</code>.</li>
<li>trigger any side effects in <a href="effector.html">Effector</a> with a run-and-forget using <code>Dispatcher</code> from within <code>thenRun</code></li>
<li>encode the reply and feed it into <code>thenReply</code></li>
</ol>
<h4><a href="#event-handler" name="event-handler" class="anchor"><span class="anchor-link"></span></a>Event handler</h4>
<p>This is simply a synchronous run of <a href="applier.html">EventApplier</a> (using <code>Dispatcher</code>). Left values are translated into thrown exceptions as Pekko/Akka doesn’t give us other means to deal with event handling errors.</p>
<h4><a href="#recovery" name="recovery" class="anchor"><span class="anchor-link"></span></a>Recovery</h4>
<p>Upon successful recovery, we log an info entry and run the effector, while we log a warning entry upon recovery failure.</p><div class="callout note tip"><div class="callout-title">Custom behavior</div>
<p>The built-in behavior is further customizable via a <code>customizeBehavior</code> function parameter that can be optionally passed into <a href="endless.runtime.pekko.deploy.PekkoDeployer.PekkoDeploymentParameters">PekkoDeploymentParameters</a> or <a href="endless.runtime.akka.deploy.AkkaDeployer.AkkaDeploymentParameters">AkkaDeploymentParameters</a>. </p></div><div class="callout warning "><div class="callout-title">Compatibility</div>
<p>Since Akka/Pekko <a href="https://doc.akka.io/docs/akka/current/common/binary-compatibility-rules.html#mixed-versioning-is-not-allowed">does not allow mixed versions</a> in a project, Akka/Pekko dependencies of <code>endless-runtime-akka</code> and <code>endless-runtime-pekko</code> respectively are marked a <code>Provided</code>. This means that your application <code>libraryDependencies</code> needs to directly include Akka or Pekko as a dependency. The minimal supported Akka version is 2.6.20, and Pekko version is 1.1.1. </p></div>
</div>
<div>
<a href="https://github.com/endless4s/endless/tree/v0.31.0/documentation/src/main/paradox/runtime.md" title="Edit this page" class="md-source-file md-edit">
Edit this page
</a>
</div>
<div class="print-only">
<span class="md-source-file md-version">
0.31.0
</span>
</div>
</article>
</div>
</div>
</main>
<footer class="md-footer">
<div class="md-footer-nav">
<nav class="md-footer-nav__inner md-grid">
<a href="deployer.html" title="Deployer" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
<div class="md-flex__cell md-flex__cell--shrink">
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
</div>
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
<span class="md-flex__ellipsis">
<span class="md-footer-nav__direction">
Previous
</span>
Deployer
</span>
</div>
</a>
<a href="example.html" title="Example app" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
<span class="md-flex__ellipsis">
<span class="md-footer-nav__direction">
Next
</span>
Example app
</span>
</div>
<div class="md-flex__cell md-flex__cell--shrink">
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
</div>
</a>
</nav>
</div>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-footer-copyright">
Powered by
<a href="https://github.com/lightbend/paradox">Paradox</a>
and
<a href="https://sbt.github.io/sbt-paradox-material-theme/">Paradox Material Theme</a>
</div>
<div class="md-footer-social">
<a href="https://github.com/endless4s/endless" class="md-footer-social__link fa fa-github"></a>
</div>
</div>
</div>
</footer>
</div>
<script src="assets/javascripts/application.583bbe55.js"></script>
<script src="assets/javascripts/paradox-material-theme.js"></script>
<script>app.initialize({version:"0.17",url:{base:"."}})</script>
<script type="text/javascript" src="lib/prettify/prettify.js"></script>
<script type="text/javascript" src="lib/prettify/lang-scala.js"></script>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
window.prettyPrint && prettyPrint();
});
</script>
<script>!function(e,a,t,n,o,c,i){e.GoogleAnalyticsObject=o,e.ga=e.ga||function(){(e.ga.q=e.ga.q||[]).push(arguments)},e.ga.l=1*new Date,c=a.createElement(t),i=a.getElementsByTagName(t)[0],c.async=1,c.src="https://www.google-analytics.com/analytics.js",i.parentNode.insertBefore(c,i)}(window,document,"script",0,"ga"),ga("create","G-KKHFXG4VB4"),ga("set","anonymizeIp",!0),ga("send","pageview");var links=document.getElementsByTagName("a");Array.prototype.map.call(links,function(e){e.host!=document.location.host&&e.addEventListener("click",function(){var a=e.getAttribute("data-md-action")||"follow";ga("send","event","outbound",a,e.href)})});if(document.forms.search){var query=document.forms.search.query;query.addEventListener("blur",function(){if(this.value){var e=document.location.pathname;ga("send","pageview",e+"?q="+this.value)}})}</script>
</body>
</html>