Question
Is there an official recommended way to create a custom RxJs Subject?
Use Case
I have a need for a QueueSubject, i.e. a Subject that queues all values passed to its next method until there is a subscriber. This is different from the built-in ReplaySubject because the ReplaySubject does not clear its buffer upon a subscription.
What I have learned so far
An exact implementation of what I need is available in this GitHub project by James Pike. The reason for my question despite this perfectly available solution is that the _subscribe method is an internal method. It is even marked as #deprecated, therefore if a linter is used, a linter rule exception needs to be added to the class to suppress the deprecation warning.
I did not find anything in the documentation about how to create a custom Subject.
You can use any Subject implementation as a reference for your own custom one, for example this one on Github.
Concerning _subscribe: You can override it with your custom class, but never call it directly from an outside consumer class (this is why it is annotated with #deprecated). The function is called by the Subject class internally following the Template Method Pattern.
In summary: Your linked implementation looks valid to me.
Related
5.5 and axon framework starter 4.5.4
I can read and write my events with eventhandler and queryhandler without problem
but when I want to use eventstore.readevents function I got serialization .I try to set my application properties both my reader and writer but not working still same error(By the way I clean database and delete old events each time).I alson try to set xstream type but still same issue
axon.serializer.general=jackson
axon.serializer.events=jackson
axon.serializer.messages=jackson
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.axonframework.serialization.UnknownSerializedType and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) ~[jackson-databind-2.12.5.jar:2.12.5]
at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1276) ~[jackson-databind-2.12.5.jar:2.12.5]
at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:400) ~[jackson-databind-2.12.5.jar:2.12.5]
First of all, I have to ask why you want to use eventStore#readEvents given that this is not a common usage. This method is used internally by the Framework and most of the time, should be kept like that.
To your problem, you can easily check on Framework code what is happening and how it uses the eventStore#readEvents method.
First of all, the signature here: DomainEventStream readEvents(String aggregateIdentifier);
It returns a DomainEventStream which is an Iterator implementation of a DomainEventMessage (as you can also see on code: public interface DomainEventStream extends Iterator<DomainEventMessage<?>> {).
Checking any of the usages, for example the EventSorcingRepository, you can see how it is used here and here and pretty much use Iterator's method for that (hasNext and peek for instance).
Using those methods will give you access to the DomainEventMessage where you can get the Type but also the Payload (and other useful things you may need).
Hope that clarifies the usage of it but also make sure you really want to use it!
I'm currently using LTTng for such performances issues, and I want to use TRACEPOINT_EVENT_CLASS and TRACEPOINT_EVENT_INSTANCE as well.
But I don't understand the 2.10 version's documentation. I wonder why we need to define TP_ARGS in each event instance as well as defining it in the event class.
Because we can't modify TP_FIELDS to change the type of any field, or compose it from many arguments.
The TP_ARGS() portion of a TRACEPOINT_EVENT_INSTANCE is used to validate that each instance matches the TRACEPOINT_EVENT_CLASS. See ust-tracepoint-event.h for more context.
I recommend that you repost your question on our mailing list/irc channel so that we can have an actual discussion regarding this. The maintainer of lttng-ust and lttng-modules, Compudj will surely provide more context and might even be open to the introduction of a new macro allowing event instance declaration without the TP_ARGS() portion.
I'm looking to share an EF Context between "data manager" objects to ensure change tracking occurs under one context as opposed to handling multiple contexts...so I'm looking into named context... but in review of this documentation, I felt it wasn't clear, and I want to ensure my assumption is correct, and if so, update the documentation: here PRISM documents the resolution of named instances via a constructor:
My assumption is that the named typed "carservice" is matched to the named parameter in the constructor to select which concrete class should be reference to that parameter based on the IVehicleService.
Is my assumption correct - either way I'll create a pull request to clarify the documentation..Either way, answering the question here will add reference to clarification/handling of named instances in PRISM.
It seems this is NOT correct assumption, and it's not possible in Unity - I refactored to avoid.
One solution that I didn't try was to simply another interface (came to mind much later), was inheriting from an existing interface, and registers the "new" interface to use a specific constructor. As I'm new to Unity, I thought I would mention. I'm answering my own question, as I can't don't think I can give credit to a comment, and I HATE leaving questions unanswered on this site!
One way of doing seemed to be to use the java.lang.Compiler
I tried to use the java.lang.Compiler inside Eclipse anddid not understand the Object any parameters for the methods of that class? And putting in a class did not seem to work either.
Compiler.command(any) // what is meant by any? What are valid objects to put there?
Compiler.compileClass(clazz) // Nothing happens when I out a class in there?
Compiler.compileClasses(string) // hm?
How to can I print a hello message with a Compiler inside Eclipse...?
Reading the documentation is a very important skill you need to learn.
Whenever you come across a class or a method that you don't know the functionality of, simply look at the documentation first.
Here is the docs for java.lang.Compiler: https://docs.oracle.com/javase/7/docs/api/java/lang/Compiler.html
This is the first sentence of the document:
The Compiler class is provided to support Java-to-native-code compilers and related services. By design, the Compiler class does nothing; it serves as a placeholder for a JIT compiler implementation.
So, the answer to your question is, it does nothing. According to the documentation, it does nothing. It is used to start up the Java compiler when the JVM starts. You are not meant to use this.
What is the best way of doing delegation in Smalltalk, more specifically in Pharo? I know of the doesNotUnderstand strategy, but it does not delegates subclassResponsability messages.
I was thinking on something that delegates every message send not explicitly implemented on the class to some specified object, like I can do, for example, with #Delegate in Groovy. Is there some already known way of doing this?
doesNotUndersand: will only work on methods that the object does not understand (thus the name), so if you already have implemented a method it will not be used (as is the case with subclassResponsibility.
If you use Pharo 5 (which should be released this week (May 2016)), you could use MetaLinks. It's a bit of an overkill, however what you are doing doesn't seem right to begin with (why would you want to delegate subclassResponsibility)?
In either case, MetaLinks allow to attach runtime behavior to your methods, for example:
You have some method that you want to delegate
MyObject>>someMethod
^ self subclassResponsiblity
And an object to which you wish to delegate to…
MyObject>>delegate
^ delegate
So you create a MetaLink
link := MetaLink new
metaObject: [ :object :selector :arguments |
object delegate perform: selector withArguments: argument ];
selector: #perform:withArguments:;
arguments: #(object selector arguments);
control: #instead.
Which you can install to any method AST you want.
(MyObject>>someMethod ast) link: link.
Now every time the method will be called, instead (that's what the control: does) of executing the method, the arguments of the message (if any) will be given to the block in metaObject:.
Although this should work and is extremely powerful mechanism, right now there are serious disadvantages that currently being addressed:
no documentation
little tooling support (it's pretty hard to debug)
a lot of work (we are working on a framework that would ease this as you would want to easily install them and uninstall them everywhere you need, but it's not ready yet, so it has to be done by hand)
recompilation removes the link (see point above)
Summary
To summarize, this is possible to do with MetaLinks as I've shown, however at the moment it's quite a lot of work, but we are addressing those issues.
what Peter was talking about is, you can override the
subclassResponsibility, just like you did for the doesNotUnderstand method.
There is no need to override every senders of "self subclassResponsibility".
For example, just delegate to the implementation of doesNotUnderstand
subclassResponsibility
^ self
doesNotUnderstand: (Message selector: thisContext sender selector
arguments: thisContext sender arguments)