Package org.apache.wsdm.interop.wcm.simulator

Source Code of org.apache.wsdm.interop.wcm.simulator.StatusSimulator

/*
* Created on May 24, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.apache.wsdm.interop.wcm.simulator;

import java.awt.Color;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JFrame;

import org.apache.wsdm.interop.wcm.impl.WcImpl;
import org.apache.wsdm.interop.wcm.impl.WsImpl;
import org.apache.wsdm.interop.wcm.impl.ui.MessagesJPanel;
import org.apache.wsdm.interop.wcm.impl.ui.StatusJPanel;
import org.apache.wsdm.interop.wcm.impl.ui.TemperatureJPanel;
import org.apache.wsdm.interop.wcm.model.IWc;
import org.apache.wsdm.interop.wcm.model.IWs;


/**
* @author wire
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class StatusSimulator  extends TimerTask  {
  private static Timer timer;
  private StatusJPanel tp;
  private InteropSimulator is=new InteropSimulator(null);
  static StatusJPanel mp;
 
  public static void main(String[] args) throws InterruptedException {
    JFrame frame = new JFrame();
    frame.setTitle("WCMgr");
    mp = new StatusJPanel();
    frame.getContentPane().add(mp);
    frame.pack();
    frame.show();

    IWs ws1=new WsImpl(0,"Ws1",null);
    IWs ws2=new WsImpl(0,"Ws2",ws1);
    IWs ws3=new WsImpl(0,"Ws3",ws2);
    //ws1.setBackup(ws3);
    IWc wc=new WcImpl(0,"Wc",ws1);
    mp.setModel(new IWs[]{wc,ws1,ws2,ws3});   

   
    timer=new Timer(true);
    timer.scheduleAtFixedRate(new StatusSimulator(mp),5000,5000);

   
    // This thread now sleeps forever
    while(true){
      Thread.sleep(10000);
    }

  }

  /* (non-Javadoc)
   * @see java.util.TimerTask#run()
   */
  public void run() {
//    IWs node;
    //mp.updateNode(new WsImpl(0,"ws1",null));
    long rand = Math.round(3*Math.random())+1;

    String name="Ws"+rand;
    mp.setCurrentWc(name);


    rand = Math.round(3*Math.random())+1;
    name="Ws"+rand;

    long color = Math.round(3*Math.random())+1;
    if(color==1){
      mp.setColor(name,Color.RED);
      return;
    }
    if(color==2){
      mp.setColor(name,Color.YELLOW);
      return;
    }
    if(color==3){
      mp.setColor(name,Color.GREEN);
      return;
    }

  }
 
  /**
   *
   */
  public StatusSimulator(StatusJPanel tp) {
    super();
    this.tp=tp;
  }
}
TOP

Related Classes of org.apache.wsdm.interop.wcm.simulator.StatusSimulator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.