0

I am new to scala and I apologize in advance if the question is stupid. I am browsing through this scala code and I am confused how the following code works

abstract class ClusterSimulatorDesc(val runTime: Double) {
  def newSimulator(constantThinkTim: Double,
               perTaskThinkTime: Double,
               blackListPercent: Double,
               schedulerWorkloadsToSweepOver: Map[String, Seq[String]],
               workloadToSchedulerMap: Map[String, Seq[String]],
               cellStateDesc: CellStateDesc,
               workloads: Seq[Workload],
               prefillWorkloads: Seq[Workload],
               logging: Boolean = false): ClusterSimulator
}

class ClusterSimulator(val cellState: CellState,
                   val schedulers: Map[String, Scheduler],
                   val workloadToSchedulerMap: Map[String, Seq[String]],
                   val workloads: Seq[Workload],
                   prefillWorkloads: Seq[Workload],
                   logging: Boolean = false,
                   monitorUtilization: Boolean = true,
                   monitoringPeriod: Double = 1.0)
                  extends Simulator(logging) {

Now if i have a function call like:-

simulatorDesc: ClusterSimulatorDesc
val simulator =
              simulatorDesc.newSimulator(constantThinkTime,
                                         perTaskThinkTime,
                                         blackListPercent,
                                         schedulerWorkloadsToSweepOver,
                                         schedulerWorkloadMap,
                                         workloadDesc.cellStateDesc,
                                         workloads,
                                         prefillWorkloads,
                                         logging)

Now the question I have is, what does "ClusterSimulator" at the end of the abstract class declaration does? And, how does the calling of "newSimulator" function happen, considering that its declared in an abstract class?

1

1 Answer 1

2
def newSimulator(....): ClusterSimulator

The method newSimulator(), when invoked, returns an instance of ClusterSimulator.

simulatorDesc: ClusterSimulatorDesc

ClusterSimulatorDesc can't be instantiated because it is abstract, but a class that extends ClusterSimulatorDesc can be instantiated and an instance of that class is also an instance of ClusterSimulatorDesc and can invoke its methods.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.