Search in sources :

Example 1 with BufferQueue

use of com.alibaba.cobar.net.buffer.BufferQueue in project cobar by alibaba.

the class FrontendConnectionFactory method make.

public FrontendConnection make(SocketChannel channel) throws IOException {
    Socket socket = channel.socket();
    socket.setReceiveBufferSize(socketRecvBuffer);
    socket.setSendBufferSize(socketSendBuffer);
    socket.setTcpNoDelay(true);
    socket.setKeepAlive(true);
    FrontendConnection c = getConnection(channel);
    c.setPacketHeaderSize(packetHeaderSize);
    c.setMaxPacketSize(maxPacketSize);
    c.setWriteQueue(new BufferQueue(writeQueueCapcity));
    c.setIdleTimeout(idleTimeout);
    c.setCharset(charset);
    return c;
}
Also used : FrontendConnection(com.alibaba.cobar.net.FrontendConnection) BufferQueue(com.alibaba.cobar.net.buffer.BufferQueue) Socket(java.net.Socket)

Example 2 with BufferQueue

use of com.alibaba.cobar.net.buffer.BufferQueue in project cobar by alibaba.

the class ShowConnection method getRow.

private static RowDataPacket getRow(FrontendConnection c, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(c.getProcessor().getName().getBytes());
    row.add(LongUtil.toBytes(c.getId()));
    row.add(StringUtil.encode(c.getHost(), charset));
    row.add(IntegerUtil.toBytes(c.getPort()));
    row.add(IntegerUtil.toBytes(c.getLocalPort()));
    row.add(StringUtil.encode(c.getSchema(), charset));
    row.add(StringUtil.encode(c.getCharset(), charset));
    row.add(LongUtil.toBytes(c.getNetInBytes()));
    row.add(LongUtil.toBytes(c.getNetOutBytes()));
    row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
    row.add(IntegerUtil.toBytes(c.getWriteAttempts()));
    ByteBuffer bb = c.getReadBuffer();
    row.add(IntegerUtil.toBytes(bb == null ? 0 : bb.capacity()));
    BufferQueue bq = c.getWriteQueue();
    row.add(IntegerUtil.toBytes(bq == null ? 0 : bq.size()));
    if (c instanceof ServerConnection) {
        ServerConnection sc = (ServerConnection) c;
        row.add(IntegerUtil.toBytes(sc.getSession().getTargetCount()));
    } else {
        row.add(null);
    }
    return row;
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) ServerConnection(com.alibaba.cobar.server.ServerConnection) ByteBuffer(java.nio.ByteBuffer) BufferQueue(com.alibaba.cobar.net.buffer.BufferQueue)

Example 3 with BufferQueue

use of com.alibaba.cobar.net.buffer.BufferQueue in project cobar by alibaba.

the class BackendConnectionFactory method postConnect.

protected void postConnect(BackendConnection c, NIOConnector connector) {
    c.setPacketHeaderSize(packetHeaderSize);
    c.setMaxPacketSize(maxPacketSize);
    c.setWriteQueue(new BufferQueue(writeQueueCapcity));
    c.setIdleTimeout(idleTimeout);
    c.setConnector(connector);
    connector.postConnect(c);
}
Also used : BufferQueue(com.alibaba.cobar.net.buffer.BufferQueue)

Aggregations

BufferQueue (com.alibaba.cobar.net.buffer.BufferQueue)3 FrontendConnection (com.alibaba.cobar.net.FrontendConnection)1 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)1 ServerConnection (com.alibaba.cobar.server.ServerConnection)1 Socket (java.net.Socket)1 ByteBuffer (java.nio.ByteBuffer)1