use of org.apache.ignite.internal.MarshallerContextImpl in project ignite by apache.
the class PlatformUtils method marshaller.
/**
* Create binary marshaller.
*
* @return Marshaller.
*/
public static GridBinaryMarshaller marshaller() {
BinaryContext ctx = new BinaryContext(BinaryNoopMetadataHandler.instance(), new IgniteConfiguration(), new NullLogger());
BinaryMarshaller marsh = new BinaryMarshaller();
marsh.setContext(new MarshallerContextImpl(null, null));
ctx.configure(marsh);
return new GridBinaryMarshaller(ctx);
}
use of org.apache.ignite.internal.MarshallerContextImpl in project ignite by apache.
the class MarshallerContextSelfTest method testClassName.
/**
* @throws Exception If failed.
*/
@Test
public void testClassName() throws Exception {
MarshallerContextImpl marshCtx = new MarshallerContextImpl(null, null);
marshCtx.onMarshallerProcessorStarted(ctx, null);
MarshallerMappingItem item = new MarshallerMappingItem(JAVA_ID, 1, String.class.getName());
marshCtx.onMappingProposed(item);
marshCtx.onMappingAccepted(item);
try (Ignite g1 = startGrid(1)) {
marshCtx = ((IgniteKernal) g1).context().marshallerContext();
String clsName = marshCtx.getClassName(JAVA_ID, 1);
assertEquals("java.lang.String", clsName);
}
}
use of org.apache.ignite.internal.MarshallerContextImpl in project ignite by apache.
the class MarshallerContextSelfTest method testCacheStructure0.
/**
* Tests that there is a null value inserted in allCaches list
* if platform ids passed to marshaller cache were not sequential (like 0, 2).
*/
@Test
public void testCacheStructure0() throws Exception {
MarshallerContextImpl ctx = new MarshallerContextImpl(null, null);
ctx.onMarshallerProcessorStarted(this.ctx, null);
MarshallerMappingItem item1 = new MarshallerMappingItem(JAVA_ID, 1, String.class.getName());
ctx.onMappingAccepted(item1);
MarshallerMappingItem item2 = new MarshallerMappingItem((byte) 2, 2, "Random.Class.Name");
ctx.onMappingProposed(item2);
List list = U.field(ctx, "allCaches");
assertNotNull("Mapping cache is null for platformId: 0", list.get(0));
assertNull("Mapping cache is not null for platformId: 1", list.get(1));
assertNotNull("Mapping cache is null for platformId: 2", list.get(2));
boolean excObserved = false;
try {
list.get(3);
} catch (ArrayIndexOutOfBoundsException ignored) {
excObserved = true;
}
assertTrue("ArrayIndexOutOfBoundsException had to be thrown", excObserved);
}
use of org.apache.ignite.internal.MarshallerContextImpl in project ignite by apache.
the class MarshallerContextSelfTest method testMultiplatformMappingsDistributing.
/**
* Test for adding non-java mappings (with platformId > 0) to MarshallerContext and distributing them
* to newly joining nodes.
*
* @throws Exception If failed.
*/
@Test
public void testMultiplatformMappingsDistributing() throws Exception {
String nonJavaClassName = "random.platform.Mapping";
Ignite grid0 = startGrid(0);
MarshallerContextImpl marshCtx0 = ((IgniteKernal) grid0).context().marshallerContext();
MarshallerMappingItem item = new MarshallerMappingItem((byte) 2, 101, nonJavaClassName);
marshCtx0.onMappingProposed(item);
marshCtx0.onMappingAccepted(item);
Ignite grid1 = startGrid(1);
MarshallerContextImpl marshCtx1 = ((IgniteKernal) grid1).context().marshallerContext();
assertEquals(nonJavaClassName, marshCtx1.getClassName((byte) 2, 101));
}
use of org.apache.ignite.internal.MarshallerContextImpl 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()));
}
Aggregations