Search in sources :

Example 1 with ProxyBuffer

use of io.mycat.beans.mysql.packet.ProxyBuffer in project Mycat2 by MyCATApache.

the class ResultSetHandler method onWriteFinished.

/**
 * 向mysql服务器写入结束,切换到读事件
 */
@Override
default void onWriteFinished(MySQLClientSession mysql) {
    ProxyBuffer proxyBuffer = mysql.currentProxyBuffer();
    // 写入完毕不清理buffer但是要把下标重置
    proxyBuffer.channelReadStartIndex(0);
    proxyBuffer.channelReadEndIndex(0);
    mysql.change2ReadOpts();
}
Also used : ProxyBuffer(io.mycat.beans.mysql.packet.ProxyBuffer)

Example 2 with ProxyBuffer

use of io.mycat.beans.mysql.packet.ProxyBuffer in project Mycat2 by MyCATApache.

the class MySQLClientSession method readFromChannel.

@Override
public boolean readFromChannel() throws IOException {
    boolean b = MySQLProxySession.super.readFromChannel();
    ProxyBuffer proxyBuffer = this.proxyBuffer;
    MycatMonitor.onBackendRead(this, proxyBuffer.currentByteBuffer(), proxyBuffer.channelReadStartIndex(), proxyBuffer.channelReadEndIndex() - proxyBuffer.channelReadStartIndex());
    return b;
}
Also used : ProxyBuffer(io.mycat.beans.mysql.packet.ProxyBuffer)

Example 3 with ProxyBuffer

use of io.mycat.beans.mysql.packet.ProxyBuffer in project Mycat2 by MyCATApache.

the class MySQLClientSession method newCurrentProxyPacket.

/**
 * 把当前的proxybuffer作为报文构造
 */
public MySQLPacket newCurrentProxyPacket(int packetLength) {
    ProxyBuffer proxyBuffer = currentProxyBuffer();
    proxyBuffer.reset();
    proxyBuffer.newBuffer(packetLength);
    MySQLPacket mySQLPacket = (MySQLPacket) proxyBuffer;
    mySQLPacket.writeSkipInWriting(4);
    return mySQLPacket;
}
Also used : MySQLPacket(io.mycat.beans.mysql.packet.MySQLPacket) ProxyBuffer(io.mycat.beans.mysql.packet.ProxyBuffer)

Example 4 with ProxyBuffer

use of io.mycat.beans.mysql.packet.ProxyBuffer in project Mycat2 by MyCATApache.

the class MySQLClientSession method writeProxyBufferToChannel.

/**
 * 最终把buffer写入通道的方法
 */
final PromiseInternal<Void> writeProxyBufferToChannel() throws IOException {
    ProxyBuffer proxyBuffer = this.currentProxyBuffer();
    int oldIndex = proxyBuffer.channelWriteStartIndex();
    proxyBuffer.writeToChannel(this.channel());
    MycatMonitor.onBackendWrite(this, proxyBuffer.currentByteBuffer(), oldIndex, proxyBuffer.channelWriteEndIndex());
    this.updateLastActiveTime();
    this.checkWriteFinished();
    getChannelKey().selector().wakeup();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("sessionId:{} writeProxyBufferToChannel successfully", sessionId());
    }
    return VertxUtil.newSuccessPromise();
}
Also used : ProxyBuffer(io.mycat.beans.mysql.packet.ProxyBuffer)

Example 5 with ProxyBuffer

use of io.mycat.beans.mysql.packet.ProxyBuffer in project Mycat2 by MyCATApache.

the class MySQLProxySession method readFromChannel.

/**
 * 读取通道的数据,该方法在mycat 与mysql session都作为通道读
 */
default boolean readFromChannel() throws IOException {
    ProxyBuffer proxyBuffer = currentProxyBuffer();
    // proxyBuffer.newBufferIfNeed();
    proxyBuffer.compactInChannelReadingIfNeed();
    boolean b = proxyBuffer.readFromChannel(this.channel());
    updateLastActiveTime();
    return b;
}
Also used : ProxyBuffer(io.mycat.beans.mysql.packet.ProxyBuffer)

Aggregations

ProxyBuffer (io.mycat.beans.mysql.packet.ProxyBuffer)9 ByteBuffer (java.nio.ByteBuffer)3 MycatException (io.mycat.MycatException)2 MySQLPacket (io.mycat.beans.mysql.packet.MySQLPacket)2 ProxyBufferImpl (io.mycat.proxy.buffer.ProxyBufferImpl)2 ErrorPacketImpl (io.mycat.beans.mysql.packet.ErrorPacketImpl)1 ResultSetCallBack (io.mycat.proxy.callback.ResultSetCallBack)1 MySQLPacketResolver (io.mycat.proxy.packet.MySQLPacketResolver)1 MySQLPayloadType (io.mycat.proxy.packet.MySQLPayloadType)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1