New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Evaluate Architecure #231
Evaluate Architecure #231
Conversation
I remember a discussion about it some time ago. The issue with this approach was that os.arch tells only the JVM arch, not really OS arch. If there is a strong use case for these properties, we would have to be careful with the javadocs. Right now the javadocs don't explicitly tell the user that it is the JVM arch, and not the OS arch. Other approaches involve reflection or JNI, to find out the OS arch, but I think that is a bit too tricky to get it done correctly. |
The discussion mentioned by @kinow is here: https://issues.apache.org/jira/browse/LANG-1145 |
Rewrite javadoc's. |
Thanks for updating the pull request @Tomschi. I don't have a use case for this. I can see where it could be used, but I don't have any project where I would use it. Code is clear, javadocs have been updated :-) So will leave it here for others to review, comment, and maybe perhaps. |
I'am using it for the jacob-project. There i have to know, if it is a 32 or 64 bit architecture to load the correct dll library. |
Gotcha, found this example https://github.com/Tomschi/jacob-parent/blob/ec3f1c10169c26f14ee1f61bd6622c67a73e26fc/jacob/src/main/java/com/jacob/com/LibraryLoader.java#L202 Looks like a valid use case. I'm all right with merging it, my +0. Let's now wait to see what others think about it. Thanks! |
I think this is a worthy addition. In my experience people often do not read documentation. Maybe we should use |
Oh, good point @PascalSchumacher have no objection to it. We could probably avoid a few misunderstandings that way. Happy with that too @Tomschi ? |
It's ok for me, i will change it. |
jira issue: https://issues.apache.org/jira/browse/LANG-1313 I plan to merge this tomorrow (if there are no objections). |
What is the real pupose for this actually? The client should not care about the arch at all. The regex match is brittle. This will likely fail on ARM and it fails here on Itanium with HP-UX for |
I think @Tomschi use case is valid, where a client could need to know the arch before loading a certain library, and we had another issue submitted LANG-1145 with similar requirement.
Note taken, perhaps before merging we can try to cover more archs, like this list: There is another place where arch is used within Commons too: We can possibly look at how crypto is using it, and if we could maybe use a similar approach here. |
@kinow The cheapest way is to produce two bundles, one for 32 bit and one for 64 bit, if possible. The lopica source is useless, it is 15 years old. Commons Crypto is better. hawtjni on GitHub has decent detection code. It is work checking. But the current approach is way too simple. |
Create class ArchUtils, which defines methods for evaluating the JVM architecture. Create test class for ArchUtils.
Looks better now @Tomschi did you use Crypto's code as reference? cc @michael-o |
Yes, the base of my code references to the commons crypto lib. |
Excellent @Tomschi I'm dropping a note to the mailing list to ask for feedback from crypto devs, as there could be some synergy. I will play with the code at home, but one thing that I noticed is that it seems to contain tabs... minor nit pick, but could you check checkstyle and make sure the code is not introducing any warnings / errors there, please? That way it will be easier to merge the PR. Thanks! |
I'm sorry. I removed the tabs. Style should be ok now. |
|
||
static { | ||
map = new HashMap<>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HashMap is not thread-safe.
Since there are public methods which can also update the map, this means the class is not thread-safe either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. The crypto implementation doesn't allow changes to the map after it has been created. I think we can use a ConcurrentHashMap, or simply follow what was done in crypto.
This methods are for me an easy and null safe way for evaluating. Further, this methods are the reason, why i have done this pull request. |
private static final void addProcessor(Processor processor) throws UnsupportedOperationException { | ||
if (!map.containsKey(processor.getName())) { | ||
map.put(processor.getName(), processor); | ||
private static final void addProcessor(String key, Processor processor) throws UnsupportedOperationException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the parameters were changed to (Processor processor, String key ...) there would be no need to create the List and unpack it.
In which case, I think they belong on the Processor class. The user code would look like:
At present the same code is
I think that looks more complicated. |
return ProcessorArch.BIT_32.equals(processor.getProcessorArch()); | ||
} else { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code could be simplified:
Processor processor = map.get(value);
return processor != null && ProcessorArch.BIT_32.equals(processor.getProcessorArch());
Similarly for other related methods
@sebbASF I refactored the classes. Do you have any suggestions, or is it ok? |
map.put(key, processor); | ||
} else { | ||
String msg = "Key " + key + " already exists in processor map"; | ||
throw new UnsupportedOperationException(msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IllegalStateException might be better here
I thought the idea was to move the isXXX methods to the Processor class. You could then say
|
I'm not sure, if we really need the isXXX methods in the Processor class, because i can directly equal the enums. |
assertNotNull(ArchUtils.getProcessor(X86)); | ||
assertNull(ArchUtils.getProcessor("NA")); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no tests for Processor type.
Agreed it's not necessary to have the isXXX methods. Currently the code is:
It would become:
As well as being longer, in the first case one has to remember to whether to use ProcessorArch or ProcessorType |
Also it occurs to me that ProcessorArch and ProcessorType could perhaps be subtypes of Processor (Arch and Type). They don't really have an independent existence, so do they need separate classes? |
1 similar comment
…. Add and refactor tests.
1 similar comment
@sebbASF What do you think about the latest changes? Is this pull request ready for merging? Thanks, Pascal |
looks good |
Merged. Thanks! |
Add static field for hardware architecure.