Wednesday, December 03, 2008

Scala only Spring RPC/Remoting Service: works

I know it should work, but didn't see and reference that it does. So I tried it out and, of course, it does.
Since the service object will be represented by an AopProxy which is basically a Java proxy, you must have the service to implement a Java Interface (proxy can be created only to interfaces). Scala does not have the notion of interfaces like Java, but the language creators did invested a lot in compatibility with java. Creating a plain Scala trait spits out a POJI (Plain Old Java Interface), which solves the issue. And even though declaring checked exception is not native to Scala, they did enabled the special throws annotation for that which helps in case your service must declare some kind of remote exception.

Here is sample interface that you would create to your spring service:

trait ScalaService {
@throws(classOf[MyRemoteException])
def bar(info: MyInfo)
}
And this is what you'll get by running javap on it:
Compiled from "ScalaService.scala"
public interface ScalaService{
public abstract void bar(MyInfo) throws MyRemoteException;
}

0 comments:

Creative Commons License This work by Eishay Smith is licensed under a Creative Commons Attribution 3.0 Unported License.