Exemplo n.º 1
0
  public SimonClient()
      throws LookupFailedException, EstablishConnectionFailed, IOException, NameBindingException {
    this.lookup = Simon.createNameLookup("localhost", PORT);
    // String connectionId = findConnectionId();
    String connectionId = CONNECTION_ID;
    server = (SimonServerInterface) lookup.lookup(connectionId);

    // this.jstream = new XStream(new JettisonMappedXmlDriver());
    // jstream.setMode(XStream.NO_REFERENCES);

    this.xstream = new XStream();
  }
Exemplo n.º 2
0
  public void connect() {

    try {
      lookup = Simon.createNameLookup(this.host, reg_port);
      Object obj = lookup.lookup("TimServer");
      server = (ITimServer) obj;
      server.login(this);
      System.out.println("Client connected to and registered of server!");

    } catch (Exception e) {
      e.printStackTrace();
      eventbus.publish(new TimEvent(Tag.INFO, "COULD NOT CONNECT TO SERVER " + this.host));
      int answer = JOptionPane.showConfirmDialog(null, ASK_FOR_RECONNECTING);

      if (answer == JOptionPane.OK_OPTION) {
        connect();
      } else {
        System.exit(1);
      }
    }
    connected = true;
  }
Exemplo n.º 3
0
  @Override
  public void onEvent(TimEvent evt) {

    switch (evt.getTag()) {
      case SENDFILE:
        Image img = this.getFile((String) evt.getObject());
        System.out.println("Image downloaded: " + img);
        // FIXME easy and dumm check for nullpointerException
        if (img != null) {
          showPreviewOfPicture(img);
        }
        break;

      case SENDRUNNER:
        try {
          Lookup lookup = Simon.createNameLookup(SERVER_HOST, REG_PORT);
          ITimRunner runner = (ITimRunner) lookup.lookup("TimRunner");
          server.submitRunnable(runner);
        } catch (Exception e) {
          e.printStackTrace();
        }
        break;

      case FILELIST:
        String[] filelist = server.listFiles();
        eventbus.publish(new TimEvent(Tag.GUIFILELIST, filelist));
        break;

      case INFO:
        System.out.println("Client received INFO-TAG!\n" + evt.getObject());
        break;

      case CLIENT_SHUTDOWN:
        this.shutdown();

      default:
        System.out.println("Client received unknown Tag on Event-Bus!");
    }
  }