Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package javaspace;
  6. import net.jini.space.JavaSpace;
  7.  
  8.  
  9. /**
  10. *
  11. * @author duszek
  12. */
  13. public class JavaSpaceLab {
  14.  
  15.     /**
  16.      * @param args the command line arguments
  17.      */
  18.     public static void main(String[] args) {
  19.         try {
  20.  
  21.          System.out.println("Szukam Java Space");
  22.  
  23.          Lookup finder = new Lookup(JavaSpace.class);
  24.  
  25.          JavaSpace space = (JavaSpace) finder.getService();
  26.  
  27.          System.out.println("Znaleziono Java Space");
  28.  
  29.          System.out.println("Zapis do JS");
  30.  
  31.          
  32.          for(int i=0; i<99; ++i)
  33.          {
  34.              MessageEntry product = new MessageEntry(i, i+1, i+2);
  35.              space.write(product, null, 60*60*60*100);
  36.              System.out.println("Pisz: "+product.ToString());
  37.          }
  38.          
  39.          System.out.println("Odczyt z JS!");
  40.          MessageEntry template = new MessageEntry();
  41.          
  42.          while(true)
  43.          {
  44.              MessageEntry first= (MessageEntry) space.takeIfExists(template, null, 60*60*100);
  45.              MessageEntry second= (MessageEntry) space.takeIfExists(template, null, 60*60*100);
  46.              MessageEntry third= (MessageEntry) space.takeIfExists(template, null, 60*60*100);
  47.              
  48.              MessageEntry newProduct = new MessageEntry();
  49.              if(first != null && second != null && third!= null)
  50.              {
  51.                  newProduct.Change(first,second,third);
  52.                  space.write(newProduct, null, 60*60*100);
  53.                  System.out.println("Pisz nowy: "+ newProduct.ToString());
  54.              }
  55.              else
  56.              {
  57.                  System.out.println("Ostateczny obiekt: " + first.ToString());
  58.                  break;
  59.              }
  60.          }
  61.       } catch(Exception e) {
  62.  
  63.          e.printStackTrace();
  64.  
  65.       }
  66.  
  67.  
  68.  
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement