atlarge-research / opencraft

Other
5 stars 2 forks source link

ActiveMQ and JMS broker - [merged] #146

Closed jdonkervliet closed 4 years ago

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 15:22

Merges feature/activemq-broker -> development

Belongs to issues #11 #12

This merge request adds a JMS broker on which ActiveMQ can run.

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 15:25

changed title from {-Feature/activemq-} broker to {+ActiveMQ and JMS+} broker

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 15:25

changed the description

jdonkervliet commented 4 years ago

In GitLab by @wubero on May 19, 2020, 15:37

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 136

Shouldn't there be a whiteline after this catch block? Since there is a finally block afterwards

jdonkervliet commented 4 years ago

In GitLab by @wubero on May 19, 2020, 15:39

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 158

Shouldn't there be a whiteline before this if? Change this or the method above so it remains consistent

jdonkervliet commented 4 years ago

In GitLab by @wubero on May 19, 2020, 15:39

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 182

Whiteline before this if

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 15:40

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 136

Correct, there should be.

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 15:44

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 158

My thinking here was that the topic subscribers were connected to the if statement, but do we want a whiteline before every if statement then?

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 15:45

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 158

If they are directly related, I'm fine with keeping them together.

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 15:52

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 182

My thinking here was also that the code before the if is related to the actual if statement

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 16:15

Commented on pom.xml line 47

Do we need a dependency for JMS as well? (I'm not sure whether Java EE is included in all JDKs and JREs by default)

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 16:17

Commented on src/main/java/net/glowstone/messaging/brokers/Brokers.java line 41

As the factory is shared between multiple ActiveMQ brokers, should't it be checked whether it already exists instead of replacing it?

Either make it a local variable or make sure that the factory is properly reused.

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 16:18

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 76

The whiteline above this if-statement isn't required, but I don't mind leaving it in either.

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 16:20

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 122

I would personally add a whiteline at the start of the try-block (as it contains multiple code blocks), and remove the whiteline at the start of the method as it only contains one code-block (the locking try-catch-finally).

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 17:48

Commented on src/main/java/net/glowstone/messaging/brokers/Brokers.java line 41

changed this line in version 2 of the diff

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 17:48

added 1 commit

Compare with previous version

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 17:49

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 136

I hope I added the whiteline where you wanted, if that is the case you can resolve this thread.

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 17:49

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 158

I decided to add the whiteline to stay consistent

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 17:50

Commented on pom.xml line 47

I believe it is not included in all JDKs by default, therefore I added JMS as a dependancy.

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 17:51

Commented on src/main/java/net/glowstone/messaging/brokers/Brokers.java line 41

I decided to create a local variable, because when multiple brokers are created the uri might be different for each broker in which case a local variable might be better.

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 17:51

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 76

I decided to keep the whiteline here to stay more consistent

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 17:51

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 122

done

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 17:53

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 182

In the end I did decide to add a whiteline to stay consistent.

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 18:00

resolved all threads

jdonkervliet commented 4 years ago

In GitLab by @wubero on May 19, 2020, 18:14

resolved all threads

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 18:21

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 20

'a connection' is a little too vague in my opinion, can you expand on that?

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 18:35

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 125

You can use computeIfAbsent here:

image

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 18:35

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 20

changed this line in version 3 of the diff

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 18:35

added 1 commit

Compare with previous version

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 18:36

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 20

I expanded the javadoc

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 18:37

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 30

Perhaps we can change the generic type name of Topic to signify the difference with the JmsTopics. Perhaps BrokerTopic?

jdonkervliet commented 4 years ago

In GitLab by @larsdetombe on May 19, 2020, 18:40

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 30

I think the generic type Topic should stay consistent. This way people know it is the same Topic that is used in other classes.

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 18:54

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 30

It is not really the same "Topic", just a generic type that can basically be anything.

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 18:58

How did the activeMQ broker perform compared to the broker we have right now? I am just curious.

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 19:03

Commented on src/main/java/net/glowstone/messaging/brokers/Brokers.java line 23

It seems you missed a return value here.

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 19:06

Commented on src/main/java/net/glowstone/messaging/brokers/Brokers.java line 38

The JmsBroker that is returned will be raw here, without any of the generic types associated with it. This means that you always have to cast it after creating it. So it would be nice if this method could return the JmsBroker immediately with the correct type.

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 19:13

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 55

The createSession documenation specifies the following:

This method has been superseded by the method createSession(int sessionMode) which specifies the same information using a single argument, and by the method createSession() which is for use in a Java EE JTA transaction. Applications should consider using those methods instead of this one.

So we should probably look into using that.

Furthermore, can you perhaps place a comment as to what the reason is for choosing that session mode and not one of the others?

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 19:16

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsSubscriber.java line 15

The consumer field is never used (only assigned). So what is the reason for it being here?

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 19:19

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 135

Would it not be possible to use the contains method directly? Currently the hashcode of sub is only based on the subscriber anyway.

jdonkervliet commented 4 years ago

In GitLab by @julian9499 on May 19, 2020, 19:33

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 36

I find this very hard to distinguish this from a single jmsTopic, maybe call it a jmsTopicMap.

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 19:34

Commented on src/main/java/net/glowstone/messaging/brokers/jms/serializers/ProtocolCodec.java line 73

You should be able to use bytesMessage.readBytes(bytes) here, since you are trying to read the maximum amount of bytes possible anyway.

jdonkervliet commented 4 years ago

In GitLab by @julian9499 on May 19, 2020, 19:35

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 156

Same here. Try to avoid multiple with an s at the end of the word. It is really similar to the singular word.

jdonkervliet commented 4 years ago

In GitLab by @julian9499 on May 19, 2020, 19:38

Commented on src/test/java/net/glowstone/messaging/brokers/jms/JmsBrokerTest.java line 48

Why are warnings suppressed here?

jdonkervliet commented 4 years ago

In GitLab by @julian9499 on May 19, 2020, 19:39

Commented on src/test/java/net/glowstone/messaging/brokers/jms/JmsBrokerTest.java line 119

Rename this to createproducer

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 19:53

Commented on src/main/java/net/glowstone/messaging/brokers/jms/serializers/ProtocolCodec.java line 84

Would it be possible to avoid copying the data over? Currently, we are first writing to a bytes array. After which we immediately write it to the ByteBuf, which seems redundant.

After a little bit of research I found out that we can use Unpooled.wrappedBuffer(<bytes array here>). This basically uses the given array as buffer. This should be okay, since nothing should be written to the buffer during decoding.

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 20:00

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 125

Correct, you could. But, if I remember correctly, the calls made inside the if-statement can throw an exception, which would require a lot of additional code to handle properly when thrown inside of a lambda expression.

If not, it might still be preferable iff its the case in the other methods (as keeping things consistent might be more important).

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 20:03

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 30

Except that it is "supposed" to be the same as used by the other classes (which are all meant to be used together). Also, it matches the interface's generic type name, which I think is better than having it renamed.

Don't get me wrong, I do agree that having to use jms.Broker is aweful!

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 20:04

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsSubscriber.java line 15

I think not storing it could lead to it being garbage collected. Which would be bad, as we never have to call it, but it does keep track of the callback we've set up.

jdonkervliet commented 4 years ago

In GitLab by @JimVliet on May 19, 2020, 20:05

Commented on src/main/java/net/glowstone/messaging/brokers/jms/serializers/ProtocolCodec.java line 56

The getBytes method starts writing the data from its buffer to bytes at the specified index. This means that the front of bytes will be empty up to index. I am pretty sure this is a bug.

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 20:06

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 36

Including the type in the name of a variable is often considered bad practice as it requires renaming the variable whenever the type changes (it's a form of code-duplication).

jdonkervliet commented 4 years ago

In GitLab by @swabbur on May 19, 2020, 20:07

Commented on src/main/java/net/glowstone/messaging/brokers/jms/JmsBroker.java line 156

I think that is mostly a problem of the English language haha