use of io.mycat.monitor.DatabaseInstanceEntry in project Mycat2 by MyCATApache.
the class VertxMySQLDatasourcePoolImpl method getConnection.
@Override
public Future<NewMycatConnection> getConnection() {
LOGGER.debug("getConnection");
Future<NewVertxConnectionImpl> map = mySQLPool.getConnection().map(sqlConnection -> {
DatabaseInstanceEntry stat = DatabaseInstanceEntry.stat(targetName);
stat.plusCon();
stat.plusQps();
return new NewVertxConnectionImpl((MySQLConnectionImpl) sqlConnection) {
long start;
@Override
public void onSend() {
start = System.currentTimeMillis();
}
@Override
public void onRev() {
long end = System.currentTimeMillis();
InstanceMonitor.plusPrt(end - start);
}
@Override
public Future<Void> close() {
stat.decCon();
return super.close();
}
};
});
map = map.onFailure(new Handler<Throwable>() {
@Override
public void handle(Throwable event) {
System.out.println(event);
}
});
return (Future) map;
}
use of io.mycat.monitor.DatabaseInstanceEntry in project Mycat2 by MyCATApache.
the class JdbcDatasourcePoolImpl method getConnection.
@Override
public Future<NewMycatConnection> getConnection() {
try {
JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
DefaultConnection defaultConnection = jdbcConnectionManager.getConnection(targetName);
DatabaseInstanceEntry stat = DatabaseInstanceEntry.stat(targetName);
stat.plusCon();
stat.plusQps();
NewMycatConnectionImpl newMycatConnection = new NewMycatConnectionImpl(targetName, defaultConnection.getRawConnection()) {
long start;
final AtomicBoolean closeFlag = new AtomicBoolean(false);
@Override
public void onSend() {
start = System.currentTimeMillis();
}
@Override
public void onRev() {
long end = System.currentTimeMillis();
InstanceMonitor.plusPrt(end - start);
}
@Override
public Future<Void> close() {
if (closeFlag.compareAndSet(false, true)) {
stat.decCon();
defaultConnection.close();
}
return Future.succeededFuture();
}
@Override
public void abandonConnection() {
if (closeFlag.compareAndSet(false, true)) {
stat.decCon();
Connection rawConnection = defaultConnection.getRawConnection();
if (rawConnection instanceof DruidPooledConnection) {
DruidPooledConnection connection = (DruidPooledConnection) rawConnection;
connection.abandond();
}
defaultConnection.close();
}
}
};
return Future.succeededFuture(new ThreadMycatConnectionImplWrapper(stat, newMycatConnection));
} catch (Throwable throwable) {
return Future.failedFuture(throwable);
}
}
use of io.mycat.monitor.DatabaseInstanceEntry in project Mycat2 by MyCATApache.
the class DatabaseInstanceChart method play.
private void play(String newValue) {
if (StringUtil.isEmpty(newValue)) {
return;
}
timeline.stop();
timeline.getKeyFrames().clear();
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(Double.parseDouble(newValue)), actionEvent -> {
Future<DatabaseInstanceEntry.DatabaseInstanceMap> instanceEntryFuture = monitorService.fetchDBEntry();
instanceEntryFuture.onSuccess(databaseInstanceEntry -> {
LinkedList<String[]> objects = new LinkedList<>();
for (Map.Entry<String, DatabaseInstanceEntry.DatabaseInstanceEntryViewEntry> entry : databaseInstanceEntry.getDatabaseInstanceMap().entrySet()) {
String key = entry.getKey();
DatabaseInstanceEntry.DatabaseInstanceEntryViewEntry value = entry.getValue();
long qpsSum = value.qps;
long con = value.con;
long thread = value.thread;
objects.add(new String[] { key, qpsSum + "", con + "", thread + "" });
}
if (objects.isEmpty()) {
objects.add(new String[] { "无数据", "无数据", "无数据", "无数据", "无数据" });
}
Platform.runLater(() -> {
TableViewOuter tableViewOuter = new TableViewOuter(tableView);
TableData tableData = new TableData(Arrays.asList("name", "qps", "con", "thread"), objects);
tableViewOuter.appendData(tableData);
});
});
}));
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}
use of io.mycat.monitor.DatabaseInstanceEntry in project Mycat2 by MyCATApache.
the class MycatNativeDatasourcePool method getConnection.
@Override
public Future<NewMycatConnection> getConnection() {
return vertxPoolConnection.getConnection().map(connection -> {
DatabaseInstanceEntry stat = DatabaseInstanceEntry.stat(targetName);
stat.plusCon();
stat.plusQps();
return new VertxMycatConnectionPool(targetName, connection, vertxPoolConnection) {
long start;
@Override
public void onSend() {
start = System.currentTimeMillis();
}
@Override
public void onRev() {
long end = System.currentTimeMillis();
InstanceMonitor.plusPrt(end - start);
}
@Override
public Future<Void> close() {
stat.decCon();
return super.close();
}
@Override
public Observable<VectorSchemaRoot> prepareQuery(String sql, List<Object> params, BufferAllocator allocator) {
return Observable.create(emitter -> {
JdbcDatasourcePoolImpl jdbcDatasourcePool = new JdbcDatasourcePoolImpl(targetName);
Future<NewMycatConnection> connectionFuture = jdbcDatasourcePool.getConnection();
connectionFuture.onSuccess(event -> {
Observable<VectorSchemaRoot> observable = event.prepareQuery(sql, params, allocator);
observable.subscribe(vectorSchemaRoot -> emitter.onNext(vectorSchemaRoot), throwable -> emitter.onError(throwable), () -> emitter.onComplete());
});
connectionFuture.onFailure(event -> emitter.onError(event));
});
}
@Override
public Future<List<Object>> call(String sql) {
JdbcDatasourcePoolImpl jdbcDatasourcePool = new JdbcDatasourcePoolImpl(targetName);
Future<NewMycatConnection> connectionFuture = jdbcDatasourcePool.getConnection();
return connectionFuture.flatMap(connection -> connection.call(sql));
}
};
});
}
Aggregations