1

I want to write an RMI library in/for Ceylon (since I have not found one so far).

The first thing I need is a proxy. In Java I used something like

Proxy.newProxyInstance(classLoader, interfaces, handler);  

1. Is there something equivalent in Ceylon? (haven't found something)


Attempting to write something like this my own, I came across this solution for the JVM using byte code manipulation. Nifty and exactly what I want.

Notice, that this can even produce a proxy for a class, not only for interface like in Java. In Ceylon this is should be legit, since there are no fields and we can simulate the whole class with method calls.

2. If creating proxies for classes is a no-go just tell me. Also, what is the Ceylon intuition/future about proxies? Shall there be (no) proxies?


In a future with proxies we have one major problem:

In Ceylon we have the default keyword, without it a method can not be refined/overwritten. This also results in final methods for the compiled Java output classes. Thereby (not even) the byte code manipulation can overwrite those and redirect them to an invocation handler/interceptor.

3. How do we deal with this?


I assume not at all? I totally get the idea of disallowing the refinement of methods and the default/final keywords, but this obstructs RMI/proxies for classes.

4. Are proxies for classes a bad idea?


And yes, there are so much more questions I am currently thinking about and investigating on: JS implementation, interfaces and default methods, etc

These points seem to be the most relevant at the moment, so let's start here.

Lii
  • 11,553
  • 8
  • 64
  • 88

2 Answers2

2

You could try using this module I wrote:

https://github.com/gavinking/ceylon.proxy

Alternatively, if you're only targeting the JVM, you could just use Java's Proxy directly.

Gavin King
  • 3,182
  • 1
  • 13
  • 11
1

During further research I found:

1. Proxies are currently part of the Ceylon 1.4 milestone (issues regarding proxies).

3. Enabling EE mode for the ceylon compiler, removes the final keyword.

From this point on the solution I found works like intended and is exactly the same as the one provided by Gavin.