Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Pedestrian Xing
Jul 19, 2007

Anyone have experience with Project Reactor and Netty? I'm trying to write a proxy that can do streaming decryption + download of large files to avoid buffering them. Netty's HTTP client gives me a Flux of ByteBuf's of arbitrary size and I need to turn that into a Flux of byte[]'s of a fixed size for decryption. Not sure what operation I'm looking for - it needs to consume every ByteBuf like map(), but each input could result in 0-N outputs. This is my first foray into reactive programming, so I might be missing something simple.

Adbot
ADBOT LOVES YOU

Hughlander
May 11, 2005

Pedestrian Xing posted:

Anyone have experience with Project Reactor and Netty? I'm trying to write a proxy that can do streaming decryption + download of large files to avoid buffering them. Netty's HTTP client gives me a Flux of ByteBuf's of arbitrary size and I need to turn that into a Flux of byte[]'s of a fixed size for decryption. Not sure what operation I'm looking for - it needs to consume every ByteBuf like map(), but each input could result in 0-N outputs. This is my first foray into reactive programming, so I might be missing something simple.

No but I have experience with Netty, and I'd just use a Pipeline to decrypt the stream before it got to Project Reactor, unless you must use their encryption.

Pedestrian Xing
Jul 19, 2007

Pedestrian Xing posted:

Anyone have experience with Project Reactor and Netty? I'm trying to write a proxy that can do streaming decryption + download of large files to avoid buffering them. Netty's HTTP client gives me a Flux of ByteBuf's of arbitrary size and I need to turn that into a Flux of byte[]'s of a fixed size for decryption. Not sure what operation I'm looking for - it needs to consume every ByteBuf like map(), but each input could result in 0-N outputs. This is my first foray into reactive programming, so I might be missing something simple.

I did finally figure this out, the answer is Flux<T>'s flatMapConcurrent(Function<T, Flux<T>>) method. It has to return a Flux, but it can have 0..N members.

Hughlander posted:

No but I have experience with Netty, and I'd just use a Pipeline to decrypt the stream before it got to Project Reactor, unless you must use their encryption.

Thanks, I did look into this. Ultimately, since I'm building on Spring Cloud Gateway, I'm not the one constructing the HTTPClient and processing the output separately seemed easier.

my bony fealty
Oct 1, 2008

word has come down from high at work that our dev team will probably start having to do some Java work soonish. I have zero Java experience, can anyone recommend resources/courses for getting started? the link in the second post here is a bit old so not sure if there's something more recent to look for. there's a few of those monolithic 70 hour courses on Udemy of course.

for context I am a dirty front-end developer who writes mostly JavaScript and has a good amount of PHP experience. thanks!

Objective Action
Jun 10, 2007



my bony fealty posted:

word has come down from high at work that our dev team will probably start having to do some Java work soonish. I have zero Java experience, can anyone recommend resources/courses for getting started? the link in the second post here is a bit old so not sure if there's something more recent to look for. there's a few of those monolithic 70 hour courses on Udemy of course.

for context I am a dirty front-end developer who writes mostly JavaScript and has a good amount of PHP experience. thanks!

Effective Java is your best bet for getting the language basics down. The thing to understand about Java is it is very old and depending on which version of Java you can code to you will have wildly nicer and more modern options for things like threads, file interactions, etc. You can do all that basically back to Java 1 but it gets more annoying the further back you go. If something feels fiddly as poo poo there is a very good chance there is a better and more modern way to do it and whatever documentation/stackoverflow you were looking at is out of date.

Some recommendations I can really make about Java coming from other languages is it has some of the finest tooling chains of any language in existence. I know people who insist on writing Java in Vim/Emacs/Notepad; those people are loving lunatics and you should not listen to them.

1) Find an IDE you like and learn the IDE's functions. I see a lot of people using the IDE like a really heavyweight text editor which is missing the point badly.
2) Learn the Java syntax, notice this is #2!
3) Start learning about the debugging and profiling tools. Flight Recorder and VisualVM are both free and get you 90% of some of the best tools around for that poo poo.

Objective Action fucked around with this message at 03:40 on Apr 16, 2020

ChickenWing
Jul 22, 2010

:v:

Objective Action posted:

1) Find an IDE you like and learn the IDE's functions. I see a lot of people using the IDE like a really heavyweight text editor which is missing the point badly.
2) Learn the Java syntax, notice this is #2!

