/* -------------------------------------------------------- * * Aaron Morris * * CS522 * * Object-Oriented Event-Driven Simulation * * * * Extended SimEvent class representing Channel transfer * * -------------------------------------------------------- */ //package datasend; import java.awt.*; public class TransferEvent extends SimEvent { String Direction; // "TO" or "FROM" a Channel Channel c; DataHandler d; String Toward; // "FORWARD" or "BACKWARD" // Basic Object Constructor. Initialize Members from SimEvent parent public TransferEvent(String Direction,int A,Message m,DataHandler d, Channel c) { this.Direction = Direction; super.message = m; super.eventType = "TRANSFER"; super.ID = m.getMsgID(); super.arrivalTime = A; super.sortValue = A; super.next = null; super.Creator = d; this.c = c; this.d = d; } // If events in waitList, get first one and execute it (now have server) public void execute(EventQueue eventList,Stats stats,int p,RandNum r) { //this.writeExecute(stats.getGlobalTime(),stats); if (Direction == "TO") { c.receive(stats.getGlobalTime(),message,eventList); } else if (Direction == "FROM") { d.receive(stats.getGlobalTime(),message); } else { stats.report.write("ERROR TRANSFERRING '" + Direction + "'"); } } public void writeExecute(int Time, Stats stats) { String Outstring = new String("TRANSFER MESSAGE #"); if (Direction == "TO") { Outstring = Outstring + this.message.getMsgID() + " FROM " + d.getName() + " TO" + " CH" + c.getID() + " Executing at Time " + Time; } else { Outstring = Outstring + this.message.getMsgID() + " FROM CH" + c.getID() + " TO " + d.getName() + " Executing at Time " + Time; } stats.report.write(Outstring); } public DataHandler getHandler() { return d; } public Channel getChannel() { return c; } }