Skip to content

Commit

Permalink
extapi->spi
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Urisman authored and Igor Urisman committed Aug 17, 2023
1 parent b00dd75 commit 3b6f6bf
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 83 deletions.
2 changes: 1 addition & 1 deletion docs/com/variant/extapi/std/demo/UserQualifyingHook.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2 title="Class UserQualifyingHook" class="title">Class UserQualifyingHook</h2>
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>com.variant.extapi.std.demo.UserQualificationHook</li>
<li>com.variant.spi.demo.UserQualificationHook</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2 title="Class TraceEventFlusherCsv" class="title">Class TraceEventFlusherCsv<
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>com.variant.extapi.std.flush.TraceEventFlusherCsv</li>
<li>com.variant.spi.stdlib.flush.TraceEventFlusherCsv</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2 title="Class TraceEventFlusherNull" class="title">Class TraceEventFlusherNul
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>com.variant.extapi.std.flush.TraceEventFlusherNull</li>
<li>com.variant.spi.stdlib.flush.TraceEventFlusherNull</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2 title="Class TraceEventFlusherServerLog" class="title">Class TraceEventFlush
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>com.variant.extapi.std.flush.TraceEventFlusherServerLog</li>
<li>com.variant.spi.stdlib.flush.TraceEventFlusherServerLog</li>
</ul>
</li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions docs/com/variant/extapi/std/flush/jdbc/JdbcAdapter.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2 title="Class JdbcAdapter" class="title">Class JdbcAdapter</h2>
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>com.variant.extapi.std.flush.jdbc.JdbcAdapter</li>
<li>com.variant.spi.stdlib.flush.jdbc.JdbcAdapter</li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -226,7 +226,7 @@ <h4>JdbcAdapter</h4>
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="executeQuery-java.sql.Connection-com.variant.extapi.std.flush.jdbc.JdbcAdapter.QueryOperation-">
<a name="executeQuery-java.sql.Connection-com.variant.spi.stdlib.flush.jdbc.JdbcAdapter.QueryOperation-">
<!-- -->
</a>
<ul class="blockList">
Expand All @@ -247,7 +247,7 @@ <h4>executeQuery</h4>
</dl>
</li>
</ul>
<a name="executeUpdate-java.sql.Connection-com.variant.extapi.std.flush.jdbc.JdbcAdapter.UpdateOperation-">
<a name="executeUpdate-java.sql.Connection-com.variant.spi.stdlib.flush.jdbc.JdbcAdapter.UpdateOperation-">
<!-- -->
</a>
<ul class="blockListLast">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ <h2 title="Class TraceEventFlusherH2" class="title">Class TraceEventFlusherH2</h
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li><a href="../../../../../../com/variant/extapi/std/flush/jdbc/TraceEventFlusherJdbc.html" title="class in com.variant.extapi.std.flush.jdbc">com.variant.extapi.std.flush.jdbc.TraceEventFlusherJdbc</a></li>
<li><a href="../../../../../../com/variant/extapi/std/flush/jdbc/TraceEventFlusherJdbc.html" title="class in com.variant.extapi.std.flush.jdbc">com.variant.spi.stdlib.flush.jdbc.TraceEventFlusherJdbc</a></li>
<li>
<ul class="inheritance">
<li>com.variant.extapi.std.flush.jdbc.TraceEventFlusherH2</li>
<li>com.variant.spi.stdlib.flush.jdbc.TraceEventFlusherH2</li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -182,7 +182,7 @@ <h3>Method Summary</h3>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.com.variant.extapi.std.flush.jdbc.TraceEventFlusherJdbc">
<li class="blockList"><a name="methods.inherited.from.class.com.variant.spi.stdlib.flush.jdbc.TraceEventFlusherJdbc">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;com.variant.extapi.std.flush.jdbc.<a href="../../../../../../com/variant/extapi/std/flush/jdbc/TraceEventFlusherJdbc.html" title="class in com.variant.extapi.std.flush.jdbc">TraceEventFlusherJdbc</a></h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h2 title="Class TraceEventFlusherJdbc" class="title">Class TraceEventFlusherJdb
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>com.variant.extapi.std.flush.jdbc.TraceEventFlusherJdbc</li>
<li>com.variant.spi.stdlib.flush.jdbc.TraceEventFlusherJdbc</li>
</ul>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ <h2 title="Class TraceEventFlusherMysql" class="title">Class TraceEventFlusherMy
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li><a href="../../../../../../com/variant/extapi/std/flush/jdbc/TraceEventFlusherJdbc.html" title="class in com.variant.extapi.std.flush.jdbc">com.variant.extapi.std.flush.jdbc.TraceEventFlusherJdbc</a></li>
<li><a href="../../../../../../com/variant/extapi/std/flush/jdbc/TraceEventFlusherJdbc.html" title="class in com.variant.extapi.std.flush.jdbc">com.variant.spi.stdlib.flush.jdbc.TraceEventFlusherJdbc</a></li>
<li>
<ul class="inheritance">
<li>com.variant.extapi.std.flush.jdbc.TraceEventFlusherMysql</li>
<li>com.variant.spi.stdlib.flush.jdbc.TraceEventFlusherMysql</li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -180,7 +180,7 @@ <h3>Method Summary</h3>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.com.variant.extapi.std.flush.jdbc.TraceEventFlusherJdbc">
<li class="blockList"><a name="methods.inherited.from.class.com.variant.spi.stdlib.flush.jdbc.TraceEventFlusherJdbc">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;com.variant.extapi.std.flush.jdbc.<a href="../../../../../../com/variant/extapi/std/flush/jdbc/TraceEventFlusherJdbc.html" title="class in com.variant.extapi.std.flush.jdbc">TraceEventFlusherJdbc</a></h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ <h2 title="Class TraceEventFlusherPostgres" class="title">Class TraceEventFlushe
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li><a href="../../../../../../com/variant/extapi/std/flush/jdbc/TraceEventFlusherJdbc.html" title="class in com.variant.extapi.std.flush.jdbc">com.variant.extapi.std.flush.jdbc.TraceEventFlusherJdbc</a></li>
<li><a href="../../../../../../com/variant/extapi/std/flush/jdbc/TraceEventFlusherJdbc.html" title="class in com.variant.extapi.std.flush.jdbc">com.variant.spi.stdlib.flush.jdbc.TraceEventFlusherJdbc</a></li>
<li>
<ul class="inheritance">
<li>com.variant.extapi.std.flush.jdbc.TraceEventFlusherPostgres</li>
<li>com.variant.spi.stdlib.flush.jdbc.TraceEventFlusherPostgres</li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -182,7 +182,7 @@ <h3>Method Summary</h3>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.com.variant.extapi.std.flush.jdbc.TraceEventFlusherJdbc">
<li class="blockList"><a name="methods.inherited.from.class.com.variant.spi.stdlib.flush.jdbc.TraceEventFlusherJdbc">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;com.variant.extapi.std.flush.jdbc.<a href="../../../../../../com/variant/extapi/std/flush/jdbc/TraceEventFlusherJdbc.html" title="class in com.variant.extapi.std.flush.jdbc">TraceEventFlusherJdbc</a></h3>
Expand Down
4 changes: 2 additions & 2 deletions docs/index-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ <h2 class="title">E</h2>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="com/variant/extapi/std/flush/jdbc/JdbcAdapter.UpdateOperation.html#execute-java.sql.Connection-">execute(Connection)</a></span> - Method in interface com.variant.extapi.std.flush.jdbc.<a href="com/variant/extapi/std/flush/jdbc/JdbcAdapter.UpdateOperation.html" title="interface in com.variant.extapi.std.flush.jdbc">JdbcAdapter.UpdateOperation</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="com/variant/extapi/std/flush/jdbc/JdbcAdapter.html#executeQuery-java.sql.Connection-com.variant.extapi.std.flush.jdbc.JdbcAdapter.QueryOperation-">executeQuery(Connection, JdbcAdapter.QueryOperation&lt;T&gt;)</a></span> - Static method in class com.variant.extapi.std.flush.jdbc.<a href="com/variant/extapi/std/flush/jdbc/JdbcAdapter.html" title="class in com.variant.extapi.std.flush.jdbc">JdbcAdapter</a></dt>
<dt><span class="memberNameLink"><a href="com/variant/extapi/std/flush/jdbc/JdbcAdapter.html#executeQuery-java.sql.Connection-com.variant.spi.stdlib.flush.jdbc.JdbcAdapter.QueryOperation-">executeQuery(Connection, JdbcAdapter.QueryOperation&lt;T&gt;)</a></span> - Static method in class com.variant.extapi.std.flush.jdbc.<a href="com/variant/extapi/std/flush/jdbc/JdbcAdapter.html" title="class in com.variant.extapi.std.flush.jdbc">JdbcAdapter</a></dt>
<dd>
<div class="block">Execute a query that returns an instance of type T</div>
</dd>
<dt><span class="memberNameLink"><a href="com/variant/extapi/std/flush/jdbc/JdbcAdapter.html#executeUpdate-java.sql.Connection-com.variant.extapi.std.flush.jdbc.JdbcAdapter.UpdateOperation-">executeUpdate(Connection, JdbcAdapter.UpdateOperation)</a></span> - Static method in class com.variant.extapi.std.flush.jdbc.<a href="com/variant/extapi/std/flush/jdbc/JdbcAdapter.html" title="class in com.variant.extapi.std.flush.jdbc">JdbcAdapter</a></dt>
<dt><span class="memberNameLink"><a href="com/variant/extapi/std/flush/jdbc/JdbcAdapter.html#executeUpdate-java.sql.Connection-com.variant.spi.stdlib.flush.jdbc.JdbcAdapter.UpdateOperation-">executeUpdate(Connection, JdbcAdapter.UpdateOperation)</a></span> - Static method in class com.variant.extapi.std.flush.jdbc.<a href="com/variant/extapi/std/flush/jdbc/JdbcAdapter.html" title="class in com.variant.extapi.std.flush.jdbc">JdbcAdapter</a></dt>
<dd>
<div class="block">Execute an update operation that does not return anything.</div>
</dd>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.variant.extapi.std.demo;
package com.variant.spi.demo;

import java.util.Arrays;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.variant.extapi.std.demo;
package com.variant.spi.demo;

import com.variant.server.api.Session;
import com.variant.server.api.lifecycle.VariationTargetingLifecycleEvent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.variant.extapi.std.flush;
package com.variant.spi.stdlib.flush;

import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
Expand All @@ -10,6 +10,7 @@
import java.nio.file.Paths;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.Optional;

import org.yaml.snakeyaml.Yaml;
import com.variant.share.schema.Variation.Experience;
Expand All @@ -20,35 +21,39 @@
* An implementation of {@link TraceEventFlusher}, which writes trace events to a local CSV file.
* The output file format conforms to the <a href="https://tools.ietf.org/html/rfc4180">IETF RFC4180</a>
*
* Configuration.<br/>You may use the <code>variant.event.flusher.class.init</code> configuration property to pass configuration details to this object.
*
* Configuration.
* A YAML string containing these properties:
* <ul>
* <li><code>header</code> - boolean - Wether or not to include the metadata header as very first line. The default is <code>false</code>
* <li><code>file</code> - string - The name of the file to write to. Will be overwritten if exists. The default is "variant-events.csv"
* <li><code>header</code> - boolean - Whether or not to include the header as very first line.
* Optional, defaults to <code>true</code>.
* <li><code>file</code> - string - The name of the local file to write to. If starts with the leading '/',
* interpreted as an absolute path. Otherwise, interpreted wrt Variant server's working
* directory. Will be overwritten if exists. Optional, defaults to <code>log/trace-events.csv</code>.
* </ul>
* Example:<br/>
* <code>variant.event.flusher.init = {"file":"/tmp/variant-events.csv","header":true}</code>
* <code>
* flusher:
* class: com.variant.spi.stdlib.TraceEventFlusherCsv
* init: '{file: /tmp/variant-events.csv, header: false}'
* </code>
*
* @since 0.10
*/
public class TraceEventFlusherCsv implements TraceEventFlusher {

private BufferedWriter out = null;

public TraceEventFlusherCsv(String string) throws Exception {
Map<String, ?> map = new Yaml().load(string);
boolean header = (boolean) map.get("header");
String outFileName = (String) map.get("file");
out = Files.newBufferedWriter(Paths.get(outFileName), CREATE, WRITE, TRUNCATE_EXISTING );

if (header) {
public TraceEventFlusherCsv(String init) throws Exception {
Map<String, ?> map =
Optional.ofNullable(init)
.map(string->(Map<String,?>)new Yaml().load(string))
.orElse(Map.of());
out = Files.newBufferedWriter(Paths.get(parseFileName(map)), CREATE, WRITE, TRUNCATE_EXISTING );
if (parseHeader(map)) {
writeLine("event_id", "event_name", "created_on", "session_id", "attributes", "variation", "experience", "is_control");
out.flush();
}
}
public TraceEventFlusherCsv() throws Exception {
this("{header: false, file: /tmp/variant-events.csv}");
}

/**
* Write a bunch of events to file.
Expand All @@ -69,18 +74,17 @@ public void flush(FlushableTraceEvent[] events, int size) throws Exception {
String attrs = attrsBuffer.toString();

for (Experience e: event.getLiveExperiences()) {
writeLine(
event.getId(),
event.getName(),
DateTimeFormatter.ISO_INSTANT.format(event.getTimestamp()),
event.getSessionId(),
attrs,
e.getVariation().getName(),
e.getName(),
e.isControl());
}
writeLine(
event.getId(),
event.getName(),
DateTimeFormatter.ISO_INSTANT.format(event.getTimestamp()),
event.getSessionId(),
attrs,
e.getVariation().getName(),
e.getName(),
e.isControl());
}
}

out.flush();
}

Expand All @@ -91,7 +95,17 @@ public void flush(FlushableTraceEvent[] events, int size) throws Exception {
public void destroy() throws Exception {
out.close();
}


private Boolean parseHeader(Map<String, ?> map) {
final var defaultValue = true;
return Optional.ofNullable(map.get("header")).map(token->(boolean)token).orElse(defaultValue);
}

private String parseFileName(Map<String, ?> map) {
final var defaultValue = "log/trace-events.csv";
return Optional.ofNullable(map.get("file")).map(token->(String)token).orElse(defaultValue);
}

/**
* Enclose the string in double quotes. If a double quote already occurs in the string,
* double it, as per the RFC
Expand All @@ -101,7 +115,6 @@ private String quoteString(String raw) {
}

private void writeLine(Object...tokens) throws IOException {

boolean first = true;
for (Object token: tokens) {
if (first) first = false;
Expand All @@ -110,7 +123,6 @@ private void writeLine(Object...tokens) throws IOException {
}
out.append(System.lineSeparator());
}

public static void main(String[] args) throws Exception {
var flusher = new TraceEventFlusherCsv("{header: true, outFileName: /tmp/foo.bar}");
System.out.println(flusher);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.variant.extapi.std.flush;
package com.variant.spi.stdlib.flush;

import com.variant.server.api.FlushableTraceEvent;
import com.variant.server.api.TraceEventFlusher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.variant.extapi.std.flush;
package com.variant.spi.stdlib.flush;

import com.variant.server.api.FlushableTraceEvent;
import com.variant.server.api.TraceEventFlusher;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.variant.extapi.std.flush.jdbc;
package com.variant.spi.stdlib.flush.jdbc;

import java.sql.Connection;
import java.sql.SQLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.variant.extapi.std.flush.jdbc;
package com.variant.spi.stdlib.flush.jdbc;

/**
* The JDBC vendors we support.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.variant.spi.stdlib.flush.jdbc;


public class TraceEventFlusherH2 extends TraceEventFlusherJdbc {

public TraceEventFlusherH2(String init) throws Exception {
super(init);
}

@Override
protected JdbcVendor getJdbcVendor() {
return JdbcVendor.H2;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.variant.extapi.std.flush.jdbc;
package com.variant.spi.stdlib.flush.jdbc;

import java.sql.*;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.variant.extapi.std.flush.jdbc;
package com.variant.spi.stdlib.flush.jdbc;

public class TraceEventFlusherMysql extends TraceEventFlusherJdbc {
public TraceEventFlusherMysql(String init) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.variant.extapi.std.flush.jdbc;
package com.variant.spi.stdlib.flush.jdbc;

import com.variant.server.api.TraceEventFlusher;

Expand Down

0 comments on commit 3b6f6bf

Please sign in to comment.