private EclipseAppHandle createAppHandle(Map arguments) throws ApplicationException { EclipseAppHandle newAppHandle = new EclipseAppHandle(getInstanceID(), arguments, this); appContainer.lock(newAppHandle); ServiceRegistration appHandleReg = (ServiceRegistration) AccessController.doPrivileged(appContainer.getRegServiceAction(new String[] {ApplicationHandle.class.getName(), IApplicationContext.class.getName()}, newAppHandle, newAppHandle.getServiceProperties())); newAppHandle.setServiceRegistration(appHandleReg); return newAppHandle; }
@Override synchronized public void removedService(ServiceReference reference, Object service) { running = false; // only wait for 5 seconds; this may timeout if forcing an application to quit takes too long // this should never timeout if the application exited normally. result = ((EclipseAppHandle) service).waitForResult(5000); EclipseAppHandle mainHandle = getMainHandle(); if (mainHandle != null) // default application has quit; now force the main threaded application to quit try { mainHandle.destroy(); } catch (Throwable t) { String message = NLS.bind(Messages.application_error_stopping, mainHandle.getInstanceId()); Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, t, null)); } this.notify(); }
protected void destroySpecific() { // when this method is called we must force the application to exit. // first set the status to stopping setAppStatus(EclipseAppHandle.FLAG_STOPPING); // now force the application to stop IApplication app = getApplication(); if (app != null) app.stop(); // make sure the app status is stopped setAppStatus(EclipseAppHandle.FLAG_STOPPED); }
synchronized public String getState() { switch (status) { case FLAG_STARTING : return STARTING; case FLAG_ACTIVE : return ApplicationHandle.RUNNING; case FLAG_STOPPING : return ApplicationHandle.STOPPING; case FLAG_STOPPED : default : // must only check this if the status is STOPPED; otherwise we throw exceptions before we have set the registration. if (getServiceRegistration() == null) throw new IllegalStateException(NLS.bind(Messages.application_error_state_stopped, getInstanceId())); return STOPPED; } }
Dictionary getServiceProperties() { Dictionary props = new Hashtable(6); props.put(ApplicationHandle.APPLICATION_PID, getInstanceId()); props.put(ApplicationHandle.APPLICATION_STATE, getState()); props.put(ApplicationHandle.APPLICATION_DESCRIPTOR, getApplicationDescriptor().getApplicationId()); props.put(EclipseAppDescriptor.APP_TYPE, ((EclipseAppDescriptor) getApplicationDescriptor()).getThreadTypeString()); props.put(ApplicationHandle.APPLICATION_SUPPORTS_EXITVALUE, Boolean.TRUE); if (defaultAppInstance.booleanValue()) props.put(EclipseAppDescriptor.APP_DEFAULT, defaultAppInstance); return props; }
private synchronized void setAppStatus(int status) { if (this.status == status) return; if ((status & EclipseAppHandle.FLAG_STARTING) != 0) throw new IllegalArgumentException("Cannot set app status to starting"); //$NON-NLS-1$ // if status is stopping and the context is already stopping then return if ((status & EclipseAppHandle.FLAG_STOPPING) != 0) if ((this.status & (EclipseAppHandle.FLAG_STOPPING | EclipseAppHandle.FLAG_STOPPED)) != 0) return; // change the service properties to reflect the state change. this.status = status; ServiceRegistration handleReg = getServiceRegistration(); if (handleReg == null) return; handleReg.setProperties(getServiceProperties()); // if the status is stopped then unregister the service if ((this.status & EclipseAppHandle.FLAG_STOPPED) != 0) { ((EclipseAppDescriptor) getApplicationDescriptor()).getContainerManager().unlock(this); handleReg.unregister(); setServiceRegistration(null); } }
synchronized (this) { if ((status & (EclipseAppHandle.FLAG_STARTING | EclipseAppHandle.FLAG_STOPPING)) == 0) throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, NLS.bind(Messages.application_instance_stopped, getInstanceId())); application = getConfiguration().createExecutableExtension("run"); //$NON-NLS-1$ app = application; notifyAll(); tempResult = NULL_RESULT; } finally { tempResult = setInternalResult(tempResult, false, null); System.out.println(NLS.bind(Messages.application_returned, (new String[] {getApplicationDescriptor().getApplicationId(), tempResult == null ? "null" : tempResult.toString()}))); //$NON-NLS-1$ return tempResult;
void launch(EclipseAppHandle appHandle) throws Exception { boolean isDefault = appHandle.isDefault(); if (((EclipseAppDescriptor) appHandle.getApplicationDescriptor()).getThreadType() == EclipseAppDescriptor.FLAG_TYPE_MAIN_THREAD) { return; throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, NLS.bind(Messages.application_error_noMainThread, appHandle.getInstanceId())); curMissingAppLauncher.launch(appHandle); else appLauncher.launch(appHandle, appHandle.getArguments().get(IApplicationContext.APPLICATION_ARGS)); } else { if (isDefault) {
private IConfigurationElement getConfiguration() { IExtension applicationExtension = ((EclipseAppDescriptor) getApplicationDescriptor()).getContainerManager().getAppExtension(getApplicationDescriptor().getApplicationId()); if (applicationExtension == null) throw new RuntimeException(NLS.bind(Messages.application_notFound, getApplicationDescriptor().getApplicationId(), ((EclipseAppDescriptor) getApplicationDescriptor()).getContainerManager().getAvailableAppsMsg())); IConfigurationElement[] configs = applicationExtension.getConfigurationElements(); if (configs.length == 0) throw new RuntimeException(NLS.bind(Messages.application_invalidExtension, getApplicationDescriptor().getApplicationId())); return configs[0]; }
public DefaultApplicationListener(EclipseAppHandle defaultApp) { ServiceReference defaultRef = defaultApp.getServiceReference(); if (defaultRef == null) { // service has been unregistered; application has ended already, // save the result for latter result = defaultApp.waitForResult(100); handleTracker = null; return; } ServiceTracker defaultAppTracker = new ServiceTracker(Activator.getContext(), defaultRef, this); defaultAppTracker.open(); EclipseAppHandle trackedApp = (EclipseAppHandle) defaultAppTracker.getService(); if (trackedApp == null) { // close tracker since we do not care about tracking the app (bug 215764) defaultAppTracker.close(); // service has been unregistered; application has ended aready, // save the result for latter result = defaultApp.waitForResult(100); handleTracker = null; } else { handleTracker = defaultAppTracker; } }
public Object run(Object context) { if (handleTracker == null) return getResult(); // app has ended, return the result EclipseAppHandle anyThreadedDefaultApp = (EclipseAppHandle) handleTracker.getService(); if (anyThreadedDefaultApp != null) // We now need to actual launch the application; this will run the application on another thread. AnyThreadAppLauncher.launchEclipseApplication(anyThreadedDefaultApp); try { while (waitOnRunning()) { EclipseAppHandle mainHandle = getMainHandle(); if (mainHandle != null) { // while we were waiting for the default application to end someone asked for a main threaded app to launch // note that we cannot hold the this lock while launching a main threaded application try { mainHandle.run(null); } catch (Throwable e) { String message = NLS.bind(Messages.application_error_starting, mainHandle.getInstanceId()); Activator.log(new FrameworkLogEntry(Activator.PI_APP, FrameworkLogEntry.WARNING, 0, message, 0, e, null)); } unsetMainHandle(mainHandle); } } } finally { handleTracker.close(); } return getResult(); }
void lock(EclipseAppHandle appHandle) throws ApplicationException { EclipseAppDescriptor eclipseApp = (EclipseAppDescriptor) appHandle.getApplicationDescriptor(); synchronized (lock) { switch (isLocked(eclipseApp)) { break; case LOCKED_SINGLETON_GLOBAL_RUNNING : throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, NLS.bind(Messages.singleton_running, activeGlobalSingleton.getInstanceId())); case LOCKED_SINGLETON_GLOBAL_APPS_RUNNING : throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, Messages.apps_running); case LOCKED_SINGLETON_SCOPED_RUNNING : throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, NLS.bind(Messages.singleton_running, activeScopedSingleton.getInstanceId())); case LOCKED_SINGLETON_LIMITED_RUNNING : throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, NLS.bind(Messages.max_running, eclipseApp.getApplicationId())); case LOCKED_MAIN_THREAD_RUNNING : throw new ApplicationException(ApplicationException.APPLICATION_NOT_LAUNCHABLE, NLS.bind(Messages.main_running, activeMain.getInstanceId())); default : break;
public void stop() { try { destroy(); } catch (IllegalStateException e) { // Do nothing; we don't care that the application was already stopped // return with no error } }
public synchronized Object waitForResult(int timeout) { try { return getExitValue(timeout); } catch (ApplicationException e) { // return null } catch (InterruptedException e) { // return null } return null; }
static void launchEclipseApplication(EclipseAppHandle appHandle) { AnyThreadAppLauncher launchable = new AnyThreadAppLauncher(appHandle); new Thread(launchable, "app thread - " + appHandle.getInstanceId()).start(); //$NON-NLS-1$ } }
public Object addingService(ServiceReference reference) { ApplicationLauncher appLauncher; ParameterizedRunnable appRunnable; synchronized (this) { appLauncher = (ApplicationLauncher) context.getService(reference); // see if there is a default main threaded application waiting to run appRunnable = defaultMainThreadAppHandle; // null out so we do not attempt to start this handle again defaultMainThreadAppHandle = null; if (appRunnable == null && missingApp) { missingAppLauncher = new MainApplicationLauncher(this); appRunnable = missingAppLauncher; missingApp = false; } } if (appRunnable != null) // found a main threaded app; start it now that the app launcher is available appLauncher.launch(appRunnable, appRunnable instanceof EclipseAppHandle ? ((EclipseAppHandle) appRunnable).getArguments().get(IApplicationContext.APPLICATION_ARGS) : null); return appLauncher; }
private synchronized void setAppStatus(int status) { if (this.status == status) return; if ((status & EclipseAppHandle.FLAG_STARTING) != 0) throw new IllegalArgumentException("Cannot set app status to starting"); //$NON-NLS-1$ // if status is stopping and the context is already stopping then return if ((status & EclipseAppHandle.FLAG_STOPPING) != 0) if ((this.status & (EclipseAppHandle.FLAG_STOPPING | EclipseAppHandle.FLAG_STOPPED)) != 0) return; // change the service properties to reflect the state change. this.status = status; ServiceRegistration handleReg = getServiceRegistration(); if (handleReg == null) return; handleReg.setProperties(getServiceProperties()); // if the status is stopped then unregister the service if ((this.status & EclipseAppHandle.FLAG_STOPPED) != 0) { ((EclipseAppDescriptor) getApplicationDescriptor()).getContainerManager().unlock(this); handleReg.unregister(); setServiceRegistration(null); } }
synchronized (this) { if ((status & (EclipseAppHandle.FLAG_STARTING | EclipseAppHandle.FLAG_STOPPING)) == 0) throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, NLS.bind(Messages.application_instance_stopped, getInstanceId())); application = getConfiguration().createExecutableExtension("run"); //$NON-NLS-1$ app = application; notifyAll(); tempResult = NULL_RESULT; } finally { tempResult = setInternalResult(tempResult, false, null); System.out.println(NLS.bind(Messages.application_returned, (new String[] {getApplicationDescriptor().getApplicationId(), tempResult == null ? "null" : tempResult.toString()}))); //$NON-NLS-1$ return tempResult;
void launch(EclipseAppHandle appHandle) throws Exception { boolean isDefault = appHandle.isDefault(); if (((EclipseAppDescriptor) appHandle.getApplicationDescriptor()).getThreadType() == EclipseAppDescriptor.FLAG_TYPE_MAIN_THREAD) { return; throw new ApplicationException(ApplicationException.APPLICATION_INTERNAL_ERROR, NLS.bind(Messages.application_error_noMainThread, appHandle.getInstanceId())); curMissingAppLauncher.launch(appHandle); else appLauncher.launch(appHandle, appHandle.getArguments().get(IApplicationContext.APPLICATION_ARGS)); } else { if (isDefault) {
Dictionary getServiceProperties() { Dictionary props = new Hashtable(6); props.put(ApplicationHandle.APPLICATION_PID, getInstanceId()); props.put(ApplicationHandle.APPLICATION_STATE, getState()); props.put(ApplicationHandle.APPLICATION_DESCRIPTOR, getApplicationDescriptor().getApplicationId()); props.put(EclipseAppDescriptor.APP_TYPE, ((EclipseAppDescriptor) getApplicationDescriptor()).getThreadTypeString()); props.put(ApplicationHandle.APPLICATION_SUPPORTS_EXITVALUE, Boolean.TRUE); if (defaultAppInstance.booleanValue()) props.put(EclipseAppDescriptor.APP_DEFAULT, defaultAppInstance); return props; }