コード例 #1
0
 /**
  * Starts the example execution, calling the class constructor\ to build and run the simulation.
  *
  * @param args command line parameters
  */
 public static void main(String[] args) {
   Log.printFormattedLine("Starting %s ...", VmListenersExample2.class.getSimpleName());
   try {
     new VmListenersExample2();
     Log.printFormattedLine("%s finished!", VmListenersExample2.class.getSimpleName());
   } catch (Exception e) {
     Log.printFormattedLine("Simulation finished due to unexpected error: %s", e);
   }
 }
コード例 #2
0
  /**
   * Creates all VM listeners to be used by every VM created.
   *
   * @see #createVm(int)
   */
  private void createVmListeners() {
    /*
    Creates the listener object that will be notified when a host is allocated to a VM.
    All VMs will use this same listener.
    The Listener is created using Java 8 Lambda Expressions.
    */
    this.onHostAllocationListener =
        eventInfo ->
            Log.printFormattedLine(
                "\t#EventListener: Host %d allocated to Vm %d at time %.2f",
                eventInfo.getHost().getId(), eventInfo.getVm().getId(), eventInfo.getTime());

    /*
    Creates the listener object that will be notified when a host is deallocated for a VM.
    All VMs will use this same listener.
    The Listener is created using Java 8 Lambda Expressions.
    */
    this.onHostDeallocationListener =
        evt ->
            Log.printFormattedLine(
                "\t#EventListener: Vm %d moved/removed from Host %d at time %.2f",
                evt.getVm().getId(), evt.getHost().getId(), evt.getTime());
  }