📄 jumpisolateprocessimpl.java
字号:
} else if (id.equals(JUMPExecutiveLifecycleRequest.ID_PAUSE_APP)) { responseMessage = handlePauseAppMessage(in); } else if ( id.equals(JUMPExecutiveLifecycleRequest.ID_RESUME_APP)) { responseMessage = handleResumeAppMessage(in); } else if ( id.equals(JUMPExecutiveLifecycleRequest.ID_DESTROY_APP)) { responseMessage = handleDestroyAppMessage(in); } else if ( id.equals(com.sun.jumpimpl.ixc.IxcMessage.ID_PORT)) { // Tell the isolate about the ixc port. // FIXME: should go away once ixc is on messaging. responseMessage = handleIxcMessage(in); } else { responseMessage = handleUnknownMessage(in); } in.getSender().sendResponseMessage(responseMessage); } catch (Throwable e) { e.printStackTrace(); } finally { synchronized (stateChangeMutex) { dispatchingStateChange = false; if (exitAfterStateChange) { System.exit(0); } } } } public void notifyDestroyed(int appId) { //TODO: send message back to executive } public void notifyPaused(int appId) { //TODO: send message back to executive } public void resumeRequest(int appId) { //TODO: send message back to executive } public String getConfigProperty(String key) { return (String)JUMPModulesConfig.getProperties().get(key); } public void terminateIsolate() { synchronized (stateChangeMutex) { if (dispatchingStateChange) { exitAfterStateChange = true; } else { System.exit(0); } } } /** * Report to the executive that we have initialized ourselves */ private void reportIsolateInitialized() { JUMPProcessProxy e = getExecutiveProcess(); RequestSenderHelper rsh = new RequestSenderHelper(this); String reqId = JUMPIsolateLifecycleRequest.ID_ISOLATE_INITIALIZED; String[] reqArgs = new String[] { Integer.toString(isolateId), "" }; JUMPRequest req = new JUMPIsolateLifecycleRequest(reqId, this); rsh.sendRequestAsync(e, req); } /** {@inheritDoc} */ public Remote getRemoteService(String name) { return serviceRegistry.getRemoteService(name); } private JUMPOutgoingMessage handleStartAppMessage(JUMPMessage in) { JUMPExecutiveLifecycleRequest elr = (JUMPExecutiveLifecycleRequest) JUMPExecutiveLifecycleRequest.fromMessage(in); byte[] barr = elr.getAppBytes(); JUMPApplication app = JUMPApplication.fromByteArray(barr); String[] args = elr.getArgs(); System.err.println("START_APP("+app+")"); int appId = -1; // Notify windowing that application is going to be started before // app container is initialized to set bounds // for the app screen area. windowing.onBeforeApplicationStarted(app); if(appContainer != null) { // The message is telling us to start an application appId = appContainer.startApp(app, args); } // Now wrap this appid in a message and return it JUMPResponseInteger resp; if (appId >= 0) { resp = new JUMPResponseInteger(in.getType(), JUMPResponseInteger.ID_SUCCESS, appId); } else { resp = new JUMPResponseInteger(in.getType(), JUMPResponseInteger.ID_FAILURE, -1); } /* * Now convert JUMPResponse to a message in response * to the incoming message */ return resp.toMessageInResponseTo(in, this); } private JUMPOutgoingMessage handlePauseAppMessage(JUMPMessage in) { JUMPExecutiveLifecycleRequest elr = (JUMPExecutiveLifecycleRequest) JUMPExecutiveLifecycleRequest.fromMessage(in); String[] args = elr.getArgs(); int appID = Integer.parseInt(args[0]); String responseId; System.err.println("PAUSE_APP("+appID+")"); try { appContainer.pauseApp(appID); responseId = JUMPResponseInteger.ID_SUCCESS; } catch (Throwable t) { responseId = JUMPResponseInteger.ID_FAILURE; } JUMPResponse resp = new JUMPResponse(in.getType(), responseId); return resp.toMessageInResponseTo(in, this); } private JUMPOutgoingMessage handleResumeAppMessage(JUMPMessage in) { JUMPExecutiveLifecycleRequest elr = (JUMPExecutiveLifecycleRequest) JUMPExecutiveLifecycleRequest.fromMessage(in); String[] args = elr.getArgs(); int appID = Integer.parseInt(args[0]); String responseId; System.err.println("RESUME_APP("+appID+")"); try { appContainer.resumeApp(appID); responseId = JUMPResponseInteger.ID_SUCCESS; } catch (Throwable t) { responseId = JUMPResponseInteger.ID_FAILURE; } JUMPResponse resp = new JUMPResponse(in.getType(), responseId); return resp.toMessageInResponseTo(in, this); } private JUMPOutgoingMessage handleDestroyAppMessage(JUMPMessage in) { JUMPExecutiveLifecycleRequest elr = (JUMPExecutiveLifecycleRequest) JUMPExecutiveLifecycleRequest.fromMessage(in); String[] args = elr.getArgs(); int appID = Integer.parseInt(args[0]); boolean unconditional = Boolean.getBoolean(args[1]); System.err.println("DESTROY_APP("+appID+")"); String responseCode = JUMPResponseInteger.ID_SUCCESS; try { appContainer.destroyApp(appID, unconditional); } catch (Throwable t) { responseCode = JUMPResponseInteger.ID_FAILURE; } JUMPResponse resp = new JUMPResponse(in.getType(), responseCode); return resp.toMessageInResponseTo(in, this); } private JUMPOutgoingMessage handleUnknownMessage(JUMPMessage in) { // Assumption of default message // A utf array, expecting a generic JUMPResponse JUMPMessageReader reader = new JUMPMessageReader(in); System.err.println("Incoming client message:"); String[] responseStrings = reader.getUTFArray(); for (int j = 0; j < responseStrings.length; j++) { System.err.println(" \""+responseStrings[j]+"\""); } JUMPOutgoingMessage out = newOutgoingMessage(in); out.addUTFArray(new String[] {"SUCCESS"}); return out; } /** * Fetches class loader to use for implementation classes in IXC. * * @return class loader to use */ private ClassLoader getImplClassLoader() { return appContainer.getClass().getClassLoader(); } /** * Extract port number from the message and tell it to the * service registry client. * FIXME: should be removed once ixc is on messaging. */ private JUMPOutgoingMessage handleIxcMessage(JUMPMessage in) { JUMPCommand message = JUMPCommand.fromMessage(in, com.sun.jumpimpl.ixc.IxcMessage.class); int port = Integer.parseInt(message.getCommandData()[0]); serviceRegistry = new ServiceRegistryClient(getImplClassLoader(), port); JUMPResponse resp = new JUMPResponse(in.getType(), JUMPResponseInteger.ID_SUCCESS); return resp.toMessageInResponseTo(in, this); } public void terminateKeepAliveThread() { keepAliveMonitor.terminate(); } static class KeepAliveMonitor { private boolean keepAlive = true; public synchronized void startWaiting() { while (keepAlive) { try { this.wait(); } catch (InterruptedException e){ /* * Ignore InterruptedException and continue with the loop. * This thread should exit only if terminate() is invoked. */ } } } public synchronized void terminate() { keepAlive = false; this.notifyAll(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -