// Path: cepsim-integration/src/main/java/ca/uwo/eng/sel/cepsim/integr/CepSimBroker.java
// public class CepSimBroker extends DatacenterBroker {
// 	
//     private Map<Vertex, Vm> verticesToVm = new HashMap<>();
//     
// 	/** Length of the simulation (in ms)*/
// 	private double simulationLength;
// 	
// 	/** Simulation interval in milliseconds. */
// 	private double simulationInterval;
//     
// 	public CepSimBroker(String name, double simulationLength, double simulationInterval) throws Exception {
// 		super(name);
// 
// 		this.simulationLength = simulationLength;
// 		this.simulationInterval = simulationInterval;
// 	}
// 
// 	
// 	
// 	@Override
// 	public void processEvent(SimEvent ev) {
// 
//         switch (ev.getTag()) {
//             case CepSimTags.CEP_EVENT_SENT:
//                 System.out.println(ev.getData());
// 
//             default:
//                 super.processEvent(ev);
//                 break;
//         }
// 
// 	}
// 	
// 	public Vm getVmAllocation(Vertex v) {
//         return verticesToVm.get(v);
//     }
// 
// 
//     public Integer getDatacenterId(Vm vm) {
//         return getVmsToDatacentersMap().get(vm.getId());
//     }
// 
// 	@Override
// 	protected void submitCloudlets() {
//         int vmIndex = 0;
//         List<Cloudlet> successfullySubmitted = new ArrayList<Cloudlet>();
//         for (Cloudlet cloudlet : getCloudletList()) {
//             Vm vm;
//             // if user didn't bind this cloudlet and it has not been executed yet
//             if (cloudlet.getVmId() == -1) {
//                 vm = getVmsCreatedList().get(vmIndex);
//             } else { // submit to the specific vm
//                 vm = VmList.getById(getVmsCreatedList(), cloudlet.getVmId());
//                 if (vm == null) { // vm was not created
//                     if(!Log.isDisabled()) {
//                         Log.print(CloudSim.clock() + ": " + getName() + ": Postponing execution of cloudlet " +
//                                 cloudlet.getCloudletId() + ": bount VM not available");
//                     }
//                     continue;
//                 }
//             }
// 
//             if (!Log.isDisabled()) {
//                 Log.print(CloudSim.clock() + ": " + getName() + ": Sending cloudlet " +
//                         cloudlet.getCloudletId() + " to VM #" + vm.getId());
//             }
// 
//             cloudlet.setVmId(vm.getId());
//             submitCloudlet(vm, cloudlet);
// 
//             // --------------------------------------------
//             // [WAH] - Added - build a map from Vertices to Vms
//             if (cloudlet instanceof CepQueryCloudlet) {
//                 CepQueryCloudlet cepCloudlet = (CepQueryCloudlet) cloudlet;
//                 for (Vertex v : cepCloudlet.getVertices()) {
//                     verticesToVm.put(v, vm);
//                 }
//             }
//             // --------------------------------------------
// 
//             cloudletsSubmitted++;
// 
// 
//             vmIndex = (vmIndex + 1) % getVmsCreatedList().size();
//             getCloudletSubmittedList().add(cloudlet);
//             successfullySubmitted.add(cloudlet);
//         }
// 
//         // remove submitted cloudlets from waiting list
//         getCloudletList().removeAll(successfullySubmitted);
// 	}
// 
// 	public void submitCloudlet(Vm vm, Cloudlet cloudlet) {
//         sendNow(getVmsToDatacentersMap().get(vm.getId()), CloudSimTags.CLOUDLET_SUBMIT, cloudlet);
//     }
// 
//     @Override
//     protected void processOtherEvent(final SimEvent ev) {
//         switch (ev.getTag()) {
//             default:
//                 super.processOtherEvent(ev);
//         }
//     }
// 	
// 
// }
// 
// Path: cepsim-integration/src/main/java/ca/uwo/eng/sel/cepsim/integr/CepSimTags.java
// public class CepSimTags {
// 
// 	public static final int BASE_VALUE = 99900;
// 
//     public static final int CEP_EVENT_SENT = BASE_VALUE + 10;
// 
// 
// }


import ca.uwo.eng.sel.cepsim.integr.CepSimBroker;
import ca.uwo.eng.sel.cepsim.integr.CepSimTags;
import ca.uwo.eng.sel.cepsim.event.EventSet;
import ca.uwo.eng.sel.cepsim.query.InputVertex;
import ca.uwo.eng.sel.cepsim.query.OutputVertex;
import org.cloudbus.cloudsim.Vm;
package ca.uwo.eng.sel.cepsim.network;


/**
 * Created by virso on 2014-11-10.
 */
public class FixedDelayNetworkInterface implements NetworkInterface {

    private CepSimBroker broker;
    private double delay; // in seconds


    public FixedDelayNetworkInterface(CepSimBroker broker, double delay) {
        this.broker = broker;
        this.delay = delay;
    }

    @Override
    public void sendMessage(double timestamp, OutputVertex orig, InputVertex dest, EventSet eventSet) {
        Vm destVm = broker.getVmAllocation(dest);

        Integer datacenterId = broker.getDatacenterId(destVm);
        double start = timestamp / 1000.0; // transform to seconds

        // destination, delay, tag, content
// Path: cepsim-integration/src/main/java/ca/uwo/eng/sel/cepsim/integr/CepSimBroker.java
// public class CepSimBroker extends DatacenterBroker {
// 	
//     private Map<Vertex, Vm> verticesToVm = new HashMap<>();
//     
// 	/** Length of the simulation (in ms)*/
// 	private double simulationLength;
// 	
// 	/** Simulation interval in milliseconds. */
// 	private double simulationInterval;
//     
// 	public CepSimBroker(String name, double simulationLength, double simulationInterval) throws Exception {
// 		super(name);
// 
// 		this.simulationLength = simulationLength;
// 		this.simulationInterval = simulationInterval;
// 	}
// 
// 	
// 	
// 	@Override
// 	public void processEvent(SimEvent ev) {
// 
//         switch (ev.getTag()) {
//             case CepSimTags.CEP_EVENT_SENT:
//                 System.out.println(ev.getData());
// 
//             default:
//                 super.processEvent(ev);
//                 break;
//         }
// 
// 	}
// 	
// 	public Vm getVmAllocation(Vertex v) {
//         return verticesToVm.get(v);
//     }
// 
// 
//     public Integer getDatacenterId(Vm vm) {
//         return getVmsToDatacentersMap().get(vm.getId());
//     }
// 
// 	@Override
// 	protected void submitCloudlets() {
//         int vmIndex = 0;
//         List<Cloudlet> successfullySubmitted = new ArrayList<Cloudlet>();
//         for (Cloudlet cloudlet : getCloudletList()) {
//             Vm vm;
//             // if user didn't bind this cloudlet and it has not been executed yet
//             if (cloudlet.getVmId() == -1) {
//                 vm = getVmsCreatedList().get(vmIndex);
//             } else { // submit to the specific vm
//                 vm = VmList.getById(getVmsCreatedList(), cloudlet.getVmId());
//                 if (vm == null) { // vm was not created
//                     if(!Log.isDisabled()) {
//                         Log.print(CloudSim.clock() + ": " + getName() + ": Postponing execution of cloudlet " +
//                                 cloudlet.getCloudletId() + ": bount VM not available");
//                     }
//                     continue;
//                 }
//             }
// 
//             if (!Log.isDisabled()) {
//                 Log.print(CloudSim.clock() + ": " + getName() + ": Sending cloudlet " +
//                         cloudlet.getCloudletId() + " to VM #" + vm.getId());
//             }
// 
//             cloudlet.setVmId(vm.getId());
//             submitCloudlet(vm, cloudlet);
// 
//             // --------------------------------------------
//             // [WAH] - Added - build a map from Vertices to Vms
//             if (cloudlet instanceof CepQueryCloudlet) {
//                 CepQueryCloudlet cepCloudlet = (CepQueryCloudlet) cloudlet;
//                 for (Vertex v : cepCloudlet.getVertices()) {
//                     verticesToVm.put(v, vm);
//                 }
//             }
//             // --------------------------------------------
// 
//             cloudletsSubmitted++;
// 
// 
//             vmIndex = (vmIndex + 1) % getVmsCreatedList().size();
//             getCloudletSubmittedList().add(cloudlet);
//             successfullySubmitted.add(cloudlet);
//         }
// 
//         // remove submitted cloudlets from waiting list
//         getCloudletList().removeAll(successfullySubmitted);
// 	}
// 
// 	public void submitCloudlet(Vm vm, Cloudlet cloudlet) {
//         sendNow(getVmsToDatacentersMap().get(vm.getId()), CloudSimTags.CLOUDLET_SUBMIT, cloudlet);
//     }
// 
//     @Override
//     protected void processOtherEvent(final SimEvent ev) {
//         switch (ev.getTag()) {
//             default:
//                 super.processOtherEvent(ev);
//         }
//     }
// 	
// 
// }
// 
// Path: cepsim-integration/src/main/java/ca/uwo/eng/sel/cepsim/integr/CepSimTags.java
// public class CepSimTags {
// 
// 	public static final int BASE_VALUE = 99900;
// 
//     public static final int CEP_EVENT_SENT = BASE_VALUE + 10;
// 
// 
// }


// Path: cepsim-integration/src/main/java/ca/uwo/eng/sel/cepsim/network/FixedDelayNetworkInterface.java
import ca.uwo.eng.sel.cepsim.integr.CepSimBroker;
import ca.uwo.eng.sel.cepsim.integr.CepSimTags;
import ca.uwo.eng.sel.cepsim.event.EventSet;
import ca.uwo.eng.sel.cepsim.query.InputVertex;
import ca.uwo.eng.sel.cepsim.query.OutputVertex;
import org.cloudbus.cloudsim.Vm;

package ca.uwo.eng.sel.cepsim.network;


/**
 * Created by virso on 2014-11-10.
 */
public class FixedDelayNetworkInterface implements NetworkInterface {

    private CepSimBroker broker;
    private double delay; // in seconds


    public FixedDelayNetworkInterface(CepSimBroker broker, double delay) {
        this.broker = broker;
        this.delay = delay;
    }

    @Override
    public void sendMessage(double timestamp, OutputVertex orig, InputVertex dest, EventSet eventSet) {
        Vm destVm = broker.getVmAllocation(dest);

        Integer datacenterId = broker.getDatacenterId(destVm);
        double start = timestamp / 1000.0; // transform to seconds

        // destination, delay, tag, content
        broker.schedule(datacenterId, this.delay, CepSimTags.CEP_EVENT_SENT,