|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 package com.nokia.mj.impl.rt.midp; |
|
19 |
|
20 import com.nokia.mj.impl.rt.support.JvmInternal; |
|
21 |
|
22 import com.nokia.mj.impl.utils.DebugUtils; |
|
23 import com.nokia.mj.impl.utils.StartUpTrace; |
|
24 |
|
25 /** |
|
26 * A Main entry class of the MIDP runtime. |
|
27 * |
|
28 * @author Nokia Corporation |
|
29 * @version $Rev$ |
|
30 */ |
|
31 public final class Main |
|
32 { |
|
33 |
|
34 /*** ----------------------------- PUBLIC ------------------------------ */ |
|
35 |
|
36 /** |
|
37 * A main entry point of the MIDP runtime. |
|
38 * @param args The arguments provided to MIDP runtime. |
|
39 */ |
|
40 public static void main(String[] args) |
|
41 { |
|
42 // Do the start up trace. |
|
43 StartUpTrace.doTrace("Midp runtime ready"); |
|
44 if (Log.mOn) Log.logI("Starting MIDP runtime"); |
|
45 |
|
46 System.out.println("java.version: " + |
|
47 System.getProperty("java.version")); |
|
48 System.out.println("java.fullversion: " + |
|
49 System.getProperty("java.fullversion")); |
|
50 boolean ok = true; |
|
51 |
|
52 try |
|
53 { |
|
54 // Start the life cycle. |
|
55 MidletLifeCycle.getInstance().doRun(args); |
|
56 StartUpTrace.doTrace("Midp runtime closing"); |
|
57 } |
|
58 catch (StartupException se) |
|
59 { |
|
60 // If the exception is set to be error, an error log is written and |
|
61 // status is marked as NOK. |
|
62 if (se.isError()) |
|
63 { |
|
64 Log.logE("Startup failure: " + se); |
|
65 ok = false; |
|
66 } |
|
67 else |
|
68 { |
|
69 if (Log.mOn) Log.logI("Startup cancelled: "+ se); |
|
70 } |
|
71 } |
|
72 |
|
73 catch (Throwable th) |
|
74 { |
|
75 Log.logE("Error in MIDP runtime: ", th); |
|
76 ok = false; |
|
77 } |
|
78 |
|
79 // Do the cleaning. |
|
80 try |
|
81 { |
|
82 // Close thread dumper. |
|
83 DebugUtils.closeThreadDumper(); |
|
84 |
|
85 // Destroy the lifecycle instance. |
|
86 MidletLifeCycle.destroyInstance(); |
|
87 |
|
88 MemoryLogger.close(); |
|
89 |
|
90 // Run gc and finalization. |
|
91 System.gc(); |
|
92 JvmInternal.runFinalization(); |
|
93 } |
|
94 catch (Throwable thr) |
|
95 { |
|
96 Log.logE("Error in MIDP runtime (final clean): ", thr); |
|
97 ok = false; |
|
98 } |
|
99 |
|
100 if (Log.mOn) Log.logI("Closing MIDP runtime, status " + |
|
101 (ok ? "OK":"NOK")); |
|
102 } |
|
103 } |
|
104 |