Skip to content
Permalink
Browse files
GERONIMO-6648 ensure the common code is extracted in a common module
  • Loading branch information
rmannibucau committed Oct 18, 2018
1 parent 859bbc8 commit bbae29b6e2513ac9bf068de7cfd61afec3bb6cd8
Showing 66 changed files with 856 additions and 263 deletions.
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>geronimo-opentracing-parent</artifactId>
<groupId>org.apache.geronimo</groupId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>geronimo-opentracing-common</artifactId>
<name>Geronimo OpenTracing :: Common</name>
<description>Implementation environment independent (no CDI).</description>

<properties>
<geronimo-opentracing.Automatic-Module-Name>org.apache.geronimo.opentracing.common</geronimo-opentracing.Automatic-Module-Name>
</properties>
</project>
@@ -1,30 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.config;
package org.apache.geronimo.microprofile.opentracing.common.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;

import javax.enterprise.inject.Vetoed;

@Vetoed
class DefaultOpenTracingConfig implements GeronimoOpenTracingConfig {
private final Map<String, String> configuration = new HashMap<>();

@@ -47,3 +47,22 @@ public String read(final String value, final String def) {
return configuration.getOrDefault(value, def);
}
}

@FunctionalInterface
public interface GeronimoOpenTracingConfig {

String read(String value, String def);

static GeronimoOpenTracingConfig create() {
try {
final Iterator<GeronimoOpenTracingConfig> iterator = ServiceLoader.load(GeronimoOpenTracingConfig.class)
.iterator();
if (iterator.hasNext()) {
return new PrefixedConfig(iterator.next());
}
} catch (final ServiceConfigurationError | ExceptionInInitializerError | NoClassDefFoundError | Exception e) {
// no-op
}
return new PrefixedConfig(new DefaultOpenTracingConfig());
}
}
@@ -14,11 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.config;
package org.apache.geronimo.microprofile.opentracing.common.config;

import javax.enterprise.inject.Vetoed;

@Vetoed
class PrefixedConfig implements GeronimoOpenTracingConfig {
private final GeronimoOpenTracingConfig delegate;

@@ -28,6 +25,9 @@ class PrefixedConfig implements GeronimoOpenTracingConfig {

@Override
public String read(final String value, final String def) {
if (value.startsWith("mp.")) {
return delegate.read(value, delegate.read("geronimo.opentracing." + value, def));
}
return delegate.read("geronimo.opentracing." + value, def);
}
}
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;
package org.apache.geronimo.microprofile.opentracing.common.impl;

import io.opentracing.Span;

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;
package org.apache.geronimo.microprofile.opentracing.common.impl;

import static java.util.Collections.list;
import static java.util.Optional.ofNullable;
@@ -25,14 +25,11 @@
import java.util.Iterator;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MultivaluedMap;

import org.apache.geronimo.microprofile.opentracing.config.GeronimoOpenTracingConfig;
import org.apache.geronimo.microprofile.opentracing.common.config.GeronimoOpenTracingConfig;
import org.apache.geronimo.microprofile.opentracing.common.spi.Bus;

import io.opentracing.Scope;
import io.opentracing.ScopeManager;
@@ -42,34 +39,40 @@
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMap;

@ApplicationScoped
public class GeronimoTracer implements Tracer {

@Inject
private ScopeManager scopeManager;

@Inject
private IdGenerator idGenerator;

@Inject
private Event<FinishedSpan> finishedSpanEvent;

@Inject
private Bus<FinishedSpan> finishedSpanEvent;
private GeronimoOpenTracingConfig config;

private String parentSpanIdHeader;
private String spanIdHeader;
private String traceIdHeader;
private String baggageHeaderPrefix;

@PostConstruct
private void init() {
public void init() {
parentSpanIdHeader = config.read("propagation.headers.parentSpanId", "X-B3-ParentSpanId");
spanIdHeader = config.read("propagation.headers.spanId", "X-B3-SpanId");
traceIdHeader = config.read("propagation.headers.traceId", "X-B3-TraceId");
baggageHeaderPrefix = config.read("propagation.headers.baggagePrefix", "baggage-");
}

public void setScopeManager(final ScopeManager scopeManager) {
this.scopeManager = scopeManager;
}

public void setIdGenerator(final IdGenerator idGenerator) {
this.idGenerator = idGenerator;
}

public void setFinishedSpanEvent(final Bus<FinishedSpan> finishedSpanEvent) {
this.finishedSpanEvent = finishedSpanEvent;
}

public void setConfig(final GeronimoOpenTracingConfig config) {
this.config = config;
}

@Override
public ScopeManager scopeManager() {
return scopeManager;
@@ -14,29 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;
package org.apache.geronimo.microprofile.opentracing.common.impl;

import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;

import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.apache.geronimo.microprofile.opentracing.config.GeronimoOpenTracingConfig;
import org.apache.geronimo.microprofile.opentracing.common.config.GeronimoOpenTracingConfig;

@ApplicationScoped
// @ApplicationScoped
public class IdGenerator {
@Inject
protected GeronimoOpenTracingConfig config;

private Supplier<Object> delegate;
private boolean counter;

@PostConstruct
void createDelegate() {
public void init() {
final String type = config.read("id.generator", "counter");
counter = "counter".equalsIgnoreCase(type);
switch (type) {
@@ -72,6 +68,10 @@ public Object get() {
}
}

public void setConfig(final GeronimoOpenTracingConfig config) {
this.config = config;
}

public boolean isCounter() {
return counter;
}
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;
package org.apache.geronimo.microprofile.opentracing.common.impl;

import java.util.Iterator;
import java.util.Map;
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;
package org.apache.geronimo.microprofile.opentracing.common.impl;

public class ReferenceImpl {

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;
package org.apache.geronimo.microprofile.opentracing.common.impl;

import io.opentracing.Scope;
import io.opentracing.Span;
@@ -14,15 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;

import javax.enterprise.context.ApplicationScoped;
package org.apache.geronimo.microprofile.opentracing.common.impl;

import io.opentracing.Scope;
import io.opentracing.ScopeManager;
import io.opentracing.Span;

@ApplicationScoped
// @ApplicationScoped
public class ScopeManagerImpl implements ScopeManager {

private final ThreadLocal<Scope> current = new ThreadLocal<>();
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;
package org.apache.geronimo.microprofile.opentracing.common.impl;

import java.util.Enumeration;
import java.util.Iterator;
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;
package org.apache.geronimo.microprofile.opentracing.common.impl;

import static java.util.stream.Collectors.toMap;

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;
package org.apache.geronimo.microprofile.opentracing.common.impl;

import java.util.Map;

@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.impl;
package org.apache.geronimo.microprofile.opentracing.common.impl;

import static java.util.Collections.singletonMap;

@@ -14,14 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.microprofile.opentracing.microprofile.client;
package org.apache.geronimo.microprofile.opentracing.common.microprofile.client;

import java.util.concurrent.ExecutorService;

import javax.enterprise.inject.spi.CDI;
import javax.ws.rs.client.ClientBuilder;

import org.apache.geronimo.microprofile.opentracing.microprofile.thread.OpenTracingExecutorService;
import org.apache.geronimo.microprofile.opentracing.common.microprofile.thread.OpenTracingExecutorService;
import org.apache.geronimo.microprofile.opentracing.common.spi.Container;
import org.eclipse.microprofile.opentracing.ClientTracingRegistrarProvider;

import io.opentracing.Tracer;
@@ -35,10 +35,10 @@ public class GeronimoClientTracingRegistrarProvider implements ClientTracingRegi
private final Tracer tracer;

public GeronimoClientTracingRegistrarProvider() {
final CDI<Object> cdi = CDI.current();
requestFilter = cdi.select(OpenTracingClientRequestFilter.class).get();
responseFilter = cdi.select(OpenTracingClientResponseFilter.class).get();
tracer = cdi.select(Tracer.class).get();
final Container container = Container.get();
requestFilter = container.lookup(OpenTracingClientRequestFilter.class);
responseFilter = container.lookup(OpenTracingClientResponseFilter.class);
tracer = container.lookup(Tracer.class);
}

@Override

0 comments on commit bbae29b

Please sign in to comment.