Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bridge): allow proxies to be used after they have been garbage collected #60

Merged
merged 12 commits into from
Mar 3, 2023

Conversation

MarkusJx
Copy link
Owner

@MarkusJx MarkusJx commented Feb 27, 2023

depends on #58
closes #57

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();

@MarkusJx MarkusJx added the enhancement New feature or request label Feb 27, 2023
@MarkusJx MarkusJx self-assigned this Feb 27, 2023
Signed-off-by: MarkusJx <[email protected]>
MarkusJx and others added 3 commits March 3, 2023 18:11
# Conflicts:
#	package-lock.json
#	package.json
#	src/node/interface_proxy/java_interface_proxy.rs
#	src/node/java_class_instance.rs
#	ts-src/java.ts
@MarkusJx MarkusJx marked this pull request as ready for review March 3, 2023 17:32
@MarkusJx MarkusJx changed the title feat: allow proxies to be used after they are garbage collected feat(bridge): allow proxies to be used after they have been garbage collected Mar 3, 2023
@MarkusJx MarkusJx merged commit e64733a into main Mar 3, 2023
@MarkusJx MarkusJx deleted the feat/daemonProxies branch March 3, 2023 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Listener dies unexpectedly
1 participant