Skip to content

Commit

Permalink
0.10.2 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor committed Sep 30, 2019
1 parent 2ff4127 commit 1c99e72
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bin/javadoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#


version=0.10.1
version=0.10.2
root_dir=$(cd $(dirname $0)/..; pwd)
javadoc_dir=${root_dir}/docs

Expand Down
2 changes: 1 addition & 1 deletion bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#


version=0.10.1
version=0.10.2
root_dir=$(cd $(dirname $0)/..; pwd)

cd $root_dir
Expand Down
Binary file not shown.
Binary file removed lib/variant-server-extapi-0.10.1.jar
Binary file not shown.
Binary file added lib/variant-server-extapi-0.10.2.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<variant.version>0.10.1</variant.version>
<variant.version>0.10.2</variant.version>

</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.variant.extapi.std.flush;

import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static java.nio.file.StandardOpenOption.WRITE;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.format.DateTimeFormatter;

import static java.nio.file.StandardOpenOption.*;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -54,11 +55,15 @@ public TraceEventFlusherCsv(Config config) throws Exception {

}

/**
* Write a bunch of events to file.
*/
@Override
public void flush(Collection<FlushableTraceEvent> events) throws Exception {
public void flush(FlushableTraceEvent[] events, int size) throws Exception {

for (FlushableTraceEvent event: events) {
for (int i = 0; i < size; i++) {

FlushableTraceEvent event = events[i];
StringBuilder attrsBuffer = new StringBuilder();
boolean first = true;
for (Map.Entry<String, String> param: event.getAttributes().entrySet()) {
Expand All @@ -84,6 +89,14 @@ public void flush(Collection<FlushableTraceEvent> events) throws Exception {
out.flush();
}

/**
* This flusher is going down. Close the file.
*/
@Override
public void destroy() throws Exception {
out.close();
}

/**
* Enclose the string in double quotes. If a double quote already occurs in the string,
* double it, as per the RFC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.variant.extapi.std.flush;

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -19,8 +17,8 @@ public class TraceEventFlusherNull implements TraceEventFlusher {
private static final Logger LOG = LoggerFactory.getLogger(TraceEventFlusherNull.class);

@Override
public void flush(Collection<FlushableTraceEvent> events) throws Exception {
LOG.debug(String.format("Discarded %s events.", events.size()));
public void flush(FlushableTraceEvent[] events, int size) throws Exception {
LOG.debug(String.format("Discarded %s events.", size));
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.variant.extapi.std.flush;

import java.time.format.DateTimeFormatter;
import java.util.Collection;
import java.util.Map;

import org.slf4j.Logger;
Expand Down Expand Up @@ -50,10 +49,10 @@ public TraceEventFlusherServerLog(Config config) {
}

@Override
public void flush(Collection<FlushableTraceEvent> events)
throws Exception {
public void flush(FlushableTraceEvent[] events, int size) throws Exception {

for (FlushableTraceEvent event: events) {
for (int i = 0; i < size; i++) {
FlushableTraceEvent event = events[i];
StringBuilder msg = new StringBuilder();
msg.append("{")
.append("event_id:'").append(event.getId()).append("', ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import com.typesafe.config.Config;
Expand Down Expand Up @@ -46,11 +47,10 @@ public TraceEventFlusherH2(Config config) throws Exception {
props.setProperty("user", user);
props.setProperty("password", password);
conn = DriverManager.getConnection(url, props);

}

@Override
public Connection getJdbcConnection() throws Exception {
public Connection getJdbcConnection() {
return conn;
}

Expand All @@ -59,4 +59,8 @@ protected JdbcVendor getJdbcVendor() {
return JdbcVendor.H2;
}

@Override
public void destroy() throws Exception {
if (conn != null) conn.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Map;

import com.variant.core.schema.Variation.Experience;
Expand All @@ -25,25 +24,26 @@ abstract public class TraceEventFlusherJdbc implements TraceEventFlusher {

/**
* Concrete subclass tells this class how to obtain a connection to its flavor of JDBC.
* JUnits will also use this to create the schema.
* JUnits will also use this to create the database schema. Subclasses should take care
* of creating the connection only once and cacheing it.
*
* @return
* @throws Exception
*/
public abstract Connection getJdbcConnection() throws Exception;
public abstract Connection getJdbcConnection();

/**
* Implementations will know the vendor.
* @return
*/
protected abstract JdbcVendor getJdbcVendor();

/**
* Persist a collection of events.
*/
@Override
final public void flush(final Collection<FlushableTraceEvent> events) throws Exception {
final public void flush(FlushableTraceEvent[] events, int size) throws Exception {

final String INSERT_EVENTS_SQL =
"INSERT INTO events (id, session_id, created_on, event_name) VALUES (?, ?, ?, ?)";

Expand All @@ -66,7 +66,8 @@ public void execute(Connection conn) throws SQLException {

PreparedStatement stmt = conn.prepareStatement(INSERT_EVENTS_SQL, Statement.RETURN_GENERATED_KEYS);

for (FlushableTraceEvent event: events) {
for (int i = 0; i < size; i++) {
FlushableTraceEvent event = events[i];
stmt.setString(1, event.getId());
stmt.setString(2, event.getSessionId());
stmt.setTimestamp(3, Timestamp.from(event.getTimestamp()));
Expand All @@ -83,7 +84,8 @@ public void execute(Connection conn) throws SQLException {
// 2. Insert into EVENT_PARAMETERS.
//
stmt = conn.prepareStatement(INSERT_EVENT_PARAMETERS_SQL);
for (FlushableTraceEvent event: events) {
for (int i = 0; i < size; i++) {
FlushableTraceEvent event = events[i];
for (Map.Entry<String, String> param: event.getAttributes().entrySet()) {
stmt.setString(1, event.getId());
stmt.setString(2, param.getKey());
Expand All @@ -100,7 +102,8 @@ public void execute(Connection conn) throws SQLException {
// 3. Insert into EVENT_EXPERIENCES.
//
stmt = conn.prepareStatement(INSERT_EVENT_EXPERIENCES_SQL);
for (FlushableTraceEvent event: events) {
for (int i = 0; i < size; i++) {
FlushableTraceEvent event = events[i];
for (Experience exp: event.getLiveExperiences()) {
stmt.setString(1, event.getId());
stmt.setString(2, exp.getVariation().getName());
Expand All @@ -115,6 +118,5 @@ public void execute(Connection conn) throws SQLException {
}
}
);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public TraceEventFlusherMysql(Config config) throws Exception {
}

@Override
public Connection getJdbcConnection() throws Exception {
public Connection getJdbcConnection() {
return conn;
}

Expand All @@ -60,4 +60,9 @@ protected JdbcVendor getJdbcVendor() {
return JdbcVendor.MYSQL;
}

@Override
public void destroy() throws Exception {
if (conn != null) conn.close();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TraceEventFlusherPostgres(Config config) throws Exception {
}

@Override
public Connection getJdbcConnection() throws Exception {
public Connection getJdbcConnection() {
return conn;
}

Expand All @@ -57,4 +57,9 @@ protected JdbcVendor getJdbcVendor() {
return JdbcVendor.POSTGRES;
}

@Override
public void destroy() throws Exception {
if (conn != null) conn.close();
}

}

0 comments on commit 1c99e72

Please sign in to comment.