使用SimPy 3时如何生成模拟输出报告

时间:2016-11-03 19:31:01

标签: python simpy

如何使用SimPy 3生成模拟报告?我正在阅读here,对于版本2,它可能会执行以下操作:

package com.server;
import java.io.*;
import java.net.*;
import java.awt.event.*;
import javax.swing.*;

public class Server extends javax.swing.JFrame {

    private ObjectOutputStream output;
    private ObjectInputStream input;
    private ServerSocket server;
    private Socket connection = null;

    /**
     * Creates new form sever
     */
    public Server() {
        //initComponents();
        startRunning();
    }

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        startRunning();
    }

     //setup and run the server
    public void startRunning(){
        try{
            //serversocket(port,queueLength)
            server = new ServerSocket(6789, 100);
            while(true){
                try{
                   waitForConnection();
                   setupStreams();
                   whileChatting();
                }catch(EOFException eofException){
                    showMessage("\n Server ended the connection!");
                }finally{
                    closeCrap();
                }
            }
        }catch(IOException ioException){
            ioException.printStackTrace();
        }
    }

    //wait for connection, then display connection 
    private void waitForConnection() throws IOException{
        showMessage("Waiting for someone to connect...\n");
        connection = server.accept();
        showMessage("Now connected to " + connection.getInetAddress()); 
    }

    //get stream to send and receive data
    private void setupStreams() throws IOException{
        output = new ObjectOutputStream(connection.getOutputStream());
        output.flush();
        input = new ObjectInputStream(connection.getInputStream());
        showMessage("\n Streams are now setup!\n");
    }

    //during the chat conversation
    private void whileChatting() throws IOException{
        String message = "SERVER -  You are now connected! ";
        sendMessage(message);
        ableToType(true);
        do{
            try{
                message = (String) input.readObject();
                showMessage("\n" + message);
            }catch(ClassNotFoundException classNotfoundException){
                showMessage("\n idk wtf the user sent!");
            }
        }while(!message.equals("CLIENT - END"));
    }

    //close streams and sockets after chatting
    private void  closeCrap(){
        showMessage("\n Closing connections...\n");
        ableToType(false);
        try{
            output.close();
            input.close();
            connection.close();
        }catch(IOException ioException){
            ioException.printStackTrace();
        }catch(NullPointerException nullPointerException){
            showMessage("You are trying to close something not opened");
        }
    }

    //send message to clients
    private void sendMessage(String message){
        try{
            output.writeObject("SERVER - " + message);
            output.flush();
            showMessage("\nSEVER - " + message);
        }catch(IOException ioException){
            System.out.println("\n Error: i cant send that message");
    //        chatWindow.append("\n Error: i cant send that message");
        }
    }

    //updates chatWindow
    private void showMessage(final String text){
        // INVOKE LATER REMOVED.
        System.out.println(text);;
    }

    //let the user type stuff
    private void ableToType(final boolean tof){
        // INVOKE LATER REMOVED.
                    System.out.println("userText -> setEditable off");
    }

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Server.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Server.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Server.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Server.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>



        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Server().setVisible(true);
            }
        });
    }
}

但是我找不到SimPy 3的报告功能。报告应该包括,例如,服务器的平均吞吐量,资源利用率和其他统计数据。

1 个答案:

答案 0 :(得分:0)

出于性能原因,默认情况下,SimPy 3不再监控您的模拟。 this guide讨论了监控模拟和收集数据的方法。