PSF-LoginServer/common/src/main/scala/net/psforever/IFinalizable.scala
2017-03-06 19:30:45 -05:00

23 lines
514 B
Scala

// Copyright (c) 2017 PSForever
package net.psforever
class ObjectFinalizedException(msg : String) extends Exception(msg)
trait IFinalizable {
var closed = false
def close = {
closed = true
}
def assertNotClosed = {
if(closed)
throw new ObjectFinalizedException(this.getClass.getCanonicalName + ": already finalized. Cannot interact with object")
}
override def finalize() = {
if(!closed)
println(this.getClass.getCanonicalName + ": class not closed. memory leaked")
}
}