Core changes
Allow proxies to be used in a synchronous context (experimental)
Added a new option called java.config.runEventLoopWhenInterfaceProxyIsActive
to enable proxies to be used in a synchronous context.
This is an experimental feature and, in some cases, may cause your program to crash.
java.config.runEventLoopWhenInterfaceProxyIsActive = true;
const proxy = java.newProxy('java.util.function.Function', {
apply: (arg: string): string => arg.toUpperCase();
});
const JavaString = java.importClass('java.lang.String');
const str = new JString('hello');
const res = str.transformSync(proxy);
// prints 'HELLO'
console.log(res);
Allow proxies to be used after they have been garbage collected
Added a new option to newProxy
which allows proxies to stay alive longer than the javascript proxy object they were previously bound to:
const proxy = java.newProxy('java.lang.Runnable', {
run: (): void => {
console.log('Hello World!');
}
}, {
keepAsDaemon: true
});
const TimeUnit = java.importClass('java.util.concurrent.TimeUnit');
const ScheduledThreadPoolExecutor = java.importClass(
'java.util.concurrent.ScheduledThreadPoolExecutor'
);
const executor = new ScheduledThreadPoolExecutor(1);
// 'proxy' will eventually be garbage collected,
// but it will be kept alive due to this option.
executor.scheduleAtFixedRateSync(proxy, 0, 1, TimeUnit.SECONDS);
// Calling proxy.reset won't do anything, in order to destroy a daemon
// proxy, the 'force' argument must be set to true
proxy.reset(true);
// Delete all daemon proxies. This will cause the executor to stop
// due to an exception thrown in the run method since the proxy
// is now invalid
java.clearDaemonProxies();
Auto-generated interface proxy definitions
The typescript definition generator now generates definitions for newProxy
on interfaces:
import { createRunnableProxy } from './java/lang/Runnable';
const proxy = createRunnableProxy({
run() {
console.log('Hello World');
}
});
What's Changed
- fix: avoid deadlock when calling proxy methods synchronously by @MarkusJx in #58
- feat(bridge): allow proxies to be used after they have been garbage collected by @MarkusJx in #60
- feat(tsDefGen): generate interface proxy definitions by @MarkusJx in #59
- feat(ci): add address sanitizer workflow by @MarkusJx in #61
- feat(tests): add test container dockerfile by @MarkusJx in #62
- fix(ci): test container not being pushed by @MarkusJx in #63
Full Changelog: v2.2.2...v2.2.3