use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.
the class IgniteKernal method createComponent.
/**
* Creates optional component.
*
* @param cls Component interface.
* @param ctx Kernal context.
* @return Created component.
* @throws IgniteCheckedException If failed to create component.
*/
private static <T extends GridComponent> T createComponent(Class<T> cls, GridKernalContext ctx) throws IgniteCheckedException {
assert cls.isInterface() : cls;
T comp = ctx.plugins().createComponent(cls);
if (comp != null)
return comp;
if (cls.equals(IgniteCacheObjectProcessor.class))
return (T) new CacheObjectBinaryProcessorImpl(ctx);
if (cls.equals(DiscoveryNodeValidationProcessor.class))
return (T) new OsDiscoveryNodeValidationProcessor(ctx);
Class<T> implCls = null;
try {
String clsName;
// Handle special case for PlatformProcessor
if (cls.equals(PlatformProcessor.class))
clsName = ctx.config().getPlatformConfiguration() == null ? PlatformNoopProcessor.class.getName() : cls.getName() + "Impl";
else
clsName = componentClassName(cls);
implCls = (Class<T>) Class.forName(clsName);
} catch (ClassNotFoundException ignore) {
// No-op.
}
if (implCls == null)
throw new IgniteCheckedException("Failed to find component implementation: " + cls.getName());
if (!cls.isAssignableFrom(implCls))
throw new IgniteCheckedException("Component implementation does not implement component interface " + "[component=" + cls.getName() + ", implementation=" + implCls.getName() + ']');
Constructor<T> constructor;
try {
constructor = implCls.getConstructor(GridKernalContext.class);
} catch (NoSuchMethodException e) {
throw new IgniteCheckedException("Component does not have expected constructor: " + implCls.getName(), e);
}
try {
return constructor.newInstance(ctx);
} catch (ReflectiveOperationException e) {
throw new IgniteCheckedException("Failed to create component [component=" + cls.getName() + ", implementation=" + implCls.getName() + ']', e);
}
}
use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.
the class GridBinaryMarshaller method threadLocalContext.
/**
* @return Thread-bound context.
*/
public static BinaryContext threadLocalContext() {
BinaryContext ctx = GridBinaryMarshaller.BINARY_CTX.get();
if (ctx == null) {
IgniteKernal ignite = IgnitionEx.localIgnite();
IgniteCacheObjectProcessor proc = ignite.context().cacheObjects();
if (proc instanceof CacheObjectBinaryProcessorImpl)
return ((CacheObjectBinaryProcessorImpl) proc).binaryContext();
else
throw new IgniteIllegalStateException("Ignite instance must be started with " + BinaryMarshaller.class.getName() + " [name=" + ignite.name() + ']');
}
return ctx;
}
use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.
the class GridCacheProcessor method withBinaryContext.
/**
* @param c Closure.
* @return Closure result.
* @throws IgniteCheckedException If failed.
*/
private <T> T withBinaryContext(IgniteOutClosureX<T> c) throws IgniteCheckedException {
IgniteCacheObjectProcessor objProc = ctx.cacheObjects();
BinaryContext oldCtx = null;
if (objProc instanceof CacheObjectBinaryProcessorImpl) {
GridBinaryMarshaller binMarsh = ((CacheObjectBinaryProcessorImpl) objProc).marshaller();
oldCtx = binMarsh == null ? null : binMarsh.pushContext();
}
try {
return c.applyx();
} finally {
if (objProc instanceof CacheObjectBinaryProcessorImpl)
GridBinaryMarshaller.popContext(oldCtx);
}
}
use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.
the class BinaryEnumsSelfTest method testZeroTypeId.
/**
* Check ability to resolve typeId from class name.
*
* @throws Exception If failed.
*/
public void testZeroTypeId() throws Exception {
startUp(true);
final BinaryContext ctx = ((CacheObjectBinaryProcessorImpl) ((IgniteEx) node1).context().cacheObjects()).binaryContext();
final BinaryObject enumObj = new BinaryEnumObjectImpl(ctx, 0, EnumType.class.getName(), EnumType.ONE.ordinal());
assert enumObj.type().isEnum();
}
use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.
the class BinaryObjectBuilderDefaultMappersSelfTest method testSetBinaryObject.
/**
*
*/
public void testSetBinaryObject() {
// Prepare marshaller context.
CacheObjectBinaryProcessorImpl proc = ((CacheObjectBinaryProcessorImpl) (grid(0)).context().cacheObjects());
proc.marshal(new GridBinaryTestClasses.TestObjectContainer());
proc.marshal(new GridBinaryTestClasses.TestObjectAllTypes());
// Actual test.
BinaryObject binaryObj = builder(GridBinaryTestClasses.TestObjectContainer.class.getName()).setField("foo", toBinary(new GridBinaryTestClasses.TestObjectAllTypes())).build();
assertTrue(binaryObj.<GridBinaryTestClasses.TestObjectContainer>deserialize().foo instanceof GridBinaryTestClasses.TestObjectAllTypes);
}
Aggregations