21
21
import java.applet.Applet;
22
22
import java.awt.Container;
23
23
import java.io.File;
24
import java.io.FileInputStream;
25
import java.io.FileOutputStream;
26
import java.io.IOException;
27
import java.lang.management.ManagementFactory;
28
import java.lang.management.ThreadMXBean;
29
24
import java.lang.reflect.Method;
30
25
import java.net.InetAddress;
31
26
import java.net.URL;
32
27
import java.net.UnknownHostException;
33
import java.nio.channels.FileChannel;
34
import java.nio.channels.FileLock;
35
28
import java.util.LinkedList;
36
29
import java.util.List;
37
30
import java.util.jar.JarFile;
42
35
import net.sourceforge.jnlp.runtime.AppThreadGroup;
43
36
import net.sourceforge.jnlp.runtime.AppletInstance;
44
37
import net.sourceforge.jnlp.runtime.ApplicationInstance;
45
import net.sourceforge.jnlp.runtime.DeploymentConfiguration;
46
38
import net.sourceforge.jnlp.runtime.JNLPClassLoader;
47
39
import net.sourceforge.jnlp.runtime.JNLPRuntime;
48
40
import net.sourceforge.jnlp.services.InstanceExistsException;
49
41
import net.sourceforge.jnlp.services.ServiceUtil;
50
import net.sourceforge.jnlp.util.FileUtils;
51
import net.sourceforge.jnlp.util.Reflect;
53
43
import javax.swing.SwingUtilities;
54
44
import javax.swing.text.html.parser.ParserDelegator;
86
76
/** If the application should call System.exit on fatal errors */
87
77
private boolean exitOnFailure = true;
89
/** a lock which is held to indicate that an instance of netx is running */
90
private FileLock fileLock;
93
81
* Create a launcher with the runtime's default update policy
201
189
public ApplicationInstance launch(JNLPFile file, Container cont) throws LaunchException {
192
JNLPRuntime.markNetxRunning();
204
194
//First checks whether offline-allowed tag is specified inside the jnlp
206
196
if (!file.getInformation().isOfflineAllowed()) {
330
320
List<String> commands = new LinkedList<String>();
332
String pathToWebstartBinary = System.getProperty("java.home") +
322
// this property is set by the javaws launcher to point to the javaws binary
323
String pathToWebstartBinary = System.getProperty("icedtea-web.bin.location");
337
324
commands.add(pathToWebstartBinary);
338
325
// use -Jargument format to pass arguments to the JVM through the launcher
339
326
for (String arg : vmArgs) {
393
380
if (!file.isApplication())
394
381
throw launchError(new LaunchException(file, null, R("LSFatal"), R("LCClient"), R("LNotApplication"), R("LNotApplicationInfo")));
397
Runtime.getRuntime().addShutdownHook(new Thread() {
423
403
IconDesc.SPLASH, preferredWidth, preferredHeight);
424
404
if (splashImageURL != null) {
425
405
ResourceTracker resourceTracker = new ResourceTracker(true);
426
resourceTracker.addResource(splashImageURL, file.getFileVersion(), updatePolicy);
406
resourceTracker.addResource(splashImageURL, file.getFileVersion(), null, updatePolicy);
427
407
splashScreen = new JNLPSplashScreen(resourceTracker, null, null);
428
408
splashScreen.setSplashImageURL(splashImageURL);
429
409
if (splashScreen.isSplashScreenValid()) {
708
* Indicate that netx is running by creating the {@link JNLPRuntime#INSTANCE_FILE} and
709
* acquiring a shared lock on it
711
private void markNetxRunning() {
713
String message = "This file is used to check if netx is running";
715
File netxRunningFile = new File(JNLPRuntime.getConfiguration()
716
.getProperty(DeploymentConfiguration.KEY_USER_NETX_RUNNING_FILE));
717
if (!netxRunningFile.exists()) {
718
netxRunningFile.getParentFile().mkdirs();
719
FileUtils.createRestrictedFile(netxRunningFile, true);
720
FileOutputStream fos = new FileOutputStream(netxRunningFile);
722
fos.write(message.getBytes());
728
FileInputStream is = new FileInputStream(netxRunningFile);
729
FileChannel channel = is.getChannel();
730
fileLock = channel.tryLock(0, Long.MAX_VALUE, true);
731
if (fileLock != null && fileLock.isShared()) {
732
if (JNLPRuntime.isDebug()) {
733
System.out.println("Acquired shared lock on " +
734
netxRunningFile.toString() + " to indicate javaws is running");
739
} catch (IOException e) {
746
* Indicate that netx is stopped by releasing the shared lock on
747
* {@link JNLPRuntime#INSTANCE_FILE}.
749
private void markNetxStopped() {
750
if (fileLock == null) {
755
fileLock.channel().close();
757
if (JNLPRuntime.isDebug()) {
758
String file = JNLPRuntime.getConfiguration()
759
.getProperty(DeploymentConfiguration.KEY_USER_NETX_RUNNING_FILE);
760
System.out.println("Release shared lock on " + file);
762
} catch (IOException e) {
768
688
* Do hacks on per-application level to allow different AppContexts to work
770
690
* @see JNLPRuntime#doMainAppContextHacks