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


Java CobarServer类代码示例

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


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

示例1: getList

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
private static List<FrontendConnection> getList(String stmt, int offset, ManagerConnection mc) {
    String ids = stmt.substring(offset).trim();
    if (ids.length() > 0) {
        String[] idList = StringUtil.split(ids, ',', true);
        List<FrontendConnection> fcList = new ArrayList<FrontendConnection>(idList.length);
        NIOProcessor[] processors = CobarServer.getInstance().getProcessors();
        for (String id : idList) {
            long value = 0;
            try {
                value = Long.parseLong(id);
            } catch (NumberFormatException e) {
                continue;
            }
            FrontendConnection fc = null;
            for (NIOProcessor p : processors) {
                if ((fc = p.getFrontends().get(value)) != null) {
                    fcList.add(fc);
                    break;
                }
            }
        }
        return fcList;
    }
    return null;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:26,代码来源:KillConnection.java

示例2: getRow

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
private static RowDataPacket getRow(String charset) {
    CobarServer server = CobarServer.getInstance();
    long startupTime = server.getStartupTime();
    long now = TimeUtil.currentTimeMillis();
    long uptime = now - startupTime;
    Runtime rt = Runtime.getRuntime();
    long total = rt.totalMemory();
    long max = rt.maxMemory();
    long used = (total - rt.freeMemory());
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(FormatUtil.formatTime(uptime, 3), charset));
    row.add(LongUtil.toBytes(used));
    row.add(LongUtil.toBytes(total));
    row.add(LongUtil.toBytes(max));
    row.add(StringUtil.encode(charset, charset));
    row.add(StringUtil.encode(CobarServer.getInstance().isOnline() ? "ON" : "OFF", charset));
    return row;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:19,代码来源:ShowServer.java

示例3: load

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
private void load() {
    String conf = System.getProperty("server.conf", "classpath:server.properties");
    Properties serverProps = new Properties();
    try {
        if (conf.startsWith(CLASSPATH_URL_PREFIX)) {
            conf = StringUtils.substringAfter(conf, CLASSPATH_URL_PREFIX);
            serverProps.load(CobarServer.class.getClassLoader().getResourceAsStream(conf));
        } else {
            serverProps.load(new FileInputStream(conf));
        }
    } catch (IOException e) {
        throw new TddlNestableRuntimeException(e);
    }

    configSystem(serverProps);

    QuarantineConfig.getInstance().resetTrustedIps(system.getTrustedIps());
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:19,代码来源:ServerLoader.java

示例4: response

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
public static void response(String stmt, ManagerConnection c) {
    int count = 0;
    Pair<String[], Integer> pair = ManagerParseSwitch.getPair(stmt);
    Map<String, MySQLDataNode> dns = CobarServer.getInstance().getConfig().getDataNodes();
    Integer idx = pair.getValue();
    for (String key : pair.getKey()) {
        MySQLDataNode dn = dns.get(key);
        if (dn != null) {
            int m = dn.getActivedIndex();
            int n = (idx == null) ? dn.next(m) : idx.intValue();
            if (dn.switchSource(n, false, "MANAGER")) {
                ++count;
            }
        }
    }
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = count;
    packet.serverStatus = 2;
    packet.write(c);
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:22,代码来源:SwitchDataSource.java

示例5: execute

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
public static void execute(ManagerConnection c) {
    final ReentrantLock lock = CobarServer.getInstance().getConfig().getLock();
    lock.lock();
    try {
        if (reload()) {
            StringBuilder s = new StringBuilder();
            s.append(c).append("Reload config success by manager");
            LOGGER.warn(s.toString());
            OkPacket ok = new OkPacket();
            ok.packetId = 1;
            ok.affectedRows = 1;
            ok.serverStatus = 2;
            ok.message = "Reload config success".getBytes();
            ok.write(c);
        } else {
            c.writeErrMessage(ErrorCode.ER_YES, "Reload config failure");
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:22,代码来源:ReloadConfig.java

示例6: execute

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
public static void execute(ManagerConnection c) {
    final ReentrantLock lock = CobarServer.getInstance().getConfig().getLock();
    lock.lock();
    try {
        if (rollback()) {
            StringBuilder s = new StringBuilder();
            s.append(c).append("Rollback config success by manager");
            LOGGER.warn(s.toString());
            OkPacket ok = new OkPacket();
            ok.packetId = 1;
            ok.affectedRows = 1;
            ok.serverStatus = 2;
            ok.message = "Rollback config success".getBytes();
            ok.write(c);
        } else {
            c.writeErrMessage(ErrorCode.ER_YES, "Rollback config failure");
        }
    } finally {
        lock.unlock();
    }
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:22,代码来源:RollbackConfig.java

示例7: getList

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
private static List<FrontendConnection> getList(String stmt, int offset, ManagerConnection mc) {
    String ids = stmt.substring(offset).trim();
    if (ids.length() > 0) {
        String[] idList = SplitUtil.split(ids, ',', true);
        List<FrontendConnection> fcList = new ArrayList<FrontendConnection>(idList.length);
        NIOProcessor[] processors = CobarServer.getInstance().getProcessors();
        for (String id : idList) {
            long value = 0;
            try {
                value = Long.parseLong(id);
            } catch (NumberFormatException e) {
                continue;
            }
            FrontendConnection fc = null;
            for (NIOProcessor p : processors) {
                if ((fc = p.getFrontends().get(value)) != null) {
                    fcList.add(fc);
                    break;
                }
            }
        }
        return fcList;
    }
    return null;
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:26,代码来源:KillConnection.java

示例8: execute

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
public static void execute(ManagerConnection 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;
    String charset = c.getCharset();
    for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
        for (BackendConnection bc : p.getBackends().values()) {
            if (bc != null) {
                RowDataPacket row = getRow(bc, charset);
                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,代码行数:24,代码来源:ShowBackend.java

示例9: getRow

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
private static RowDataPacket getRow(String charset) {
    CobarServer server = CobarServer.getInstance();
    long startupTime = server.getStartupTime();
    long now = TimeUtil.currentTimeMillis();
    long uptime = now - startupTime;
    Runtime rt = Runtime.getRuntime();
    long total = rt.totalMemory();
    long max = rt.maxMemory();
    long used = (total - rt.freeMemory());
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(FormatUtil.formatTime(uptime, 3), charset));
    row.add(LongUtil.toBytes(used));
    row.add(LongUtil.toBytes(total));
    row.add(LongUtil.toBytes(max));
    row.add(LongUtil.toBytes(server.getConfig().getReloadTime()));
    row.add(LongUtil.toBytes(server.getConfig().getRollbackTime()));
    row.add(StringUtil.encode(charset, charset));
    row.add(StringUtil.encode(CobarServer.getInstance().isOnline() ? "ON" : "OFF", charset));
    return row;
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:21,代码来源:ShowServer.java

示例10: execute

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
public static void execute(String stmt, ManagerConnection c) {
    int count = 0;
    Pair<String[], Integer> keys = ManagerParseStop.getPair(stmt);
    if (keys.getKey() != null && keys.getValue() != null) {
        long time = keys.getValue().intValue() * 1000L;
        Map<String, MySQLDataNode> dns = CobarServer.getInstance().getConfig().getDataNodes();
        for (String key : keys.getKey()) {
            MySQLDataNode dn = dns.get(key);
            if (dn != null) {
                dn.setHeartbeatRecoveryTime(TimeUtil.currentTimeMillis() + time);
                ++count;
                StringBuilder s = new StringBuilder();
                s.append(dn.getName()).append(" stop heartbeat '");
                logger.warn(s.append(FormatUtil.formatTime(time, 3)).append("' by manager."));
            }
        }
    }
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = count;
    packet.serverStatus = 2;
    packet.write(c);
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:24,代码来源:StopHeartbeat.java

示例11: response

import com.alibaba.cobar.CobarServer; //导入依赖的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

示例12: response

import com.alibaba.cobar.CobarServer; //导入依赖的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

示例13: getRouteResultset

import com.alibaba.cobar.CobarServer; //导入依赖的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

示例14: execute

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
public void execute() throws Exception {
    lock.lock();
    try {
        this.isRunning = true;
        this.packetId = 0;
        this.buffer = session.getSource().allocate();
    } finally {
        lock.unlock();
    }
    final MySQLConnection conn = session.getTarget(route);
    if (conn == null) {
        CobarConfig conf = CobarServer.getInstance().getConfig();
        MySQLDataNode dn = conf.getDataNodes().get(route.getName());
        dn.getConnection(this, null);
    } else {
        conn.setRunning(true);
        session.getSource().getProcessor().getExecutor().execute(new Runnable() {
            @Override
            public void run() {
                _execute(conn);
            }
        });
    }
}
 
开发者ID:alibaba,项目名称:cobar,代码行数:25,代码来源:SingleNodeHandler.java

示例15: execute

import com.alibaba.cobar.CobarServer; //导入依赖的package包/类
public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();

    // write header
    buffer = header.write(buffer, c);

    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }

    // write eof
    buffer = eof.write(buffer, c);

    // write rows
    byte packetId = eof.packetId;
    String charset = c.getCharset();
    for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
        for (FrontendConnection fc : p.getFrontends().values()) {
            if (!fc.isClosed()) {
                RowDataPacket row = getRow(fc, charset);
                row.packetId = ++packetId;
                buffer = row.write(buffer, c);
            }
        }
    }

    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);

    // write buffer
    c.write(buffer);
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:36,代码来源:ShowConnectionSQL.java


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