Search in sources :

Example 1 with BinaryInputStream

use of org.apache.ignite.internal.binary.streams.BinaryInputStream 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 BinaryInputStream

use of org.apache.ignite.internal.binary.streams.BinaryInputStream in project ignite by apache.

the class CacheObjectBinaryProcessorImpl method unmarshal.

/**
     * @param ptr Off-heap pointer.
     * @param forceHeap If {@code true} creates heap-based object.
     * @return Object.
     * @throws BinaryObjectException If failed.
     */
public Object unmarshal(long ptr, boolean forceHeap) throws BinaryObjectException {
    assert ptr > 0 : ptr;
    int size = GridUnsafe.getInt(ptr);
    ptr += 4;
    byte type = GridUnsafe.getByte(ptr++);
    if (type != CacheObject.TYPE_BYTE_ARR) {
        assert size > 0 : size;
        BinaryInputStream in = new BinaryOffheapInputStream(ptr, size, forceHeap);
        return binaryMarsh.unmarshal(in);
    } else
        return U.copyMemory(ptr, size);
}
Also used : BinaryOffheapInputStream(org.apache.ignite.internal.binary.streams.BinaryOffheapInputStream) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream)

Example 3 with BinaryInputStream

use of org.apache.ignite.internal.binary.streams.BinaryInputStream in project ignite by apache.

the class OdbcMessageParser method decode.

/** {@inheritDoc} */
@Override
public SqlListenerRequest decode(byte[] msg) {
    assert msg != null;
    BinaryInputStream stream = new BinaryHeapInputStream(msg);
    BinaryReaderExImpl reader = new BinaryReaderExImpl(marsh.context(), stream, ctx.config().getClassLoader(), true);
    byte cmd = reader.readByte();
    SqlListenerRequest res;
    switch(cmd) {
        case OdbcRequest.QRY_EXEC:
            {
                String cache = reader.readString();
                String sql = reader.readString();
                int argsNum = reader.readInt();
                Object[] params = new Object[argsNum];
                for (int i = 0; i < argsNum; ++i) params[i] = SqlListenerUtils.readObject(reader, true);
                res = new OdbcQueryExecuteRequest(cache, sql, params);
                break;
            }
        case OdbcRequest.QRY_FETCH:
            {
                long queryId = reader.readLong();
                int pageSize = reader.readInt();
                res = new OdbcQueryFetchRequest(queryId, pageSize);
                break;
            }
        case OdbcRequest.QRY_CLOSE:
            {
                long queryId = reader.readLong();
                res = new OdbcQueryCloseRequest(queryId);
                break;
            }
        case OdbcRequest.META_COLS:
            {
                String cache = reader.readString();
                String table = reader.readString();
                String column = reader.readString();
                res = new OdbcQueryGetColumnsMetaRequest(cache, table, column);
                break;
            }
        case OdbcRequest.META_TBLS:
            {
                String catalog = reader.readString();
                String schema = reader.readString();
                String table = reader.readString();
                String tableType = reader.readString();
                res = new OdbcQueryGetTablesMetaRequest(catalog, schema, table, tableType);
                break;
            }
        case OdbcRequest.META_PARAMS:
            {
                String cacheName = reader.readString();
                String sqlQuery = reader.readString();
                res = new OdbcQueryGetParamsMetaRequest(cacheName, sqlQuery);
                break;
            }
        default:
            throw new IgniteException("Unknown ODBC command: [cmd=" + cmd + ']');
    }
    return res;
}
Also used : BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) BinaryInputStream(org.apache.ignite.internal.binary.streams.BinaryInputStream) SqlListenerRequest(org.apache.ignite.internal.processors.odbc.SqlListenerRequest) IgniteException(org.apache.ignite.IgniteException) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream)

Aggregations

BinaryInputStream (org.apache.ignite.internal.binary.streams.BinaryInputStream)3 BinaryReaderExImpl (org.apache.ignite.internal.binary.BinaryReaderExImpl)2 BinaryHeapInputStream (org.apache.ignite.internal.binary.streams.BinaryHeapInputStream)2 IgniteException (org.apache.ignite.IgniteException)1 BinaryWriterExImpl (org.apache.ignite.internal.binary.BinaryWriterExImpl)1 BinaryHeapOutputStream (org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream)1 BinaryOffheapInputStream (org.apache.ignite.internal.binary.streams.BinaryOffheapInputStream)1 SqlListenerRequest (org.apache.ignite.internal.processors.odbc.SqlListenerRequest)1