Пример #1
0
 @Override
 public ByteBuffer write(ByteBuffer buffer, FrontendConnection c) {
   int size = calcPacketSize();
   buffer = c.checkWriteBuffer(buffer, c.getPacketHeaderSize() + size);
   BufferUtil.writeUB3(buffer, size);
   buffer.put(packetId);
   buffer.put(fieldCount);
   BufferUtil.writeUB2(buffer, warningCount);
   BufferUtil.writeUB2(buffer, status);
   return buffer;
 }
Пример #2
0
  public void startup() throws IOException {
    SystemConfig system = CobarServer.getInstance().getConfig().getSystem();
    FrontendConnection.setServerVersion(VERSION);
    // start processors
    NIOProcessor[] processors = new NIOProcessor[system.getProcessors()];

    for (int i = 0; i < processors.length; i++) {
      processors[i] =
          new NIOProcessor(
              "Processor" + i, system.getProcessorHandler(), system.getProcessorExecutor());
      processors[i].startup();
    }

    // startup connector
    NIOConnector connector = new NIOConnector("BeeConnector");

    connector.setProcessors(processors);
    connector.start();

    // startup server
    SimpleServerConnectionFactory sf = new SimpleServerConnectionFactory();

    sf.setIdleTimeout(system.getIdleTimeout()); // one hour
    sf.setContainer(ContainerLoader.getDefaultContainer());

    NIOAcceptor server = new NIOAcceptor("BeeServer", m_port, sf);

    server.setProcessors(processors);
    server.start();

    Threads.forGroup("Bee").start(new ProcessorCheckTask(processors));

    LOGGER.info(String.format("BEE server started at %s", m_port));
  }
Пример #3
0
 public void write(FrontendConnection c) {
   ByteBuffer buffer = c.allocate();
   BufferUtil.writeUB3(buffer, getPacketLength());
   buffer.put(packetId);
   buffer.put(protocolVersion);
   BufferUtil.writeWithNull(buffer, serverVersion);
   BufferUtil.writeUB4(buffer, threadId);
   BufferUtil.writeWithNull(buffer, seed);
   BufferUtil.writeUB2(buffer, serverCapabilities);
   buffer.put(serverCharsetIndex);
   BufferUtil.writeUB2(buffer, serverStatus);
   // buffer.position(buffer.position() + 13);
   for (int i = 1; i <= 13; i++) {
     buffer.put((byte) 0);
   }
   BufferUtil.writeWithNull(buffer, restOfScrambleBuff);
   c.write(buffer);
 }
Пример #4
0
 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);
 }