1 package org.sapia.ubik.rmi.server.transport.http; 2 3 import java.io.EOFException ; 4 import java.io.IOException ; 5 import java.io.InvalidClassException ; 6 import java.io.NotSerializableException ; 7 8 import org.sapia.ubik.net.PooledThread; 9 import org.sapia.ubik.net.Request; 10 import org.sapia.ubik.rmi.server.Config; 11 import org.sapia.ubik.rmi.server.Log; 12 import org.sapia.ubik.rmi.server.RMICommand; 13 import org.sapia.ubik.rmi.server.invocation.InvokeCommand; 14 import org.sapia.ubik.rmi.server.perf.PerfAnalyzer; 15 import org.sapia.ubik.rmi.server.transport.RmiConnection; 16 17 18 28 class HttpRmiServerThread extends PooledThread { 29 private PerfAnalyzer _perf = PerfAnalyzer.getInstance(); 30 31 34 protected void doExec(Object task) { 35 if (Log.isDebug()) { 36 Log.debug(getClass(), "handling request"); 37 } 38 39 Request req = (Request) task; 40 RmiConnection conn = (RmiConnection) req.getConnection(); 41 RMICommand cmd; 42 Object resp = null; 43 44 try { 45 if (Log.isDebug()) { 46 Log.debug(getClass(), "receiving command"); 47 } 48 49 cmd = (RMICommand) req.getConnection().receive(); 50 51 if (Log.isDebug()) { 52 Log.debug(getClass(), 53 "command received: " + cmd.getClass().getName() + " from " + 54 req.getConnection().getServerAddress() + '@' + cmd.getVmId()); 55 } 56 57 cmd.init(new Config(req.getServerAddress(), req.getConnection())); 58 59 try { 60 if (_perf.isEnabled()) { 61 if (cmd instanceof InvokeCommand) { 62 _perf.getTopic(getClass().getName() + ".RemoteCall").start(); 63 } 64 } 65 66 resp = cmd.execute(); 67 68 if (_perf.isEnabled()) { 69 if (cmd instanceof InvokeCommand) { 70 _perf.getTopic(getClass().getName() + ".RemoteCall").end(); 71 } 72 } 73 } catch (Throwable t) { 74 t.printStackTrace(); 75 t.fillInStackTrace(); 76 resp = t; 77 } 78 79 if (_perf.isEnabled()) { 80 if (cmd instanceof InvokeCommand) { 81 _perf.getTopic(getClass().getName() + ".SendResponse").start(); 82 } 83 } 84 85 conn.send(resp, cmd.getVmId(), cmd.getServerAddress().getTransportType()); 86 87 if (_perf.isEnabled()) { 88 if (cmd instanceof InvokeCommand) { 89 _perf.getTopic(getClass().getName() + ".SendResponse").end(); 90 } 91 } 92 } catch (RuntimeException e) { 93 Log.error(getClass(), "RuntimeException caught sending response", e); 94 95 try { 96 e.fillInStackTrace(); 97 req.getConnection().send(e); 98 } catch (IOException e2) { 99 req.getConnection().close(); 100 101 return; 102 } 103 } catch (ClassNotFoundException e) { 104 e.fillInStackTrace(); 105 Log.error(getClass(), "Class not found while receiving request", e); 106 107 try { 108 req.getConnection().send(e); 109 } catch (IOException e2) { 110 e2.fillInStackTrace(); 111 req.getConnection().close(); 112 113 return; 114 } 115 } catch (EOFException e) { 116 e.fillInStackTrace(); 117 req.getConnection().close(); 118 119 return; 120 } catch (java.net.SocketException e) { 121 e.fillInStackTrace(); 122 req.getConnection().close(); 123 124 return; 125 } catch (NotSerializableException e) { 126 e.fillInStackTrace(); 127 Log.error(getClass().getName(), 128 "Could not serialize class while sending response", e); 129 130 try { 131 req.getConnection().send(e); 132 } catch (IOException e2) { 133 req.getConnection().close(); 134 135 return; 136 } 137 } catch (InvalidClassException e) { 138 e.fillInStackTrace(); 139 Log.error(getClass(), "Class is invalid; object could not be sent", e); 140 141 e.fillInStackTrace(); 142 143 try { 144 req.getConnection().send(e); 145 } catch (IOException e2) { 146 req.getConnection().close(); 147 148 return; 149 } 150 } catch (java.io.IOException e) { 151 e.fillInStackTrace(); 152 153 try { 154 req.getConnection().send(e); 155 } catch (IOException e2) { 156 req.getConnection().close(); 157 158 return; 159 } 160 } 161 } 162 } 163 | Popular Tags |