开发者

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. 开发者_StackOverflow中文版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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