Skip to content

Commit

Permalink
Merge pull request #60 from openzipkin/style-fixes
Browse files Browse the repository at this point in the history
Fixes imports per style and removes unnecessary "this" qualification
  • Loading branch information
adriancole committed Jan 8, 2016
2 parents 7498019 + 531bedf commit 2a6ef00
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 110 deletions.
4 changes: 2 additions & 2 deletions zipkin-java-core/src/main/java/io/zipkin/Annotation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2015 The OpenZipkin Authors
* Copyright 2015-2016 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -85,7 +85,7 @@ public Builder endpoint(Endpoint endpoint) {
}

public Annotation build() {
return Annotation.create(this.timestamp, this.value, this.endpoint);
return Annotation.create(timestamp, value, endpoint);
}
}

Expand Down
4 changes: 2 additions & 2 deletions zipkin-java-core/src/main/java/io/zipkin/DependencyLink.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2015 The OpenZipkin Authors
* Copyright 2015-2016 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -68,7 +68,7 @@ public Builder callCount(long callCount) {
}

public DependencyLink build() {
return new DependencyLink(this.parent, this.child, this.callCount);
return new DependencyLink(parent, child, callCount);
}
}

Expand Down
2 changes: 1 addition & 1 deletion zipkin-java-core/src/main/java/io/zipkin/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Builder port(short port) {
}

public Endpoint build() {
return new Endpoint(this.serviceName, this.ipv4, this.port);
return new Endpoint(serviceName, ipv4, port);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.twitter.zipkin.common.Dependencies;
import com.twitter.zipkin.common.DependencyLink;
import io.zipkin.SpanStore;
import io.zipkin.internal.Nullable;
import java.util.ArrayList;
import java.util.List;
import scala.Option;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public Future<Seq<List<Span>>> getTraces(QueryRequest input) {
Tuple2<String, String> keyValue = i.next();
request.addBinaryAnnotation(keyValue._1(), keyValue._2());
}
return toSeqFuture(this.spanStore.getTraces(request.build()));
return toSeqFuture(spanStore.getTraces(request.build()));
}

@Override
public Future<Seq<List<Span>>> getTracesByIds(Seq<Object> input) {
java.util.List<Long> traceIds = JavaConversions.asJavaCollection(input).stream()
.map(o -> Long.valueOf(o.toString())).collect(toList());
return toSeqFuture(this.spanStore.getTracesByIds(traceIds));
return toSeqFuture(spanStore.getTracesByIds(traceIds));
}

