|
He's run into it in two pieces of published software; it's nothing he's written. That said, I don't know enough about the output of that tool to say for sure what's wrong; it's the damnedest thing and I can't find anything on Google about it.
|
# ? May 10, 2015 04:11 |
|
|
# ? Jun 13, 2024 05:33 |
|
So im working on a web crawler for a fun hobby type project. I've been reading about how caching DNS lookups could help reduce I/O wait time, but im not really sure how i would go about doing that. The way the crawler works now is that there are many 'Domain' objects responsible for synchronously crawling pages that belong to a domain, using java.net.HttpURLConnection and java.net.url.openConnection(). Is there a way that i could have each Domain object store the results of the first dns lookup so that it wont have to run a lookup for each subsequent page crawl? I don't know a whole lot about the way DNS lookups work or how the java.net library handles them so any insight would be helpful.
|
# ? May 10, 2015 08:57 |
|
ROFLburger posted:So im working on a web crawler for a fun hobby type project. I've been reading about how caching DNS lookups could help reduce I/O wait time, but im not really sure how i would go about doing that. This sounds like premature optimization, but the first thing to do would be to see how many DNS lookups are actually happening. You can do this with a network traffic monitoring software like WireShark. To explain the results it will be helpful to find out what DNS caching settings Java is using (depends on Java version and if running with a security manager) and what is going on in the operating system's DNS cache (e.g. command ipconfig /displaydns on Windows).
|
# ? May 10, 2015 10:33 |
|
Whats the style consensus on member classes accessing parent class members directly via ParentClass.this versus passing a reference to the member class on construction?code:
code:
|
# ? May 10, 2015 15:03 |
|
The way that's written, you don't have to do either one, just use foo directly.
|
# ? May 10, 2015 15:42 |
|
ROFLburger posted:So im working on a web crawler for a fun hobby type project. I've been reading about how caching DNS lookups could help reduce I/O wait time, but im not really sure how i would go about doing that. First google result about java dns caching: http://docs.aws.amazon.com/AWSSdkDocsJava/latest//DeveloperGuide/java-dg-jvm-ttl.html
|
# ? May 10, 2015 15:43 |
|
Kilson posted:The way that's written, you don't have to do either one, just use foo directly. Right, but the question is on style: is it stylistically favorable for member classes to reference parent class members directly or by passing a reference of the parent class to the member class through the member class constructor?
|
# ? May 10, 2015 15:54 |
|
Woodsy Owl posted:Right, but the question is on style: is it stylistically favorable for member classes to reference parent class members directly or by passing a reference of the parent class to the member class through the member class constructor? Why wouldn't direct access to your own containing class be okay? On the other hand, the second style would allow for access to instances of the containing class other than the one that contains your instance, which seems kind of messy to me but might have situational applications.
|
# ? May 10, 2015 15:58 |
|
Woodsy Owl posted:Right, but the question is on style: is it stylistically favorable for member classes to reference parent class members directly or by passing a reference of the parent class to the member class through the member class constructor? The first way, and only when it's not clear whose member you're accessing without it, or when you need to pass the parent class as an argument. I would consider the second approach a big code smell, as it is not only unnecessary (you already have a synthetic accessor to your outer class) but a potential source of both confusion and bugs. If I saw it in the wild, I would assume your inner class had been sloppily transplanted into the outer class without thought.
|
# ? May 10, 2015 16:53 |
|
A non-static inner class is already pretty tightly coupled to an instance of the outer class - you can't even construct an instance of the inner class without already having an instance of the outer one. Stylistically, if you want to access members of the containing instance of the outer class, you should just do that. If you pass in an instance of the outer class, that suggests you don't want such a tight coupling (e.g. perhaps the instance of the outer class referred to can be null, or might change over the lifetime of the object, or whatever). If that is the case, it should be a static inner class instead, or just an entirely separate class.
|
# ? May 10, 2015 16:59 |
|
So this is a general question, but I am implementing it in Java so here it is. I have a somewhat hierarchical structure in my code, something like this: code:
code:
code:
My current approach is to use Map<String,Factory<Strategy1>> or whatever, but I am not sure that's the best way to go about it.
|
# ? May 10, 2015 17:19 |
|
It looks a lot like you're trying to solve the Dependency Injection problem. I'd recommend taking a look at some of the mature DI frameworks around and seeing if any of them is suitable for your needs.
|
# ? May 10, 2015 17:31 |
|
I would use Jackson's polymorphic support (http://wiki.fasterxml.com/JacksonPolymorphicDeserialization) and maybe the @JsonCreator annotation to use the constructor when deserializing.
|
# ? May 10, 2015 17:40 |
|
Jabor posted:It looks a lot like you're trying to solve the Dependency Injection problem. I'd recommend taking a look at some of the mature DI frameworks around and seeing if any of them is suitable for your needs. Yes! I think so. I only encountered the definition of DI in testing books but it's correct. Now my main problem is that I work with a team of academicians and to be honest I can't expect them to go through Guice or Spring. I had a small lecture on what @Nullable and @NonNull mean and if I start adding more weird stuff I make the code illegible for anyone but me. Is there a framework that is easily readable? Need to look at Jackson I guess.
|
# ? May 10, 2015 17:55 |
|
CarrKnight posted:What would be the best way to do this? Notice that the various implementations of Strategy1 (and 2) have constructors with different parameters (and potentially sub-strategies). I would write something like Java code:
Max Facetime fucked around with this message at 21:05 on May 10, 2015 |
# ? May 10, 2015 21:02 |
|
Awesome. Is there a name for this kind of pattern? That's pretty much what I do except I make it into a separate factory class, well really Function<Json,Strategy> since I might need to modify the parameters through GUI after they are read but before the strategies are created.
|
# ? May 10, 2015 22:57 |
|
CarrKnight posted:Yes! I think so. I only encountered the definition of DI in testing books but it's correct. If you set up Guice correctly they can just consider it black magic.
|
# ? May 11, 2015 00:12 |
|
For Uni, I need to learn Swing. I don't do much GUI work at the best of times, and I've been using FX when I have. Does anyone have like a small tutorial other than the Oracle one? I'm basically looking for something that shows you how to make a couple of projects ranging from lambda function listeners to something a little more advance. The lectures on it are a bit of a mess.
|
# ? May 11, 2015 01:47 |
|
Cool site I found if anyone wants to host a hobby webapp online or gently caress around with cloud poo poo your managers keep talking about from RedHat. Pretty much the only credible site I found that hosts java projects. Found it while googling around for a host for a small app a goon asked for. Once you run the set up poo poo it'll generate the SSH token and a git repo for you. When you push your app upstream it automatically compiles and starts the app via Maven. https://www.openshift.com/
|
# ? May 16, 2015 06:01 |
lamentable dustman posted:Cool site I found if anyone wants to host a hobby webapp online or gently caress around with cloud poo poo your managers keep talking about from RedHat. Pretty much the only credible site I found that hosts java projects. Don't Heroku and AWS let you host Java applications?
|
|
# ? May 16, 2015 06:31 |
|
Openshift has a better free plan than heroku, but is worse in every other way.
|
# ? May 16, 2015 14:26 |
|
Any recommendations for code visualization tools? I'm looking for a tool that can rip through a dozen module project with hundreds of classes using relatively common features such as Spring dependency injection, and produce a graph of all classes, inheritances, and dependencies. Extra points if it includes library dependency support. It should produce graphical output that has easily modifiable visualization, and the modifications should be able to be saved and updated as code changes. For the right tool, tens of thousands of dollars in licensing fees would not be out of the question at all.
|
# ? May 20, 2015 03:54 |
|
For a software architecture course we used Understand (https://scitools.com/) on decent sized open source projects. I can't comment on the DI support since we didn't really look at that but it seemed to cope with large projects pretty well and had quite a bit of organization/visualization support. It's been a year though.
|
# ? May 20, 2015 04:55 |
|
carry on then posted:For a software architecture course we used Understand (https://scitools.com/) on decent sized open source projects. I can't comment on the DI support since we didn't really look at that but it seemed to cope with large projects pretty well and had quite a bit of organization/visualization support. It's been a year though. This is an interesting tool, thank you. Do you know anything about A-Spice certification as it relates to this? Given the auto background, it seems like a natural choice.
|
# ? May 20, 2015 05:43 |
|
more like dICK posted:Openshift has a better free plan than heroku, but is worse in every other way. What's so bad about it? I've only briefly messed around with it. edit: Wait what the 3 gears is 3 gears per account and not per app? Well that's really lovely. piratepilates fucked around with this message at 06:39 on May 21, 2015 |
# ? May 20, 2015 20:25 |
|
edit:figured it out
DholmbladRU fucked around with this message at 21:59 on May 26, 2015 |
# ? May 26, 2015 14:11 |
If I have a Socket connected from a client to a server and I want to fiddle with a custom protocol, is there a more graceful way of having the server handle commands than either (1) barfing serialized 'ServerCommand' objects across the network with ObjectStream or (2) writing plain strings like, "doActionA"?
|
|
# ? May 27, 2015 05:02 |
|
Jo posted:If I have a Socket connected from a client to a server and I want to fiddle with a custom protocol, is there a more graceful way of having the server handle commands than either (1) barfing serialized 'ServerCommand' objects across the network with ObjectStream or (2) writing plain strings like, "doActionA"? What do you mean by "graceful"? If you're at the socket level, you essentially have to write bytes on the wire. What those bytes mean, that's entirely up to you. There's no way around that. Now, you may come and say that you don't want to serialize objects using ObjectStream. That's fine, there are a billion other ways to serialize objects (to json, to xml, to other binary protocols like protobuf or msgpack). Or maybe you don't want to send objects at all (or strings). That's fine too, you can send numbers: 1 means actionA, 2 means actionB, etc., but that'll be quite hard to maintain if it gets big, but I suppose you could do it. But, you can send anything you want. If you can make bytes out of it, you can send the kitchen sink if you so desire.
|
# ? May 27, 2015 05:43 |
Volguus posted:What do you mean by "graceful"? If you're at the socket level, you essentially have to write bytes on the wire. What those bytes mean, that's entirely up to you. There's no way around that. Now, you may come and say that you don't want to serialize objects using ObjectStream. That's fine, there are a billion other ways to serialize objects (to json, to xml, to other binary protocols like protobuf or msgpack). By graceful, I meant, something less seemingly barbaric than writing a server which reads a character from the socket and throws it into a switch statement, then reads a few more characters and reassembles objects. That feels really old-school, like something I'd do in C in 1990. If that's not actually stupid or horribly unacceptable, I think I'll just make a CommandObject and dump that over the wire. I'd figured Java might have some "community standard" or "de facto" accepted way of doing it. "Oh, actually you're supposed to subclass the CommunicationProtocolWriter," or something like that.
|
|
# ? May 27, 2015 06:38 |
|
Jo posted:By graceful, I meant, something less seemingly barbaric than writing a server which reads a character from the socket and throws it into a switch statement, then reads a few more characters and reassembles objects. That feels really old-school, like something I'd do in C in 1990. If that's not actually stupid or horribly unacceptable, I think I'll just make a CommandObject and dump that over the wire. I'd figured Java might have some "community standard" or "de facto" accepted way of doing it. "Oh, actually you're supposed to subclass the CommunicationProtocolWriter," or something like that. There are already quite a bunch of protocols invented for network communication, but since you said you wanted to create your own there is no really any way around it but send bytes over the wire.
|
# ? May 27, 2015 12:57 |
|
Jo posted:By graceful, I meant, something less seemingly barbaric than writing a server which reads a character from the socket and throws it into a switch statement, then reads a few more characters and reassembles objects. That feels really old-school, like something I'd do in C in 1990. If that's not actually stupid or horribly unacceptable, I think I'll just make a CommandObject and dump that over the wire. I'd figured Java might have some "community standard" or "de facto" accepted way of doing it. "Oh, actually you're supposed to subclass the CommunicationProtocolWriter," or something like that. You say barbaric, but it's actually just about efficiency. The network is still usually the bottleneck for performance, so the less you need to send to get the job done, the better (especially if you're writing an application-layer protocol on top of TCP, which is quite chatty on its own.) There's not much point to make sending Java objects part of the command function of the protocol unless you have an application that specifically benefits from doing that in production, but it's possible so go hog wild.
|
# ? May 27, 2015 13:55 |
|
Having some issues with a java spring POST api. When I change the RequestBody to a String I can get the string being sent in with the port request. However when it is set to PostCountry I get the below error message. Does anything have thoughts? I am using jackson-core 2.5.3 code:
code:
code:
edit: as a work around I change the ResponseBody to a string. And parsed out that json string using GSON. Seems to be working DholmbladRU fucked around with this message at 15:54 on Jun 3, 2015 |
# ? Jun 3, 2015 15:08 |
|
Are you setting the content type on the request to application/json or whatever? edit: yep, sorry, I missed that it was at the bottom. That's a weird place for it. Can you verify that the request actually has the correct content-type header? Kilson fucked around with this message at 20:59 on Jun 3, 2015 |
# ? Jun 3, 2015 18:45 |
|
Kilson posted:Are you setting the content type on the request to application/json or whatever? Yes you can see in the screenshot the application/type is correctly set to json
|
# ? Jun 3, 2015 19:18 |
|
figured it out! needed this in the mvc-dispatcher file code:
|
# ? Jun 3, 2015 21:07 |
|
I was gonna say, if it works with a string and the string is in the right format then your serialization is messed up somehow, expecting some token it isn't getting or something. Needing to include jackson could do it I'm not using Spring atm (although I played around with it once) but it can help with REST APIs to actually return some kind of Response object with the JSON baked into its data field rather than just saying "return string" and counting on the API to map it for you. Plus that way you get more control over the response, if you need to send back an HTML error code or something.
|
# ? Jun 3, 2015 21:19 |
|
No questions, just wanted to share something that popped up on HN: http://java.metagno.me/
|
# ? Jun 6, 2015 20:07 |
|
Trying to understand how to approach this problem. I have a java spring application which is running on tomcat. As part of the application I need to build xml(.kml) files which are accessible through a url localhost:port/resources/kml. I am unsure how to write files to the disk or exploded war in order to make them accessible via this url. This seems like a common type of functionality. The kml files will be written for one time use, but they are very large.
|
# ? Jun 8, 2015 16:31 |
|
DholmbladRU posted:Trying to understand how to approach this problem. I have a java spring application which is running on tomcat. As part of the application I need to build xml(.kml) files which are accessible through a url localhost:port/resources/kml. I am unsure how to write files to the disk or exploded war in order to make them accessible via this url. This seems like a common type of functionality. The kml files will be written for one time use, but they are very large. You don't necessarily need it baked in the WAR file. As long as your spring application is listening to localhost:port/resources/kml and responds with a service, then you can just have your service read the XML files at runtime (so long as they have permission) and then return the file in whatever manner you wish; plaintext HTML or something fancier. Should be pretty straightforward. Sounds like you need to look into implementing a service to listen to port/resources/kml using spring, and then have that service return your XML.
|
# ? Jun 8, 2015 16:45 |
|
|
# ? Jun 13, 2024 05:33 |
|
Zaphod42 posted:You don't necessarily need it baked in the WAR file. As long as your spring application is listening to localhost:port/resources/kml and responds with a service, then you can just have your service read the XML files at runtime (so long as they have permission) and then return the file in whatever manner you wish; plaintext HTML or something fancier. Should be pretty straightforward. Accessing the files via url is not the problem. What I am unsure of is how to properly write to that directory, without breaking 'rules'...
|
# ? Jun 8, 2015 17:59 |