/** {@inheritDoc} */ @Override public Marshaller create() { return new BinaryMarshaller(); } }
/** * 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, new IgniteConfiguration()); return new GridBinaryMarshaller(ctx); }
BinaryMarshaller marsh = new BinaryMarshaller(); marsh.setContext(new MarshallerContextWithNoStorage()); assertEquals(simpleObj, marsh.unmarshal(marsh.marshal(simpleObj), null)); simpleBinary.arr = new long[] {100, 200, 300}; assertEquals(simpleBinary, marsh.unmarshal(marsh.marshal(simpleBinary), null)); simpleExtr.arr = new long[] {20000, 300000, 400000}; assertEquals(simpleExtr, marsh.unmarshal(marsh.marshal(simpleExtr), null));
if (!BinaryMarshaller.available()) { U.warn(log, "OptimizedMarshaller is not supported on this JVM " + "(only recent 1.6 and 1.7 versions HotSpot VMs are supported). " + marsh = new BinaryMarshaller();
/** {@inheritDoc} */ @Override protected void marshal0(@Nullable Object obj, OutputStream out) throws IgniteCheckedException { byte[] arr = marshal(obj); try { out.write(arr); } catch (Exception e) { throw new BinaryObjectException("Failed to marshal the object: " + obj, e); } }
/** * @throws Exception If failed. */ @Test public void testDeclaredBodyEnum() throws Exception { final MarshallerContextTestImpl ctx = new MarshallerContextTestImpl(); ctx.registerClassName((byte)0, 1, EnumObject.class.getName()); ctx.registerClassName((byte)0, 2, DeclaredBodyEnum.class.getName()); BinaryMarshaller marsh = binaryMarshaller(); marsh.setContext(ctx); EnumObject obj = new EnumObject(1L, "test 1", DeclaredBodyEnum.TWO); final byte[] marshal = marsh.marshal(obj); final Object restored = marsh.unmarshal(marshal, null); assertTrue(restored instanceof EnumObject); obj = (EnumObject)restored; assertEquals(1, obj.id); assertEquals(DeclaredBodyEnum.TWO.ordinal(), obj.type.ordinal()); assertEquals(DeclaredBodyEnum.TWO, obj.type); assertTrue(obj.type == DeclaredBodyEnum.TWO); }
/** {@inheritDoc} */ @SuppressWarnings("IfMayBeConditional") @Override public void unmarshall(Marshaller m, GridKernalContext ctx) { if (errKeys != null || errKeysBytes == null) return; try { final ClassLoader ldr = U.resolveClassLoader(ctx.config()); if (m instanceof BinaryMarshaller) // To avoid deserializing of enum types. errKeys = ((BinaryMarshaller)m).binaryMarshaller().unmarshal(errKeysBytes, ldr); else errKeys = U.unmarshal(m, errKeysBytes, ldr); } catch (IgniteCheckedException e) { throw new IgniteException(e); } }
/** * @param cfg Configuration to check for possible performance issues. */ private void suggestOptimizations(IgniteConfiguration cfg) { GridPerformanceSuggestions perf = ctx.performance(); if (ctx.collision().enabled()) perf.add("Disable collision resolution (remove 'collisionSpi' from configuration)"); if (ctx.checkpoint().enabled()) perf.add("Disable checkpoints (remove 'checkpointSpi' from configuration)"); if (cfg.isMarshalLocalJobs()) perf.add("Disable local jobs marshalling (set 'marshalLocalJobs' to false)"); if (cfg.getIncludeEventTypes() != null && cfg.getIncludeEventTypes().length != 0) perf.add("Disable grid events (remove 'includeEventTypes' from configuration)"); if (BinaryMarshaller.available() && (cfg.getMarshaller() != null && !(cfg.getMarshaller() instanceof BinaryMarshaller))) perf.add("Use default binary marshaller (do not set 'marshaller' explicitly)"); }
/** * @param marsh Binary marshaller. * @param cfg Configuration. * @throws BinaryObjectException In case of error. */ public void configure(BinaryMarshaller marsh, IgniteConfiguration cfg) throws BinaryObjectException { if (marsh == null) return; this.marsh = marsh; marshCtx = marsh.getContext(); BinaryConfiguration binaryCfg = cfg.getBinaryConfiguration(); if (binaryCfg == null) binaryCfg = new BinaryConfiguration(); assert marshCtx != null; optmMarsh.setContext(marshCtx); configure( binaryCfg.getNameMapper(), binaryCfg.getIdMapper(), binaryCfg.getSerializer(), binaryCfg.getTypeConfigurations() ); compactFooter = binaryCfg.isCompactFooter(); }
if (!BinaryMarshaller.available()) { U.warn(log, "OptimizedMarshaller is not supported on this JVM " + "(only recent 1.6 and 1.7 versions HotSpot VMs are supported). " + marsh = new BinaryMarshaller();
/** {@inheritDoc} */ @Override protected BinaryObjectExImpl toBinary(BinaryMarshaller marsh, Object obj) throws Exception { byte[] bytes = marsh.marshal(obj); return new BinaryObjectImpl(ctx, bytes, 0); } }
/** {@inheritDoc} */ @SuppressWarnings("IfMayBeConditional") @Override public void unmarshall(Marshaller m, GridKernalContext ctx) { if (params != null) return; assert paramsBytes != null; try { final ClassLoader ldr = U.resolveClassLoader(ctx.config()); if (m instanceof BinaryMarshaller) // To avoid deserializing of enum types. params = ((BinaryMarshaller)m).binaryMarshaller().unmarshal(paramsBytes, ldr); else params = U.unmarshal(m, paramsBytes, ldr); } catch (IgniteCheckedException e) { throw new IgniteException(e); } }
/** * @param cfg Configuration to check for possible performance issues. */ private void suggestOptimizations(IgniteConfiguration cfg) { GridPerformanceSuggestions perf = ctx.performance(); if (ctx.collision().enabled()) perf.add("Disable collision resolution (remove 'collisionSpi' from configuration)"); if (ctx.checkpoint().enabled()) perf.add("Disable checkpoints (remove 'checkpointSpi' from configuration)"); if (cfg.isMarshalLocalJobs()) perf.add("Disable local jobs marshalling (set 'marshalLocalJobs' to false)"); if (cfg.getIncludeEventTypes() != null && cfg.getIncludeEventTypes().length != 0) perf.add("Disable grid events (remove 'includeEventTypes' from configuration)"); if (BinaryMarshaller.available() && (cfg.getMarshaller() != null && !(cfg.getMarshaller() instanceof BinaryMarshaller))) perf.add("Use default binary marshaller (do not set 'marshaller' explicitly)"); }
/** * @param marsh Binary marshaller. * @param cfg Configuration. * @throws BinaryObjectException In case of error. */ public void configure(BinaryMarshaller marsh, IgniteConfiguration cfg) throws BinaryObjectException { if (marsh == null) return; this.marsh = marsh; marshCtx = marsh.getContext(); BinaryConfiguration binaryCfg = cfg.getBinaryConfiguration(); if (binaryCfg == null) binaryCfg = new BinaryConfiguration(); assert marshCtx != null; optmMarsh.setContext(marshCtx); configure( binaryCfg.getNameMapper(), binaryCfg.getIdMapper(), binaryCfg.getSerializer(), binaryCfg.getTypeConfigurations() ); compactFooter = binaryCfg.isCompactFooter(); }
@Override public Marshaller call() throws Exception { return new BinaryMarshaller(); } };
/** Create new marshaller implementation. */ private GridBinaryMarshaller createImpl(BinaryConfiguration binCfg) { IgniteConfiguration igniteCfg = new IgniteConfiguration(); if (binCfg == null) { binCfg = new BinaryConfiguration(); binCfg.setCompactFooter(false); } igniteCfg.setBinaryConfiguration(binCfg); BinaryContext ctx = new BinaryContext(metaHnd, igniteCfg, new NullLogger()); BinaryMarshaller marsh = new BinaryMarshaller(); marsh.setContext(marshCtx); ctx.configure(marsh, igniteCfg); ctx.registerUserTypesSchema(); return new GridBinaryMarshaller(ctx); } }
/** * @throws Exception If failed. */ @Test public void testUnregisteredClass() throws Exception { BinaryMarshaller m = binaryMarshaller(null, Collections.singletonList(Value.class.getName())); ClassFieldObject res = m.unmarshal(m.marshal(new ClassFieldObject(Value.class)), null); assertEquals(Value.class, res.cls); }
@Override public void applyx(TestObject obj) throws IgniteCheckedException { tuple.set(marsh.marshal(obj)); } };
/** {@inheritDoc} */ @SuppressWarnings("IfMayBeConditional") @Override public void unmarshall(Marshaller m, GridKernalContext ctx) { if (params != null) return; assert paramsBytes != null; try { final ClassLoader ldr = U.resolveClassLoader(ctx.config()); if (m instanceof BinaryMarshaller) // To avoid deserializing of enum types. params = ((BinaryMarshaller)m).binaryMarshaller().unmarshal(paramsBytes, ldr); else params = U.unmarshal(m, paramsBytes, ldr); } catch (IgniteCheckedException e) { throw new IgniteException(e); } }