EventStore / EventStore.JVM

Event Store JVM Client
https://geteventstore.com
BSD 3-Clause "New" or "Revised" License
223 stars 40 forks source link

Question about Java/Scala interface #87

Open ralphejohnson opened 7 years ago

ralphejohnson commented 7 years ago

I'm a longtime Java programmer. I've never programmed in Scala, though I have read papers that had short Actor programs using Akka/Scala, and figured it wouldn't be that hard to figure out how to use the JVM EventStore interface. I'm gradually figuring things out, but am not yet successful. The examples don't do anything with the Events that they read, and I couldn't figure out how to get the data out of it. For one kind of message, I have binary data. I eventually figured out that given an event e, I could use e.data().data().value().toArray() to get the binary data back. Not the most intuitive, and maybe not the best way. But my real point is that it would be nice to see some Java examples that actually used the data in events. Events are Scala objects, not Java objects, and it is not trivial for a Java programmer to figure out how to access them.

The ExConnection interface uses EventNumber, which is a Scala definition. How do you make an EventNumber in Java? I tried EventNumber.Exact(_nextTransaction) but it doesn't like any of the types I choose for _nextTransaction. It apparently wants a Scala integer. How do I convert a Java integer into a Scala integer?

EsConnection.readEvent produces a future. However, I want the value of the future. How do I wait til the future "arrives" and get the event? Again, if the examples were just a little more complicated and actually did something with the event then it would probably be obvious.

t3hnar commented 7 years ago

Hi @ralphejohnson

But my real point is that it would be nice to see some Java examples that actually used the data in events. Events are Scala objects, not Java objects, and it is not trivial for a Java programmer to figure out how to access them.

Is there concrete Scala example you'd like to see translated in Java?

The ExConnection interface uses EventNumber, which is a Scala definition. How do you make an EventNumber in Java? I tried EventNumber.Exact(_nextTransaction) but it doesn't like any of the types I choose for _nextTransaction. It apparently wants a Scala integer. How do I convert a Java integer into a Scala integer?

have you tried new EventNumber.Exact(_nextTransaction) ?

EsConnection.readEvent produces a future. However, I want the value of the future. How do I wait til the future "arrives" and get the event? Again, if the examples were just a little more complicated and actually did something with the event then it would probably be obvious.

I suppose this might help http://doc.akka.io/docs/akka/2.5.0/java/futures.html

Mousaka commented 7 years ago

I am also having problems instantiating some classes. I cannot manage to use the method createProjection in ProjectionsClient because I cannot create a valid value for the ProjectionMode-parameter. This is my attempt:

final ProjectionsClient client = new ProjectionsClient(settings, system);
final String result = client.createProjection(projectionName, projectionCode, ProjectionsClient.ProjectionMode.OneTime, true);

What does not work here is ProjectionsClient.ProjectionMode.OneTime. I tried looking for constructors, constants or methods that gives a ProjectionMode but I cannot find anything.