Commit 51ef4f76 authored by terrymanu's avatar terrymanu
Browse files

merge DQL & DML to SQLExecuteEventListener

parent c7325a4f
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -21,8 +21,7 @@ import com.google.common.base.Preconditions;
import io.opentracing.Tracer;
import io.opentracing.util.GlobalTracer;
import io.shardingsphere.core.exception.ShardingException;
import io.shardingsphere.opentracing.listener.execution.DMLExecuteEventListener;
import io.shardingsphere.opentracing.listener.execution.DQLExecuteEventListener;
import io.shardingsphere.opentracing.listener.execution.SQLExecuteEventListener;
import io.shardingsphere.opentracing.listener.execution.OverallExecuteEventListener;
import io.shardingsphere.opentracing.listener.merger.MergeEventListener;
import io.shardingsphere.opentracing.listener.routing.RouteEventListener;
@@ -68,8 +67,7 @@ public final class ShardingTracer {
    private static void registerListeners() {
        new RouteEventListener().register();
        new OverallExecuteEventListener().register();
        new DQLExecuteEventListener().register();
        new DMLExecuteEventListener().register();
        new SQLExecuteEventListener().register();
        new MergeEventListener().register();
    }
    
+0 −43
Original line number Diff line number Diff line
/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * 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
 *
 *     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.
 * </p>
 */

package io.shardingsphere.opentracing.listener.execution;

import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import io.shardingsphere.core.executor.event.DMLExecutionEvent;

/**
 * DML execute event listener.
 * 
 * @author gaohongtao
 * @author wangkai
 * @author maxiaoguang
 */
public final class DMLExecuteEventListener extends ExecuteEventListener {
    
    /**
     * Listen DML execution event.
     *
     * @param event DML execution event
     */
    @Subscribe
    @AllowConcurrentEvents
    public void listen(final DMLExecutionEvent event) {
        tracing(event);
    }
}
+0 −43
Original line number Diff line number Diff line
/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * 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
 *
 *     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.
 * </p>
 */

package io.shardingsphere.opentracing.listener.execution;

import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import io.shardingsphere.core.executor.event.DQLExecutionEvent;

/**
 * DQL execute event listener.
 * 
 * @author gaohongtao
 * @author wangkai
 * @author maxiaoguang
 */
public final class DQLExecuteEventListener extends ExecuteEventListener {
    
    /**
     * Listen DQL execution event.
     *
     * @param event DQL execution event
     */
    @Subscribe
    @AllowConcurrentEvents
    public void listen(final DQLExecutionEvent event) {
        tracing(event);
    }
}
+18 −5
Original line number Diff line number Diff line
@@ -18,14 +18,16 @@
package io.shardingsphere.opentracing.listener.execution;

import com.google.common.base.Joiner;
import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import io.opentracing.ActiveSpan;
import io.opentracing.Span;
import io.opentracing.tag.Tags;
import io.shardingsphere.core.executor.event.SQLExecutionEvent;
import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap;
import io.shardingsphere.opentracing.ShardingTags;
import io.shardingsphere.opentracing.ShardingTracer;
import io.shardingsphere.opentracing.listener.OpenTracingListener;
import io.shardingsphere.opentracing.ShardingTags;

/**
 * SQL execute event listener.
@@ -34,7 +36,7 @@ import io.shardingsphere.opentracing.ShardingTags;
 * @author wangkai
 * @author maxiaoguang
 */
public abstract class ExecuteEventListener extends OpenTracingListener<SQLExecutionEvent> {
public final class SQLExecuteEventListener extends OpenTracingListener<SQLExecutionEvent> {
    
    private static final String OPERATION_NAME_PREFIX = "/SHARDING-SPHERE/EXECUTE/";
    
@@ -46,8 +48,19 @@ public abstract class ExecuteEventListener extends OpenTracingListener<SQLExecut
    
    private final ThreadLocal<ActiveSpan> trunkInBranchSpan = new ThreadLocal<>();
    
    /**
     * Listen SQL execution event.
     *
     * @param event SQL execution event
     */
    @Subscribe
    @AllowConcurrentEvents
    public void listen(final SQLExecutionEvent event) {
        tracing(event);
    }
    
    @Override
    protected final void beforeExecute(final SQLExecutionEvent event) {
    protected void beforeExecute(final SQLExecutionEvent event) {
        if (ExecutorDataMap.getDataMap().containsKey(SNAPSHOT_DATA_KEY) && null == trunkSpan.get() && null == branchSpan.get()) {
            trunkInBranchSpan.set(((ActiveSpan.Continuation) ExecutorDataMap.getDataMap().get(SNAPSHOT_DATA_KEY)).activate());
        }
@@ -61,7 +74,7 @@ public abstract class ExecuteEventListener extends OpenTracingListener<SQLExecut
    }
    
    @Override
    protected final void tracingFinish() {
    protected void tracingFinish() {
        if (null == branchSpan.get()) {
            return;
        }
@@ -75,7 +88,7 @@ public abstract class ExecuteEventListener extends OpenTracingListener<SQLExecut
    }
    
    @Override
    protected final Span getFailureSpan() {
    protected Span getFailureSpan() {
        return branchSpan.get();
    }
}