use of io.mycat.proxy.session.MySQLClientSession in project Mycat2 by MyCATApache.
the class MySQLTaskUtil method proxyBackend.
public static void proxyBackend(MycatSession session, String sql) {
MySQLClientSession mySQLSession = session.getMySQLSession();
MySQLPacketExchanger.MySQLProxyNIOHandler.INSTANCE.proxyBackend(mySQLSession, DEFAULT_BACKEND_SESSION_REQUEST_FAILED_CALLBACK, ResponseType.QUERY, session, MySQLPacketUtil.generateComQueryPacket(sql));
}
use of io.mycat.proxy.session.MySQLClientSession in project Mycat2 by MyCATApache.
the class MySQLDatasourcePool method waitForIdleSession.
private Future<MySQLClientSession> waitForIdleSession(boolean wait) {
PromiseInternal<MySQLClientSession> promise = VertxUtil.newPromise();
ReactorEnvThread reactorEnvThread;
if (Thread.currentThread() instanceof ReactorEnvThread) {
reactorEnvThread = (ReactorEnvThread) Thread.currentThread();
} else {
reactorEnvThread = this.server.getReactorManager().getRandomReactor();
}
if (wait) {
ScheduleUtil.getTimer().schedule(() -> {
nextStageForSession(promise, reactorEnvThread);
}, datasourceConfig.getMaxConnectTimeout() / datasourceConfig.getMaxRetryCount(), TimeUnit.MILLISECONDS);
} else {
nextStageForSession(promise, reactorEnvThread);
}
return promise;
}
use of io.mycat.proxy.session.MySQLClientSession in project Mycat2 by MyCATApache.
the class MycatMonitorCallback method getSession.
static Session getSession() {
SessionThread thread = getThread();
Session curSession = thread.getCurSession();
if (curSession instanceof MycatSession) {
return curSession;
} else if (curSession instanceof MySQLClientSession) {
MycatSession mycatSession = ((MySQLClientSession) curSession).getMycat();
if (mycatSession == null) {
return curSession;
} else {
return mycatSession;
}
} else {
throw new MycatException("unknown session");
}
}
use of io.mycat.proxy.session.MySQLClientSession in project Mycat2 by MyCATApache.
the class LoaddataContext method proxy.
public void proxy(MycatSession mycat, String replicaName, String defaultDataBaseName) {
int packetId = 2;
MySQLPacketSplitter splitter = new PacketSplitterImpl();
splitter.init(context.size());
while (splitter.nextPacketInPacketSplitter()) {
packetId++;
}
byte[] bytes = MySQLPacketUtil.generateMySQLPacket(2, context.toByteArray());
context = null;
splitter = null;
int emptyPacketId = packetId;
mycat.setHandleContentOfFilename(false);
MySQLClientSession mySQLSession = mycat.getMySQLSession();
mySQLSession.setMonopolizeType(MySQLSessionMonopolizeType.NONE);
RequestHandler.INSTANCE.request(mycat.getMySQLSession(), bytes, new RequestCallback() {
@Override
public void onFinishedSend(MySQLClientSession session, Object sender, Object attr) {
byte[] emptyPacket = MySQLPacketUtil.generateMySQLPacket(emptyPacketId, new byte[] {});
// @todo
// MySQLProxyNIOHandler
// .INSTANCE.proxyBackend(mycat, emptyPacket, targetName,defaultDataBaseName, null, ResponseType.QUERY,
// MySQLProxyNIOHandler.INSTANCE, DEFAULT_BACKEND_SESSION_REQUEST_FAILED_CALLBACK
// );
}
@Override
public void onFinishedSendException(Exception e, Object sender, Object attr) {
mycat.setMySQLSession(null);
mycat.setLastMessage(e.toString());
mycat.writeErrorEndPacketBySyncInProcessError();
}
});
}
Aggregations