Search in sources :

Example 1 with BinaryReaderExImpl

use of org.apache.ignite.internal.binary.BinaryReaderExImpl in project ignite by apache.

the class SqlListenerNioListener method onHandshake.

/**
     * Perform handshake.
     *
     * @param ses Session.
     * @param msg Message bytes.
     */
private void onHandshake(GridNioSession ses, byte[] msg) {
    BinaryInputStream stream = new BinaryHeapInputStream(msg);
    BinaryReaderExImpl reader = new BinaryReaderExImpl(null, stream, null, true);
    byte cmd = reader.readByte();
    if (cmd != SqlListenerRequest.HANDSHAKE) {
        log.error("Unexpected SQL client request (will close session): " + ses.remoteAddress());
        ses.close();
        return;
    }
    short verMajor = reader.readShort();
    short verMinor = reader.readShort();
    short verMaintenance = reader.readShort();
    SqlListenerProtocolVersion ver = SqlListenerProtocolVersion.create(verMajor, verMinor, verMaintenance);
    String errMsg = null;
    if (SUPPORTED_VERS.contains(ver)) {
        // Prepare context.
        SqlListenerConnectionContext connCtx = prepareContext(ver, reader);
        ses.addMeta(CONN_CTX_META_KEY, connCtx);
    } else {
        log.warning("Unsupported version: " + ver.toString());
        errMsg = "Unsupported version.";
    }
    // Send response.
    BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(8), null, null);
    if (errMsg == null)
        writer.writeBoolean(true);
    else {
        writer.writeBoolean(false);
        writer.writeShort(CURRENT_VER.major());
        writer.writeShort(CURRENT_VER.minor());
        writer.writeShort(CURRENT_VER.maintenance());
        writer.doWriteString(errMsg);
    }
    ses.send(writer.array());
}
Also used : BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) BinaryHeapOutputStream(org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl)

Example 2 with BinaryReaderExImpl

use of org.apache.ignite.internal.binary.BinaryReaderExImpl in project ignite by apache.

the class JdbcThinTcpIo method handshake.

/**
     * @throws IOException On error.
     * @throws IgniteCheckedException On error.
     */
public void handshake() throws IOException, IgniteCheckedException {
    BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(HANDSHAKE_MSG_SIZE), null, null);
    writer.writeByte((byte) SqlListenerRequest.HANDSHAKE);
    writer.writeShort(CURRENT_VER.major());
    writer.writeShort(CURRENT_VER.minor());
    writer.writeShort(CURRENT_VER.maintenance());
    writer.writeByte(SqlListenerNioListener.JDBC_CLIENT);
    writer.writeBoolean(distributedJoins);
    writer.writeBoolean(enforceJoinOrder);
    send(writer.array());
    BinaryReaderExImpl reader = new BinaryReaderExImpl(null, new BinaryHeapInputStream(read()), null, null, false);
    boolean accepted = reader.readBoolean();
    if (accepted)
        return;
    short maj = reader.readShort();
    short min = reader.readShort();
    short maintenance = reader.readShort();
    String err = reader.readString();
    SqlListenerProtocolVersion ver = SqlListenerProtocolVersion.create(maj, min, maintenance);
    throw new IgniteCheckedException("Handshake failed [driverProtocolVer=" + CURRENT_VER + ", remoteNodeProtocolVer=" + ver + ", err=" + err + ']');
}
Also used : SqlListenerProtocolVersion(org.apache.ignite.internal.processors.odbc.SqlListenerProtocolVersion) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryHeapOutputStream(org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl)

Example 3 with BinaryReaderExImpl

use of org.apache.ignite.internal.binary.BinaryReaderExImpl in project ignite by apache.

the class ClientMessageParser method decode.

/**
 * {@inheritDoc}
 */
@Override
public ClientListenerRequest decode(byte[] msg) {
    assert msg != null;
    BinaryInputStream inStream = new BinaryHeapInputStream(msg);
    // skipHdrCheck must be true (we have 103 op code).
    BinaryRawReaderEx reader = new BinaryReaderExImpl(marsh.context(), inStream, null, null, true, true);
    return decode(reader);
}
Also used : BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx)

