简体   繁体   中英

Can Scala be used with Service Component Architecture?

Does anyone know if Scala can be used with SCA (Service Component Architecture) open source implementations such as Fabric3 or Apache Tuscany? I found no such information online. I know Scala compiles to Java, but I was wondering if dependency injection would complicate things. Thanks.

The FraSCAti platform already supports Scala as an implementation language for SCA components. You can check out the following example :

@Service
trait PrintService {
    def print(msg: String)
}

class Server extends PrintService {    
    println("SERVER created.")

    @Property protected var header = "->"
    @Property private var count = 1

    /** PrintService implementation. */
    def print(msg: String) {
        println("Server: begin printing...")
        for (i <- 0 until count)
            println(header + msg)
        println("Server: print done.")
    }        
}

@Service(classOf[Runnable])
class Client extends Runnable {
    println("CLIENT created")

    @Reference(required = true) private var service: PrintService = _
    def setPrintService(s: PrintService) { service = s }

    // Runnable interface implementation
    def run = service print "hello world"
}

The examples in the repository also illustrates how to use beans to implement these components.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM