/// <summary> /// TBD /// </summary> /// <param name="assembly">TBD</param> /// <param name="materializer">TBD</param> /// <param name="log">TBD</param> /// <param name="logics">TBD</param> /// <param name="connections">TBD</param> /// <param name="onAsyncInput">TBD</param> /// <param name="fuzzingMode">TBD</param> /// <param name="context">TBD</param> public GraphInterpreter( GraphAssembly assembly, IMaterializer materializer, ILoggingAdapter log, GraphStageLogic[] logics, Connection[] connections, Action <GraphStageLogic, object, Action <object> > onAsyncInput, bool fuzzingMode, IActorRef context) { Logics = logics; Assembly = assembly; Materializer = materializer; Log = log; Connections = connections; OnAsyncInput = onAsyncInput; FuzzingMode = fuzzingMode; Context = context; RunningStagesCount = Assembly.Stages.Length; _shutdownCounter = new int[assembly.Stages.Length]; for (var i = 0; i < _shutdownCounter.Length; i++) { var shape = assembly.Stages[i].Shape; _shutdownCounter[i] = shape.Inlets.Count() + shape.Outlets.Count(); } _eventQueue = new Connection[1 << (32 - (assembly.ConnectionCount - 1).NumberOfLeadingZeros())]; _mask = _eventQueue.Length - 1; }
public void StartScheduler(int lapse, IMaterializer materializer) { Source.Tick(TimeSpan.FromSeconds(0), TimeSpan.FromMinutes(lapse), "") .Select(_ => ping.TryPingServer()) .Select(r => r.ToJson()) .RunWith(Sink.ForEach <string>(f => factRepository.SendFact(f)), materializer); }
public StreamsAsyncEnumerableRerunnable(Source <T, TMat> source, IMaterializer materializer, int minBuf, int maxBuf) : this(source, materializer) { thisSinkQueue = defaultSinkqueue.WithAttributes( Attributes.CreateInputBuffer(minBuf, maxBuf)); }
/// <summary> /// Create and Read list of object from database. /// </summary> /// <param name="procedureName">Stored procedure name.</param> /// <param name="commandParameters">Sql parameters.</param> /// <returns>List of objects T.</returns> protected List <T> Execute_GetList <T>(IMaterializer <T> materializer, string procedureName, List <SqlParameter> commandParameters) where T : class { if (procedureName == null) { throw new ArgumentNullException("procedureName"); } List <T> result; try { using (DataReaderAdapter reader = DbHelper.ExecuteReaderEx(DatabaseAlias, procedureName, commandParameters)) { result = materializer.Materialize_List(reader); } } catch (SqlException e) { ThrowRecognisedException(e, procedureName, commandParameters); throw; } return(result); }
public AzureTableQueryEdgeCaseSpecs(ITestOutputHelper output) : base(Config(), nameof(AzureTableQueryEdgeCaseSpecs), output) { _output = output; Materializer = Sys.Materializer(); ReadJournal = Sys.ReadJournalFor <AzureTableStorageReadJournal>(AzureTableStorageReadJournal.Identifier); }
/// <summary> /// Create and Read object from database. /// </summary> /// <param name="query">SQL query to execute.</param> /// <returns>Object T.</returns> protected T Execute_Query_Get <T>(IMaterializer <T> materializer, string query, List <SqlParameter> commandParameters) where T : class { if (query == null) { throw new ArgumentNullException("query"); } T result; try { using (DataReaderAdapter reader = DbHelper.ExecuteQueryReaderEx(DatabaseAlias, query, commandParameters)) { result = materializer.Materialize(reader); } } catch (SqlException e) { ThrowRecognisedException(e, "Custom SQL query", new List <SqlParameter>()); throw; } return(result); }
public virtual async Task <IEnumerable <T> > Get(string id) { IMaterializer materializer = MaterializerFactory(); List <T> results = new List <T>(); string[] arrIds; if (id.Contains(",")) { arrIds = id.Split(','); } else { arrIds = new string[] { id }; } foreach (string singleid in arrIds) { T hit = await materializer.GetByIdAsync <T>(singleid); if (hit != null) { results.Add(hit); } } return(results); }
protected BaseJournalDaoWithReadMessages(IAdvancedScheduler ec, IMaterializer mat, AkkaPersistenceDataConnectionFactory connectionFactory) { this.ec = ec; this.mat = mat; _connectionFactory = connectionFactory; }
/// <summary> /// In this base class, the Post operation is essentially a no-op. It returns a materialized /// copy of the object (which is meaningless unless the materializer implements /// some logic that does something to it), but fulfills the JSONAPI requirement /// that the POST operation return the POSTed object. It should probably be /// overridden in any implementation. /// </summary> /// <param name="postedObj"></param> /// <returns></returns> public virtual Task <IList <T> > Post([FromBody] IList <T> postedObjs) { foreach (T postedObj in postedObjs) { IMaterializer materializer = this.MaterializerFactory(); } return(Task.FromResult(postedObjs)); }
//[System.Web.OData.EnableQuery] // Do this yourself! /// <summary> /// Default Get method implementation. Returns the result of /// Note: You can easily add OData query support by overriding this method and decorating /// it with the [System.Web.OData.EnableQuery] attribute. /// </summary> /// <returns></returns> public virtual IQueryable <T> Get() { IMaterializer materializer = MaterializerFactory(); IQueryable <T> es = QueryableFactory(materializer); return(es); }
public static void AssertAllStagesStopped(this AkkaSpec spec, Action block, IMaterializer materializer) { AssertAllStagesStopped(spec, () => { block(); return(NotUsed.Instance); }, materializer); }
public Bug61FixSpec(ITestOutputHelper output, DatabaseFixture databaseFixture) : base(CreateSpecConfig(databaseFixture, Counter.GetAndIncrement()), "MongoDbCurrentEventsByTagSpec", output) { _output = output; output.WriteLine(databaseFixture.ConnectionString + Counter.Current); Materializer = Sys.Materializer(); ReadJournal = Sys.ReadJournalFor <MongoDbReadJournal>(MongoDbReadJournal.Identifier); }
public KafkaIntegrationTests(string actorSystemName, ITestOutputHelper output, KafkaFixture fixture) : base(Default(), actorSystemName, output) { _fixture = fixture; Materializer = Sys.Materializer(); Sys.Log.Info("Starting test: " + output.GetCurrentTestName()); }
public ByteArrayJournalDao(IAdvancedScheduler sched, IMaterializer mat, AkkaPersistenceDataConnectionFactory connection, JournalConfig journalConfig, Akka.Serialization.Serialization serializer, ILoggingAdapter logger) : base(sched, mat, connection, journalConfig, new ByteArrayJournalSerializer(journalConfig, serializer, journalConfig.PluginConfig.TagSeparator), logger) { }
internal static ActorMaterializer Downcast(IMaterializer materializer) { //FIXME this method is going to cause trouble for other Materializer implementations if (materializer is ActorMaterializer) { return((ActorMaterializer)materializer); } throw new ArgumentException($"Expected {typeof(ActorMaterializer)} but got {materializer.GetType()}"); }
public static IServiceCollection AddAkka(this IServiceCollection services, ActorSystem actorSystem) { ActorSystem = actorSystem; Materializer = actorSystem.Materializer(); // Register ActorSystem services.AddSingleton <ActorSystem>((provider) => actorSystem); return(services); }
/// <summary> /// Similar to Post, this method doesn't do much. It calls MaterializeUpdateAsync() on the /// input and returns it. It should probably always be overridden. /// </summary> /// <param name="id"></param> /// <param name="payload"></param> /// <returns></returns> public virtual async Task <IList <T> > Put(string id, IList <T> putObjs) { IMaterializer materializer = this.MaterializerFactory(); IList <T> materialList = new List <T>(); foreach (T putObj in putObjs) { materialList.Add(await materializer.MaterializeUpdateAsync <T>(putObj)); } return(materialList); }
private static async Task StreamExample(IMaterializer materializer) { //TODO: FILL THE CREDENTIALS! var credentials = new Credentials("<github_username>", "<github_password>"); var source = Source.ActorPublisher <Issue>(OctokitIssuesPublisher.Props("akkadotnet", "akka.net", credentials)); var i = 0; await source .Select(issue => Tuple.Create(i++, issue)) .RunForeach(t => { Console.WriteLine($"{t.Item1}\t{t.Item2.Title}"); }, materializer); }
public ByteArraySnapshotDao( AkkaPersistenceDataConnectionFactory connectionFactory, SnapshotConfig snapshotConfig, Akka.Serialization.Serialization serialization, IMaterializer mat, ILoggingAdapter logger) { _logger = logger; _mat = mat; _snapshotConfig = snapshotConfig; _serialization = serialization; _connectionFactory = connectionFactory; _serializer = new ByteArraySnapshotSerializer(serialization, _snapshotConfig); }
public void SetupAkkaActors() { const string akkaConfig = @" akka { loglevel = WARNING } "; ActorSystem = ActorSystem.Create("hashing", ConfigurationFactory.ParseString(akkaConfig)); Materializer = ActorSystem.Materializer(); ManualResetSlimForAkka = new ManualResetEventSlim(); PipelineActorRef = ActorSystem.ActorOf(PipelineActor.Configure(InputElements, CombineBy, ManualResetSlimForAkka), "pipeline"); }
public GraphInterpreter( GraphAssembly assembly, IMaterializer materializer, ILoggingAdapter log, IInHandler[] inHandlers, IOutHandler[] outHandlers, GraphStageLogic[] logics, Action <GraphStageLogic, object, Action <object> > onAsyncInput, bool fuzzingMode, IActorRef context) { Logics = logics; Assembly = assembly; Materializer = materializer; Log = log; InHandlers = inHandlers; OutHandlers = outHandlers; OnAsyncInput = onAsyncInput; FuzzingMode = fuzzingMode; Context = context; ConnectionSlots = new object[assembly.ConnectionCount]; for (var i = 0; i < ConnectionSlots.Length; i++) { ConnectionSlots[i] = Empty.Instance; } PortStates = new int[assembly.ConnectionCount]; for (var i = 0; i < PortStates.Length; i++) { PortStates[i] = InReady; } RunningStagesCount = Assembly.Stages.Length; _shutdownCounter = new int[assembly.Stages.Length]; for (var i = 0; i < _shutdownCounter.Length; i++) { var shape = assembly.Stages[i].Shape; _shutdownCounter[i] = shape.Inlets.Count() + shape.Outlets.Count(); } _eventQueue = new int[1 << (32 - (assembly.ConnectionCount - 1).NumberOfLeadingZeros())]; _mask = _eventQueue.Length - 1; }
protected StreamsTransport(ActorSystem system, Config config) { System = system; Config = config; Settings = StreamsTransportSettings.Create(Config); Log = Logging.GetLogger(System, GetType()); SchemeIdentifier = (Settings.EnableSsl ? "ssl." : string.Empty) + Settings.TransportMode.ToString().ToLowerInvariant(); StreamSupervisor = system.AsInstanceOf <ExtendedActorSystem>().SystemActorOf( Props.Create(() => new StreamsTransportSupervisor()), Uri.EscapeUriString(SchemeIdentifier) + "-supervisor"); // block here and get access to the materializer used for creating // future stream actors StreamMaterializer = StreamSupervisor .Ask <IMaterializer>(StreamsTransportSupervisor.GetMaterializer.Instance, Settings.ConnectTimeout) .Result; }
public static void Example(IMaterializer materializer) { Source <Tuple <string, WatcherChangeTypes>, NotUsed> directoryTrigger = null; var delimeter = ByteString.FromString("\r\n"); var getLines = Flow.Create <ByteString>() .Via(Framing.Delimiter(delimeter, maximumFrameLength: 256, allowTruncation: true)) .Select(bytes => bytes.DecodeString()); var newFilesLines = directoryTrigger .Where(t => t.Item2 == WatcherChangeTypes.Created) .Select(t => t.Item1) .MergeMany(breadth: 100, flatten: fileName => FileIO.FromFile(new FileInfo(fileName)) .Via(getLines) .MapMaterializedValue(_ => NotUsed.Instance)); }
/// <summary> /// Initializes the states of all the stage logics by calling <see cref="GraphStageLogic.PreStart"/>. /// The passed-in materializer is intended to be a <see cref="SubFusingMaterializer"/> /// that avoids creating new Actors when stages materialize sub-flows.If no /// such materializer is available, passing in null will reuse the normal /// materializer for the GraphInterpreter—fusing is only an optimization. /// </summary> /// <param name="subMaterializer">TBD</param> public void Init(IMaterializer subMaterializer) { SubFusingMaterializer = subMaterializer ?? Materializer; for (var i = 0; i < Logics.Length; i++) { var logic = Logics[i]; logic.StageId = i; logic.Interpreter = this; try { logic.BeforePreStart(); logic.PreStart(); } catch (Exception e) { if (Log.IsErrorEnabled) { Log.Error(e, $"Error during PreStart in [{Assembly.Stages[logic.StageId]}]"); } logic.FailStage(e); } AfterStageHasRun(logic); } }
public GraphInterpreter( GraphAssembly assembly, IMaterializer materializer, ILoggingAdapter log, IInHandler[] inHandlers, IOutHandler[] outHandlers, GraphStageLogic[] logics, Action<GraphStageLogic, object, Action<object>> onAsyncInput, bool fuzzingMode) { Logics = logics; Assembly = assembly; Materializer = materializer; Log = log; InHandlers = inHandlers; OutHandlers = outHandlers; OnAsyncInput = onAsyncInput; FuzzingMode = fuzzingMode; ConnectionSlots = new object[assembly.ConnectionCount]; for (var i = 0; i < ConnectionSlots.Length; i++) ConnectionSlots[i] = Empty.Instance; PortStates = new int[assembly.ConnectionCount]; for (var i = 0; i < PortStates.Length; i++) PortStates[i] = InReady; RunningStagesCount = Assembly.Stages.Length; _shutdownCounter = new int[assembly.Stages.Length]; for (var i = 0; i < _shutdownCounter.Length; i++) { var shape = assembly.Stages[i].Shape; _shutdownCounter[i] = shape.Inlets.Count() + shape.Outlets.Count(); } _eventQueue = new int[1 << (32 - (assembly.ConnectionCount - 1).NumberOfLeadingZeros())]; _mask = _eventQueue.Length - 1; }
public FlowAskSpec(ITestOutputHelper output) : base(SpecConfig, output) { _materializer = Sys.Materializer(); }
/// <summary> /// Shortcut for running this <see cref="Source{TOut,TMat}"/> with a foreach procedure. The given procedure is invoked /// for each received element. /// The returned <see cref="Task"/> will be completed with Success when reaching the /// normal end of the stream, or completed with Failure if there is a failure signaled in /// the stream. /// </summary> /// <param name="action">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public Task RunForeach(Action <TOut> action, IMaterializer materializer) => RunWith(Sink.ForEach(action), materializer);
/// <summary> /// Shortcut for running this <see cref="Source{TOut,TMat}"/> with a reduce function. /// The given function is invoked for every received element, giving it its previous /// output (from the second element) and the element as input. /// The returned <see cref="Task{TOut}"/> will be completed with value of the final /// function evaluation when the input stream ends, or completed with Failure /// if there is a failure signaled in the stream. /// </summary> /// <param name="reduce">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public Task <TOut> RunSum(Func <TOut, TOut, TOut> reduce, IMaterializer materializer) => RunWith(Sink.Sum(reduce), materializer);
/// <summary> /// Shortcut for running this <see cref="Source{TOut,TMat}"/> with a async <paramref name="aggregate"/> function. /// The given function is invoked for every received element, giving it its previous /// output (or the given <paramref name="zero"/> value) and the element as input. /// The returned <see cref="Task{TOut2}"/> will be completed with value of the final /// function evaluation when the input stream ends, or completed with Failure /// if there is a failure signaled in the stream. /// </summary> /// <typeparam name="TOut2">TBD</typeparam> /// <param name="zero">TBD</param> /// <param name="aggregate">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public Task <TOut2> RunAggregateAsync <TOut2>(TOut2 zero, Func <TOut2, TOut, Task <TOut2> > aggregate, IMaterializer materializer) => RunWith(Sink.AggregateAsync(zero, aggregate), materializer);
/// <summary> /// Connect this <see cref="Source{TOut,TMat}"/> to a <see cref="Sink{TIn,TMat}"/> and run it. The returned value is the materialized value /// of the <see cref="Sink{TIn,TMat}"/> , e.g. the <see cref="IPublisher{TIn}"/> of a <see cref="Sink.Publisher{TIn}"/>. /// </summary> /// <typeparam name="TMat2">TBD</typeparam> /// <param name="sink">TBD</param> /// <param name="materializer">TBD</param> /// <returns>TBD</returns> public TMat2 RunWith <TMat2>(IGraph <SinkShape <TOut>, TMat2> sink, IMaterializer materializer) => ToMaterialized(sink, Keep.Right).Run(materializer);
protected static IPublisher <TOut> ToPublisher <TOut>(Source <TOut, NotUsed> source, IMaterializer materializer) { return(source.RunWith(Sink.AsPublisher <TOut>(false), materializer)); }
/// <summary> /// Initializes the states of all the stage logics by calling <see cref="GraphStageLogic.PreStart"/>. /// The passed-in materializer is intended to be a <see cref="SubFusingMaterializer"/> /// that avoids creating new Actors when stages materialize sub-flows.If no /// such materializer is available, passing in null will reuse the normal /// materializer for the GraphInterpreter—fusing is only an optimization. /// </summary> public void Init(IMaterializer subMaterializer) { SubFusingMaterializer = subMaterializer ?? Materializer; for (var i = 0; i < Logics.Length; i++) { var logic = Logics[i]; logic.StageId = i; logic.Interpreter = this; try { logic.BeforePreStart(); logic.PreStart(); } catch (Exception e) { if (Log.IsErrorEnabled) Log.Error(e, $"Error during PreStart in [{Assembly.Stages[logic.StageId]}]"); logic.FailStage(e); } AfterStageHasRun(logic); } }