当前位置: 首页>>代码示例>>Java>>正文


Java ServerConnection类代码示例

本文整理汇总了Java中com.alibaba.cobar.server.ServerConnection的典型用法代码示例。如果您正苦于以下问题:Java ServerConnection类的具体用法?Java ServerConnection怎么用?Java ServerConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServerConnection类属于com.alibaba.cobar.server包,在下文中一共展示了ServerConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: response

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
public static void response(String stmt, int offset, ManagerConnection mc) {
    int count = 0;
    List<FrontendConnection> list = getList(stmt, offset, mc);
    if (list != null) {
        for (NIOConnection c : list) {
            StringBuilder s = new StringBuilder();
            logger.warn(s.append(c).append("killed by manager").toString());

            if (c instanceof ServerConnection) {
                ((ServerConnection) c).kill();
            } else {
                c.close();
            }
            count++;
        }
    }
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = count;
    packet.serverStatus = 2;
    packet.write(mc);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:23,代码来源:KillConnection.java

示例2: response

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = header.write(buffer, c);
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    buffer = eof.write(buffer, c);
    byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(FrontendConnection.getServerVersion().getBytes());
    row.packetId = ++packetId;
    buffer = row.write(buffer, c);
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    c.write(buffer);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:18,代码来源:SelectVersion.java

示例3: oneSetResponse

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
private static void oneSetResponse(String stmt, ServerConnection c, int rs) {
    if ((rs & 0xff) == CHARACTER_SET_CLIENT) {
        /* 忽略client属性设置 */
        c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
    } else {
        String charset = stmt.substring(rs >>> 8).trim();
        if (charset.endsWith(";")) {
            /* 结尾为 ; 标识符 */
            charset = charset.substring(0, charset.length() - 1);
        }

        if (charset.startsWith("'") || charset.startsWith("`")) {
            /* 与mysql保持一致,引号里的字符集不做trim操作 */
            charset = charset.substring(1, charset.length() - 1);
        }

        // 设置字符集
        setCharset(charset, c);
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:21,代码来源:CharacterSet.java

示例4: setCharset

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
private static void setCharset(String charset, ServerConnection c) {
    if ("null".equalsIgnoreCase(charset)) {
        /* 忽略字符集为null的属性设置 */
        c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
    } else if (c.setCharset(charset)) {
        c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
    } else {
        try {
            if (c.setCharsetIndex(Integer.parseInt(charset))) {
                c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
            } else {
                c.writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, "Unknown charset :" + charset);
            }
        } catch (RuntimeException e) {
            c.writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, "Unknown charset :" + charset);
        }
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:19,代码来源:CharacterSet.java

示例5: response

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = header.write(buffer, c);
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    buffer = eof.write(buffer, c);
    byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(getUser(c));
    row.packetId = ++packetId;
    buffer = row.write(buffer, c);
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    c.write(buffer);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:18,代码来源:SelectUser.java

示例6: response

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = header.write(buffer, c);
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    buffer = eof.write(buffer, c);
    byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(c.getSchema(), c.getCharset()));
    row.packetId = ++packetId;
    buffer = row.write(buffer, c);
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    c.write(buffer);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:18,代码来源:SelectDatabase.java

示例7: handle

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
public static void handle(String stmt, ServerConnection c, int offset) {
    switch (ServerParseShow.parse(stmt, offset)) {
        case ServerParseShow.DATABASES:
            ShowDatabases.response(c);
            break;

        case ServerParseShow.CONNECTION:
            ShowConnection.execute(c);
            break;
        //            case ServerParseShow.DATASOURCES:
        //                // ShowDataSources.response(c);
        //                // break;
        //            case ServerParseShow.COBAR_STATUS:
        //                // ShowCobarStatus.response(c);
        //                // break;
        case ServerParseShow.SLOW:
            ShowSQLSlow.execute(c);
            break;
        case ServerParseShow.PHYSICAL_SLOW:
            ShowPhysicalSQLSlow.execute(c);
            break;
        default:
            c.execute(stmt, ServerParse.SHOW);
    }
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:26,代码来源:ShowHandler.java

示例8: getRow

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
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;
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:26,代码来源:ShowConnection.java

示例9: response

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = header.write(buffer, c);
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    buffer = eof.write(buffer, c);
    byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(Versions.SERVER_VERSION);
    row.packetId = ++packetId;
    buffer = row.write(buffer, c);
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    c.write(buffer);
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:18,代码来源:SelectVersion.java

示例10: response

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
public static void response(ServerConnection c, byte[] data) {
    HeartbeatPacket hp = new HeartbeatPacket();
    hp.read(data);
    if (CobarServer.getInstance().isOnline()) {
        OkPacket ok = new OkPacket();
        ok.packetId = 1;
        ok.affectedRows = hp.id;
        ok.serverStatus = 2;
        ok.write(c);
        if (HEARTBEAT.isInfoEnabled()) {
            HEARTBEAT.info(responseMessage("OK", c, hp.id));
        }
    } else {
        ErrorPacket error = new ErrorPacket();
        error.packetId = 1;
        error.errno = ErrorCode.ER_SERVER_SHUTDOWN;
        error.message = String.valueOf(hp.id).getBytes();
        error.write(c);
        if (HEARTBEAT.isInfoEnabled()) {
            HEARTBEAT.info(responseMessage("ERROR", c, hp.id));
        }
    }
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:24,代码来源:Heartbeat.java

示例11: response

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
public static void response(ServerConnection c) {
    if (CobarServer.getInstance().isOnline()) {
        ByteBuffer buffer = c.allocate();
        buffer = header.write(buffer, c);
        for (FieldPacket field : fields) {
            buffer = field.write(buffer, c);
        }
        buffer = eof.write(buffer, c);
        byte packetId = eof.packetId;
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(getUser(c));
        row.packetId = ++packetId;
        buffer = row.write(buffer, c);
        EOFPacket lastEof = new EOFPacket();
        lastEof.packetId = ++packetId;
        buffer = lastEof.write(buffer, c);
        c.write(buffer);
    } else {
        error.write(c);
    }
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:22,代码来源:SelectUser.java

示例12: getRouteResultset

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
private static RouteResultset getRouteResultset(ServerConnection c, String stmt) {
    String db = c.getSchema();
    if (db == null) {
        c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
        return null;
    }
    SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
    if (schema == null) {
        c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
        return null;
    }
    try {
        return ServerRouter.route(schema, stmt, c.getCharset(), c);
    } catch (SQLNonTransientException e) {
        StringBuilder s = new StringBuilder();
        logger.warn(s.append(c).append(stmt).toString(), e);
        String msg = e.getMessage();
        c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
        return null;
    }
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:22,代码来源:ExplainHandler.java

示例13: handle

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
public static void handle(String stmt, ServerConnection c, int offset) {
    switch (ServerParseShow.parse(stmt, offset)) {
    case ServerParseShow.DATABASES:
        ShowDatabases.response(c);
        break;
    case ServerParseShow.DATASOURCES:
        ShowDataSources.response(c);
        break;
    case ServerParseShow.COBAR_STATUS:
        ShowCobarStatus.response(c);
        break;
    case ServerParseShow.COBAR_CLUSTER:
        ShowCobarCluster.response(c);
        break;
    default:
        c.execute(stmt, ServerParse.SHOW);
    }
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:19,代码来源:ShowHandler.java

示例14: fieldEofResponse

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
@Override
public void fieldEofResponse(byte[] header, List<byte[]> fields, byte[] eof, MySQLConnection conn) {
    lock.lock();
    try {
        if (fieldsReturned) {
            return;
        }
        fieldsReturned = true;
        header[3] = ++packetId;
        ServerConnection source = session.getSource();
        buffer = source.writeToBuffer(header, buffer);
        for (int i = 0, len = fields.size(); i < len; ++i) {
            byte[] field = fields.get(i);
            field[3] = ++packetId;
            buffer = source.writeToBuffer(field, buffer);
        }
        eof[3] = ++packetId;
        buffer = source.writeToBuffer(eof, buffer);
    } finally {
        lock.unlock();
    }
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:23,代码来源:MultiNodeQueryHandler.java

示例15: okResponse

import com.alibaba.cobar.server.ServerConnection; //导入依赖的package包/类
@Override
public void okResponse(byte[] data, MySQLConnection conn) {
    boolean executeResponse = false;
    try {
        executeResponse = conn.syncAndExcute();
    } catch (UnsupportedEncodingException e) {
        executeException(conn);
    }
    if (executeResponse) {
        conn.setRunning(false);
        ServerConnection source = session.getSource();
        if (source.isAutocommit()) {
            session.clearConnections();
        }
        endRunning();
        OkPacket ok = new OkPacket();
        ok.read(data);
        source.setLastInsertId(ok.insertId);
        buffer = source.writeToBuffer(data, buffer);
        source.write(buffer);
    }
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:23,代码来源:SingleNodeHandler.java


注:本文中的com.alibaba.cobar.server.ServerConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。