I wouldn't really agree with this, most IDE functions don't make sense until you've used the language more. For a free IDE, I'd say VSCode (never used it but I don't think I'll ever voluntarily recommend eclipse again). If you're allowed a bit of IDE budget (or if you already have licenses for frontend work) pick up IntelliJ IDEA. I'm pretty sure these both have the added benefit of having modules for your frontend work as well as java.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

ChickenWing posted:

I wouldn't really agree with this, most IDE functions don't make sense until you've used the language more. For a free IDE, I'd say VSCode (never used it but I don't think I'll ever voluntarily recommend eclipse again). If you're allowed a bit of IDE budget (or if you already have licenses for frontend work) pick up IntelliJ IDEA. I'm pretty sure these both have the added benefit of having modules for your frontend work as well as java.

IntelliJ IDEA Community Edition is free and quite full featured, I'd recommend that ahead of VSCode for Java.

Hippie Hedgehog
Feb 19, 2007

Ever cuddled a hedgehog?

carry on then posted:

IntelliJ IDEA Community Edition is free and quite full featured, I'd recommend that ahead of VSCode for Java.

Seconded! IDEA before VSCode before Eclipse before ... Sublime text, I guess?
You don't need to pay for IDEA unless you need to use it for JS projects or need the paid support options.

abraham linksys
Sep 6, 2010

:darksouls:
I absolutely would not be writing Java or Kotlin without IDEA. I feel a little weird about having a language so reliant on the IDE (especially with Kotlin, since unsurprisingly there isn't much alternative tooling out there), but it is a tool that makes everything about the language make more sense to me.

On the other hand, I don't think you need to crack a book open and learn your whole IDE front to back before continuing. I'd run through a hello world in your IDE so you learn some of the basics, and then just learn incrementally. You should be trying to build and run apps and tests through your IDE (which is easy with IDEA's Maven/Gradle integration) and be comfortable with the debugger (which, if you've used a browser debugger before, you would be familiar with). The refactor tools are helpful but situational; you'll probably discover them when you need them.

In addition, as a full-stack developer, I would not go overboard trying to use IDEA for everything, since (a) that actually is where you get into the part of IDEA that costs money and (b) trying to integrate things like your frontend builds into IDEA will require a lot more overhead than you'd probably want. I just keep VS Code and IntelliJ running simultaneously (and did grab the uber-basic VSCode Kotlin plugin just so I could take a peek at backend code without opening IntellIJ when I'm focusing on frontend).

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

The help menu actually has some great stuff for learning IntelliJ

  • the keymap reference has the most important shortcuts, and some of them are marked as the ones you should definitely learn because of how useful the functions are
  • Tip of the Day points out some stuff that might catch your eye without being too overwhelming
  • there's another thing I forget the name of but it tells you how often you use stuff and you can see what you're neglecting

that and the "type what you want" shortcuts are great ways to explore as you go. You don't need to learn it all but there's a lot there that'll help you!

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE
IntelliJ is by far the best of the Java IDEs out there. Although in particular I disagree with the decision to remap ctrl-Y from undo, I think that causes a lot of needless suffering. No need to buy the full thing, the community edition is 95% of what you need (the big one being any sort of front-end editing).

Netbeans is passable especially if you are using older Ant style stuff and you dont know what youre missing. Eclipse is eclipse, its an IDE designed by engineers, its incredibly extensible and anything is possible, and nothing is easy. The Turing Tarpit for IDEs.

Frankly the best thing Ive found for editing frontends is... Notepad++. It does a pretty reasonable job of handling JSP syntax and there is no editor on the planet that can handle the nightmare of context-aware JSP editing. The include syntax and overlapping layers of JSP and JSTL means you basically have all the parseability of PHP calling CGI includes.

Thymeleaf templating is strongly recommended for any sort of sanity.

Paul MaudDib fucked around with this message at 02:47 on Apr 17, 2020

Splinter
Jul 4, 2003
Cowabunga!

Paul MaudDib posted:

Thymeleaf templating is strongly recommended for any sort of sanity.

I'm a big fan of Pebble (which is a port of Twig, Symfony's templating engine). Recommend it as an alternative for those that don't gel with the "everything is a tag attribute" approach of Thymeleaf and some others.

CPColin
Sep 9, 2003

Big ol' smile.

Paul MaudDib posted:

Thymeleaf templating is strongly recommended for any sort of sanity.

Hell yes to this. Opening up my templates in a normal browser without having to start the server is great.

BabyFur Denny
Mar 18, 2003
Hello this is the Java thread!

