Do not be too strict, here is my interpretation of this code. Let us call the owner of reactive-streams Roland.
At first Roland needs a Common Interface for all inboundSignals
static interface Signal {};
ConcurrentLinkedQueue<Signal> inboundSignals = new ConcurrentLinkedQueue<Signal>();
Signals like Cancel
, Subscribe
and Send
have allways the same purpose are immutable and occur very frequently, so it is good Idea to implements they as Joshua Bloch's Singleton:
enum Cancel implements Signal { Instance; };
enum Subscribe implements Signal { Instance; };
enum Send implements Signal { Instance; };
the other way to do the same is similar to your proposal and my favorite:
enum CommonSignals implements Signal{
Cancel {
@Override
void debug() {
System.out.println("Cancel");
}
},
Subscribe {
@Override
void debug() {
System.out.println("Subscribe");
}
},
Send {
@Override
void debug() {
System.out.println("Send");
}
};
abstract void debug();
[...] some other methods I could need in the future
}
As you can see, this is a different implementation. But the idea is the same - Signal as singleton
We move on and find this code:
static final class Request implements Signal {
final long n;
Request(final long n) { // every Request has different value of n
this.n = n;
}
};
Since inboundSignals
can contain multiple Request
objects it is not possible to implement this type of Signal as Singleton. Therefore it can not be a member of CommonSignals
or implemented as enum
.
Conclusion
Roland used one of many possibilities to implement a singletons. I think that's more a matter of taste how to do it.