- * 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.
- *
- */
- METRICS_MILLISECONDS_PERIOD("metrics.millisecond.period", "30000", long.class),
-
/**
* Worker thread max size.
*
diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/batch/BatchPreparedStatementExecutor.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/batch/BatchPreparedStatementExecutor.java
index 5535888393d712ffa9a42497be1c035358730e84..97683a490c6beb531bd279b7a804c9bc238a3d19 100644
--- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/batch/BatchPreparedStatementExecutor.java
+++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/batch/BatchPreparedStatementExecutor.java
@@ -17,13 +17,11 @@
package com.dangdang.ddframe.rdb.sharding.executor.type.batch;
-import com.codahale.metrics.Timer.Context;
import com.dangdang.ddframe.rdb.sharding.constant.DatabaseType;
import com.dangdang.ddframe.rdb.sharding.constant.SQLType;
import com.dangdang.ddframe.rdb.sharding.executor.BaseStatementUnit;
import com.dangdang.ddframe.rdb.sharding.executor.ExecuteCallback;
import com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine;
-import com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext;
import lombok.RequiredArgsConstructor;
import java.util.Collection;
@@ -54,18 +52,13 @@ public final class BatchPreparedStatementExecutor {
* @return execute results
*/
public int[] executeBatch() {
- Context context = MetricsContext.start("ShardingPreparedStatement-executeBatch");
- try {
- return accumulate(executorEngine.executeBatch(sqlType, batchPreparedStatementUnits, parameterSets, new ExecuteCallback() {
-
- @Override
- public int[] execute(final BaseStatementUnit baseStatementUnit) throws Exception {
- return baseStatementUnit.getStatement().executeBatch();
- }
- }));
- } finally {
- MetricsContext.stop(context);
- }
+ return accumulate(executorEngine.executeBatch(sqlType, batchPreparedStatementUnits, parameterSets, new ExecuteCallback() {
+
+ @Override
+ public int[] execute(final BaseStatementUnit baseStatementUnit) throws Exception {
+ return baseStatementUnit.getStatement().executeBatch();
+ }
+ }));
}
private int[] accumulate(final List results) {
diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/prepared/PreparedStatementExecutor.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/prepared/PreparedStatementExecutor.java
index 508f80a721e2c1df7a2ed304f1c758683ffb1d92..7a09dc41ed884eb8b2fe3c28814fedd91db9278c 100644
--- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/prepared/PreparedStatementExecutor.java
+++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/prepared/PreparedStatementExecutor.java
@@ -17,12 +17,10 @@
package com.dangdang.ddframe.rdb.sharding.executor.type.prepared;
-import com.codahale.metrics.Timer.Context;
import com.dangdang.ddframe.rdb.sharding.constant.SQLType;
import com.dangdang.ddframe.rdb.sharding.executor.BaseStatementUnit;
import com.dangdang.ddframe.rdb.sharding.executor.ExecuteCallback;
import com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine;
-import com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext;
import lombok.RequiredArgsConstructor;
import java.sql.PreparedStatement;
@@ -53,20 +51,13 @@ public final class PreparedStatementExecutor {
* @return result set list
*/
public List executeQuery() {
- Context context = MetricsContext.start("ShardingPreparedStatement-executeQuery");
- List result;
- try {
- result = executorEngine.executePreparedStatement(sqlType, preparedStatementUnits, parameters, new ExecuteCallback() {
-
- @Override
- public ResultSet execute(final BaseStatementUnit baseStatementUnit) throws Exception {
- return ((PreparedStatement) baseStatementUnit.getStatement()).executeQuery();
- }
- });
- } finally {
- MetricsContext.stop(context);
- }
- return result;
+ return executorEngine.executePreparedStatement(sqlType, preparedStatementUnits, parameters, new ExecuteCallback() {
+
+ @Override
+ public ResultSet execute(final BaseStatementUnit baseStatementUnit) throws Exception {
+ return ((PreparedStatement) baseStatementUnit.getStatement()).executeQuery();
+ }
+ });
}
/**
@@ -75,19 +66,14 @@ public final class PreparedStatementExecutor {
* @return effected records count
*/
public int executeUpdate() {
- Context context = MetricsContext.start("ShardingPreparedStatement-executeUpdate");
- try {
- List results = executorEngine.executePreparedStatement(sqlType, preparedStatementUnits, parameters, new ExecuteCallback() {
-
- @Override
- public Integer execute(final BaseStatementUnit baseStatementUnit) throws Exception {
- return ((PreparedStatement) baseStatementUnit.getStatement()).executeUpdate();
- }
- });
- return accumulate(results);
- } finally {
- MetricsContext.stop(context);
- }
+ List results = executorEngine.executePreparedStatement(sqlType, preparedStatementUnits, parameters, new ExecuteCallback() {
+
+ @Override
+ public Integer execute(final BaseStatementUnit baseStatementUnit) throws Exception {
+ return ((PreparedStatement) baseStatementUnit.getStatement()).executeUpdate();
+ }
+ });
+ return accumulate(results);
}
private int accumulate(final List results) {
@@ -104,21 +90,16 @@ public final class PreparedStatementExecutor {
* @return return true if is DQL, false if is DML
*/
public boolean execute() {
- Context context = MetricsContext.start("ShardingPreparedStatement-execute");
- try {
- List result = executorEngine.executePreparedStatement(sqlType, preparedStatementUnits, parameters, new ExecuteCallback() {
-
- @Override
- public Boolean execute(final BaseStatementUnit baseStatementUnit) throws Exception {
- return ((PreparedStatement) baseStatementUnit.getStatement()).execute();
- }
- });
- if (null == result || result.isEmpty() || null == result.get(0)) {
- return false;
+ List result = executorEngine.executePreparedStatement(sqlType, preparedStatementUnits, parameters, new ExecuteCallback() {
+
+ @Override
+ public Boolean execute(final BaseStatementUnit baseStatementUnit) throws Exception {
+ return ((PreparedStatement) baseStatementUnit.getStatement()).execute();
}
- return result.get(0);
- } finally {
- MetricsContext.stop(context);
+ });
+ if (null == result || result.isEmpty() || null == result.get(0)) {
+ return false;
}
+ return result.get(0);
}
}
diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/statement/StatementExecutor.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/statement/StatementExecutor.java
index 5f6b17028274d5f5c35ff2494ee2e1ec40c31735..c60dad1b4842f56e88f05253d2a8784b6b6eeb3b 100644
--- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/statement/StatementExecutor.java
+++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/type/statement/StatementExecutor.java
@@ -17,12 +17,10 @@
package com.dangdang.ddframe.rdb.sharding.executor.type.statement;
-import com.codahale.metrics.Timer.Context;
import com.dangdang.ddframe.rdb.sharding.constant.SQLType;
import com.dangdang.ddframe.rdb.sharding.executor.BaseStatementUnit;
import com.dangdang.ddframe.rdb.sharding.executor.ExecuteCallback;
import com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine;
-import com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext;
import lombok.RequiredArgsConstructor;
import java.sql.ResultSet;
@@ -53,20 +51,13 @@ public final class StatementExecutor {
* @return result set list
*/
public List executeQuery() {
- Context context = MetricsContext.start("ShardingStatement-executeQuery");
- List result;
- try {
- result = executorEngine.executeStatement(sqlType, statementUnits, new ExecuteCallback() {
-
- @Override
- public ResultSet execute(final BaseStatementUnit baseStatementUnit) throws Exception {
- return baseStatementUnit.getStatement().executeQuery(baseStatementUnit.getSqlExecutionUnit().getSql());
- }
- });
- } finally {
- MetricsContext.stop(context);
- }
- return result;
+ return executorEngine.executeStatement(sqlType, statementUnits, new ExecuteCallback() {
+
+ @Override
+ public ResultSet execute(final BaseStatementUnit baseStatementUnit) throws Exception {
+ return baseStatementUnit.getStatement().executeQuery(baseStatementUnit.getSqlExecutionUnit().getSql());
+ }
+ });
}
/**
@@ -133,19 +124,14 @@ public final class StatementExecutor {
}
private int executeUpdate(final Updater updater) {
- Context context = MetricsContext.start("ShardingStatement-executeUpdate");
- try {
- List results = executorEngine.executeStatement(sqlType, statementUnits, new ExecuteCallback() {
-
- @Override
- public Integer execute(final BaseStatementUnit baseStatementUnit) throws Exception {
- return updater.executeUpdate(baseStatementUnit.getStatement(), baseStatementUnit.getSqlExecutionUnit().getSql());
- }
- });
- return accumulate(results);
- } finally {
- MetricsContext.stop(context);
- }
+ List results = executorEngine.executeStatement(sqlType, statementUnits, new ExecuteCallback() {
+
+ @Override
+ public Integer execute(final BaseStatementUnit baseStatementUnit) throws Exception {
+ return updater.executeUpdate(baseStatementUnit.getStatement(), baseStatementUnit.getSqlExecutionUnit().getSql());
+ }
+ });
+ return accumulate(results);
}
private int accumulate(final List results) {
@@ -220,22 +206,17 @@ public final class StatementExecutor {
}
private boolean execute(final Executor executor) {
- Context context = MetricsContext.start("ShardingStatement-execute");
- try {
- List result = executorEngine.executeStatement(sqlType, statementUnits, new ExecuteCallback() {
-
- @Override
- public Boolean execute(final BaseStatementUnit baseStatementUnit) throws Exception {
- return executor.execute(baseStatementUnit.getStatement(), baseStatementUnit.getSqlExecutionUnit().getSql());
- }
- });
- if (null == result || result.isEmpty() || null == result.get(0)) {
- return false;
+ List result = executorEngine.executeStatement(sqlType, statementUnits, new ExecuteCallback() {
+
+ @Override
+ public Boolean execute(final BaseStatementUnit baseStatementUnit) throws Exception {
+ return executor.execute(baseStatementUnit.getStatement(), baseStatementUnit.getSqlExecutionUnit().getSql());
}
- return result.get(0);
- } finally {
- MetricsContext.stop(context);
+ });
+ if (null == result || result.isEmpty() || null == result.get(0)) {
+ return false;
}
+ return result.get(0);
}
private interface Updater {
diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/adapter/AbstractConnectionAdapter.java
index 0d0b02b991590c35ce52c3b40322e80520921d20..047e4f866a1cc8411ef0214718e5ba3182907a59 100644
--- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/adapter/AbstractConnectionAdapter.java
+++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/adapter/AbstractConnectionAdapter.java
@@ -18,7 +18,6 @@
package com.dangdang.ddframe.rdb.sharding.jdbc.adapter;
import com.dangdang.ddframe.rdb.sharding.jdbc.unsupported.AbstractUnsupportedOperationConnection;
-import com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -90,7 +89,6 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera
@Override
public void close() throws SQLException {
closed = true;
- MetricsContext.clear();
Collection exceptions = new LinkedList<>();
for (Connection each : getConnections()) {
try {
diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/connection/ShardingConnection.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/connection/ShardingConnection.java
index 8cabc96fe5c1c8cb0942e75bcf250e7fbceace7c..e330dced13b236b468ec08a29d262144be9e365e 100644
--- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/connection/ShardingConnection.java
+++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/connection/ShardingConnection.java
@@ -17,16 +17,13 @@
package com.dangdang.ddframe.rdb.sharding.jdbc.core.connection;
-import com.codahale.metrics.Timer.Context;
import com.dangdang.ddframe.rdb.sharding.constant.SQLType;
import com.dangdang.ddframe.rdb.sharding.hint.HintManagerHolder;
-import com.dangdang.ddframe.rdb.sharding.jdbc.core.ShardingContext;
import com.dangdang.ddframe.rdb.sharding.jdbc.adapter.AbstractConnectionAdapter;
+import com.dangdang.ddframe.rdb.sharding.jdbc.core.ShardingContext;
+import com.dangdang.ddframe.rdb.sharding.jdbc.core.datasource.MasterSlaveDataSource;
import com.dangdang.ddframe.rdb.sharding.jdbc.core.statement.ShardingPreparedStatement;
import com.dangdang.ddframe.rdb.sharding.jdbc.core.statement.ShardingStatement;
-import com.dangdang.ddframe.rdb.sharding.jdbc.core.datasource.MasterSlaveDataSource;
-import com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext;
-import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import lombok.Getter;
@@ -65,7 +62,6 @@ public final class ShardingConnection extends AbstractConnectionAdapter {
* @throws SQLException SQL exception
*/
public Collection getConnectionForDDL(final String dataSourceName) throws SQLException {
- final Context metricsContext = MetricsContext.start(Joiner.on("-").join("ShardingConnection-getConnectionForDDL", dataSourceName));
DataSource dataSource = shardingContext.getShardingRule().getDataSourceRule().getDataSource(dataSourceName);
Preconditions.checkState(null != dataSource, "Missing the rule of %s in DataSourceRule", dataSourceName);
Collection dataSources = new LinkedList<>();
@@ -81,7 +77,6 @@ public final class ShardingConnection extends AbstractConnectionAdapter {
replayMethodsInvocation(connection);
result.add(connection);
}
- MetricsContext.stop(metricsContext);
return result;
}
@@ -98,7 +93,6 @@ public final class ShardingConnection extends AbstractConnectionAdapter {
if (connection.isPresent()) {
return connection.get();
}
- Context metricsContext = MetricsContext.start(Joiner.on("-").join("ShardingConnection-getConnection", dataSourceName));
DataSource dataSource = shardingContext.getShardingRule().getDataSourceRule().getDataSource(dataSourceName);
Preconditions.checkState(null != dataSource, "Missing the rule of %s in DataSourceRule", dataSourceName);
String realDataSourceName;
@@ -109,7 +103,6 @@ public final class ShardingConnection extends AbstractConnectionAdapter {
realDataSourceName = dataSourceName;
}
Connection result = dataSource.getConnection();
- MetricsContext.stop(metricsContext);
connectionMap.put(realDataSourceName, result);
replayMethodsInvocation(result);
return result;
diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/datasource/MasterSlaveDataSource.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/datasource/MasterSlaveDataSource.java
index a17cc5a2c0b79d191bdf4f82701865e0a18988b3..980aba050335c2eac40f78ee2af8bc63cfd78a2a 100644
--- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/datasource/MasterSlaveDataSource.java
+++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/datasource/MasterSlaveDataSource.java
@@ -109,7 +109,7 @@ public final class MasterSlaveDataSource extends AbstractDataSourceAdapter {
for (DataSource each : slaveDataSources) {
String slaveDatabaseProductName;
try (Connection slaveConnection = each.getConnection()) {
- slaveDatabaseProductName = slaveConnection.getMetaData().getDatabaseProductName();
+ slaveDatabaseProductName = slaveConnection.getMetaData().getDatabaseProductName();
}
Preconditions.checkState(result.equals(slaveDatabaseProductName), String.format("Database type inconsistent with '%s' and '%s'", result, slaveDatabaseProductName));
}
diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/datasource/ShardingDataSource.java
index f155fda2398faacca59a72beac4f39da853e3955..ef94aba1d3b83e6f47ffe9639ce030fe61838239 100644
--- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/datasource/ShardingDataSource.java
+++ b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/core/datasource/ShardingDataSource.java
@@ -26,7 +26,6 @@ import com.dangdang.ddframe.rdb.sharding.executor.ExecutorEngine;
import com.dangdang.ddframe.rdb.sharding.jdbc.adapter.AbstractDataSourceAdapter;
import com.dangdang.ddframe.rdb.sharding.jdbc.core.ShardingContext;
import com.dangdang.ddframe.rdb.sharding.jdbc.core.connection.ShardingConnection;
-import com.dangdang.ddframe.rdb.sharding.metrics.MetricsContext;
import com.google.common.base.Preconditions;
import javax.sql.DataSource;
@@ -84,7 +83,6 @@ public class ShardingDataSource extends AbstractDataSourceAdapter implements Aut
@Override
public ShardingConnection getConnection() throws SQLException {
- MetricsContext.init(shardingProperties);
return new ShardingConnection(shardingContext);
}
diff --git a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/metrics/MetricsContext.java b/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/metrics/MetricsContext.java
deleted file mode 100644
index 6f0c3da1a373c1b5bf815bf2ad9e2a398787975a..0000000000000000000000000000000000000000
--- a/sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/metrics/MetricsContext.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 1999-2015 dangdang.com.
- *
- * 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.
- *