ivantod
Mar 27, 2010

Mahalo, fuckers.

Splinter posted:

I'm a big fan of Pebble (which is a port of Twig, Symfony's templating engine). Recommend it as an alternative for those that don't gel with the "everything is a tag attribute" approach of Thymeleaf and some others.

A hearty recommendation of Pebble from my side also. We use it at work and i'm very happy with it. It seems to give you enough power to do things, but without ending in JSP territory where suddenly you find that your entire application code is now inside the JSP templates. Also I like the Twig/Pebble template inheritance/block override concept as I feel it really gives a lot of flexibility for not a huge amount of effort.

Ither
Jan 30, 2010

I've used FreeMarker for some personal projects.

It was pretty good at handling what I wanted.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Pebble works pretty well for me too.

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe
Oh man I've been trying to set up IntelliJ and JDKs up so I can start playing around with Scala and boy do I remember why I left the Java ecosystem. Everything is somehow even more archaic than even C++.

Does anyone know why, when I try to attach debugging in IntelliJ to the SBT console, it says everything is connected, but ir doesn't seem to stop at my breakpoints? I set it all up with JDK 8 since that is the only version I could get to play nice with SBT in IntelliJ.

hooah
Feb 6, 2006
WTF?

Joda posted:

Oh man I've been trying to set up IntelliJ and JDKs up so I can start playing around with Scala and boy do I remember why I left the Java ecosystem. Everything is somehow even more archaic than even C++.

Does anyone know why, when I try to attach debugging in IntelliJ to the SBT console, it says everything is connected, but ir doesn't seem to stop at my breakpoints? I set it all up with JDK 8 since that is the only version I could get to play nice with SBT in IntelliJ.

I've never had any problems debugging Java code, so maybe Scala's the problem here?

Joda
Apr 24, 2010

When I'm off, I just like to really let go and have fun, y'know?

Fun Shoe

hooah posted:

I've never had any problems debugging Java code, so maybe Scala's the problem here?

Oh yeah, it's definitely a problem with how IntelliJ works with either Scala or SBT. We don't have a Scala thread though, so I'm asking here.

i vomit kittens
Apr 25, 2019


So I have a Spring app where there are different roles that can have different permissions based on what they're supposed to be handling. Using repositories, is there any way to search for a certain matching Key/Value pair directly? Currently I'm just querying all of the roles and looping through each of their permissions. The map for a role that could manage events would look like this (It's written in Kotlin, but it's more of a general Spring question so hopefully it still fits here):

code:
    var permissions: MutableMap<String, Boolean> = mutableMapOf(
            "canManageEvents" to true,
            "canManageVoting" to false,
            "canManageAbsences" to false
    )
So say I wanted to find all roles that have the matching Key/Value pair of <canManageEvents, true>. Is there a findBy... function I could define to do that, or if not what would be a better way than what I'm doing now? I tried doing findByPermissionsContains but apparently that only looks for the keys and not the whole pair.

i vomit kittens fucked around with this message at 06:38 on Apr 25, 2020

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!
Can't you just put in only the permissions that are true and assume everything else is false? That way you only have to search for a key.

Twerk from Home
Jan 17, 2009

This avatar brought to you by the 'save our dead gay forums' foundation.
I've got some fairly basic Thread-related questions while coming back to Java from a long time away. The last time I wrote Java professionally, it was an applet talking CORBA to the backend, I was using Eclipse, and checked code into CVS. I feel like I've got a working understanding of common concurrency issues and safety from spending time in Go recently, but Java's heavier thread abstraction leaves me with some questions.

Specifically, my team inherited an Android app. It is using Go mobile bindings for some of its functionality, which we're working to port over to Kotlin or Java. I need to get up to speed on good JVM networking practices in general though because we also will be developing the Scala backend going forward. It's doing a lot of not-HTTP network calls, which means things that would normally be handled by a library have been hand-rolled.
  1. Are there any reasons to prefer sync over async IO on Android in 2020? This app is doing a lot of sync i/o with what feels to me like big threadpools, 32+ threads. Where it's easy and convenient to rip out & make async, is this generally a good idea?
  2. For that matter, what's a smell that you have too many threads? Is hundreds in an Android app client perfectly normal? What about on the backend, is thousands of threads when targeting middle-weight VMs (~8 core/16GB) perfectly appropriate? Or is number of threads not a smell and I should just monitor and see?
  3. Where I pass callbacks to a library (OkHttp for doing async http) am I likely to cause problems if I do CPU-heavy stuff or blocking I/O on the thread that ran the callback, managed by the library?
  4. Am I making a mountain out of a molehill? Should I just make even bigger threadpools and think about Threads more like goroutines, AKA just use them whenever I/O is going to happen?

