
org.netbeans.html.boot.fx.FXGCPresenter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of net.java.html.boot.fx Show documentation
Show all versions of net.java.html.boot.fx Show documentation
A presentation provider to show JavaFX WebView
when a Java/HTML based application is about to boot.
The newest version!
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.html.boot.fx;
import java.io.File;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.logging.Level;
import javafx.scene.web.WebView;
/** Presenter for stress testing. It tries to force few GC cycles
* before returning a Java object from {@link WebView} to simulate the
* fact that in JDK8 newer than build 112 the Java objects exposed to
* {@link WebView} are held by weak references.
*
* @author Jaroslav Tulach
*/
public final class FXGCPresenter extends AbstractFXPresenter {
static {
try {
try {
Class> c = Class.forName("javafx.application.Platform");
// OK, on classpath
} catch (ClassNotFoundException classNotFoundException) {
File f = new File(System.getProperty("java.home"), "lib/jfxrt.jar");
if (f.exists()) {
Method m = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
m.setAccessible(true);
URL l = f.toURI().toURL();
m.invoke(ClassLoader.getSystemClassLoader(), l);
}
}
} catch (Exception ex) {
throw new LinkageError("Can't add jfxrt.jar on the classpath", ex);
}
}
private final WebView[] lastWebView;
public FXGCPresenter() {
this(null);
}
FXGCPresenter(WebView[] lastWebView) {
this.lastWebView = lastWebView;
}
@Override
void waitFinished() {
FXBrwsr.waitFinished();
}
@Override
WebView findView(final URL resource) {
WebView view = FXBrwsr.findWebView(resource, this);
if (lastWebView != null) {
lastWebView[0] = view;
}
return view;
}
@Override
Object emitJavaObject(Object[] pojo, int hash, int id) {
Reference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy