Revision 41312 trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/impl/DefaultPluginsManager.java

View differences:

DefaultPluginsManager.java
75 75
        public void run() {
76 76
            if ( this.in_event_thread ) {
77 77
                if ( !SwingUtilities.isEventDispatchThread() ) {
78
                    SwingUtilities.invokeLater(new Runnable() {
79
                        public void run() {
80
                            try {
81
                                task.run();
82
                            } catch(Exception ex) {
83
                                logger.warn("Errors in execution of "+type+" task '"+name+"'.",ex);
78
                    try {
79
                        SwingUtilities.invokeAndWait(new Runnable() {
80
                            public void run() {
81
                                Task.this.run();
84 82
                            }
85
                        }
86
                    });
83
                        });
84
                    } catch (InterruptedException ex) {
85
                        // Do nothing
86
                    } catch (Exception ex) {
87
                       logger.warn("Errors in execution of "+type+" task '"+name+"'.",ex);
88

  
89
                    }
87 90
                    return;
88 91
                }
89 92
            }
93
            logger.info("Running "+type+" task '"+name+"' (priority "+priority+").");
90 94
            try {
91 95
                task.run();
92 96
            } catch(Exception ex) {
......
121 125
	 *  
122 126
	 */
123 127
	public PluginServices getPlugin(Class<? extends IExtension> extension) {
124
	    String pluginName = ((PluginClassLoader)extension.getClassLoader()).getPluginName();
125
		return  this.getPlugin(pluginName);
128
            String pluginName = ((PluginClassLoader)extension.getClassLoader()).getPluginName();
129
            return  this.getPlugin(pluginName);
126 130
	}
127 131

  
128 132
	public PluginServices getPlugin(Object obj) {
129 133
            if( obj instanceof IExtension ) {
130
                return this.getPlugin(obj.getClass());
134
                Class<? extends IExtension> klass = (Class<? extends IExtension>) obj.getClass();
135
                return this.getPlugin(klass);
131 136
            }
132 137
            PluginClassLoader loader = (PluginClassLoader) obj.getClass().getClassLoader();
133 138
            String pluginName = loader.getPluginName();
......
249 254
        return Launcher.getApplicationHomeFolder();
250 255
    }
251 256

  
252
    public void addOnStartupTask(String name, Runnable task, boolean in_event_thread, int priority) {
257
    public void addStartupTask(String name, Runnable task, boolean in_event_thread, int priority) {
253 258
        this.onStartupTasks.add( new Task("startup", name, task, in_event_thread, priority));
254 259
    }
255 260

  
256
    public void addOnShutdownTask(String name, Runnable task, boolean in_event_thread, int priority) {
261
    public void addShutdownTask(String name, Runnable task, boolean in_event_thread, int priority) {
257 262
        this.onShutdownTasks.add( new Task("shutdown",name, task, in_event_thread, priority));
258 263
    }
259 264

  
260
    public void executeOnStartupTasks() {
265
    public void executeStartupTasks() {
261 266
        logger.info("Executing startup tasks.");
262 267
        Thread th = new Thread(new Runnable() {
263 268
            public void run() {
......
267 272
                    // Ignore error
268 273
                }
269 274
                Collections.sort(onStartupTasks);
270
                for ( Task task : onStartupTasks ) {
275
                for( int i=onStartupTasks.size()-1; i>=0; i--) {
276
                    Task task = onStartupTasks.get(i);
271 277
                    task.run();
272 278
                }
273 279
            }
......
275 281
        th.start();
276 282
    }
277 283
    
278
    public void executeOnShutdownTasks() {
284
    public void executeShutdownTasks() {
279 285
        logger.info("Executing shutdown tasks.");
280 286
        Collections.sort(onShutdownTasks);
281
        for ( Task task : onShutdownTasks ) {
287
        for( int i=onShutdownTasks.size()-1; i>=0; i--) {
288
            Task task = onShutdownTasks.get(i);
282 289
            task.run();
283 290
        }
284 291
    }

Also available in: Unified diff