Finally, is this a sane way to handle doing blocking tasks in response to UDP packets? I know it needs error handling. Let's say that doPacketProcessing is either CPU heavy, does blocking I/O, or both.

code:
    Executors.newSingleThreadExecutor().execute(() -> {
        while (true) {
          byte[] buffer = new byte[8192];
          DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
          socket.receive(packet);

          executorService.submit(() -> doPacketProcessing(packet));
        }
    });

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Async i/o is better than having a bajillion threads, but it's overall not a huge deal. Having threads sit blocked on i/o doesn't really consume a lot of resources.

With regards to callbacks, most well-behaved libraries (e.g. anything using ListenableFuture) expect you to pass in an ExecutorService or Handler or similar to actually run your callback on. If you intend to do heavy computation in your callback, you should make sure to pass in the ExecutorService for your background threadpool or a similar place where it's appropriate to do that computation.

CPColin
Sep 9, 2003

Big ol' smile.
Kotlin coroutines are good, if you can use those.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

CPColin posted:

Kotlin coroutines are good, if you can use those.

They're just a quick trivial complete rewrite of your entire source away!

CPColin
Sep 9, 2003

Big ol' smile.

carry on then posted:

They're just a quick trivial complete rewrite of your entire source away!

1) Wrong
2) They're porting stuff over from a different language anyway

chippy
Aug 16, 2006

OK I DON'T GET IT
Having an issue with some Buttons (org.eclipse.swt.widgets.Button), if I set their text to a string longer than about 5 characters, the text isn't displayed. The buttons themselves are pretty wide with ample room for the text, and in a Group using a FillLayout. Does anyone have any idea what the issue might be?

chippy
Aug 16, 2006

OK I DON'T GET IT

chippy posted:

Having an issue with some Buttons (org.eclipse.swt.widgets.Button), if I set their text to a string longer than about 5 characters, the text isn't displayed. The buttons themselves are pretty wide with ample room for the text, and in a Group using a FillLayout. Does anyone have any idea what the issue might be?

Fuuuuuck I hate SWT so much

Hekk
Oct 12, 2012

'smeper fi

chippy posted:

Fuuuuuck I hate SWT so much

Give me a little bit to dig through some old stuff I did and let me see if I have anything using SWT. Off hand, I know I have. JavaFX app using GridPane but that isn't exactly what you need. Is there a specific reason it HAS to be SWT or can you use something else for the GUI?

chippy
Aug 16, 2006

OK I DON'T GET IT

Hekk posted:

Give me a little bit to dig through some old stuff I did and let me see if I have anything using SWT. Off hand, I know I have. JavaFX app using GridPane but that isn't exactly what you need. Is there a specific reason it HAS to be SWT or can you use something else for the GUI?

I'm an extending an existing GUI which has already been written in SWT and it's just what we use here so I don't think I've much of a choice. I guess I might be able to re-create it from scratch but I only needed to add a couple of buttons.
I've ripped out almost all the other GUI components so I can try to add them in one-by-one and find out what's causing this, and I've discovered that the buttons are apparently determining their height from the length of their text :psyduck:



I presume there's a layout manager causing this somewhere but I thought I'd commented them all out. Seems like such bizarre behaviour.

Hippie Hedgehog
Feb 19, 2007

Ever cuddled a hedgehog?
Did someone swap the arguments for height and width somewhere in your code base? That's awful weird indeed.

chippy
Aug 16, 2006

OK I DON'T GET IT

Hippie Hedgehog posted:

Did someone swap the arguments for height and width somewhere in your code base? That's awful weird indeed.

It's so messed up. They are just SWT Buttons. Current the parent composite has a vertical FillLayout, and then I'm adding a Group to that with a horizontal RowLayout, and then I'm adding the buttons to that. But I've tried so many different combinations at this point and they always seem to take their height from the text. I had zero loving clue what's going on at this point.

DreamingofRoses
Jun 27, 2013
Nap Ghost
Ignore dumb question, I was making things too complicated.

DreamingofRoses fucked around with this message at 23:00 on Apr 30, 2020

chippy
Aug 16, 2006

OK I DON'T GET IT

chippy posted:

