/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public override IPublisher <TOut> Create(MaterializationContext context, out IActorRef materializer) { var publisherRef = ActorMaterializerHelper.Downcast(context.Materializer).ActorOf(context, _props); materializer = publisherRef; return(new ActorPublisherImpl <TOut>(publisherRef)); }
/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public override IPublisher <TOut> Create(MaterializationContext context, out IActorRef materializer) { var mat = ActorMaterializerHelper.Downcast(context.Materializer); materializer = mat.ActorOf(context, ActorRefSourceActor <TOut> .Props(_bufferSize, _overflowStrategy, mat.Settings)); return(new ActorPublisherImpl <TOut>(materializer)); }
private Pair <Key, Tuple> ParseColumnGroup(Tuple tuple, MaterializationContext context, int groupIndex, RecordPartMapping mapping) { TypeReferenceAccuracy accuracy; int typeId = ExtractTypeId(mapping.ApproximateType, context.TypeIdRegistry, tuple, mapping.TypeIdColumnIndex, out accuracy); var typeMapping = typeId == TypeInfo.NoTypeId ? null : context.GetTypeMapping(groupIndex, mapping.ApproximateType, typeId, mapping.Columns); if (typeMapping == null) { return(new Pair <Key, Tuple>(null, null)); } bool canCache = accuracy == TypeReferenceAccuracy.ExactType; Key key; if (typeMapping.KeyTransform.Descriptor.Count <= WellKnown.MaxGenericKeyLength) { key = KeyFactory.Materialize(Domain, context.Session.StorageNodeId, typeMapping.Type, tuple, accuracy, canCache, typeMapping.KeyIndexes); } else { var keyTuple = typeMapping.KeyTransform.Apply(TupleTransformType.TransformedTuple, tuple); key = KeyFactory.Materialize(Domain, context.Session.StorageNodeId, typeMapping.Type, keyTuple, accuracy, canCache, null); } if (accuracy == TypeReferenceAccuracy.ExactType) { var entityTuple = typeMapping.Transform.Apply(TupleTransformType.Tuple, tuple); return(new Pair <Key, Tuple>(key, entityTuple)); } return(new Pair <Key, Tuple>(key, null)); }
/// <summary> /// This method is the reason why SinkModule.create may return something that is /// not a Subscriber: a VirtualPublisher is used in order to avoid the immediate /// subscription a VirtualProcessor would perform (and it also saves overhead). /// </summary> public override object Create(MaterializationContext context, out IPublisher <TIn> materializer) { var processor = new VirtualProcessor <TIn>(); materializer = processor; return(processor); }
public override object Create(MaterializationContext context, out Task materializer) { var p = new TaskCompletionSource <NotUsed>(); materializer = p.Task; return(new SinkholeSubscriber <TIn>(p)); }
public override object Create(MaterializationContext context, out IActorRef materializer) { var subscriberRef = ActorMaterializer.Downcast(context.Materializer).ActorOf(context, _props); materializer = subscriberRef; return(ActorSubscriber.Create <TIn>(subscriberRef)); }
/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public override IPublisher <TOut> Create(MaterializationContext context, out ISubscriber <TOut> materializer) { var processor = new VirtualProcessor <TOut>(); materializer = processor; return(processor); }
/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="task">TBD</param> /// <returns>TBD</returns> public override IPublisher <ByteString> Create(MaterializationContext context, out Task <IOResult> task) { var materializer = ActorMaterializerHelper.Downcast(context.Materializer); var ioResultPromise = new TaskCompletionSource <IOResult>(); IPublisher <ByteString> pub; try { // can throw, i.e. FileNotFound var inputStream = _createInputStream(); var props = InputStreamPublisher .Props(inputStream, ioResultPromise, _chunkSize) .WithDispatcher(context .EffectiveAttributes .GetMandatoryAttribute <ActorAttributes.Dispatcher>() .Name); var actorRef = materializer.ActorOf(context, props); pub = new ActorPublisherImpl <ByteString>(actorRef); } catch (Exception ex) { ioResultPromise.TrySetException(ex); pub = new ErrorPublisher <ByteString>(ex, Attributes.GetNameOrDefault("inputStreamSource")); } task = ioResultPromise.Task; return(pub); }
public override IActorRef ActorOf(MaterializationContext context, Props props) { var dispatcher = props.Deploy.Dispatcher == Deploy.NoDispatcherGiven ? EffectiveSettings(context.EffectiveAttributes).Dispatcher : props.Dispatcher; return(ActorOf(props, context.StageName, dispatcher)); }
IUntypedSubscriber ISinkModule.Create(MaterializationContext context, out object materializer) { TMat m; var result = Create(context, out m); materializer = m; return(UntypedSubscriber.FromTyped(result)); }
object ISinkModule.Create(MaterializationContext context, out object materializer) { TMat m; var result = Create(context, out m); materializer = m; return(result); }
IUntypedPublisher ISourceModule.Create(MaterializationContext context, out object materializer) { TMat m; var result = Create(context, out m); materializer = m; return(UntypedPublisher.FromTyped(result)); }
public override object Create(MaterializationContext context, out IPublisher <TIn> materializer) { var actorMaterializer = ActorMaterializer.Downcast(context.Materializer); var settings = actorMaterializer.EffectiveSettings(Attributes); var fanoutRef = actorMaterializer.ActorOf(context, FanoutProcessorImpl <TIn> .Props(settings)); var fanoutProcessor = ActorProcessorFactory.Create <TIn, TIn>(fanoutRef); materializer = fanoutProcessor; return(fanoutProcessor); }
public override object Create(MaterializationContext context, out TestSubscriber.Probe <ByteString> materializer) { var promise = _properties.Probes[_properties.ProbesWriterTop]; var probe = TestSubscriber.CreateSubscriberProbe <ByteString>(_properties.Kit); promise.SetResult(probe); _properties.ProbesWriterTop++; materializer = probe; return(probe); }
public override object Create(MaterializationContext context, out NotUsed materializer) { var actorMaterializer = ActorMaterializer.Downcast(context.Materializer); var effectiveSettings = actorMaterializer.EffectiveSettings(context.EffectiveAttributes); var subscriberRef = actorMaterializer.ActorOf(context, ActorRefSinkActor.Props(_ref, effectiveSettings.MaxInputBufferSize, _onCompleteMessage)); materializer = null; return(new ActorSubscriberImpl <TIn>(subscriberRef)); }
/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public override object Create(MaterializationContext context, out IPublisher <TIn> materializer) { var actorMaterializer = ActorMaterializerHelper.Downcast(context.Materializer); var settings = actorMaterializer.EffectiveSettings(Attributes); var impl = actorMaterializer.ActorOf(context, FanoutProcessorImpl <TIn, TStreamBuffer> .Props(settings, _onTerminated)); var fanoutProcessor = new ActorProcessor <TIn, TIn>(impl); impl.Tell(new ExposedPublisher(fanoutProcessor)); // Resolve cyclic dependency with actor. This MUST be the first message no matter what. materializer = fanoutProcessor; return(fanoutProcessor); }
public EntityLoadInfo( ValueBuffer valueBuffer, [NotNull] Func <ValueBuffer, object> materializer, [CanBeNull] Dictionary <Type, int[]> typeIndexMap = null) { // hot path Debug.Assert(materializer != null); _materializationContext = new MaterializationContext(valueBuffer); _materializer = c => materializer(c.ValueBuffer); _typeIndexMap = typeIndexMap; }
/// <summary> /// Initializes a new instance of the <see cref="EntityLoadInfo" /> struct. /// </summary> /// <param name="materializationContext"> The current <see cref="MaterializationContext" /> for creating the entity. </param> /// <param name="materializer"> The method to materialize the data into an entity instance. </param> /// <param name="typeIndexMap"> Dictionary containing mapping from property indexes to values in ValueBuffer. </param> public EntityLoadInfo( MaterializationContext materializationContext, [NotNull] Func <MaterializationContext, object> materializer, [CanBeNull] Dictionary <Type, int[]> typeIndexMap = null) { // hot path Debug.Assert(materializer != null); _materializationContext = materializationContext; _materializer = materializer; _typeIndexMap = typeIndexMap; }
/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public override object Create(MaterializationContext context, out Task <IOResult> materializer) { var mat = ActorMaterializerHelper.Downcast(context.Materializer); var settings = mat.EffectiveSettings(context.EffectiveAttributes); var ioResultPromise = new TaskCompletionSource <IOResult>(); var os = _createOutput(); var props = OutputStreamSubscriber.Props(os, ioResultPromise, settings.MaxInputBufferSize, _autoFlush); var actorRef = mat.ActorOf(context, props); materializer = ioResultPromise.Task; return(new ActorSubscriberImpl <ByteString>(actorRef)); }
/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="task">TBD</param> /// <returns>TBD</returns> public override IPublisher <ByteString> Create(MaterializationContext context, out Task <IOResult> task) { // FIXME rewrite to be based on GraphStage rather than dangerous downcasts var materializer = ActorMaterializerHelper.Downcast(context.Materializer); var settings = materializer.EffectiveSettings(context.EffectiveAttributes); var ioResultPromise = new TaskCompletionSource <IOResult>(); var props = FilePublisher.Props(_f, ioResultPromise, _chunkSize, settings.InitialInputBufferSize, settings.MaxInputBufferSize); var dispatcher = context.EffectiveAttributes.GetAttribute(DefaultAttributes.IODispatcher.GetAttribute <ActorAttributes.Dispatcher>()); var actorRef = materializer.ActorOf(context, props.WithDispatcher(dispatcher.Name)); task = ioResultPromise.Task; return(new ActorPublisherImpl <ByteString>(actorRef)); }
/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public override object Create(MaterializationContext context, out Task <IOResult> materializer) { var mat = ActorMaterializerHelper.Downcast(context.Materializer); var settings = mat.EffectiveSettings(context.EffectiveAttributes); var ioResultPromise = new TaskCompletionSource <IOResult>(); var props = FileSubscriber.Props(_f, ioResultPromise, settings.MaxInputBufferSize, _fileMode); var dispatcher = context.EffectiveAttributes.GetAttribute(DefaultAttributes.IODispatcher.AttributeList.First()) as ActorAttributes.Dispatcher; var actorRef = mat.ActorOf(context, props.WithDispatcher(dispatcher.Name)); materializer = ioResultPromise.Task; return(new ActorSubscriberImpl <ByteString>(actorRef)); }
private Record ParseRow(Tuple tuple, MaterializationContext context, RecordPartMapping[] recordPartMappings) { var count = recordPartMappings.Length; if (count == 1) { return(new Record(tuple, ParseColumnGroup(tuple, context, 0, recordPartMappings[0]))); } var pairs = new List <Pair <Key, Tuple> >( recordPartMappings .Select((recordPartMapping, i) => ParseColumnGroup(tuple, context, i, recordPartMapping))); return(new Record(tuple, pairs)); }
private static MaterializationContext SnapshotValueBuffer( IEntityType entityType, MaterializationContext c) { var comparers = GetStructuralComparers(entityType.GetProperties()); var copy = new object[comparers.Count]; for (var index = 0; index < comparers.Count; index++) { copy[index] = SnapshotValue(comparers[index], c.ValueBuffer[index]); } return(new MaterializationContext(new ValueBuffer(copy), c.Context)); }
/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public override object Create(MaterializationContext context, out Task <IOResult> materializer) { var mat = ActorMaterializerHelper.Downcast(context.Materializer); var settings = mat.EffectiveSettings(context.EffectiveAttributes); var ioResultPromise = new TaskCompletionSource <IOResult>(); var props = FileSubscriber.Props(_f, ioResultPromise, settings.MaxInputBufferSize, _startPosition, _fileMode, _autoFlush, _flushSignaler); var actorRef = mat.ActorOf( context, props.WithDispatcher(context .EffectiveAttributes .GetMandatoryAttribute <ActorAttributes.Dispatcher>() .Name)); materializer = ioResultPromise.Task; return(new ActorSubscriberImpl <ByteString>(actorRef)); }
public IEnumerable <Record> Read(IEnumerable <Tuple> source, RecordSetHeader header, Session session) { CacheItem cacheItem; var recordPartCount = header.ColumnGroups.Count; var context = new MaterializationContext(session, recordPartCount); lock (_lock) { if (!cache.TryGetItem(header, false, out cacheItem)) { var typeIdColumnName = Domain.Handlers.NameBuilder.TypeIdColumnName; var model = context.Model; var mappings = new RecordPartMapping[recordPartCount]; for (int i = 0; i < recordPartCount; i++) { var columnGroup = header.ColumnGroups[i]; var approximateType = columnGroup.TypeInfoRef.Resolve(model); var columnMapping = new List <Pair <int> >(); var typeIdColumnIndex = -1; foreach (var columnIndex in columnGroup.Columns) { var column = (MappedColumn)header.Columns[columnIndex]; var columnInfo = column.ColumnInfoRef.Resolve(model); FieldInfo fieldInfo; if (!approximateType.Fields.TryGetValue(columnInfo.Field.Name, out fieldInfo)) { continue; } var targetColumnIndex = fieldInfo.MappingInfo.Offset; if (columnInfo.Name == typeIdColumnName) { typeIdColumnIndex = column.Index; } columnMapping.Add(new Pair <int>(targetColumnIndex, columnIndex)); } mappings[i] = new RecordPartMapping(typeIdColumnIndex, columnMapping.ToArray(), approximateType); } cacheItem = new CacheItem(header, mappings); cache.Add(cacheItem); } } return(source.Select(tuple => ParseRow(tuple, context, cacheItem.Mappings))); }
public override object Create(MaterializationContext context, out NotUsed materializer) { materializer = NotUsed.Instance; return(new CancellingSubscriber <T>()); }
public override object Create(MaterializationContext context, out TestSubscriber.Probe <T> materializer) { materializer = _testKit.CreateSubscriberProbe <T>(); return(materializer); }
private static Object NullMaterializer(MaterializationContext materializationContext) { throw new InvalidOperationException("Stub for nullable reference type"); }
public override IPublisher <T> Create(MaterializationContext context, out TestPublisher.Probe <T> materializer) { materializer = _testKit.CreatePublisherProbe <T>(); return(materializer); }
/// <summary> /// Create the Subscriber or VirtualPublisher that consumes the incoming /// stream, plus the materialized value. Since Subscriber and VirtualPublisher /// do not share a common supertype apart from AnyRef this is what the type /// union devolves into; unfortunately we do not have union types at our /// disposal at this point. /// </summary> public abstract object Create(MaterializationContext context, out TMat materializer);