1 21 22 package org.apache.derby.impl.drda; 23 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 import java.net.Socket ; 28 import java.util.Enumeration ; 29 import java.util.Hashtable ; 30 import org.apache.derby.iapi.tools.i18n.LocalizedResource; 31 import java.sql.SQLException ; 32 33 37 class Session 38 { 39 40 protected static final int INIT = 1; protected static final int ATTEXC = 2; protected static final int SECACC = 3; protected static final int CHKSEC = 4; protected static final int CLOSED = 5; 47 protected static final int DRDA_SESSION = 1; 49 protected static final int CMD_SESSION = 2; 50 51 private static final String TRACENAME_PREFIX = "Server"; 53 private static final String TRACENAME_SUFFIX = ".trace"; 54 55 protected Socket clientSocket; protected int connNum; protected InputStream sessionInput; protected OutputStream sessionOutput; protected String traceFileName; protected boolean traceOn; protected int state; protected int sessionType; protected String drdaID; protected DssTrace dssTrace; protected AppRequester appRequester; protected Database database; protected int qryinsid; protected LocalizedResource langUtil; 72 private Hashtable dbtable; 74 85 Session (int connNum, Socket clientSocket, String traceDirectory, 86 boolean traceOn) throws IOException 87 { 88 this.connNum = connNum; 89 this.clientSocket = clientSocket; 90 this.traceOn = traceOn; 91 if (traceOn) 92 dssTrace = new DssTrace(); 93 dbtable = new Hashtable (); 94 initialize(traceDirectory); 95 } 96 97 101 protected void close() throws SQLException 102 { 103 104 try { 105 sessionInput.close(); 106 sessionOutput.close(); 107 clientSocket.close(); 108 if (dbtable != null) 109 for (Enumeration e = dbtable.elements() ; e.hasMoreElements() ;) 110 { 111 ((Database) e.nextElement()).close(); 112 } 113 114 }catch (IOException e) {} finally { 116 state = CLOSED; 117 dbtable = null; 118 database = null; 119 } 120 } 121 122 127 protected void initTrace(String traceDirectory) 128 { 129 if (traceDirectory != null) 130 traceFileName = traceDirectory + "/" + TRACENAME_PREFIX+ 131 connNum+ TRACENAME_SUFFIX; 132 else 133 traceFileName = TRACENAME_PREFIX +connNum+ TRACENAME_SUFFIX; 134 traceOn = true; 135 if (dssTrace == null) 136 dssTrace = new DssTrace(); 137 dssTrace.startComBufferTrace (traceFileName); 138 } 139 140 145 protected void setTraceOn(String traceDirectory) 146 { 147 if (traceOn) 148 return; 149 initTrace(traceDirectory); 150 } 151 156 protected boolean isTraceOn() 157 { 158 if (traceOn) 159 return true; 160 else 161 return false; 162 } 163 164 169 protected int getConnNum() 170 { 171 return connNum; 172 } 173 174 178 protected void setTraceOff() 179 { 180 if (! traceOn) 181 return; 182 traceOn = false; 183 if (traceFileName != null) 184 dssTrace.stopComBufferTrace(); 185 } 186 189 protected void addDatabase(Database d) 190 { 191 dbtable.put(d.dbName, d); 192 } 193 194 197 protected Database getDatabase(String dbName) 198 { 199 return (Database)dbtable.get(dbName); 200 } 201 202 210 protected int getRequiredSecurityCodepoint() 211 { 212 switch (state) 213 { 214 case ATTEXC: 215 return CodePoint.ACCSEC; 218 case SECACC: 219 return CodePoint.SECCHK; 222 default: 223 return -1; 224 } 225 } 226 227 232 protected boolean requiresSecurityCodepoint() 233 { 234 return (getRequiredSecurityCodepoint() != -1); 235 } 236 237 241 protected void setState(int s) 242 { 243 state = s; 244 } 245 246 251 private void initialize(String traceDirectory) 252 throws IOException 253 { 254 sessionInput = clientSocket.getInputStream(); 255 sessionOutput = clientSocket.getOutputStream(); 256 if (traceOn) 257 initTrace(traceDirectory); 258 state = INIT; 259 } 260 261 protected String buildRuntimeInfo(String indent, LocalizedResource localLangUtil) 262 { 263 String s = ""; 264 s += indent + localLangUtil.getTextMessage("DRDA_RuntimeInfoSessionNumber.I") 265 + connNum + "\n"; 266 if (database == null) 267 return s; 268 s += database.buildRuntimeInfo(indent,localLangUtil); 269 s += "\n"; 270 return s; 271 } 272 } 273 | Popular Tags |