Search in sources :

Example 11 with BinaryContext

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

the class ClientListenerNioListener method onHandshake.

/**
 * Perform handshake.
 *
 * @param ses Session.
 * @param msg Message bytes.
 */
private void onHandshake(GridNioSession ses, ClientMessage msg) {
    BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration(), null);
    BinaryMarshaller marsh = new BinaryMarshaller();
    marsh.setContext(new MarshallerContextImpl(null, null));
    ctx.configure(marsh);
    BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, new BinaryHeapInputStream(msg.payload()), null, true);
    byte cmd = reader.readByte();
    if (cmd != ClientListenerRequest.HANDSHAKE) {
        U.warn(log, "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, ses);
        ensureClientPermissions(clientType);
        if (connCtx.isVersionSupported(ver)) {
            connCtx.initializeFromHandshake(ses, ver, reader);
            ses.addMeta(CONN_CTX_META_KEY, connCtx);
        } else
            throw new IgniteCheckedException("Unsupported version: " + ver.asString());
        cancelHandshakeTimeout(ses);
        connCtx.handler().writeHandshake(writer);
        metrics.onHandshakeAccept(clientType);
    } catch (IgniteAccessControlException authEx) {
        metrics.onFailedAuth();
        writer.writeBoolean(false);
        writer.writeShort((short) 0);
        writer.writeShort((short) 0);
        writer.writeShort((short) 0);
        writer.doWriteString(authEx.getMessage());
        if (ver.compareTo(ClientConnectionContext.VER_1_1_0) >= 0)
            writer.writeInt(ClientStatus.AUTH_FAILED);
    } catch (IgniteCheckedException e) {
        U.warn(log, "Error during handshake [rmtAddr=" + ses.remoteAddress() + ", msg=" + e.getMessage() + ']');
        metrics.onGeneralReject();
        ClientListenerProtocolVersion currVer;
        if (connCtx == null)
            currVer = ClientListenerProtocolVersion.create(0, 0, 0);
        else
            currVer = connCtx.defaultVersion();
        writer.writeBoolean(false);
        writer.writeShort(currVer.major());
        writer.writeShort(currVer.minor());
        writer.writeShort(currVer.maintenance());
        writer.doWriteString(e.getMessage());
        if (ver.compareTo(ClientConnectionContext.VER_1_1_0) >= 0)
            writer.writeInt(ClientStatus.FAILED);
    }
    ses.send(new ClientMessage(writer.array()));
}
Also used : MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) BinaryHeapOutputStream(org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) IgniteAccessControlException(org.apache.ignite.internal.processors.authentication.IgniteAccessControlException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl)

Example 12 with BinaryContext

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

the class ClientBinary method buildEnum.

/**
 * {@inheritDoc}
 */
@Override
public BinaryObject buildEnum(String typeName, String name) {
    if (typeName == null || typeName.isEmpty())
        throw new IllegalArgumentException("typeName");
    if (name == null || name.isEmpty())
        throw new IllegalArgumentException("name");
    BinaryContext ctx = marsh.context();
    int typeId = ctx.typeId(typeName);
    BinaryMetadata metadata = ctx.metadata0(typeId);
    if (metadata == null)
        throw new BinaryObjectException(String.format("Failed to get metadata for type [typeId=%s, typeName='%s']", typeId, typeName));
    Integer ordinal = metadata.getEnumOrdinalByName(name);
    if (ordinal == null)
        throw new BinaryObjectException(String.format("Failed to resolve enum ordinal by name [typeId=%s, typeName='%s', name='%s']", typeId, typeName, name));
    return new BinaryEnumObjectImpl(ctx, typeId, null, ordinal);
}
Also used : BinaryContext(org.apache.ignite.internal.binary.BinaryContext) BinaryEnumObjectImpl(org.apache.ignite.internal.binary.BinaryEnumObjectImpl) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 13 with BinaryContext

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

the class ClientBinary method registerEnum.

/**
 * {@inheritDoc}
 */
@Override
public BinaryType registerEnum(String typeName, Map<String, Integer> vals) {
    if (typeName == null || typeName.isEmpty())
        throw new IllegalArgumentException("typeName");
    BinaryContext ctx = marsh.context();
    int typeId = ctx.typeId(typeName);
    ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, null, null, null, true, vals), false);
    return ctx.metadata(typeId);
}
Also used : BinaryContext(org.apache.ignite.internal.binary.BinaryContext) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata)

Example 14 with BinaryContext

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

the class ClientBinary method buildEnum.

/**
 * {@inheritDoc}
 */
@Override
public BinaryObject buildEnum(String typeName, int ord) {
    if (typeName == null || typeName.isEmpty())
        throw new IllegalArgumentException("typeName");
    BinaryContext ctx = marsh.context();
    int typeId = ctx.typeId(typeName);
    return new BinaryEnumObjectImpl(ctx, typeId, null, ord);
}
Also used : BinaryContext(org.apache.ignite.internal.binary.BinaryContext) BinaryEnumObjectImpl(org.apache.ignite.internal.binary.BinaryEnumObjectImpl)

Example 15 with BinaryContext

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

the class ClientBinaryTypePutRequest method process.

/**
 * {@inheritDoc}
 */
@Override
public ClientResponse process(ClientConnectionContext ctx) {
    BinaryContext binCtx = ((CacheObjectBinaryProcessorImpl) ctx.kernalContext().cacheObjects()).binaryContext();
    binCtx.updateMetadata(meta.typeId(), meta, false);
    return super.process(ctx);
}
Also used : CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) BinaryContext(org.apache.ignite.internal.binary.BinaryContext)

Aggregations

BinaryContext (org.apache.ignite.internal.binary.BinaryContext)22 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)14 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)12 NullLogger (org.apache.ignite.logger.NullLogger)10 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)7 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)6 MarshallerContextTestImpl (org.apache.ignite.marshaller.MarshallerContextTestImpl)6 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 IgniteException (org.apache.ignite.IgniteException)3 MarshallerContextImpl (org.apache.ignite.internal.MarshallerContextImpl)3 BinaryWriterExImpl (org.apache.ignite.internal.binary.BinaryWriterExImpl)3 BinaryHeapOutputStream (org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream)3 CacheObjectBinaryProcessorImpl (org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl)3 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryType (org.apache.ignite.binary.BinaryType)2 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2