private static Future<Seq<List<Span>>> toSeqFuture(java.util.List<java.util.List<io.zipkin.Span>> traces) {
Expand All @@ -90,17 +90,17 @@ private static Future<Seq<List<Span>>> toSeqFuture(java.util.List<java.util.List

@Override
public Future<Seq<String>> getAllServiceNames() {
return Future.value(JavaConversions.asScalaBuffer(this.spanStore.getServiceNames()).seq());
return Future.value(JavaConversions.asScalaBuffer(spanStore.getServiceNames()).seq());
}

@Override
public Future<Seq<String>> getSpanNames(String service) {
return Future.value(JavaConversions.asScalaBuffer(this.spanStore.getSpanNames(service)).seq());
return Future.value(JavaConversions.asScalaBuffer(spanStore.getSpanNames(service)).seq());
}

@Override
public Future<BoxedUnit> apply(Seq<Span> input) {
this.spanStore.accept(ScalaSpanStoreAdapter.invert(input).iterator());
spanStore.accept(ScalaSpanStoreAdapter.invert(input).iterator());
return Future.Unit();
}

Expand Down
16 changes: 8 additions & 8 deletions zipkin-java-jdbc/src/main/java/io/zipkin/jdbc/JDBCSpanStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public JDBCSpanStore(DataSource datasource, Settings settings, @Nullable Execute
}

void clear() throws SQLException {
try (Connection conn = this.datasource.getConnection()) {
try (Connection conn = datasource.getConnection()) {
context(conn).truncate(ZIPKIN_SPANS).execute();
context(conn).truncate(ZIPKIN_ANNOTATIONS).execute();
}
Expand All @@ -91,7 +91,7 @@ void clear() throws SQLException {
@Override
public void accept(Iterator<Span> spans) {
if (!spans.hasNext()) return;
try (Connection conn = this.datasource.getConnection()) {
try (Connection conn = datasource.getConnection()) {
DSLContext create = context(conn);

List<Query> inserts = new ArrayList<>();
Expand Down Expand Up @@ -167,7 +167,7 @@ public void accept(Iterator<Span> spans) {
private List<List<Span>> getTraces(@Nullable QueryRequest request, @Nullable List<Long> traceIds) {
final Map<Long, List<Span>> spansWithoutAnnotations;
final Map<Pair<?>, List<Record>> dbAnnotations;
try (Connection conn = this.datasource.getConnection()) {
try (Connection conn = datasource.getConnection()) {
if (request != null) {
traceIds = toTraceIdQuery(context(conn), request).fetch(ZIPKIN_SPANS.TRACE_ID);
}
Expand Down Expand Up @@ -241,8 +241,8 @@ private DSLContext context(Connection conn) {
return DSL.using(new DefaultConfiguration()
.set(conn)
.set(JDBCUtils.dialect(conn))
.set(this.settings)
.set(this.listenerProvider));
.set(settings)
.set(listenerProvider));
}

@Override
Expand All @@ -252,7 +252,7 @@ public List<List<Span>> getTracesByIds(List<Long> traceIds) {

@Override
public List<String> getServiceNames() {
try (Connection conn = this.datasource.getConnection()) {
try (Connection conn = datasource.getConnection()) {
return context(conn)
.selectDistinct(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME)
.from(ZIPKIN_ANNOTATIONS)
Expand All @@ -268,7 +268,7 @@ public List<String> getServiceNames() {
public List<String> getSpanNames(String serviceName) {
if (serviceName == null) return emptyList();
serviceName = serviceName.toLowerCase(); // service names are always lowercase!
try (Connection conn = this.datasource.getConnection()) {
try (Connection conn = datasource.getConnection()) {
return context(conn)
.selectDistinct(ZIPKIN_SPANS.NAME)
.from(ZIPKIN_SPANS)
Expand All @@ -286,7 +286,7 @@ public List<String> getSpanNames(String serviceName) {
@Override
public List<DependencyLink> getDependencies(long endTs, @Nullable Long lookback) {
endTs = endTs * 1000;
try (Connection conn = this.datasource.getConnection()) {
try (Connection conn = datasource.getConnection()) {
Map<Long, List<Record3<Long, Long, Long>>> parentChild = context(conn)
.select(ZIPKIN_SPANS.TRACE_ID, ZIPKIN_SPANS.PARENT_ID, ZIPKIN_SPANS.ID)
.from(ZIPKIN_SPANS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2015 The OpenZipkin Authors
* Copyright 2015-2016 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -16,10 +16,8 @@
*/
package io.zipkin.jdbc.internal.generated;


import io.zipkin.jdbc.internal.generated.tables.ZipkinAnnotations;
import io.zipkin.jdbc.internal.generated.tables.ZipkinSpans;

import javax.annotation.Generated;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2015 The OpenZipkin Authors
* Copyright 2015-2016 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -16,16 +16,12 @@
*/
package io.zipkin.jdbc.internal.generated;


import io.zipkin.jdbc.internal.generated.tables.ZipkinAnnotations;
import io.zipkin.jdbc.internal.generated.tables.ZipkinSpans;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.Generated;

import org.jooq.Table;
import org.jooq.impl.SchemaImpl;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2015 The OpenZipkin Authors
* Copyright 2015-2016 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -16,11 +16,8 @@
*/
package io.zipkin.jdbc.internal.generated.tables;


import io.zipkin.jdbc.internal.generated.Zipkin;

import javax.annotation.Generated;

import org.jooq.Field;
import org.jooq.Record;
import org.jooq.Table;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2015 The OpenZipkin Authors
* Copyright 2015-2016 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -16,11 +16,8 @@
*/
package io.zipkin.jdbc.internal.generated.tables;


import io.zipkin.jdbc.internal.generated.Zipkin;

import javax.annotation.Generated;

import org.jooq.Field;
import org.jooq.Record;
import org.jooq.Table;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2015 The OpenZipkin Authors
* Copyright 2015-2016 The OpenZipkin Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -13,16 +13,14 @@
*/
package io.zipkin.server;

import io.zipkin.server.brave.BraveConfiguration;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.context.annotation.Import;

import io.zipkin.server.brave.BraveConfiguration;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,34 @@ public ZipkinQueryApiV1(SpanStore spanStore, ZipkinSpanWriter spanWriter, Codec.
@RequestMapping(value = "/dependencies", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
public byte[] getDependencies(@RequestParam(value = "endTs", required = true) long endTs,
@RequestParam(value = "lookback", required = false) Long lookback) {
return this.jsonCodec.writeDependencyLinks(this.spanStore.getDependencies(endTs, lookback != null ? lookback : defaultLookback));
return jsonCodec.writeDependencyLinks(spanStore.getDependencies(endTs, lookback != null ? lookback : defaultLookback));
}

@RequestMapping(value = "/services", method = RequestMethod.GET)
public List<String> getServiceNames() {
return this.spanStore.getServiceNames();
return spanStore.getServiceNames();
}

@RequestMapping(value = "/spans", method = RequestMethod.GET)
public List<String> getSpanNames(
@RequestParam(value = "serviceName", required = true) String serviceName) {
return this.spanStore.getSpanNames(serviceName);
return spanStore.getSpanNames(serviceName);
}

@RequestMapping(value = "/spans", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.ACCEPTED)
public void uploadSpansJson(@RequestBody byte[] body) {
List<Span> spans = this.jsonCodec.readSpans(body);
List<Span> spans = jsonCodec.readSpans(body);
if (spans == null) throw new MalformedSpansException(APPLICATION_JSON_VALUE);
this.spanWriter.write(this.spanStore, spans);
spanWriter.write(spanStore, spans);
}

@RequestMapping(value = "/spans", method = RequestMethod.POST, consumes = APPLICATION_THRIFT)
@ResponseStatus(HttpStatus.ACCEPTED)
public void uploadSpansThrift(@RequestBody byte[] body) {
List<Span> spans = this.thriftCodec.readSpans(body);
List<Span> spans = thriftCodec.readSpans(body);
if (spans == null) throw new MalformedSpansException(APPLICATION_THRIFT);
this.spanWriter.write(this.spanStore, spans);
spanWriter.write(spanStore, spans);
}

@RequestMapping(value = "/traces", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
Expand Down Expand Up @@ -127,19 +127,19 @@ public byte[] getTraces(
}
}
}
return this.jsonCodec.writeTraces(this.spanStore.getTraces(builder.build()));
return jsonCodec.writeTraces(spanStore.getTraces(builder.build()));
}

@RequestMapping(value = "/trace/{traceId}", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
public byte[] getTrace(@PathVariable String traceId) {
@SuppressWarnings("resource")
long id = new Buffer().writeUtf8(traceId).readHexadecimalUnsignedLong();
List<List<Span>> traces = this.spanStore.getTracesByIds(Collections.singletonList(id));
List<List<Span>> traces = spanStore.getTracesByIds(Collections.singletonList(id));

if (traces.isEmpty()) {
throw new TraceNotFoundException(traceId, id);
}
return this.jsonCodec.writeSpans(traces.get(0));
return jsonCodec.writeSpans(traces.get(0));
}

@ExceptionHandler(TraceNotFoundException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
*/
package io.zipkin.server;

import com.github.kristofa.brave.Brave;
import io.zipkin.Codec;
import io.zipkin.SpanStore;
import io.zipkin.TraceIdSampler;
import io.zipkin.jdbc.JDBCSpanStore;
import io.zipkin.server.ZipkinServerProperties.Store.Type;
import io.zipkin.server.brave.TraceWritesSpanStore;
import javax.sql.DataSource;

import org.jooq.ExecuteListenerProvider;
import org.jooq.conf.Settings;
import org.springframework.beans.BeansException;
Expand All @@ -30,14 +35,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import com.github.kristofa.brave.Brave;

import io.zipkin.Codec;
import io.zipkin.SpanStore;
import io.zipkin.jdbc.JDBCSpanStore;
import io.zipkin.server.ZipkinServerProperties.Store.Type;
import io.zipkin.server.brave.TraceWritesSpanStore;

@Configuration
@EnableConfigurationProperties(ZipkinServerProperties.class)
@EnableAsync(proxyTargetClass=true)
Expand Down Expand Up @@ -68,8 +65,8 @@ TraceIdSampler traceIdSampler(@Value("${zipkin.collector.sample-rate}") float ra
@Bean
SpanStore spanStore() {
SpanStore result;
if (this.datasource != null && this.server.getStore().getType() == Type.mysql) {
result = new JDBCSpanStore(this.datasource, new Settings().withRenderSchema(false), this.listener);
if (datasource != null && server.getStore().getType() == Type.mysql) {
result = new JDBCSpanStore(datasource, new Settings().withRenderSchema(false), listener);
} else {
result = new InMemorySpanStore();
}
Expand All @@ -92,8 +89,8 @@ public Object postProcessBeforeInitialization(Object bean, String beanName)
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
if (bean instanceof SpanStore && this.brave!=null) {
return new TraceWritesSpanStore(this.brave, (SpanStore) bean);
if (bean instanceof SpanStore && brave != null) {
return new TraceWritesSpanStore(brave, (SpanStore) bean);
}
return bean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ZipkinServerProperties {
private Store store = new Store();

public Store getStore() {
return this.store;
return store;
}

static class Store {
Expand All @@ -31,7 +31,7 @@ enum Type {
private Type type = Type.mem;

public Type getType() {
return this.type;
return type;
}

public void setType(Type type) {
Expand Down
Loading

0 comments on commit 2a6ef00

Please sign in to comment.