Example #1
0
 protected static void doDeleteHost() {
   synchronized (hosts) {
     for (Host host : hosts.getSelection()) {
       hosts.removeObject(host);
       servicesTable.removeService(host.getName());
     }
     saveData();
   }
 }
Example #2
0
 private static void disconnect(Host host, AsyncServiceManagerServer proxy) {
   if (proxy != null) servicesTable.removeService(host.getName());
   Host newHost = new Host(host.getName(), host.getPort());
   newHost.setIncluded(host.isIncluded());
   newHost.setState("DISCONNECTED");
   hosts.updateObject(newHost);
   try {
     discovery.removeHost(
         InetAddress.getByName(host.getName()).getHostAddress() + ":" + host.getPort());
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Example #3
0
 private static void saveData() {
   Map data = new HashMap();
   data.put("hosts", hosts.getObjectList());
   data.put("hidden", hidden.getObjectList());
   data.put("configurations", configurations);
   File f = new File("ServiceManager.ser");
   try {
     if (!f.exists()) f.createNewFile();
     ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f));
     out.writeObject(data);
     out.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #4
0
 private static void loadData() {
   File f = new File("ServiceManager.ser");
   try {
     if (!f.exists()) return;
     ObjectInputStream in = new ObjectInputStream(new FileInputStream(f));
     Map data = (Map) in.readObject();
     for (Iterator it = ((Collection) data.get("hosts")).iterator(); it.hasNext(); )
       hosts.updateObject((Host) it.next());
     for (Iterator it = ((Collection) data.get("hidden")).iterator(); it.hasNext(); )
       hidden.updateObject((ServiceInfo) it.next());
     configurations = (Set<String>) data.get("configurations");
     in.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #5
0
  private static void updateHosts() {
    boolean changed = false;
    synchronized (hosts) {
      for (Host host : hosts.getObjectList()) {
        AsyncServiceManagerServer proxy = proxies.get(host.getName());
        boolean connected = false;
        if (proxy != null) {
          try {
            connected =
                ((Boolean) ((Future) proxy.isServiceManager()).get(10, TimeUnit.SECONDS))
                    .booleanValue();
          } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        } else {
          ClientBootstrap bootstrap =
              new ClientBootstrap(new NioClientSocketChannelFactory(executor, executor));

          HessianProxyFactory factory =
              new HessianProxyFactory(executor, host.getName() + ":" + host.getPort());
          bootstrap.setPipelineFactory(new RPCClientPipelineFactory(executor, factory));

          // Start the connection attempt.
          ChannelFuture future =
              bootstrap.connect(new InetSocketAddress(host.getName(), host.getPort()));
          try {
            future.await(10000);
            connected = future.isSuccess();

            if (connected) {
              Map options = new HashMap();
              proxy =
                  (AsyncServiceManagerServer)
                      factory.create(
                          AsyncServiceManagerServer.class,
                          ClientMain.class.getClassLoader(),
                          options);
              connected =
                  ((Boolean) ((Future) proxy.isServiceManager()).get(10, TimeUnit.SECONDS))
                      .booleanValue();
              if (connected) {
                proxies.put(host.getName(), proxy);
                Host newHost = new Host(host.getName(), host.getPort());
                newHost.setIncluded(host.isIncluded());
                newHost.setState("CONNECTED");
                hosts.updateObject(newHost);
                if (host.isIncluded()) servicesTable.addService(host.getName(), proxy);
              } else future.getChannel().close();
            }
          } catch (Exception e) {
            System.out.println("error accessing " + host.getName());
            connected = false;
            if (future != null) future.getChannel().close();
          }
        }

        if (!connected) {
          disconnect(host, proxies.remove(host.getName()));
          changed = true;
        } else if (proxy == null && !"DISCONNECTED".equals(host.getState())) {
          Host newHost = new Host(host.getName(), host.getPort());
          newHost.setIncluded(host.isIncluded());
          newHost.setState("DISCONNECTED");
          hosts.updateObject(newHost);
        }
      }
    }
  }
Example #6
0
  protected static void doInstall() {
    final InstallDialog install = new InstallDialog();

    final JDialog dialog = new JDialog(frame);
    final Vector<String> listData = new Vector<String>();
    for (Host host : hosts.getObjectList()) {
      listData.add(host.getName());
    }
    install._HOSTS_LIST.setListData(listData);
    for (int i = 0; i < listData.size(); i++) install._HOSTS_LIST.setSelectedIndex(i);
    List<ServiceInfo> selected = servicesTable.getSelection();
    if (selected.size() > 0) {
      ServiceInfo selection = selected.get(0);
    }
    install._CONFIGURATION.setModel(new DefaultComboBoxModel(new Vector(configurations)));
    install._OK_BUTTON.setAction(
        new AbstractAction("INSTALL") {

          public void actionPerformed(ActionEvent e) {
            int[] selInd = install._HOSTS_LIST.getSelectedIndices();
            install._OK_BUTTON.setEnabled(false);
            install._MESSAGE.setText("installing");
            for (int i : selInd) {
              install._MESSAGE.setText(install._MESSAGE.getText() + " - " + listData.get(i) + ": ");
              AsyncServiceManagerServer proxy = proxies.get(listData.get(i));
              if (proxy != null) {
                boolean result = false;
                try {
                  result =
                      ((Boolean)
                              ((Future)
                                      proxy.yajswInstall(
                                          (String) install._CONFIGURATION.getSelectedItem()))
                                  .get(10, TimeUnit.SECONDS))
                          .booleanValue();
                } catch (Exception e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
                }
                if (result) install._MESSAGE.setText(install._MESSAGE.getText() + "success");
                else install._MESSAGE.setText(install._MESSAGE.getText() + "error");
              } else install._MESSAGE.setText(install._MESSAGE.getText() + "no connection");
              if (!configurations.contains(install._CONFIGURATION.getSelectedItem())) {
                configurations.add((String) install._CONFIGURATION.getSelectedItem());
              }
            }
            saveData();
          }
        });
    install._CANCEL_BUTTON.setAction(
        new AbstractAction("CLOSE") {

          public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
          }
        });
    dialog.add(install);
    dialog.setLocationRelativeTo(frame);
    dialog.setSize(570, 320);
    dialog.setModalityType(ModalityType.APPLICATION_MODAL);
    dialog.setVisible(true);
  }