*/
-package io.shardingsphere.core.spi.event.connection.close;
+package io.shardingsphere.core.spi.connection.close;
-import io.shardingsphere.core.spi.event.ShardingStartEvent;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
/**
- * Close connection start event.
+ * Connection hook.
*
- * @author zhangyonglun
+ * @author zhangliang
*/
-@RequiredArgsConstructor
-@Getter
-public final class CloseConnectionStartEvent extends ShardingStartEvent {
+public interface CloseConnectionHook {
- private final String dataSource;
+ /**
+ * Handle when close connection started.
+ *
+ * @param dataSourceName data source name
+ * @param dataSourceMetaData data source meta data
+ */
+ void start(String dataSourceName, DataSourceMetaData dataSourceMetaData);
- private final DataSourceMetaData dataSourceMetaData;
+ /**
+ * Handle when close connection finished success.
+ */
+ void finishSuccess();
+
+ /**
+ * Handle when close connection finished failure.
+ *
+ * @param cause failure cause
+ */
+ void finishFailure(Exception cause);
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/close/SPICloseConnectionHook.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/close/SPICloseConnectionHook.java
new file mode 100644
index 0000000000000..d79b8a803f12d
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/close/SPICloseConnectionHook.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * 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.
+ *
+ */
+
+package io.shardingsphere.core.spi.connection.close;
+
+import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
+
+import java.util.ServiceLoader;
+
+/**
+ * Connection hook for SPI.
+ *
+ * @author zhangliang
+ */
+public final class SPICloseConnectionHook implements CloseConnectionHook {
+
+ private static final ServiceLoader SERVICE_LOADER;
+
+ static {
+ SERVICE_LOADER = ServiceLoader.load(CloseConnectionHook.class);
+ }
+
+ @Override
+ public void start(final String dataSourceName, final DataSourceMetaData dataSourceMetaData) {
+ for (CloseConnectionHook each : SERVICE_LOADER) {
+ each.start(dataSourceName, dataSourceMetaData);
+ }
+ }
+
+ @Override
+ public void finishSuccess() {
+ for (CloseConnectionHook each : SERVICE_LOADER) {
+ each.finishSuccess();
+ }
+ }
+
+ @Override
+ public void finishFailure(final Exception cause) {
+ for (CloseConnectionHook each : SERVICE_LOADER) {
+ each.finishFailure(cause);
+ }
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/event/connection/get/GetConnectionFinishEvent.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/get/GetConnectionHook.java
similarity index 50%
rename from sharding-core/src/main/java/io/shardingsphere/core/spi/event/connection/get/GetConnectionFinishEvent.java
rename to sharding-core/src/main/java/io/shardingsphere/core/spi/connection/get/GetConnectionHook.java
index 1d51d2d884cb5..93e881d4f0dc0 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/spi/event/connection/get/GetConnectionFinishEvent.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/get/GetConnectionHook.java
@@ -15,23 +15,36 @@
*
*/
-package io.shardingsphere.core.spi.event.connection.get;
+package io.shardingsphere.core.spi.connection.get;
-import io.shardingsphere.core.spi.event.ShardingFinishEvent;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
/**
- * Get connection finish event.
+ * Connection hook.
*
- * @author zhangyonglun
+ * @author zhangliang
*/
-@RequiredArgsConstructor
-@Getter
-public final class GetConnectionFinishEvent extends ShardingFinishEvent {
+public interface GetConnectionHook {
- private final int connectionCount;
+ /**
+ * Handle when get connection started.
+ *
+ * @param dataSourceName data source name
+ */
+ void start(String dataSourceName);
- private final DataSourceMetaData dataSourceMetaData;
+ /**
+ * Handle when get connection finished success.
+ *
+ * @param dataSourceMetaData data source meta data
+ * @param connectionCount connection count
+ */
+ void finishSuccess(DataSourceMetaData dataSourceMetaData, int connectionCount);
+
+ /**
+ * Handle when get connection finished failure.
+ *
+ * @param cause failure cause
+ */
+ void finishFailure(Exception cause);
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/get/SPIGetConnectionHook.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/get/SPIGetConnectionHook.java
new file mode 100644
index 0000000000000..ec691dd38288d
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/get/SPIGetConnectionHook.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * 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.
+ *
+ */
+
+package io.shardingsphere.core.spi.connection.get;
+
+import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
+
+import java.util.ServiceLoader;
+
+/**
+ * Connection hook loader.
+ *
+ * @author zhangliang
+ */
+public final class SPIGetConnectionHook implements GetConnectionHook {
+
+ private static final ServiceLoader SERVICE_LOADER;
+
+ static {
+ SERVICE_LOADER = ServiceLoader.load(GetConnectionHook.class);
+ }
+
+ @Override
+ public void start(final String dataSourceName) {
+ for (GetConnectionHook each : SERVICE_LOADER) {
+ each.start(dataSourceName);
+ }
+ }
+
+ @Override
+ public void finishSuccess(final DataSourceMetaData dataSourceMetaData, final int connectionCount) {
+ for (GetConnectionHook each : SERVICE_LOADER) {
+ each.finishSuccess(dataSourceMetaData, connectionCount);
+ }
+ }
+
+ @Override
+ public void finishFailure(final Exception cause) {
+ for (GetConnectionHook each : SERVICE_LOADER) {
+ each.finishFailure(cause);
+ }
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/event/ShardingEventHandler.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/event/ShardingEventHandler.java
index 383f7f909230c..78e8ca30b06bc 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/spi/event/ShardingEventHandler.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/event/ShardingEventHandler.java
@@ -22,7 +22,7 @@
*
* @author zhangliang
* @param type of start event
- * @param type of finish event
+ * @param type of finishSuccess event
*/
public interface ShardingEventHandler {
@@ -34,9 +34,9 @@ public interface ShardingEventHandler type of start event
- * @param type of finish event
+ * @param type of finishSuccess event
*/
public interface ShardingEventHandlerLoader {
@@ -34,9 +34,9 @@ public interface ShardingEventHandlerLoader
- * 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.
- *
- */
-
-package io.shardingsphere.core.spi.event.connection.close;
-
-import io.shardingsphere.core.spi.event.ShardingEventHandlerLoader;
-
-import java.util.ServiceLoader;
-
-/**
- * Connection event handler loader.
- *
- * @author zhangliang
- */
-public final class CloseConnectionEventHandlerLoader implements ShardingEventHandlerLoader {
-
- private static final CloseConnectionEventHandlerLoader INSTANCE = new CloseConnectionEventHandlerLoader();
-
- private final ServiceLoader serviceLoader;
-
- private CloseConnectionEventHandlerLoader() {
- serviceLoader = ServiceLoader.load(CloseConnectionEventHandler.class);
- }
-
- /**
- * Get instance.
- *
- * @return instance
- */
- public static CloseConnectionEventHandlerLoader getInstance() {
- return INSTANCE;
- }
-
- @Override
- public void start(final CloseConnectionStartEvent event) {
- for (CloseConnectionEventHandler each : serviceLoader) {
- each.start(event);
- }
- }
-
- @Override
- public void finish(final CloseConnectionFinishEvent event) {
- for (CloseConnectionEventHandler each : serviceLoader) {
- each.finish(event);
- }
- }
-}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/event/connection/close/CloseConnectionFinishEvent.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/event/connection/close/CloseConnectionFinishEvent.java
deleted file mode 100644
index e4c2f81fee735..0000000000000
--- a/sharding-core/src/main/java/io/shardingsphere/core/spi/event/connection/close/CloseConnectionFinishEvent.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * 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.
- *
- * 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.
- *
- * 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.
- *
- * 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.
- *
- * 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.
- *
- * 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.
- *
- * 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.
- *
- * 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.
- *
- * 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.
- *
+ * 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.
+ *
+ */
+
+package io.shardingsphere.core.spi.executor;
+
+import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
+import io.shardingsphere.core.routing.RouteUnit;
+
+import java.util.List;
+import java.util.ServiceLoader;
+
+/**
+ * SQL Execution hook for SPI.
+ *
+ * @author zhangliang
+ */
+public final class SPISQLExecutionHook implements SQLExecutionHook {
+
+ private static final ServiceLoader SERVICE_LOADER;
+
+ static {
+ SERVICE_LOADER = ServiceLoader.load(SQLExecutionHook.class);
+ }
+
+ @Override
+ public void start(final RouteUnit routeUnit, final List parameters, final DataSourceMetaData dataSourceMetaData) {
+ for (SQLExecutionHook each : SERVICE_LOADER) {
+ each.start(routeUnit, parameters, dataSourceMetaData);
+ }
+ }
+
+ @Override
+ public void finishSuccess() {
+ for (SQLExecutionHook each : SERVICE_LOADER) {
+ each.finishSuccess();
+ }
+ }
+
+ @Override
+ public void finishFailure(final Exception cause) {
+ for (SQLExecutionHook each : SERVICE_LOADER) {
+ each.finishFailure(cause);
+ }
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/event/executor/SQLExecutionStartEvent.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/executor/SQLExecutionHook.java
similarity index 56%
rename from sharding-core/src/main/java/io/shardingsphere/core/spi/event/executor/SQLExecutionStartEvent.java
rename to sharding-core/src/main/java/io/shardingsphere/core/spi/executor/SQLExecutionHook.java
index 2eb3d24bebb80..2f88ec8bbff04 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/spi/event/executor/SQLExecutionStartEvent.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/executor/SQLExecutionHook.java
@@ -15,28 +15,38 @@
*
*/
-package io.shardingsphere.core.spi.event.executor;
+package io.shardingsphere.core.spi.executor;
-import io.shardingsphere.core.spi.event.ShardingStartEvent;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
import io.shardingsphere.core.routing.RouteUnit;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import java.util.List;
/**
- * SQL execution start event.
+ * SQL Execution hook.
*
* @author zhangliang
*/
-@RequiredArgsConstructor
-@Getter
-public final class SQLExecutionStartEvent extends ShardingStartEvent {
+public interface SQLExecutionHook {
- private final RouteUnit routeUnit;
+ /**
+ * Handle when SQL execution started.
+ *
+ * @param routeUnit route unit
+ * @param parameters parameters
+ * @param dataSourceMetaData data source meta data
+ */
+ void start(RouteUnit routeUnit, List parameters, DataSourceMetaData dataSourceMetaData);
- private final List parameters;
+ /**
+ * Handle when SQL execution finished success.
+ */
+ void finishSuccess();
- private final DataSourceMetaData dataSourceMetaData;
+ /**
+ * Handle when SQL execution finished failure.
+ *
+ * @param cause failure cause
+ */
+ void finishFailure(Exception cause);
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/parsing/ParsingHook.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/parsing/ParsingHook.java
new file mode 100644
index 0000000000000..02dc7a39a396a
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/parsing/ParsingHook.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ */
+
+package io.shardingsphere.core.spi.parsing;
+
+import java.util.ServiceLoader;
+
+/**
+ * Parsing hook for SPI.
+ *
+ * @author zhangliang
+ */
+public final class SPIParsingHook implements ParsingHook {
+
+ private static final ServiceLoader SERVICE_LOADER;
+
+ static {
+ SERVICE_LOADER = ServiceLoader.load(ParsingHook.class);
+ }
+
+ @Override
+ public void start(final String sql) {
+ for (ParsingHook each : SERVICE_LOADER) {
+ each.start(sql);
+ }
+ }
+
+ @Override
+ public void finishSuccess() {
+ for (ParsingHook each : SERVICE_LOADER) {
+ each.finishSuccess();
+ }
+ }
+
+ @Override
+ public void finishFailure(final Exception cause) {
+ for (ParsingHook each : SERVICE_LOADER) {
+ each.finishFailure(cause);
+ }
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/root/RootInvokeHandler.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/root/RootInvokeHook.java
similarity index 81%
rename from sharding-core/src/main/java/io/shardingsphere/core/spi/root/RootInvokeHandler.java
rename to sharding-core/src/main/java/io/shardingsphere/core/spi/root/RootInvokeHook.java
index dd2c284a8910f..c4afa755854a4 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/spi/root/RootInvokeHandler.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/root/RootInvokeHook.java
@@ -18,19 +18,19 @@
package io.shardingsphere.core.spi.root;
/**
- * Root invoke handler.
+ * Root invoke hook.
*
* @author zhangliang
*/
-public interface RootInvokeHandler {
+public interface RootInvokeHook {
/**
- * Start invoke.
+ * Handle when root invoke started.
*/
void start();
/**
- * Finish invoke.
+ * Handle when root invoke finished success.
*/
- void finish();
+ void finishSuccess();
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/root/RootInvokeHandlerLoader.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/root/SPIRootInvokeHook.java
similarity index 52%
rename from sharding-core/src/main/java/io/shardingsphere/core/spi/root/RootInvokeHandlerLoader.java
rename to sharding-core/src/main/java/io/shardingsphere/core/spi/root/SPIRootInvokeHook.java
index 790dc0c3f7632..ac38e9f66da41 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/spi/root/RootInvokeHandlerLoader.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/root/SPIRootInvokeHook.java
@@ -20,44 +20,29 @@
import java.util.ServiceLoader;
/**
- * Root invoke handler loader.
+ * Root invoke hook for SPI.
*
* @author zhangliang
*/
-public final class RootInvokeHandlerLoader {
+public final class SPIRootInvokeHook implements RootInvokeHook {
- private static final RootInvokeHandlerLoader INSTANCE = new RootInvokeHandlerLoader();
+ private static final ServiceLoader SERVICE_LOADER;
- private final ServiceLoader serviceLoader;
-
- private RootInvokeHandlerLoader() {
- serviceLoader = ServiceLoader.load(RootInvokeHandler.class);
- }
-
- /**
- * Get instance.
- *
- * @return instance
- */
- public static RootInvokeHandlerLoader getInstance() {
- return INSTANCE;
+ static {
+ SERVICE_LOADER = ServiceLoader.load(RootInvokeHook.class);
}
- /**
- * Start invoke.
- */
+ @Override
public void start() {
- for (RootInvokeHandler each : serviceLoader) {
+ for (RootInvokeHook each : SERVICE_LOADER) {
each.start();
}
}
- /**
- * Finish invoke.
- */
- public void finish() {
- for (RootInvokeHandler each : serviceLoader) {
- each.finish();
+ @Override
+ public void finishSuccess() {
+ for (RootInvokeHook each : SERVICE_LOADER) {
+ each.finishSuccess();
}
}
}
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/AbstractStatementExecutor.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/AbstractStatementExecutor.java
index d822b7d5aa576..c4ad09731ef4e 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/AbstractStatementExecutor.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/AbstractStatementExecutor.java
@@ -88,9 +88,12 @@ public AbstractStatementExecutor(final int resultSetType, final int resultSetCon
this.resultSetConcurrency = resultSetConcurrency;
this.resultSetHoldability = resultSetHoldability;
this.connection = shardingConnection;
- sqlExecutePrepareTemplate = TransactionType.XA == TransactionTypeHolder.get() ? new SQLExecutePrepareTemplate(connection.getShardingContext().getMaxConnectionsSizePerQuery())
- : new SQLExecutePrepareTemplate(connection.getShardingContext().getMaxConnectionsSizePerQuery(), connection.getShardingContext().getExecuteEngine());
- sqlExecuteTemplate = new SQLExecuteTemplate(connection.getShardingContext().getExecuteEngine());
+ DatabaseType databaseType = connection.getShardingContext().getDatabaseType();
+ int maxConnectionsSizePerQuery = connection.getShardingContext().getMaxConnectionsSizePerQuery();
+ ShardingExecuteEngine executeEngine = connection.getShardingContext().getExecuteEngine();
+ sqlExecutePrepareTemplate = TransactionType.XA == TransactionTypeHolder.get()
+ ? new SQLExecutePrepareTemplate(databaseType, maxConnectionsSizePerQuery) : new SQLExecutePrepareTemplate(databaseType, maxConnectionsSizePerQuery, executeEngine);
+ sqlExecuteTemplate = new SQLExecuteTemplate(executeEngine);
}
protected final void cacheStatements() {
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
index 79af61eb3c92b..4a7219278dda8 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java
@@ -25,12 +25,6 @@
import io.shardingsphere.core.constant.transaction.TransactionOperationType;
import io.shardingsphere.core.constant.transaction.TransactionType;
import io.shardingsphere.core.event.ShardingEventBusInstance;
-import io.shardingsphere.core.spi.event.connection.close.CloseConnectionEventHandlerLoader;
-import io.shardingsphere.core.spi.event.connection.close.CloseConnectionFinishEvent;
-import io.shardingsphere.core.spi.event.connection.close.CloseConnectionStartEvent;
-import io.shardingsphere.core.spi.event.connection.get.GetConnectionEventHandlerLoader;
-import io.shardingsphere.core.spi.event.connection.get.GetConnectionFinishEvent;
-import io.shardingsphere.core.spi.event.connection.get.GetConnectionStartEvent;
import io.shardingsphere.core.event.transaction.xa.XATransactionEvent;
import io.shardingsphere.core.hint.HintManagerHolder;
import io.shardingsphere.core.jdbc.adapter.executor.ForceExecuteCallback;
@@ -38,7 +32,10 @@
import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaDataFactory;
import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager;
-import io.shardingsphere.core.spi.root.RootInvokeHandlerLoader;
+import io.shardingsphere.core.spi.connection.close.CloseConnectionHook;
+import io.shardingsphere.core.spi.connection.close.SPICloseConnectionHook;
+import io.shardingsphere.core.spi.root.RootInvokeHook;
+import io.shardingsphere.core.spi.root.SPIRootInvokeHook;
import io.shardingsphere.core.transaction.TransactionTypeHolder;
import lombok.RequiredArgsConstructor;
@@ -77,7 +74,11 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
private final ForceExecuteTemplate forceExecuteTemplate = new ForceExecuteTemplate<>();
- private final ForceExecuteTemplate> forceExecuteTemplateForClose = new ForceExecuteTemplate<>();
+ private final ForceExecuteTemplate> forceExecuteTemplateForClose = new ForceExecuteTemplate<>();
+
+ private final RootInvokeHook rootInvokeHook = new SPIRootInvokeHook();
+
+ private final CloseConnectionHook closeConnectionHook = new SPICloseConnectionHook();
/**
* Get database connection.
@@ -100,7 +101,6 @@ public final Connection getConnection(final String dataSourceName) throws SQLExc
* @throws SQLException SQL exception
*/
public final List getConnections(final ConnectionMode connectionMode, final String dataSourceName, final int connectionSize) throws SQLException {
- GetConnectionEventHandlerLoader.getInstance().start(new GetConnectionStartEvent(dataSourceName));
DataSource dataSource = getDataSourceMap().get(dataSourceName);
Preconditions.checkState(null != dataSource, "Missing the data source name: '%s'", dataSourceName);
Collection connections;
@@ -124,8 +124,6 @@ public final List getConnections(final ConnectionMode connectionMode
cachedConnections.putAll(dataSourceName, result);
}
}
- GetConnectionEventHandlerLoader.getInstance().finish(
- new GetConnectionFinishEvent(connections.size(), DataSourceMetaDataFactory.newInstance(databaseType, result.get(0).getMetaData().getURL())));
return result;
}
@@ -228,22 +226,19 @@ public final void close() throws SQLException {
@Override
public void execute(final Entry cachedConnections) throws SQLException {
Connection connection = cachedConnections.getValue();
- CloseConnectionEventHandlerLoader.getInstance().start(
- new CloseConnectionStartEvent(cachedConnections.getKey(), DataSourceMetaDataFactory.newInstance(databaseType, connection.getMetaData().getURL())));
- CloseConnectionFinishEvent finishEvent = new CloseConnectionFinishEvent();
+ closeConnectionHook.start(cachedConnections.getKey(), DataSourceMetaDataFactory.newInstance(databaseType, connection.getMetaData().getURL()));
try {
connection.close();
+ closeConnectionHook.finishSuccess();
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
- finishEvent.setException(ex);
+ closeConnectionHook.finishFailure(ex);
throw ex;
- } finally {
- CloseConnectionEventHandlerLoader.getInstance().finish(finishEvent);
}
}
});
- RootInvokeHandlerLoader.getInstance().finish();
+ rootInvokeHook.finishSuccess();
}
@Override
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnection.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnection.java
index e7bde79d0c460..c0ceef129ff06 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnection.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnection.java
@@ -22,7 +22,8 @@
import io.shardingsphere.core.jdbc.core.statement.ShardingPreparedStatement;
import io.shardingsphere.core.jdbc.core.statement.ShardingStatement;
import io.shardingsphere.core.rule.MasterSlaveRule;
-import io.shardingsphere.core.spi.root.RootInvokeHandlerLoader;
+import io.shardingsphere.core.spi.root.RootInvokeHook;
+import io.shardingsphere.core.spi.root.SPIRootInvokeHook;
import lombok.Getter;
import javax.sql.DataSource;
@@ -48,11 +49,13 @@ public final class ShardingConnection extends AbstractConnectionAdapter {
private final ShardingContext shardingContext;
+ private final RootInvokeHook rootInvokeHook = new SPIRootInvokeHook();
+
public ShardingConnection(final Map dataSourceMap, final ShardingContext shardingContext) {
super(shardingContext.getDatabaseType());
this.dataSourceMap = dataSourceMap;
this.shardingContext = shardingContext;
- RootInvokeHandlerLoader.getInstance().start();
+ rootInvokeHook.start();
}
/**
diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/cases/assertion/IntegrateTestCasesLoader.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/cases/assertion/IntegrateTestCasesLoader.java
index 9c0f94b4cee43..ac7c956383ea5 100644
--- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/cases/assertion/IntegrateTestCasesLoader.java
+++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/cases/assertion/IntegrateTestCasesLoader.java
@@ -163,7 +163,7 @@ public DQLIntegrateTestCase getDQLIntegrateTestCase(final String sqlCaseId) {
// Preconditions.checkState(dqlIntegrateTestCaseMap.containsKey(sqlCaseId), "Can't find SQL of id: " + sqlCaseId);
// TODO remove when transfer finished
if (!dqlIntegrateTestCaseMap.containsKey(sqlCaseId)) {
- log.warn("Have not finish case `{}`", sqlCaseId);
+ log.warn("Have not finishSuccess case `{}`", sqlCaseId);
}
return (DQLIntegrateTestCase) dqlIntegrateTestCaseMap.get(sqlCaseId);
}
@@ -179,7 +179,7 @@ public DMLIntegrateTestCase getDMLIntegrateTestCase(final String sqlCaseId) {
// Preconditions.checkState(dmlIntegrateTestCaseMap.containsKey(sqlCaseId), "Can't find SQL of id: " + sqlCaseId);
// TODO remove when transfer finished
if (!dmlIntegrateTestCaseMap.containsKey(sqlCaseId)) {
- log.warn("Have not finish case `{}`", sqlCaseId);
+ log.warn("Have not finishSuccess case `{}`", sqlCaseId);
}
return (DMLIntegrateTestCase) dmlIntegrateTestCaseMap.get(sqlCaseId);
}
@@ -195,7 +195,7 @@ public DDLIntegrateTestCase getDDLIntegrateTestCase(final String sqlCaseId) {
// Preconditions.checkState(ddlIntegrateTestCaseMap.containsKey(sqlCaseId), "Can't find SQL of id: " + sqlCaseId);
// TODO remove when transfer finished
if (!ddlIntegrateTestCaseMap.containsKey(sqlCaseId)) {
- log.warn("Have not finish case `{}`", sqlCaseId);
+ log.warn("Have not finishSuccess case `{}`", sqlCaseId);
}
return (DDLIntegrateTestCase) ddlIntegrateTestCaseMap.get(sqlCaseId);
}
@@ -211,7 +211,7 @@ public DCLIntegrateTestCase getDCLIntegrateTestCase(final String sqlCaseId) {
// Preconditions.checkState(ddlIntegrateTestCaseMap.containsKey(sqlCaseId), "Can't find SQL of id: " + sqlCaseId);
// TODO remove when transfer finished
if (!dclIntegrateTestCaseMap.containsKey(sqlCaseId)) {
- log.warn("Have not finish case `{}`", sqlCaseId);
+ log.warn("Have not finishSuccess case `{}`", sqlCaseId);
}
return (DCLIntegrateTestCase) dclIntegrateTestCaseMap.get(sqlCaseId);
}
diff --git a/sharding-opentracing/src/main/java/io/shardingsphere/opentracing/handler/connection/OpenTracingCloseConnectionEventHandler.java b/sharding-opentracing/src/main/java/io/shardingsphere/opentracing/handler/connection/OpenTracingCloseConnectionEventHandler.java
deleted file mode 100644
index 3df05fa91a41f..0000000000000
--- a/sharding-opentracing/src/main/java/io/shardingsphere/opentracing/handler/connection/OpenTracingCloseConnectionEventHandler.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * 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.
- *
- * 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.
- *
- * 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.
- *
- * 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.
- *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ */
+
+package io.shardingsphere.opentracing.handler.tracing.parsing;
+
+import io.opentracing.Span;
+import io.opentracing.Tracer.SpanBuilder;
+import io.opentracing.tag.Tags;
+import io.shardingsphere.core.spi.parsing.ParsingHook;
+import io.shardingsphere.opentracing.constant.ShardingTags;
+import io.shardingsphere.opentracing.handler.tracing.OpenTracingHandlerTemplate;
+import io.shardingsphere.opentracing.handler.tracing.OpenTracingSpanFinishCallbackAdapter;
+import io.shardingsphere.opentracing.handler.tracing.OpenTracingSpanStartCallback;
+
+/**
+ * Open tracing parsing hook.
+ *
+ * @author zhangliang
+ */
+public final class OpenTracingParsingHook implements ParsingHook {
+
+ private static final String OPERATION_NAME = "/" + ShardingTags.COMPONENT_NAME + "/parseSQL/";
+
+ private final OpenTracingHandlerTemplate handlerTemplate = new OpenTracingHandlerTemplate(OPERATION_NAME);
+
+ @Override
+ public void start(final String sql) {
+ handlerTemplate.start(new OpenTracingSpanStartCallback() {
+
+ @Override
+ public Span initSpan(final SpanBuilder spanBuilder) {
+ return spanBuilder.withTag(Tags.DB_STATEMENT.getKey(), sql).startManual();
+ }
+ });
+ }
+
+ @Override
+ public void finishSuccess() {
+ handlerTemplate.finishSuccess(new OpenTracingSpanFinishCallbackAdapter());
+ }
+
+ @Override
+ public void finishFailure(final Exception cause) {
+ handlerTemplate.finishFailure(cause, new OpenTracingSpanFinishCallbackAdapter());
+ }
+}
diff --git a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.connection.close.CloseConnectionHook b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.connection.close.CloseConnectionHook
new file mode 100644
index 0000000000000..e951760c43422
--- /dev/null
+++ b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.connection.close.CloseConnectionHook
@@ -0,0 +1 @@
+io.shardingsphere.opentracing.handler.tracing.connection.OpenTracingCloseConnectionHook
diff --git a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.connection.get.GetConnectionHook b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.connection.get.GetConnectionHook
new file mode 100644
index 0000000000000..c5002654e8ed3
--- /dev/null
+++ b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.connection.get.GetConnectionHook
@@ -0,0 +1 @@
+io.shardingsphere.opentracing.handler.tracing.connection.OpenTracingGetConnectionHook
diff --git a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.connection.close.CloseConnectionEventHandler b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.connection.close.CloseConnectionEventHandler
deleted file mode 100644
index 7a469b59afc23..0000000000000
--- a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.connection.close.CloseConnectionEventHandler
+++ /dev/null
@@ -1 +0,0 @@
-io.shardingsphere.opentracing.handler.connection.OpenTracingCloseConnectionEventHandler
diff --git a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.connection.get.GetConnectionEventHandler b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.connection.get.GetConnectionEventHandler
deleted file mode 100644
index 058abad3bae57..0000000000000
--- a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.connection.get.GetConnectionEventHandler
+++ /dev/null
@@ -1 +0,0 @@
-io.shardingsphere.opentracing.handler.connection.OpenTracingGetConnectionEventHandler
diff --git a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.executor.SQLExecutionEventHandler b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.executor.SQLExecutionEventHandler
deleted file mode 100644
index 29b8f0ba748a3..0000000000000
--- a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.executor.SQLExecutionEventHandler
+++ /dev/null
@@ -1 +0,0 @@
-io.shardingsphere.opentracing.handler.executor.OpenTracingSQLExecutionEventHandler
diff --git a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.parsing.ParsingEventHandler b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.parsing.ParsingEventHandler
deleted file mode 100644
index cc968b7cacc0f..0000000000000
--- a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.event.parsing.ParsingEventHandler
+++ /dev/null
@@ -1 +0,0 @@
-io.shardingsphere.opentracing.handler.parsing.OpenTracingParsingEventHandler
diff --git a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.executor.SQLExecutionHook b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.executor.SQLExecutionHook
new file mode 100644
index 0000000000000..4102fbd9efacd
--- /dev/null
+++ b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.executor.SQLExecutionHook
@@ -0,0 +1 @@
+io.shardingsphere.opentracing.handler.tracing.executor.OpenTracingSQLExecutionHook
diff --git a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.parsing.ParsingHook b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.parsing.ParsingHook
new file mode 100644
index 0000000000000..35beb2ec30c9c
--- /dev/null
+++ b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.parsing.ParsingHook
@@ -0,0 +1 @@
+io.shardingsphere.opentracing.handler.tracing.parsing.OpenTracingParsingHook
diff --git a/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.root.RootInvokeHandler b/sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.root.RootInvokeHook
similarity index 100%
rename from sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.root.RootInvokeHandler
rename to sharding-opentracing/src/main/resources/META-INF/services/io.shardingsphere.core.spi.root.RootInvokeHook
diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/AllHandlerTests.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/AllHandlerTests.java
index 77de7ab38a860..2c23c97ed7287 100644
--- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/AllHandlerTests.java
+++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/AllHandlerTests.java
@@ -17,10 +17,10 @@
package io.shardingsphere.opentracing.handler;
-import io.shardingsphere.opentracing.handler.connection.OpenTracingCloseConnectionEventHandlerTest;
-import io.shardingsphere.opentracing.handler.connection.OpenTracingGetConnectionEventHandlerTest;
-import io.shardingsphere.opentracing.handler.executor.OpenTracingSQLExecutionEventHandlerTest;
-import io.shardingsphere.opentracing.handler.parsing.OpenTracingParsingEventHandlerTest;
+import io.shardingsphere.opentracing.handler.tracing.connection.OpenTracingCloseConnectionEventHandlerTest;
+import io.shardingsphere.opentracing.handler.tracing.connection.OpenTracingGetConnectionEventHandlerTest;
+import io.shardingsphere.opentracing.handler.tracing.executor.OpenTracingSQLExecutionEventHandlerTest;
+import io.shardingsphere.opentracing.handler.tracing.parsing.OpenTracingParsingEventHandlerTest;
import io.shardingsphere.opentracing.handler.root.OpenTracingRootInvokeHandlerTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/root/OpenTracingRootInvokeHandlerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/root/OpenTracingRootInvokeHandlerTest.java
index 6b762bc883c46..b3314c16647fb 100644
--- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/root/OpenTracingRootInvokeHandlerTest.java
+++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/root/OpenTracingRootInvokeHandlerTest.java
@@ -18,7 +18,8 @@
package io.shardingsphere.opentracing.handler.root;
import io.shardingsphere.core.executor.sql.execute.threadlocal.ExecutorDataMap;
-import io.shardingsphere.core.spi.root.RootInvokeHandlerLoader;
+import io.shardingsphere.core.spi.root.RootInvokeHook;
+import io.shardingsphere.core.spi.root.SPIRootInvokeHook;
import io.shardingsphere.opentracing.handler.BaseOpenTracingHandlerTest;
import org.junit.Test;
@@ -29,15 +30,15 @@
public final class OpenTracingRootInvokeHandlerTest extends BaseOpenTracingHandlerTest {
- private final RootInvokeHandlerLoader loader = RootInvokeHandlerLoader.getInstance();
+ private final RootInvokeHook rootInvokeHook = new SPIRootInvokeHook();
@Test
public void assertRootInvoke() {
- loader.start();
+ rootInvokeHook.start();
assertTrue(OpenTracingRootInvokeHandler.isTrunkThread());
assertNotNull(OpenTracingRootInvokeHandler.getActiveSpan().get());
assertTrue(ExecutorDataMap.getDataMap().containsKey(OpenTracingRootInvokeHandler.ROOT_SPAN_CONTINUATION));
- loader.finish();
+ rootInvokeHook.finishSuccess();
assertFalse(OpenTracingRootInvokeHandler.isTrunkThread());
assertNull(OpenTracingRootInvokeHandler.getActiveSpan().get());
}
diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/connection/OpenTracingCloseConnectionEventHandlerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/connection/OpenTracingCloseConnectionEventHandlerTest.java
similarity index 79%
rename from sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/connection/OpenTracingCloseConnectionEventHandlerTest.java
rename to sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/connection/OpenTracingCloseConnectionEventHandlerTest.java
index d4d8eb66fe8b0..5c4755ca311e1 100644
--- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/connection/OpenTracingCloseConnectionEventHandlerTest.java
+++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/connection/OpenTracingCloseConnectionEventHandlerTest.java
@@ -15,14 +15,13 @@
*
*/
-package io.shardingsphere.opentracing.handler.connection;
+package io.shardingsphere.opentracing.handler.tracing.connection;
import io.opentracing.mock.MockSpan;
import io.opentracing.tag.Tags;
-import io.shardingsphere.core.spi.event.connection.close.CloseConnectionEventHandlerLoader;
-import io.shardingsphere.core.spi.event.connection.close.CloseConnectionFinishEvent;
-import io.shardingsphere.core.spi.event.connection.close.CloseConnectionStartEvent;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
+import io.shardingsphere.core.spi.connection.close.CloseConnectionHook;
+import io.shardingsphere.core.spi.connection.close.SPICloseConnectionHook;
import io.shardingsphere.opentracing.constant.ShardingTags;
import io.shardingsphere.opentracing.handler.BaseOpenTracingHandlerTest;
import org.hamcrest.CoreMatchers;
@@ -37,15 +36,15 @@
public final class OpenTracingCloseConnectionEventHandlerTest extends BaseOpenTracingHandlerTest {
- private final CloseConnectionEventHandlerLoader loader = CloseConnectionEventHandlerLoader.getInstance();
+ private final CloseConnectionHook closeConnectionHook = new SPICloseConnectionHook();
@Test
public void assertExecuteSuccess() {
DataSourceMetaData dataSourceMetaData = mock(DataSourceMetaData.class);
when(dataSourceMetaData.getHostName()).thenReturn("localhost");
when(dataSourceMetaData.getPort()).thenReturn(8888);
- loader.start(new CloseConnectionStartEvent("test_ds_name", dataSourceMetaData));
- loader.finish(new CloseConnectionFinishEvent());
+ closeConnectionHook.start("test_ds_name", dataSourceMetaData);
+ closeConnectionHook.finishSuccess();
assertThat(getTracer().finishedSpans().size(), is(1));
MockSpan actual = getTracer().finishedSpans().get(0);
assertThat(actual.operationName(), is("/Sharding-Sphere/closeConnection/"));
@@ -62,10 +61,8 @@ public void assertExecuteFailure() {
DataSourceMetaData dataSourceMetaData = mock(DataSourceMetaData.class);
when(dataSourceMetaData.getHostName()).thenReturn("localhost");
when(dataSourceMetaData.getPort()).thenReturn(8888);
- loader.start(new CloseConnectionStartEvent("test_ds_name", dataSourceMetaData));
- CloseConnectionFinishEvent finishEvent = new CloseConnectionFinishEvent();
- finishEvent.setException(new RuntimeException("close connection error"));
- loader.finish(finishEvent);
+ closeConnectionHook.start("test_ds_name", dataSourceMetaData);
+ closeConnectionHook.finishFailure(new RuntimeException("close connection error"));
assertThat(getTracer().finishedSpans().size(), is(1));
MockSpan actual = getTracer().finishedSpans().get(0);
assertThat(actual.operationName(), is("/Sharding-Sphere/closeConnection/"));
diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/connection/OpenTracingGetConnectionEventHandlerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/connection/OpenTracingGetConnectionEventHandlerTest.java
similarity index 82%
rename from sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/connection/OpenTracingGetConnectionEventHandlerTest.java
rename to sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/connection/OpenTracingGetConnectionEventHandlerTest.java
index dbb0c21eb8866..49757df7d09b0 100644
--- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/connection/OpenTracingGetConnectionEventHandlerTest.java
+++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/connection/OpenTracingGetConnectionEventHandlerTest.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.opentracing.handler.connection;
+package io.shardingsphere.opentracing.handler.tracing.connection;
import io.opentracing.ActiveSpan;
import io.opentracing.ActiveSpan.Continuation;
@@ -23,9 +23,8 @@
import io.opentracing.tag.Tags;
import io.shardingsphere.core.executor.sql.execute.threadlocal.ExecutorDataMap;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
-import io.shardingsphere.core.spi.event.connection.get.GetConnectionEventHandlerLoader;
-import io.shardingsphere.core.spi.event.connection.get.GetConnectionFinishEvent;
-import io.shardingsphere.core.spi.event.connection.get.GetConnectionStartEvent;
+import io.shardingsphere.core.spi.connection.get.GetConnectionHook;
+import io.shardingsphere.core.spi.connection.get.SPIGetConnectionHook;
import io.shardingsphere.opentracing.constant.ShardingTags;
import io.shardingsphere.opentracing.handler.BaseOpenTracingHandlerTest;
import io.shardingsphere.opentracing.handler.root.OpenTracingRootInvokeHandler;
@@ -44,16 +43,16 @@
public final class OpenTracingGetConnectionEventHandlerTest extends BaseOpenTracingHandlerTest {
- private final GetConnectionEventHandlerLoader loader = GetConnectionEventHandlerLoader.getInstance();
+ private final GetConnectionHook getConnectionHook = new SPIGetConnectionHook();
@Test
public void assertExecuteSuccessTrunkThread() {
new OpenTracingRootInvokeHandler().start();
- loader.start(new GetConnectionStartEvent("test_ds_name"));
+ getConnectionHook.start("test_ds_name");
DataSourceMetaData dataSourceMetaData = mock(DataSourceMetaData.class);
when(dataSourceMetaData.getHostName()).thenReturn("localhost");
when(dataSourceMetaData.getPort()).thenReturn(8888);
- loader.finish(new GetConnectionFinishEvent(3, dataSourceMetaData));
+ getConnectionHook.finishSuccess(dataSourceMetaData, 3);
assertThat(getTracer().finishedSpans().size(), is(1));
MockSpan actual = getTracer().finishedSpans().get(0);
assertThat(actual.operationName(), is("/Sharding-Sphere/getConnection/"));
@@ -64,7 +63,7 @@ public void assertExecuteSuccessTrunkThread() {
assertThat(actualTags.get(Tags.PEER_HOSTNAME.getKey()), CoreMatchers.is("localhost"));
assertThat(actualTags.get(Tags.PEER_PORT.getKey()), CoreMatchers.is(8888));
assertThat(actualTags.get(ShardingTags.CONNECTION_COUNT.getKey()), CoreMatchers.is(3));
- new OpenTracingRootInvokeHandler().finish();
+ new OpenTracingRootInvokeHandler().finishSuccess();
}
@Test
@@ -73,12 +72,12 @@ public void assertExecuteSuccessBranchThread() {
ActiveSpan activeSpan = mock(ActiveSpan.class);
when(activeSpanContinuation.activate()).thenReturn(activeSpan);
ExecutorDataMap.getDataMap().put(OpenTracingRootInvokeHandler.ROOT_SPAN_CONTINUATION, activeSpanContinuation);
- loader.start(new GetConnectionStartEvent("test_ds_name"));
+ getConnectionHook.start("test_ds_name");
assertNotNull(OpenTracingRootInvokeHandler.getActiveSpan().get());
DataSourceMetaData dataSourceMetaData = mock(DataSourceMetaData.class);
when(dataSourceMetaData.getHostName()).thenReturn("localhost");
when(dataSourceMetaData.getPort()).thenReturn(8888);
- loader.finish(new GetConnectionFinishEvent(3, dataSourceMetaData));
+ getConnectionHook.finishSuccess(dataSourceMetaData, 3);
assertThat(getTracer().finishedSpans().size(), is(1));
MockSpan actual = getTracer().finishedSpans().get(0);
assertThat(actual.operationName(), is("/Sharding-Sphere/getConnection/"));
@@ -96,10 +95,8 @@ public void assertExecuteSuccessBranchThread() {
@Test
public void assertExecuteFailure() {
new OpenTracingRootInvokeHandler().start();
- loader.start(new GetConnectionStartEvent("test_ds_name"));
- GetConnectionFinishEvent finishEvent = new GetConnectionFinishEvent(3, null);
- finishEvent.setException(new RuntimeException("get connection error"));
- loader.finish(finishEvent);
+ getConnectionHook.start("test_ds_name");
+ getConnectionHook.finishFailure(new RuntimeException("get connection error"));
assertThat(getTracer().finishedSpans().size(), is(1));
MockSpan actual = getTracer().finishedSpans().get(0);
assertThat(actual.operationName(), is("/Sharding-Sphere/getConnection/"));
@@ -107,6 +104,6 @@ public void assertExecuteFailure() {
assertThat(actualTags.get(Tags.COMPONENT.getKey()), CoreMatchers.is(ShardingTags.COMPONENT_NAME));
assertThat(actualTags.get(Tags.SPAN_KIND.getKey()), CoreMatchers.is(Tags.SPAN_KIND_CLIENT));
assertSpanError(actual, RuntimeException.class, "get connection error");
- new OpenTracingRootInvokeHandler().finish();
+ new OpenTracingRootInvokeHandler().finishSuccess();
}
}
diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/executor/OpenTracingSQLExecutionEventHandlerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/executor/OpenTracingSQLExecutionEventHandlerTest.java
similarity index 85%
rename from sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/executor/OpenTracingSQLExecutionEventHandlerTest.java
rename to sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/executor/OpenTracingSQLExecutionEventHandlerTest.java
index e5b2ed7abdd23..8968e88cf0ee4 100644
--- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/executor/OpenTracingSQLExecutionEventHandlerTest.java
+++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/executor/OpenTracingSQLExecutionEventHandlerTest.java
@@ -15,19 +15,18 @@
*
*/
-package io.shardingsphere.opentracing.handler.executor;
+package io.shardingsphere.opentracing.handler.tracing.executor;
import io.opentracing.ActiveSpan;
import io.opentracing.ActiveSpan.Continuation;
import io.opentracing.mock.MockSpan;
import io.opentracing.tag.Tags;
-import io.shardingsphere.core.spi.event.executor.SQLExecutionEventHandlerLoader;
-import io.shardingsphere.core.spi.event.executor.SQLExecutionFinishEvent;
-import io.shardingsphere.core.spi.event.executor.SQLExecutionStartEvent;
import io.shardingsphere.core.executor.sql.execute.threadlocal.ExecutorDataMap;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaData;
import io.shardingsphere.core.routing.RouteUnit;
import io.shardingsphere.core.routing.SQLUnit;
+import io.shardingsphere.core.spi.executor.SPISQLExecutionHook;
+import io.shardingsphere.core.spi.executor.SQLExecutionHook;
import io.shardingsphere.opentracing.constant.ShardingTags;
import io.shardingsphere.opentracing.handler.BaseOpenTracingHandlerTest;
import io.shardingsphere.opentracing.handler.root.OpenTracingRootInvokeHandler;
@@ -49,7 +48,7 @@
public final class OpenTracingSQLExecutionEventHandlerTest extends BaseOpenTracingHandlerTest {
- private final SQLExecutionEventHandlerLoader loader = SQLExecutionEventHandlerLoader.getInstance();
+ private final SQLExecutionHook sqlExecutionHook = new SPISQLExecutionHook();
@Test
public void assertExecuteSuccessForTrunkThread() {
@@ -58,8 +57,8 @@ public void assertExecuteSuccessForTrunkThread() {
when(dataSourceMetaData.getHostName()).thenReturn("localhost");
when(dataSourceMetaData.getPort()).thenReturn(8888);
SQLUnit sqlUnit = new SQLUnit("SELECT * FROM XXX;", Collections.>emptyList());
- loader.start(new SQLExecutionStartEvent(new RouteUnit("ds_test", sqlUnit), Arrays.asList("1", 2), dataSourceMetaData));
- loader.finish(new SQLExecutionFinishEvent());
+ sqlExecutionHook.start(new RouteUnit("ds_test", sqlUnit), Arrays.asList("1", 2), dataSourceMetaData);
+ sqlExecutionHook.finishSuccess();
assertThat(getTracer().finishedSpans().size(), is(1));
MockSpan actual = getTracer().finishedSpans().get(0);
assertThat(actual.operationName(), is("/Sharding-Sphere/executeSQL/"));
@@ -72,7 +71,7 @@ public void assertExecuteSuccessForTrunkThread() {
assertThat(actualTags.get(Tags.DB_INSTANCE.getKey()), CoreMatchers.is("ds_test"));
assertThat(actualTags.get(Tags.DB_STATEMENT.getKey()), CoreMatchers.is("SELECT * FROM XXX;"));
assertThat(actualTags.get(ShardingTags.DB_BIND_VARIABLES.getKey()), CoreMatchers.is("1,2"));
- new OpenTracingRootInvokeHandler().finish();
+ new OpenTracingRootInvokeHandler().finishSuccess();
}
@Test
@@ -85,9 +84,9 @@ public void assertExecuteSuccessForBranchThread() {
when(dataSourceMetaData.getHostName()).thenReturn("localhost");
when(dataSourceMetaData.getPort()).thenReturn(8888);
SQLUnit sqlUnit = new SQLUnit("SELECT * FROM XXX;", Collections.>emptyList());
- loader.start(new SQLExecutionStartEvent(new RouteUnit("ds_test", sqlUnit), Arrays.asList("1", 2), dataSourceMetaData));
+ sqlExecutionHook.start(new RouteUnit("ds_test", sqlUnit), Arrays.asList("1", 2), dataSourceMetaData);
assertNotNull(OpenTracingRootInvokeHandler.getActiveSpan().get());
- loader.finish(new SQLExecutionFinishEvent());
+ sqlExecutionHook.finishSuccess();
assertThat(getTracer().finishedSpans().size(), is(1));
MockSpan actual = getTracer().finishedSpans().get(0);
assertThat(actual.operationName(), is("/Sharding-Sphere/executeSQL/"));
@@ -111,10 +110,8 @@ public void assertExecuteFailure() {
when(dataSourceMetaData.getHostName()).thenReturn("localhost");
when(dataSourceMetaData.getPort()).thenReturn(8888);
SQLUnit sqlUnit = new SQLUnit("SELECT * FROM XXX;", Collections.>emptyList());
- loader.start(new SQLExecutionStartEvent(new RouteUnit("ds_test", sqlUnit), Collections.emptyList(), dataSourceMetaData));
- SQLExecutionFinishEvent finishEvent = new SQLExecutionFinishEvent();
- finishEvent.setException(new RuntimeException("SQL execution error"));
- loader.finish(finishEvent);
+ sqlExecutionHook.start(new RouteUnit("ds_test", sqlUnit), Collections.emptyList(), dataSourceMetaData);
+ sqlExecutionHook.finishFailure(new RuntimeException("SQL execution error"));
assertThat(getTracer().finishedSpans().size(), is(1));
MockSpan actual = getTracer().finishedSpans().get(0);
assertThat(actual.operationName(), is("/Sharding-Sphere/executeSQL/"));
@@ -128,6 +125,6 @@ public void assertExecuteFailure() {
assertThat(actualTags.get(Tags.DB_STATEMENT.getKey()), CoreMatchers.is("SELECT * FROM XXX;"));
assertThat(actualTags.get(ShardingTags.DB_BIND_VARIABLES.getKey()), CoreMatchers.is(""));
assertSpanError(actual, RuntimeException.class, "SQL execution error");
- new OpenTracingRootInvokeHandler().finish();
+ new OpenTracingRootInvokeHandler().finishSuccess();
}
}
diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/parsing/OpenTracingParsingEventHandlerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/parsing/OpenTracingParsingEventHandlerTest.java
similarity index 77%
rename from sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/parsing/OpenTracingParsingEventHandlerTest.java
rename to sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/parsing/OpenTracingParsingEventHandlerTest.java
index fc8dfc249292e..29d4dcd105df7 100644
--- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/parsing/OpenTracingParsingEventHandlerTest.java
+++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/handler/tracing/parsing/OpenTracingParsingEventHandlerTest.java
@@ -15,14 +15,13 @@
*
*/
-package io.shardingsphere.opentracing.handler.parsing;
+package io.shardingsphere.opentracing.handler.tracing.parsing;
import io.opentracing.mock.MockSpan;
import io.opentracing.tag.Tags;
-import io.shardingsphere.core.spi.event.parsing.ParsingEventHandlerLoader;
-import io.shardingsphere.core.spi.event.parsing.ParsingFinishEvent;
-import io.shardingsphere.core.spi.event.parsing.ParsingStartEvent;
import io.shardingsphere.core.exception.ShardingException;
+import io.shardingsphere.core.spi.parsing.ParsingHook;
+import io.shardingsphere.core.spi.parsing.SPIParsingHook;
import io.shardingsphere.opentracing.constant.ShardingTags;
import io.shardingsphere.opentracing.handler.BaseOpenTracingHandlerTest;
import org.hamcrest.CoreMatchers;
@@ -35,12 +34,12 @@
public final class OpenTracingParsingEventHandlerTest extends BaseOpenTracingHandlerTest {
- private final ParsingEventHandlerLoader loader = ParsingEventHandlerLoader.getInstance();
+ private final ParsingHook parsingHook = new SPIParsingHook();
@Test
public void assertExecuteSuccess() {
- loader.start(new ParsingStartEvent("SELECT * FROM XXX;"));
- loader.finish(new ParsingFinishEvent());
+ parsingHook.start("SELECT * FROM XXX;");
+ parsingHook.finishSuccess();
assertThat(getTracer().finishedSpans().size(), is(1));
MockSpan actual = getTracer().finishedSpans().get(0);
assertThat(actual.operationName(), is("/Sharding-Sphere/parseSQL/"));
@@ -52,10 +51,8 @@ public void assertExecuteSuccess() {
@Test
public void assertExecuteFailure() {
- loader.start(new ParsingStartEvent("SELECT * FROM XXX;"));
- ParsingFinishEvent finishEvent = new ParsingFinishEvent();
- finishEvent.setException(new ShardingException("parse SQL error"));
- loader.finish(finishEvent);
+ parsingHook.start("SELECT * FROM XXX;");
+ parsingHook.finishFailure(new ShardingException("parse SQL error"));
assertThat(getTracer().finishedSpans().size(), is(1));
MockSpan actual = getTracer().finishedSpans().get(0);
assertThat(actual.operationName(), is("/Sharding-Sphere/parseSQL/"));
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/connection/BackendConnection.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/connection/BackendConnection.java
index bf6955f6dd106..5c4a161f87fc8 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/connection/BackendConnection.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/connection/BackendConnection.java
@@ -19,14 +19,10 @@
import io.shardingsphere.core.constant.ConnectionMode;
import io.shardingsphere.core.constant.DatabaseType;
-import io.shardingsphere.core.spi.event.connection.close.CloseConnectionEventHandlerLoader;
-import io.shardingsphere.core.spi.event.connection.close.CloseConnectionFinishEvent;
-import io.shardingsphere.core.spi.event.connection.close.CloseConnectionStartEvent;
-import io.shardingsphere.core.spi.event.connection.get.GetConnectionEventHandlerLoader;
-import io.shardingsphere.core.spi.event.connection.get.GetConnectionFinishEvent;
-import io.shardingsphere.core.spi.event.connection.get.GetConnectionStartEvent;
import io.shardingsphere.core.metadata.datasource.DataSourceMetaDataFactory;
import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager;
+import io.shardingsphere.core.spi.connection.close.CloseConnectionHook;
+import io.shardingsphere.core.spi.connection.close.SPICloseConnectionHook;
import io.shardingsphere.proxy.config.RuleRegistry;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -60,6 +56,8 @@ public final class BackendConnection implements AutoCloseable {
private final Collection cachedResultSets = new CopyOnWriteArrayList<>();
+ private final CloseConnectionHook closeConnectionHook = new SPICloseConnectionHook();
+
/**
* Get connections of current thread datasource.
*
@@ -70,21 +68,9 @@ public final class BackendConnection implements AutoCloseable {
* @throws SQLException SQL exception
*/
public List getConnections(final ConnectionMode connectionMode, final String dataSourceName, final int connectionSize) throws SQLException {
- try {
- GetConnectionEventHandlerLoader.getInstance().start(new GetConnectionStartEvent(dataSourceName));
- List result = ruleRegistry.getBackendDataSource().getConnections(connectionMode, dataSourceName, connectionSize);
- cachedConnections.addAll(result);
- GetConnectionEventHandlerLoader.getInstance().finish(
- new GetConnectionFinishEvent(result.size(), DataSourceMetaDataFactory.newInstance(DatabaseType.MySQL, result.get(0).getMetaData().getURL())));
- return result;
- // CHECKSTYLE:OFF
- } catch (final Exception ex) {
- // CHECKSTYLE:ON
- GetConnectionFinishEvent finishEvent = new GetConnectionFinishEvent(0, null);
- finishEvent.setException(ex);
- GetConnectionEventHandlerLoader.getInstance().finish(finishEvent);
- throw ex;
- }
+ List result = ruleRegistry.getBackendDataSource().getConnections(connectionMode, dataSourceName, connectionSize);
+ cachedConnections.addAll(result);
+ return result;
}
/**
@@ -154,16 +140,13 @@ private Collection closeStatements() {
private Collection closeConnections() {
Collection result = new LinkedList<>();
for (Connection each : cachedConnections) {
- CloseConnectionFinishEvent finishEvent = new CloseConnectionFinishEvent();
try {
- CloseConnectionEventHandlerLoader.getInstance().start(
- new CloseConnectionStartEvent(each.getCatalog(), DataSourceMetaDataFactory.newInstance(DatabaseType.MySQL, each.getMetaData().getURL())));
+ closeConnectionHook.start(each.getCatalog(), DataSourceMetaDataFactory.newInstance(DatabaseType.MySQL, each.getMetaData().getURL()));
each.close();
+ closeConnectionHook.finishSuccess();
} catch (SQLException ex) {
- finishEvent.setException(ex);
+ closeConnectionHook.finishFailure(ex);
result.add(ex);
- } finally {
- CloseConnectionEventHandlerLoader.getInstance().finish(finishEvent);
}
}
return result;
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngine.java
index f820e4784b914..7d81d5defcd2f 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngine.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngine.java
@@ -21,6 +21,7 @@
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.constant.SQLType;
import io.shardingsphere.core.constant.transaction.TransactionType;
+import io.shardingsphere.core.executor.ShardingExecuteEngine;
import io.shardingsphere.core.executor.ShardingExecuteGroup;
import io.shardingsphere.core.executor.StatementExecuteUnit;
import io.shardingsphere.core.executor.sql.execute.SQLExecuteCallback;
@@ -97,9 +98,12 @@ public final class JDBCExecuteEngine implements SQLExecuteEngine {
public JDBCExecuteEngine(final BackendConnection backendConnection, final JDBCExecutorWrapper jdbcExecutorWrapper) {
this.backendConnection = backendConnection;
this.jdbcExecutorWrapper = jdbcExecutorWrapper;
- sqlExecutePrepareTemplate = TransactionType.XA == ProxyContext.getInstance().getTransactionType() ? new SQLExecutePrepareTemplate(ProxyContext.getInstance().getMaxConnectionsSizePerQuery())
- : new SQLExecutePrepareTemplate(ProxyContext.getInstance().getMaxConnectionsSizePerQuery(), BackendExecutorContext.getInstance().getExecuteEngine());
- sqlExecuteTemplate = new SQLExecuteTemplate(BackendExecutorContext.getInstance().getExecuteEngine());
+ DatabaseType databaseType = DatabaseType.MySQL;
+ int maxConnectionsSizePerQuery = ProxyContext.getInstance().getMaxConnectionsSizePerQuery();
+ ShardingExecuteEngine executeEngine = BackendExecutorContext.getInstance().getExecuteEngine();
+ sqlExecutePrepareTemplate = TransactionType.XA == ProxyContext.getInstance().getTransactionType()
+ ? new SQLExecutePrepareTemplate(databaseType, maxConnectionsSizePerQuery) : new SQLExecutePrepareTemplate(databaseType, maxConnectionsSizePerQuery, executeEngine);
+ sqlExecuteTemplate = new SQLExecuteTemplate(executeEngine);
}
@SuppressWarnings("unchecked")
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/mysql/MySQLFrontendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/mysql/MySQLFrontendHandler.java
index 361e15989b4d1..6ddf719de9ad7 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/mysql/MySQLFrontendHandler.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/mysql/MySQLFrontendHandler.java
@@ -22,7 +22,8 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.EventLoopGroup;
-import io.shardingsphere.core.spi.root.RootInvokeHandlerLoader;
+import io.shardingsphere.core.spi.root.RootInvokeHook;
+import io.shardingsphere.core.spi.root.SPIRootInvokeHook;
import io.shardingsphere.proxy.backend.jdbc.connection.BackendConnection;
import io.shardingsphere.proxy.config.ProxyContext;
import io.shardingsphere.proxy.frontend.common.FrontendHandler;
@@ -60,6 +61,8 @@ public final class MySQLFrontendHandler extends FrontendHandler {
private final AuthorityHandler authorityHandler = new AuthorityHandler();
+ private final RootInvokeHook rootInvokeHook = new SPIRootInvokeHook();
+
@Override
protected void handshake(final ChannelHandlerContext context) {
int connectionId = ConnectionIdGenerator.getInstance().nextId();
@@ -113,7 +116,7 @@ class CommandExecutor implements Runnable {
@Override
public void run() {
- RootInvokeHandlerLoader.getInstance().start();
+ rootInvokeHook.start();
try (MySQLPacketPayload payload = new MySQLPacketPayload(message);
BackendConnection backendConnection = new BackendConnection()) {
setBackendConnection(backendConnection);
@@ -135,7 +138,7 @@ public void run() {
// CHECKSTYLE:ON
context.writeAndFlush(new ErrPacket(1, ServerErrorCode.ER_STD_UNKNOWN_EXCEPTION, ex.getMessage()));
}
- RootInvokeHandlerLoader.getInstance().finish();
+ rootInvokeHook.finishSuccess();
}
private CommandPacket getCommandPacket(final MySQLPacketPayload payload, final BackendConnection backendConnection, final FrontendHandler frontendHandler) throws SQLException {