|
I wasn't sure if I should put this here or in General questions. My distributed systems course is taught in Java. Our project is to implement basic active and passive replication on a local network. We need to be able to create new processes if an existing process crashes. I saw that this can be done in Java using ProcessBuilder. I was wondering though how you would create a new process on a different machine? I know that you could use a server that you could request to create the new process for you. However, I feel that would go a bit against the spirit of our project (if that server fails then you can no longer create new processes on that machine unless you replicate *that* server also, which I'd prefer to avoid).
|
# ? Dec 5, 2008 14:01 |
|
|
# ? May 9, 2024 08:41 |
|
I'm brainstorming on a simple java app that requires data exchange over the internet to work on shared data. Possible features include chat. I'm leaning towards the idea of having a separate persistent server as opposed to a "host peer" so users can continue working should the host lose connectivity or quit. I was considering using PHP/MySQL as the server. Each client could make HTTP requests with different arguments to the script to pull shared data, although this doesn't allow event-based interaction -- the clients would have to constantly poll the server. I was initially attracted to this because there's essentially zero chance firewalls and the like would interfere. I suppose what I'm asking for is a brief, high-level suggestion to approach this problem. Synchronization is important, as is network visibility. I'd like users, especially those behind routers, to be able to get going without worrying about firewalls and port forwarding.
|
# ? Dec 5, 2008 16:13 |
|
Boz0r posted:I'm doing a Java Applet for programming class, and my applet works fine in eclipse, but as soon as I load it into a html file, it doesn't. Can you link to an HTML file containing the applet so we can see what exactly is not working?
|
# ? Dec 5, 2008 17:35 |
|
Boz0r posted:What could be wrong?
|
# ? Dec 5, 2008 17:37 |
|
In an RDBMS, it's typical to normalize something like UserType (or PaymentMethod) into into its own table like 1=admin, 2=viewer (or 1=cash, 2=cheque, 3=creditcard), and other tables reference them by id. Such tables won't change, typically. In Java code, it makes sense to think of these as enums, so a Payment class would have a PaymentMethod field, where PaymentMethod is an enum: PaymentMethod.CASH, PaymentMethod.CHEQUE, etc. How can I use Hibernate to represent this common use case? The following links are what google has to say about the issue, but these solutions seem overly complex and/or are several years old. http://www.hibernate.org/265.html http://www.hibernate.org/265.html http://appfuse.org/display/APF/Java+5+Enums+Persistence+with+Hibernate http://www.hibernate.org/272.html http://snipplr.com/view/5379/java-5-enum-hibernate-mapping/ http://hibernate.org/203.html Does anyone have experience with this, and/or can vouch for one of the linked solutions? Enlighten me! (E: Don't get me wrong, I'm usually all for just trying things out, but the linked solutions look old, long and complicated, and this very well may be a case of someone here saying "oh just do X, it works great".) epswing fucked around with this message at 17:52 on Dec 5, 2008 |
# ? Dec 5, 2008 17:47 |
|
chocojosh posted:I wasn't sure if I should put this here or in General questions. You can probably use http://java.sun.com/javase/technologies/core/basic/rmi/index.jsp. You can have a remote object sitting there and it can create a process for you. Although in case that this object is no longer there, it would fail
|
# ? Dec 5, 2008 17:53 |
|
hexadecimal posted:You can probably use http://java.sun.com/javase/technologies/core/basic/rmi/index.jsp. This is always the case, really: to create a process on a different computer, you will have to have a server process (and a remote object definitely involves a server) on that machine, and it is possible for that process to go down.
|
# ? Dec 6, 2008 00:51 |
|
rjmccall posted:This is always the case, really: to create a process on a different computer, you will have to have a server process (and a remote object definitely involves a server) on that machine, and it is possible for that process to go down. True. I don't know much about creating Java processes, but if I was to create them on some machine remotely I would probably try to use RMI for the sake of simplicity.
|
# ? Dec 6, 2008 01:13 |
|
rjmccall posted:This is always the case, really: to create a process on a different computer, you will have to have a server process (and a remote object definitely involves a server) on that machine, and it is possible for that process to go down. Thanks. I thought maybe I was missing something because it was never actually covered in the course (we're just told "assume these processes are running on different hosts").
|
# ? Dec 6, 2008 06:54 |
|
Say I was writing a program that was only allowed to run for an amount of time only known at run time. How would I get the program to clock itself and terminate when it was supposed to?
|
# ? Dec 6, 2008 23:14 |
|
Clanpot Shake posted:Say I was writing a program that was only allowed to run for an amount of time only known at run time. How would I get the program to clock itself and terminate when it was supposed to? http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#currentTimeMillis() Measure time in beginning then implement some checks that terminate after current time - start time exceeded some limit you set.
|
# ? Dec 6, 2008 23:21 |
|
hexadecimal posted:http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html#currentTimeMillis()
|
# ? Dec 6, 2008 23:38 |
|
For my final project in my intro java class, I need to code minesweeper with an animated timer. I'm not too worried about the animated timer, because that seems pretty straightforward; just three animated blocks that run through labels 0-9 at the appropriate intervals. However, I want to run my approach for the actual body of the game past some people who know what they're doing, so they can tell me if I'm doing something fundamentally wrong. Basically, I'm planning to have two 2-d arrays, one full of booleans and one full of jbuttons. The boolean array will determine if a cell in the array contains a bomb, and the button array will be the actual board that the player clicks. They'll click a button (x, y), and it'll reference boolean array cell (x, y). If it's a bomb, it'll switch the jlabel on the button to a picture of a mine, and the game ends. If it's not a bomb, it'll check all the boolean array cells (x-1, y-1), (x-1, y), (x-1, y+1), and so on, incrementing a count for each bomb it finds. When it checks all the squares, it'll change the jbutton to display a jlabel which will be a picture of whatever number the count ended up being. I want to use pictures in the jlabels to make sure that the label gets displayed at the same size every time. Is this sounding like a feasible approach, or is there some aspect of java I'm not understanding which makes doing it this way completely terrible?
|
# ? Dec 7, 2008 06:43 |
|
Coca Koala posted:For my final project in my intro java class, I need to code minesweeper with an animated timer. You could extend the JPanel class, something like code:
(I know someone is going to say "gadzooks, you're embedding application logic in a gui component, that's filthy", but c'mon, it's an intro course.) Edit: vvv Sure, whichever component he ends up using! The point I was trying to emphasize was not needing two 2d arrays. epswing fucked around with this message at 17:00 on Dec 7, 2008 |
# ? Dec 7, 2008 07:41 |
|
Clanpot Shake posted:Say I was writing a program that was only allowed to run for an amount of time only known at run time. How would I get the program to clock itself and terminate when it was supposed to? Use the Timer class: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Timer.html Add a TimerTask which just closes the application when it's run, and set the delay to whatever it is set to at runtime. epswing posted:You could extend the JPanel class, something like Why extend JPanel? If you want it as an array of buttons on a grid extend JButton, JPanel is a container for multiple components. Or if you don't want it to function like an actual button extend JComponent. Twitchy fucked around with this message at 16:25 on Dec 7, 2008 |
# ? Dec 7, 2008 16:11 |
|
epswing posted:You could extend the JPanel class, something like that's a really clever idea. Thanks!
|
# ? Dec 7, 2008 21:12 |
|
epswing posted:In an RDBMS, it's typical to normalize something like UserType (or PaymentMethod) into into its own table like 1=admin, 2=viewer (or 1=cash, 2=cheque, 3=creditcard), and other tables reference them by id. Such tables won't change, typically. In Java code, it makes sense to think of these as enums, so a Payment class would have a PaymentMethod field, where PaymentMethod is an enum: PaymentMethod.CASH, PaymentMethod.CHEQUE, etc. We do it that way, use a UserType to handle the mapping, you should be able to do it pretty generically and handle just about every type you'll encounter (they usually just pass a number id through to hibernate on persistence, the other parameters of the enum are just for pretty printing and stuff). You can then use the enum object itself in HQL/Criteria/setters/etc.
|
# ? Dec 8, 2008 03:44 |
|
I'm finding your reply somewhat vague. What do you mean by "that way"? Can you give an example?
|
# ? Dec 8, 2008 07:10 |
|
Ok, I'm trying to write an implementation of RSA in java. The only problem is, when I read in a text file, how do I convert a generic string into an integer? I have it reading in line by line and it keeps giving me a number format exception, probably because it can't change a string to an integer. But it seems to have no problem outputting integers into normal strings. When I have it decrypting a file full of numbers, I just read in a line, use modpow(d,n) on it and use fileout.write ( stuff) and it just writes the integer to the file, but as letters! I want to know how to read in letters as numbers. It lets me output numbers as letters so why can't I do the reverse? Here's my function if anyone cares: public void encrypt( String plainTextFile, String cipherTextFile, BigInteger e, BigInteger n) { BigInteger data, blob; String glob; try { FileReader fileIn = new FileReader( plainTextFile); BufferedReader in = new BufferedReader( fileIn); FileOutputStream fileOut = new FileOutputStream( cipherTextFile); while ( ( glob = in.readLine()) != null) { blob = new BigInteger( glob );<---- this is the problem System.out.println(blob); data = blob.modPow( e, n ); System.out.println(data); fileOut.write( Integer.parseInt( data.toString())); } in.close(); fileOut.close(); } catch(Throwable t) { System.err.println("Error: " + t);} } I have tried replacing that line with blob = new BigInteger( Integer.parseInt(glob) ); but it won't compile, saying that Biginteger(long) has private access.
|
# ? Dec 8, 2008 15:07 |
|
Convert by changing the string to a byte array, then using the array to construct a BigInteger.
|
# ? Dec 8, 2008 16:11 |
|
Bill O'Riley is GENIUS posted:Ok, I'm trying to write an implementation of RSA in java. The only problem is, when I read in a text file, how do I convert a generic string into an integer? I have it reading in line by line and it keeps giving me a number format exception, probably because it can't change a string to an integer. But it seems to have no problem outputting integers into normal strings. When I have it decrypting a file full of numbers, I just read in a line, use modpow(d,n) on it and use fileout.write ( stuff) and it just writes the integer to the file, but as letters! I want to know how to read in letters as numbers. It lets me output numbers as letters so why can't I do the reverse? Try outputting glob and seeing what the value is. I'm thinking there may be a problem with extra whitespace (the javadoc says specifically extra whitespace is not allowed). Also, you do NOT want to first parse to a long and then to a big integer -- a long can only contain a number of a certain size which will be much less than the BigInteger. You would be first making your number the size of the long (there may be some overflow here changing the numerical value also) and then you'd be assigning that smaller number to a BigInt.
|
# ? Dec 8, 2008 16:11 |
|
Alright guys, thanks, but I've run into another problem. When it encrypts stuff, it just throws it all in to the file- no new lines or white space of any kind. This is really bad for my decryptor since it reads line by line- is there any way I can insert things into the encrypted file so the decryptor will be able to just break things off and decrypt them?
|
# ? Dec 8, 2008 17:32 |
|
Read a constant number of bytes at a time, every time. The number should be defined for the algorithm as the block size.
|
# ? Dec 8, 2008 20:21 |
|
Since FreePastry is used with Java, I figured I'd ask here as well.Cedra posted:Does anyone have any experience with FreePastry and Windows? I'm using it with a Vista laptop and an XP desktop, though I've made 2 nodes within the same machine, and they see each other, but again, the logger does not provide any "recieved it" messages.
|
# ? Dec 8, 2008 20:57 |
|
1337JiveTurkey posted:Read a constant number of bytes at a time, every time. The number should be defined for the algorithm as the block size. Yeah, but there's no guarantee of the size of the ciphertext blocks. If I'm using a 128-bit modulus each encrypted character could be of any size less than that.
|
# ? Dec 8, 2008 22:08 |
|
Cedra posted:Since FreePastry is used with Java, I figured I'd ask here as well. Windows firewall? Also, whenever I have network issues I always bust out wireshark.
|
# ? Dec 8, 2008 22:51 |
|
epswing posted:I'm finding your reply somewhat vague. What do you mean by "that way"? Can you give an example? All the samples you posted use a UserType to control the marshalling between the enum and the database, the only real differences between them are personal preference. That's pretty much how everyone does it. The cleanest example is probably http://appfuse.org/display/APF/Java+5+Enums+Persistence+with+Hibernate and you can take it a bit further and put and interface over your enums so you don't have to always specify the identifierMethod or the valueOfMethod.
|
# ? Dec 9, 2008 00:01 |
|
Bill O'Riley is GENIUS posted:Yeah, but there's no guarantee of the size of the ciphertext blocks. If I'm using a 128-bit modulus each encrypted character could be of any size less than that. The way it's expected to be done is you use the asymmetric encryption to transfer the session key which is a symmetric cypher. Then you use that to encrypt the actual file. Asymmetric encryption is just too slow to use on its own.
|
# ? Dec 9, 2008 04:18 |
|
1337JiveTurkey posted:The way it's expected to be done is you use the asymmetric encryption to transfer the session key which is a symmetric cypher. Then you use that to encrypt the actual file. Asymmetric encryption is just too slow to use on its own. In English?
|
# ? Dec 9, 2008 05:22 |
|
The idea is that you always use a block size smaller than the actual key and then give it a predetermined padding. When the recipient gets the message, they decrypt the message block, remove the padding, and then have the message. The encoded message would need to be transmitted with the length of the encrypted message in bytes sent first so you know where the end is. In practice you don't end up doing this multiple times because the algorithm's so slow. Instead you'd send a securely randomly generated key (called the session key) for some other algorithm like AES. That way you'd only need to encrypt one message giving the algorithm type, the key, and the nonce (one time number used to initialize the algorithm). Then the receiver gets that key and you use the shared session key to encrypt the real message. AES and other similar encryption algorithms always produce output blocks the exact same size as the input blocks, so you know that if you're using 128-bit blocks, you always grab the next 128 bits to get the next block. At the end of the session, you just throw away that key and create a new one for the next session.
|
# ? Dec 9, 2008 06:21 |
|
TRex EaterofCars posted:Windows firewall? Also, whenever I have network issues I always bust out wireshark. I wish I knew how to make it track my packets, because it doesn't seem to be doing such a thing. I'm doing the usual 'pick an interface then start capturing packets' but whenever I try to start a node nothing on Wireshark seems related to packets being sent around the FreePastry ring. [edit]Scratch that, I tried capping packets between 2 physical machines and it works, it appears Freepastry wasn't using the NIC to send packets to itself, oops. Now I just need to make head and tail of this information :/ Cedra fucked around with this message at 22:38 on Dec 10, 2008 |
# ? Dec 10, 2008 21:52 |
|
Cedra posted:I wish I knew how to make it track my packets, because it doesn't seem to be doing such a thing. I'm doing the usual 'pick an interface then start capturing packets' but whenever I try to start a node nothing on Wireshark seems related to packets being sent around the FreePastry ring. Unfortunately, Windows doesn't have a loopback adapter. You can't use libpcap to capture information on localhost, which is kind of stupid but them's the breaks.
|
# ? Dec 11, 2008 00:21 |
|
Could anyone recommend a decent java gaming book? I want to learn how to make a simple 2d game. Side-scroller or something like that.
|
# ? Dec 13, 2008 00:28 |
|
When I google for Java GUI designers that incorporate SWT, I get a bunch of stuff from 2003 to 2005 that mentions incomplete projects or commercial stuff. Is there anything openly available that can design SWT GUIs well these days? I've been restricting my searches to the past year and still not finding anything definitive. I am writing my own GUI code for many things, but I have many tedious windows to develop that I don't want to completely build and code manually.
|
# ? Dec 13, 2008 22:57 |
|
Eclipse is written using SWT, so I would imagine it has a nice SWT designer. Maybe you overlooked it.
|
# ? Dec 13, 2008 23:12 |
|
MEAT TREAT posted:Eclipse is written using SWT, so I would imagine it has a nice SWT designer. Maybe you overlooked it. There's a few I can install and play with, but it gets tedious adding and removing them from the system after giving them a cursory attempt.
|
# ? Dec 13, 2008 23:38 |
|
If it's commercial work you're doing, it might be worth going for one of the options that cost money - sometimes you just have to drop cash on things. Otherwise, is there any reason you'd not move to Swing? Netbeans's Matisse GUI editor is actually pretty great, but Swing-only.
|
# ? Dec 14, 2008 01:25 |
|
zootm posted:If it's commercial work you're doing, it might be worth going for one of the options that cost money - sometimes you just have to drop cash on things. Otherwise, is there any reason you'd not move to Swing? Netbeans's Matisse GUI editor is actually pretty great, but Swing-only. As for switching to Swing, I went to SWT because it was the one that made my head explode the least. It was the first GUI toolkit I tried that I managed to understand more closely. I still see some big quirks in it; try to update a progress bar within the same thread as the drawing thread and you'll find it won't work, for example. I have a question with chaining constructors. Is there a way to write a constructor to use another one in the same class after doing some processing? I noticed if I tried to do something like: code:
|
# ? Dec 14, 2008 21:44 |
|
Rocko Bonaparte posted:I have a question with chaining constructors. Is there a way to write a constructor to use another one in the same class after doing some processing? I noticed if I tried to do something like: A call to a this() or super() constructor must be in the first line of the constructor, so that's why you're getting a compile error. Try code:
|
# ? Dec 14, 2008 22:14 |
|
|
# ? May 9, 2024 08:41 |
|
dancavallaro posted:A call to a this() or super() constructor must be in the first line of the constructor, so that's why you're getting a compile error. Try
|
# ? Dec 15, 2008 01:34 |