1 55 56 package org.apache.bsf.debug.serverImpl; 57 58 import java.io.*; 59 import org.apache.bsf.util.BSFDebugManagerImpl; 60 import org.apache.bsf.debug.*; 61 import org.apache.bsf.debug.util.*; 62 import org.apache.bsf.debug.jsdi.*; 63 import org.apache.bsf.debug.meta.*; 64 65 public class ObjectServer extends SocketConnection implements Runnable { 66 public Dispatcher fDispatchers[]; 67 68 private BSFDebugManagerImpl fDebugManager; 69 private Thread m_thread; 70 private boolean m_outStreamLocked = false, m_ready = false; 71 private Object m_outStreamLock = new Object (), m_readyLock = new Object (); 72 private static GatedListener m_listener; 73 74 public ObjectServer(BSFDebugManagerImpl debugManager, int port) { 75 fDebugManager = debugManager; 76 exportSkeleton(debugManager); 77 78 if (port <= 0) port = DebugConstants.BSF_DEBUG_SERVER_PORT; 79 80 m_thread = new Thread (this, "JSDI Server Thread"); 81 m_thread.start(); 82 83 if (m_listener != null) { 84 DebugLog.stdoutPrintln("BSF Debug Listener instantiated already.", 85 DebugLog.BSF_LOG_L1); 86 } 87 else m_listener = new GatedListener (this, port); 88 } 89 90 public BSFDebugManagerImpl getDebugManager() { 91 return fDebugManager; 92 } 93 94 public void run() { 95 fDispatchers = new Dispatcher[4]; 96 fDispatchers[0] = new DebugManagerDispatcher(this); 97 fDispatchers[1] = new JsEngineDispatcher(this); 98 fDispatchers[2] = new JsContextDispatcher(this); 99 fDispatchers[3] = new JsObjectDispatcher(this); 100 101 fStubs = new ServerStubTable(this); 102 103 this.exportSkeleton(fDebugManager); 106 107 while (true) { 108 synchronized(m_readyLock) { 109 try { 110 if (!m_ready) m_readyLock.wait(); 111 } 112 catch (Exception ex) { 113 continue; 117 } 118 m_ready = false; 119 } 120 listen(); 121 m_listener.awake(); 122 } 123 } 124 125 protected void setIOStreams(InputStream istream, OutputStream ostream, 126 DataInputStream distream, 127 DataOutputStream dostream) { 128 fInputStream = istream; 129 fOutputStream = ostream; 130 fDataInputStream = distream; 131 fDataOutputStream = dostream; 132 } 133 134 protected void awake() { 135 synchronized(m_readyLock) { 136 m_ready = true; 137 m_readyLock.notify(); 138 } 139 } 140 141 protected void dispatchInvocation(ResultCell rcell) 142 throws Exception { 143 int selfTid,selfUid; 144 Skeleton self; 145 146 switch(rcell.classId) { 147 case DebugConstants.BSF_DEBUG_MANAGER_TID: 148 fDispatchers[0].dispatch(rcell); 149 break; 150 case DebugConstants.JS_ENGINE_TID: 151 fDispatchers[1].dispatch(rcell); 152 break; 153 case DebugConstants.JS_CONTEXT_TID: 154 fDispatchers[2].dispatch(rcell); 155 break; 156 case DebugConstants.JS_OBJECT_TID: 157 fDispatchers[3].dispatch(rcell); 158 break; 159 default: 160 throw new Error ("Wire Protocol Format Error"); 161 } 162 } 163 } 164 | Popular Tags |