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()));
}
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);
}
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);
}
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);
}
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);
}
Aggregations