Example 4 with BinaryReaderExImpl

use of org.apache.ignite.internal.binary.BinaryReaderExImpl in project ignite by apache.

the class ClientListenerNioListener method onHandshake.

/**
 * Perform handshake.
 *
 * @param ses Session.
 * @param msg Message bytes.
 */
private void onHandshake(GridNioSession ses, byte[] msg) {
    BinaryInputStream stream = new BinaryHeapInputStream(msg);
    BinaryReaderExImpl reader = new BinaryReaderExImpl(null, stream, null, true);
    byte cmd = reader.readByte();
    if (cmd != ClientListenerRequest.HANDSHAKE) {
        log.error("Unexpected client request (will close session): " + ses.remoteAddress());
        ses.close();
        return;
    }
    short verMajor = reader.readShort();
    short verMinor = reader.readShort();
    short verMaintenance = reader.readShort();
    ClientListenerProtocolVersion ver = ClientListenerProtocolVersion.create(verMajor, verMinor, verMaintenance);
    BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(8), null, null);
    byte clientType = reader.readByte();
    ClientListenerConnectionContext connCtx = null;
    try {
        connCtx = prepareContext(clientType);
        ensureClientPermissions(clientType);
        if (connCtx.isVersionSupported(ver)) {
            connCtx.initializeFromHandshake(ver, reader);
            ses.addMeta(CONN_CTX_META_KEY, connCtx);
        } else {
            log.warning("Unsupported version: " + ver.toString());
            throw new IgniteCheckedException("Unsupported version.");
        }
        connCtx.handler().writeHandshake(writer);
    } catch (IgniteCheckedException e) {
        log.error("Error on handshake. " + e.getMessage(), e);
        ClientListenerProtocolVersion currVer;
        if (connCtx == null)
            currVer = ClientListenerProtocolVersion.create(0, 0, 0);
        else
            currVer = connCtx.currentVersion();
        writer.writeBoolean(false);
        writer.writeShort(currVer.major());
        writer.writeShort(currVer.minor());
        writer.writeShort(currVer.maintenance());
        writer.doWriteString(e.getMessage());
    }
    ses.send(writer.array());
}
Also used : BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) BinaryHeapOutputStream(org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl)

Example 5 with BinaryReaderExImpl

use of org.apache.ignite.internal.binary.BinaryReaderExImpl in project ignite by apache.

the class ClientServicesImpl method serviceDescriptors.

/**
 * {@inheritDoc}
 */
@Override
public Collection<ClientServiceDescriptor> serviceDescriptors() {
    return ch.service(ClientOperation.SERVICE_GET_DESCRIPTORS, req -> checkGetServiceDescriptorsSupported(req.clientChannel().protocolCtx()), res -> {
        try (BinaryReaderExImpl reader = utils.createBinaryReader(res.in())) {
            int sz = res.in().readInt();
            Collection<ClientServiceDescriptor> svcs = new ArrayList<>(sz);
            for (int i = 0; i < sz; i++) svcs.add(readServiceDescriptor(reader));
            return svcs;
        } catch (IOException e) {
            throw new ClientException(e);
        }
    });
}
Also used : BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) ClientServiceDescriptor(org.apache.ignite.client.ClientServiceDescriptor) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ClientException(org.apache.ignite.client.ClientException)

Aggregations

BinaryReaderExImpl (org.apache.ignite.internal.binary.BinaryReaderExImpl)19 BinaryHeapInputStream (org.apache.ignite.internal.binary.streams.BinaryHeapInputStream)15 BinaryWriterExImpl (org.apache.ignite.internal.binary.BinaryWriterExImpl)10 BinaryInputStream (org.apache.ignite.internal.binary.streams.BinaryInputStream)9 BinaryHeapOutputStream (org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream)8 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 HashMap (java.util.HashMap)3 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)3 JdbcResponse (org.apache.ignite.internal.processors.odbc.jdbc.JdbcResponse)3 Array (java.lang.reflect.Array)2 SQLException (java.sql.SQLException)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2