Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!

P Marksson

Ranch Hand
+ Follow
since Nov 08, 2015
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by P Marksson

Using Spring Boot JPA, I am trying to futureize my project by have all repository classes return CompletableFutures.

So I created an interface that extends Repository:



However, Spring seems eager to create a bean of this interface and crashes during startup with the following message:



I tried excluding this interface by different ways with no success. What do I do?
6 months ago
Hi!

This are the queries I execute:



The first two queries works fine. The third one, yields syntax error with the following error message:


I really don't understand why. I am using the CLI interface on Mac OS.
I am using a HandlerInterceptor to intercept calls to my rest endpoint/servlet. Here I wan't to do custom authentication and reject the request if the user is not authentic. In the interceptor, I wan't to create a bean with prototype scope that will be available for the target endpoint during that request.

public ResponseEntity<Void> somePostEndpoint(@Context AuthenticUser user) {
...

Is this possible?
1 year ago
So I wan't to code a server for a dating site, for educational reasons. Seems like a fairly complicated task and a great opportunity to learn new stuff!
But there are some challenges that I have yet manage to figure out by brainstorming with myself. Here are some of them:

Availability: Being able to see if someone is online. Possible live updating, or is this to much? I am thinking of using websockets for this. Also, how do we scale websockets? All tutorial I see online make use of static variables, which goes against the rules of scalability.

Live update of chat messages: I guess this would be achieved by websockets? How would the server know when to send messages via websockets? I mean the insertion of the new message in the database must trigger some component of the websocket?

Premium users: Is there a cheaper alternative to paying users than Paypal?

Caching: So people will have profile pictures and more in their photo album. Obviously you can't load these from the database every time. I saw one tutorial suggesting to use nginx for caching, but that seems a bit complicated. How would you resolve something like this?

Also, how do the server keep track of users whom are online or offline? Doing a login in will of course make the user online. But logging out is a different story because people often just close their browser without signing out.
Do the server track activity and switch to offline after X minutes of inactivity?

Are frameworks like OpenFire or Firebase an overkill for this task?

I think scalability is very important.

Thanks in advance!
1 year ago
I have an app idea where the design and is similar to HQ. I want to code with Java with a MySQL database. The reason I picked these two is because Java is a strong language and both are supported by Google App Engine.

However, coding a system like HQ is a big question mark. The server the app speaks with is so different from a "normal" server. I mean it's not a traditional server where the client ask for data when needed. It's rather the opposite.

For those whom haven't tried HQ, here is how it works:
After running the app for the first time, the user register an account. Two times per day, at a fixed time schedule, a user can sign up for a competition 10 minutes prior to start. While a user waits in a lobby, they can see how many people signed, updating live. There is also a chat for everyone. Usually there are around 400k users for a competition. The competitions take about 15 minutes close afterwards. The user have to wait until next competition before being able to do something in the app.

Questions:

- What architecture do you think they are using? REST or web sockets or both?
- What process trigger a new competition? Is it a cron job?
- How can the server send so much data to so many persons simultaneously?
- How do the app know when a competition starts? Do they poll the server constantly or is this pushed to everyone with the app installed? I know the app sends a push notification but I thinking on when the app is open.
- Finally, how would You code an system like this?
1 year ago

Jeanne Boyarsky wrote:JUnit 5 solves this problem. There are @BeforeAll and @AfterAll annotations so you  can run code at those points.

JUnit 5 is on Milestone 4 and releases late in the year.



Not true. BeforeAll and AfterAll is just a renaming of BeforeClass and AfterClass.
2 years ago
Already tried that. Using a custom runner, you can't know when the last test have run, so you won't know when it's time to shut everything down.
2 years ago
Shouldn't have said that we only start Elastic Search and a Jetty server, because we start about 5 or 6 embedded servers and in future probably. Most of these use random ports which we access by a embeddedServerInstance.getPort() call.
This is just one reason why we can't do this with a Maven plugin/profile.

We are looking for something that would emulate a @BeforeAll or @BeforePackage that could exist in JUnit. We want to do this in code.
2 years ago

Stephan van Hulst wrote:Why do your unit tests require a Jetty server?

You should be mocking services that your classes need.



Integration tests.
2 years ago
Each of my test class starts the infrastructure required to do the tests. These components consist of Elastic Search and a Jetty server. Having each test class start and stop these and also running all the test classes sequentially is not the most efficient thing to do, since it takes ages to complete the tests. Starting the infrastructure once -> Run all the test classes -> Stopping it would be much more efficient but not easily achieved.

The difficulties comes when you try to make it work in your IDEA and Maven(where we use failsafe plugin). Using shutdown hooks to close all the infrastructure down almost worked. Gitlab(it's like Jenkins I guess) did not like shutdown hooks and there are no guarantees they will run.
Since we use JUnit 4,I looked into JUnit Suites, which did not work in IDEA.

Some ideas?
2 years ago
Thanks for the inputs.

I will consider having the server simply forward all the request and let device B do the calculations.
The purpose of the server is to do all the calculations so the mobile devices don't have to do it. Basically, device A could sends few messages per second to device B. I am afraid forwarding every request to device B would drain its battery.

AFAIK, the battery consumption of having the Bluetooth on is minimal. But I am interested in this "lower-quality network location service". Could you please elaborate?

Regarding the use of bluetooth, I found an very interesting method:
https://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#getRemoteDevice(java.lang.String)
2 years ago
Doesn't this forum have an edit button?

Anyway, want to note that battery usage is critical. And in my experience bluetooth should be way cheaper than GPS.
2 years ago
So I have encountered a problem and have two solutions to it that I need some feedback on. Or perhaps a better solution

I have two android devices that communicate with each other through a server. All the requests to the server are done by REST and all the requests by the server to the phone is done by push messages(using Firebase).

In my app, without trying to reveal to much info, one device A need to tell device B that something have happen. But before it does that, it need to check if device B is within close proximity. And if they are, ignore the message.

Idea 1:
1) Device A sends a REST request to the server, telling that something may have happen. Also include device A's GPS coords.
2) Server ask device B for its GPS coordinate by sending a push notification.
3) Device B receives the push message and sends a REST request to the server, containing its GPS coords.
4) Compare the GPS coords and determine if they are close to each other. If not, send a message to device B, telling it something have happen.

Idea 2:
1) Device A check if it can connect to device B or if it is connected to device B via Bluetooth.
2) If not, send a REST request to the server, telling that something definitely have happen.
3) Server simply forward the message to device B.

While idea 2 sounds easy and better, I am suspicious towards the use of Bluetooth. Basically, I am not use it's possible for device A to know that it actually is device B. So I am questioning the reliability of the second idea.
The first idea is on the other hand hard to implement. And I simply don't like it.  
2 years ago
I would say JSF, JSP and all those old technologies are obsolete.

Basically, by using JSF, you pack your app with both front end and back end code. Ugly :/

When those technologies where developed, the average computer where slow. Thus, having a front end app using Anulgar or React was a bad idea. Everything would look sluggish and laggy.
Todays computer are fast, and all the JSF rendering can be moved to a browser(i.e by using Angular, React etc). Chrome V8 for example compile javascript code to native code.

Rendering on server side is redundant as for today. It's cumbersome a complete waste of resources and CPU power.
2 years ago
JSF