- * 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 5535888393d71..97683a490c6be 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 508f80a721e2c..7a09dc41ed884 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 ResultSet execute(final BaseStatementUnit baseStatementUnit) throws Excep
* @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 @@ private int accumulate(final List results) {
* @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 5f6b17028274d..c60dad1b4842f 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 int executeUpdate(final Statement statement, final String sql) throws SQL
}
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 boolean execute(final Statement statement, final String sql) throws SQLEx
}
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 0d0b02b991590..047e4f866a1cc 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 final void rollback() throws SQLException {
@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 8cabc96fe5c1c..e330dced13b23 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 Collection getConnectionForDDL(final String dataSourceName) t
replayMethodsInvocation(connection);
result.add(connection);
}
- MetricsContext.stop(metricsContext);
return result;
}
@@ -98,7 +93,6 @@ public Connection getConnection(final String dataSourceName, final SQLType sqlTy
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 Connection getConnection(final String dataSourceName, final SQLType sqlTy
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 a17cc5a2c0b79..980aba050335c 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 String getDatabaseProductName() throws SQLException {
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 f155fda2398fa..ef94aba1d3b83 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.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 @@ private String getDatabaseProductName(final ShardingRule shardingRule) throws SQ
@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 6f0c3da1a373c..0000000000000
--- 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.
- *