Esempio n. 1
0
 private void moveCacheToState(ComponentStatus state) {
   switch (state) {
     case INITIALIZING:
       cacheStatus.setText(statusStarting);
       processAction(actionButton, true);
       break;
     case RUNNING:
       setCacheTabsStatus(true);
       actionButton.setText(stopCacheButtonLabel);
       processAction(actionButton, false);
       cacheStatus.setText(statusStarted);
       updateTitleBar();
       break;
     case STOPPING:
       cacheStatus.setText(statusStopping);
       processAction(actionButton, true);
       break;
     case TERMINATED:
       setCacheTabsStatus(false);
       actionButton.setText(startCacheButtonLabel);
       processAction(actionButton, false);
       cacheStatus.setText(statusStopped);
       updateTitleBar();
   }
   controlPanelTab.repaint();
 }
Esempio n. 2
0
 private void processAction(JButton button, boolean start) {
   button.setEnabled(!start);
   cacheStatusProgressBar.setVisible(start);
   cacheStatusProgressBar.setEnabled(start);
 }
Esempio n. 3
0
  public InfinispanDemo(String cfgFileName) {
    asyncExecutor = Executors.newFixedThreadPool(1);

    cacheConfigFile = cfgFileName;
    cacheStatusProgressBar.setVisible(false);
    cacheStatusProgressBar.setEnabled(false);
    configFileName.setText(cacheConfigFile);

    // data tables
    clusterTableModel = new ClusterTableModel();
    clusterTable.setModel(clusterTableModel);
    cachedDataTableModel = new CachedDataTableModel();
    dataTable.setModel(cachedDataTableModel);

    // default state of the action button should be unstarted.
    actionButton.setText(startCacheButtonLabel);
    cacheStatus.setText(statusStopped);

    // when we start up scan the classpath for a file named
    actionButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (actionButton.getText().equals(startCacheButtonLabel)) {
              // start cache
              startCache();
            } else if (actionButton.getText().equals(stopCacheButtonLabel)) {
              // stop cache
              stopCache();
            }
          }
        });

    goButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            processAction(goButton, true);

            // do this in a separate thread
            asyncExecutor.execute(
                new Runnable() {
                  public void run() {
                    // based on the value of the radio button:
                    if (putEntryRadioButton.isSelected()) {
                      cache.put(
                          keyTextField.getText(),
                          valueTextField.getText(),
                          lifespan(),
                          TimeUnit.MILLISECONDS,
                          maxIdle(),
                          TimeUnit.MILLISECONDS);
                    } else if (removeEntryRadioButton.isSelected()) {
                      cache.remove(keyTextField.getText());
                    } else if (getEntryRadioButton.isSelected()) {
                      cache.get(keyTextField.getText());
                    }
                    dataViewTab.repaint();
                    processAction(goButton, false);

                    // reset these values
                    lifespanSpinner.setValue(cache.getConfiguration().getExpirationLifespan());
                    maxIdleSpinner.setValue(cache.getConfiguration().getExpirationMaxIdle());
                    // now switch to the data pane
                    mainPane.setSelectedIndex(1);
                  }

                  private long lifespan() {
                    try {
                      String s = lifespanSpinner.getValue().toString();
                      return Long.parseLong(s);
                    } catch (Exception e) {
                      return cache.getConfiguration().getExpirationLifespan();
                    }
                  }

                  private long maxIdle() {
                    try {
                      String s = maxIdleSpinner.getValue().toString();
                      return Long.parseLong(s);
                    } catch (Exception e) {
                      return cache.getConfiguration().getExpirationMaxIdle();
                    }
                  }
                });
          }
        });

    removeEntryRadioButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            keyTextField.setEnabled(true);
            valueTextField.setEnabled(false);
            lifespanSpinner.setEnabled(false);
            maxIdleSpinner.setEnabled(false);
          }
        });

    putEntryRadioButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            keyTextField.setEnabled(true);
            valueTextField.setEnabled(true);
            lifespanSpinner.setEnabled(true);
            maxIdleSpinner.setEnabled(true);
          }
        });

    getEntryRadioButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            keyTextField.setEnabled(true);
            valueTextField.setEnabled(false);
            lifespanSpinner.setEnabled(false);
            maxIdleSpinner.setEnabled(false);
          }
        });

    generateSlider.addChangeListener(
        new ChangeListener() {

          public void stateChanged(ChangeEvent e) {
            randomGeneratorButton.setText(
                "Generate " + generateSlider.getValue() + " Random Entries");
          }
        });

    randomGeneratorButton.setText("Generate " + generateSlider.getValue() + " Random Entries");

    randomGeneratorButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            processAction(randomGeneratorButton, true);

            // process this asynchronously
            asyncExecutor.execute(
                new Runnable() {
                  public void run() {
                    int entries = generateSlider.getValue();

                    Map<String, String> rand = new HashMap<String, String>();
                    while (rand.size() < entries) rand.put(randomString(), randomString());

                    cache.putAll(rand);

                    processAction(randomGeneratorButton, false);
                    generateSlider.setValue(50);
                    // now switch to the data pane
                    mainPane.setSelectedIndex(1);
                  }
                });
          }

          private String randomString() {
            return Integer.toHexString(r.nextInt(Integer.MAX_VALUE)).toUpperCase();
          }
        });
    cacheClearButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            processAction(cacheClearButton, true);
            asyncExecutor.execute(
                new Runnable() {
                  public void run() {
                    cache.clear();
                    processAction(cacheClearButton, false);
                    // now switch to the data pane
                    mainPane.setSelectedIndex(1);
                  }
                });
          }
        });

    refreshButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            processAction(refreshButton, true);
            asyncExecutor.execute(
                new Runnable() {
                  public void run() {
                    InfinispanDemo.this.updateCachedDataTable();
                    processAction(refreshButton, false);
                    // now switch to the data pane
                    mainPane.setSelectedIndex(1);
                  }
                });
          }
        });
  }