public TR InObjectStreamOutObjectStream <TR>(int type, Action <IBinaryStream> writeAction, Func <IBinaryStream, IPlatformTargetInternal, TR> readAction, IPlatformTargetInternal arg) { PlatformMemoryStream outStream = null; long outPtr = 0; PlatformMemoryStream inStream = null; long inPtr = 0; try { if (writeAction != null) { outStream = IgniteManager.Memory.Allocate().GetStream(); writeAction(outStream); outPtr = outStream.SynchronizeOutput(); } if (readAction != null) { inStream = IgniteManager.Memory.Allocate().GetStream(); inPtr = inStream.MemoryPointer; } var res = UU.TargetInObjectStreamOutObjectStream(_target, type, ((PlatformJniTarget)arg).Target, outPtr, inPtr); if (readAction == null) { return(default(TR)); } inStream.SynchronizeInput(); var target = res == null ? null : new PlatformJniTarget(res, _marsh); return(readAction(inStream, target)); } catch (JavaException jex) { throw ConvertException(jex); } finally { try { if (inStream != null) { inStream.Dispose(); } } finally { if (outStream != null) { outStream.Dispose(); } } } }
/// <summary> /// Check stream reallocation. /// </summary> /// <param name="mem">Memory.</param> private void CheckStreamReallocate(IPlatformMemory mem) { Assert.IsTrue(mem.Capacity >= 256); int dataLen = 2048 + 13; Random rand = new Random(); byte[] data = new byte[dataLen]; for (int i = 0; i < data.Length; i++) { data[i] = (byte)rand.Next(0, 255); } PlatformMemoryStream stream = mem.Stream(); stream.WriteByteArray(data); stream.SynchronizeOutput(); Assert.IsTrue(mem.Capacity >= dataLen); stream.Reset(); stream.SynchronizeInput(); byte[] data0 = stream.ReadByteArray(dataLen); Assert.AreEqual(data, data0); }
/// <summary> /// Invokes the proxy. /// </summary> /// <param name="method">Method.</param> /// <param name="args">Arguments.</param> /// <returns> /// Invocation result. /// </returns> private object InvokeProxyMethod(MethodBase method, object[] args) { using (var inStream = new PlatformMemoryStream(_memory.Allocate())) using (var outStream = new PlatformMemoryStream(_memory.Allocate())) { // 1) Write to a stream inStream.WriteBool(SrvKeepBinary); // WriteProxyMethod does not do this, but Java does ServiceProxySerializer.WriteProxyMethod(_marsh.StartMarshal(inStream), method, args); inStream.SynchronizeOutput(); inStream.Seek(0, SeekOrigin.Begin); // 2) call InvokeServiceMethod string mthdName; object[] mthdArgs; ServiceProxySerializer.ReadProxyMethod(inStream, _marsh, out mthdName, out mthdArgs); var result = ServiceProxyInvoker.InvokeServiceMethod(_svc, mthdName, mthdArgs); ServiceProxySerializer.WriteInvocationResult(outStream, _marsh, result.Key, result.Value); _marsh.StartMarshal(outStream).WriteString("unused"); // fake Java exception details outStream.SynchronizeOutput(); outStream.Seek(0, SeekOrigin.Begin); return(ServiceProxySerializer.ReadInvocationResult(outStream, _marsh, KeepBinary)); } }
/** <inheritdoc /> */ public T InObjectStreamOutObjectStream <T>(int type, IPlatformTarget arg, Action <IBinaryRawWriter> writeAction, Func <IBinaryRawReader, IPlatformTarget, T> readAction) { PlatformMemoryStream outStream = null; long outPtr = 0; PlatformMemoryStream inStream = null; long inPtr = 0; try { if (writeAction != null) { outStream = IgniteManager.Memory.Allocate().GetStream(); var writer = _marsh.StartMarshal(outStream); writeAction(writer); FinishMarshal(writer); outPtr = outStream.SynchronizeOutput(); } if (readAction != null) { inStream = IgniteManager.Memory.Allocate().GetStream(); inPtr = inStream.MemoryPointer; } var res = UU.TargetInObjectStreamOutObjectStream(_target, type, GetTargetPtr(arg), outPtr, inPtr); if (readAction == null) { return(default(T)); } inStream.SynchronizeInput(); return(readAction(_marsh.StartUnmarshal(inStream), GetPlatformTarget(res))); } catch (JavaException jex) { throw ConvertException(jex); } finally { try { if (inStream != null) { inStream.Dispose(); } } finally { if (outStream != null) { outStream.Dispose(); } } } }
/// <summary> /// Perform out-in operation. /// </summary> /// <param name="type">Operation type.</param> /// <param name="outAction">Out action.</param> /// <param name="inAction">In action.</param> /// <param name="arg">Argument.</param> /// <returns>Result.</returns> protected unsafe TR DoOutInOp <TR>(int type, Action <BinaryWriter> outAction, Func <IBinaryStream, IUnmanagedTarget, TR> inAction, void *arg) { PlatformMemoryStream outStream = null; long outPtr = 0; PlatformMemoryStream inStream = null; long inPtr = 0; try { if (outAction != null) { outStream = IgniteManager.Memory.Allocate().GetStream(); var writer = _marsh.StartMarshal(outStream); outAction(writer); FinishMarshal(writer); outPtr = outStream.SynchronizeOutput(); } if (inAction != null) { inStream = IgniteManager.Memory.Allocate().GetStream(); inPtr = inStream.MemoryPointer; } var res = UU.TargetInObjectStreamOutObjectStream(_target, type, arg, outPtr, inPtr); if (inAction == null) { return(default(TR)); } inStream.SynchronizeInput(); return(inAction(inStream, res)); } finally { try { if (inStream != null) { inStream.Dispose(); } } finally { if (outStream != null) { outStream.Dispose(); } } } }
private long CacheInvoke(long memPtr) { using (PlatformMemoryStream stream = IgniteManager.Memory.Get(memPtr).GetStream()) { var result = ReadAndRunCacheEntryProcessor(stream, _ignite); stream.Reset(); result.Write(stream, _ignite.Marshaller); stream.SynchronizeOutput(); } return(0); }
private void CacheInvoke(void *target, long inMemPtr, long outMemPtr) { SafeCall(() => { using (PlatformMemoryStream inStream = IgniteManager.Memory.Get(inMemPtr).GetStream()) { var result = ReadAndRunCacheEntryProcessor(inStream, _ignite); using (PlatformMemoryStream outStream = IgniteManager.Memory.Get(outMemPtr).GetStream()) { result.Write(outStream, _ignite.Marshaller); outStream.SynchronizeOutput(); } } }); }
/// <summary> /// Writes the partitions assignment to a stream. /// </summary> /// <param name="parts">The parts.</param> /// <param name="stream">The stream.</param> /// <param name="marsh">The marshaller.</param> internal static void WritePartitions(IEnumerable <IEnumerable <IClusterNode> > parts, PlatformMemoryStream stream, Marshaller marsh) { Debug.Assert(parts != null); Debug.Assert(stream != null); Debug.Assert(marsh != null); IBinaryRawWriter writer = marsh.StartMarshal(stream); var partCnt = 0; writer.WriteInt(partCnt); // reserve size foreach (var part in parts) { if (part == null) { throw new IgniteException("IAffinityFunction.AssignPartitions() returned invalid partition: null"); } partCnt++; var nodeCnt = 0; var cntPos = stream.Position; writer.WriteInt(nodeCnt); // reserve size foreach (var node in part) { nodeCnt++; writer.WriteGuid(node.Id); } var endPos = stream.Position; stream.Seek(cntPos, SeekOrigin.Begin); stream.WriteInt(nodeCnt); stream.Seek(endPos, SeekOrigin.Begin); } stream.SynchronizeOutput(); stream.Seek(0, SeekOrigin.Begin); writer.WriteInt(partCnt); }
/// <summary> /// Perform simple out-in operation accepting single argument. /// </summary> /// <param name="type">Operation type.</param> /// <param name="val">Value.</param> /// <returns>Result.</returns> protected TR DoOutInOp <T1, TR>(int type, T1 val) { using (PlatformMemoryStream outStream = IgniteManager.Memory.Allocate().GetStream()) { using (PlatformMemoryStream inStream = IgniteManager.Memory.Allocate().GetStream()) { BinaryWriter writer = _marsh.StartMarshal(outStream); writer.WriteObject(val); FinishMarshal(writer); UU.TargetInStreamOutStream(_target, type, outStream.SynchronizeOutput(), inStream.MemoryPointer); inStream.SynchronizeInput(); return(Unmarshal <TR>(inStream)); } } }
/// <summary> /// Perform out-in operation. /// </summary> /// <param name="type">Operation type.</param> /// <param name="outAction">Out action.</param> /// <param name="inAction">In action.</param> /// <param name="arg">Argument.</param> /// <returns>Result.</returns> protected unsafe TR DoOutInOp <TR>(int type, Action <BinaryWriter> outAction, Func <IBinaryStream, TR> inAction, void *arg) { using (PlatformMemoryStream outStream = IgniteManager.Memory.Allocate().GetStream()) { using (PlatformMemoryStream inStream = IgniteManager.Memory.Allocate().GetStream()) { BinaryWriter writer = _marsh.StartMarshal(outStream); outAction(writer); FinishMarshal(writer); UU.TargetInObjectStreamOutStream(_target, type, arg, outStream.SynchronizeOutput(), inStream.MemoryPointer); inStream.SynchronizeInput(); return(inAction(inStream)); } } }
/// <summary> /// Perform out-in operation. /// </summary> /// <param name="type">Operation type.</param> /// <param name="outAction">Out action.</param> /// <param name="inAction">In action.</param> protected void DoOutInOp(int type, Action <BinaryWriter> outAction, Action <IBinaryStream> inAction) { using (PlatformMemoryStream outStream = IgniteManager.Memory.Allocate().GetStream()) { using (PlatformMemoryStream inStream = IgniteManager.Memory.Allocate().GetStream()) { BinaryWriter writer = _marsh.StartMarshal(outStream); outAction(writer); FinishMarshal(writer); UU.TargetInStreamOutStream(_target, type, outStream.SynchronizeOutput(), inStream.MemoryPointer); inStream.SynchronizeInput(); inAction(inStream); } } }
/// <summary> /// Perform out-in operation. /// </summary> /// <param name="type">Operation type.</param> /// <param name="outAction">Out action.</param> /// <returns>Result.</returns> protected TR DoOutInOp <TR>(int type, Action <PortableWriterImpl> outAction) { using (PlatformMemoryStream outStream = IgniteManager.Memory.Allocate().Stream()) { using (PlatformMemoryStream inStream = IgniteManager.Memory.Allocate().Stream()) { PortableWriterImpl writer = _marsh.StartMarshal(outStream); outAction(writer); FinishMarshal(writer); UU.TargetInStreamOutStream(_target, type, outStream.SynchronizeOutput(), inStream.MemoryPointer); inStream.SynchronizeInput(); return(Unmarshal <TR>(inStream)); } } }
/// <summary> /// Prepare lifecycle beans. /// </summary> /// <param name="reader">Reader.</param> /// <param name="outStream">Output stream.</param> /// <param name="handleRegistry">Handle registry.</param> private static void PrepareLifecycleBeans(BinaryReader reader, PlatformMemoryStream outStream, HandleRegistry handleRegistry) { IList <LifecycleBeanHolder> beans = new List <LifecycleBeanHolder> { new LifecycleBeanHolder(new InternalLifecycleBean()) // add internal bean for events }; // 1. Read beans defined in Java. int cnt = reader.ReadInt(); for (int i = 0; i < cnt; i++) { beans.Add(new LifecycleBeanHolder(CreateLifecycleBean(reader))); } // 2. Append beans definied in local configuration. ICollection <ILifecycleBean> nativeBeans = _startup.Configuration.LifecycleBeans; if (nativeBeans != null) { foreach (ILifecycleBean nativeBean in nativeBeans) { beans.Add(new LifecycleBeanHolder(nativeBean)); } } // 3. Write bean pointers to Java stream. outStream.WriteInt(beans.Count); foreach (LifecycleBeanHolder bean in beans) { outStream.WriteLong(handleRegistry.AllocateCritical(bean)); } outStream.SynchronizeOutput(); // 4. Set beans to STARTUP object. _startup.LifecycleBeans = beans; }
/// <summary> /// Prepare callback invoked from Java. /// </summary> /// <param name="inStream">Input stream with data.</param> /// <param name="outStream">Output stream.</param> /// <param name="handleRegistry">Handle registry.</param> /// <param name="log">Log.</param> internal static void OnPrepare(PlatformMemoryStream inStream, PlatformMemoryStream outStream, HandleRegistry handleRegistry, ILogger log) { try { BinaryReader reader = BinaryUtils.Marshaller.StartUnmarshal(inStream); PrepareConfiguration(reader, outStream, log); PrepareLifecycleHandlers(reader, outStream, handleRegistry); PrepareAffinityFunctions(reader, outStream); outStream.SynchronizeOutput(); } catch (Exception e) { _startup.Error = e; throw; } }
public void TestPlatformMemoryStream() { var stream = new PlatformMemoryStream(GetMemory()); TestStream(stream, false, () => stream.SynchronizeOutput()); }