It's so messed up. They are just SWT Buttons. Current the parent composite has a vertical FillLayout, and then I'm adding a Group to that with a horizontal RowLayout, and then I'm adding the buttons to that. But I've tried so many different combinations at this point and they always seem to take their height from the text. I had zero loving clue what's going on at this point.

I ended up basically rebuilding the layout from scratch and the weird behaviour went away. It was easier than figuring out what the previous guy had done.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

chippy posted:

I ended up basically rebuilding the layout from scratch and the weird behaviour went away. It was easier than figuring out what the previous guy had done.

This has absolutely been my experience with SWT as well.

Xenophanes
Nov 8, 2015
Sorry for a newbie question, but I've become deeply lost on a homework problem regarding implementing a generic tree structure that is supposed to imitate a string-keyed dictionary structure by having each node of the tree have 26 children corresponding to letters of the alphabet, which then allow you to access the value of a node by traversing down the tree one letter at a time. What I'm having trouble with is initializing the array of links to children, which are explicitly stated to be initialized by the constructor and to be null until accessed, but I can't initialize a generic array of 26 nulls. I'm probably fundamentally misunderstanding something, but here's my latest stab at the code:

code:
 public class MyNode <T> {
    private T data;
    private MyNode<T>[] children;

    public MyNode() {
        this.data = null;
        this.children = (MyNode<T>[]) new Object[26];
    }
This throws a class cast exception. I've tried just not initializing my array, but then I need to access specific indices of the array to check if they are null or point to another node. Thanks for any help.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Xenophanes posted:

Sorry for a newbie question, but I've become deeply lost on a homework problem regarding implementing a generic tree structure that is supposed to imitate a string-keyed dictionary structure by having each node of the tree have 26 children corresponding to letters of the alphabet, which then allow you to access the value of a node by traversing down the tree one letter at a time. What I'm having trouble with is initializing the array of links to children, which are explicitly stated to be initialized by the constructor and to be null until accessed, but I can't initialize a generic array of 26 nulls. I'm probably fundamentally misunderstanding something, but here's my latest stab at the code:

code:
 public class MyNode <T> {
    private T data;
    private MyNode<T>[] children;

    public MyNode() {
        this.data = null;
        this.children = (MyNode<T>[]) new Object[26];
    }
This throws a class cast exception. I've tried just not initializing my array, but then I need to access specific indices of the array to check if they are null or point to another node. Thanks for any help.

Are you required to use an array? Are you required to use generics?

I'm asking because even in my quick searches, it comes out pretty strongly that arrays of generics are just flat out not allowed in Java: https://www.ibm.com/developerworks/java/library/j-jtp01255/index.html

It seems like one of those two requirements was to give to make this work. To get the exact behavior you seem to be looking for, I'd use an ArrayList, but of course, I don't know the constraints of your assignment, this might not be allowed:

code:
import java.util.ArrayList;

public class Test<T> {
    private T data;
    private ArrayList<Test<T>> children;

    public Test() {
        this.data = null;
        this.children = new ArrayList<Test<T>>(26);
	for (int i = 0; i < 26; i++) { this.children.add(null); }
    }
}
I really hope they aren't expecting you to hard code 26 member variables of type MyNode<T>, one per letter...

carry on then fucked around with this message at 04:28 on May 5, 2020

Xenophanes
Nov 8, 2015
Yeah, those were both requirements. After poking at it for about 6 hours I got it to work(?) with
code:
    public MyNode() {
        this.data = null;
        MyNode[] test = new MyNode[26];
        this.children = (MyNode<T>[]) test;
    }
I don't understand how casting it to the generic form after initializing the array works when doing what seems to me to be the same thing in one line doesn't compile, but here's hoping it doesn't cause everything to fall apart down the line. Thanks so much for the help.

Xenophanes fucked around with this message at 05:20 on May 5, 2020

Adbot
ADBOT LOVES YOU

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

Xenophanes posted:

Yeah, those were both requirements. After poking at it for about 6 hours I got it to work(?) with
code:
    public MyNode() {
        this.data = null;
        MyNode[] test = new MyNode[26];
        this.children = (MyNode<T>[]) test;
    }
I don't understand how casting it to the generic form after initializing the array works when doing what seems to me to be the same thing in one line doesn't compile, but here's hoping it doesn't cause everything to fall apart down the line. Thanks so much for the help.

I think the difference here that you were creating it as Object[] originally, but here as MyNode[], not that it's on the same line.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply