Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.rmi.RemoteException;
- import lots.Lot;
- import net.jini.core.entry.UnusableEntryException;
- import net.jini.core.transaction.TransactionException;
- import net.jini.space.JavaSpace;
- public class Test {
- private JavaSpace space;
- private static int FIVE_SECONDS = 5000;
- private static int ONE_MINUTE = 1000 * 60;
- public Test() {
- space = (JavaSpace) SpaceUtils.getSpace();
- if (space == null){
- System.err.println("Failed to find the javaspace");
- System.exit(1);
- }
- // Write a few objects to the space
- Lot lot1 = new Lot();
- lot1.id = 1;
- lot1.title = "Blue Car";
- lot1.description = "This is a really nice car";
- lot1.seller = 1;
- lot1.price = 1999.99;
- Lot lot2 = new Lot();
- lot2.id = 2;
- lot2.title = "iPhone 6";
- lot2.description = "It works well";
- lot2.seller = 2;
- lot2.price = 610.99;
- try {
- //space.write(lot1, null, ONE_MINUTE);
- //space.write(lot2, null, ONE_MINUTE);
- } catch (Exception e) {
- }
- // Lets try get the second one back
- Lot template1 = new Lot();
- template1.id = 1;
- try {
- Lot received = (Lot) space.take(template1, null, FIVE_SECONDS);
- if(received == null) {
- System.out.println("That doesnt exist");
- } else {
- System.out.println(received.toString());
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement