📄 netagent.java
字号:
int getSvrcod() { return svrcod_; } public void flush_() throws DisconnectException { sendRequest(); reply_.initialize(); } // Close socket and its streams. public void close_() throws SqlException { // can we just close the socket here, do we need to close streams individually SqlException accumulatedExceptions = null; if (rawSocketInputStream_ != null) { try { rawSocketInputStream_.close(); } catch (java.io.IOException e) { // note when {6} = 0 it indicates the socket was closed. // this should be ok since we are going to go an close the socket // immediately following this call. // changing {4} to e.getMessage() may require pub changes accumulatedExceptions = new SqlException(logWriter_, e, "A communication error has been detected. " + "Communication protocol being used: {0}. " + "Communication API being used: {1}. " + "Location where the error was detected: {2}. " + "Communication function detecting the error: {3}. " + "Protocol specific error codes(s) {4}, {5}, {6}. " + "TCP/IP " + "SOCKETS " + "Agent.close() " + "InputStream.close() " + e.getMessage() + " " + "* " + "0"); //"08001", //-30081); } finally { rawSocketInputStream_ = null; } } if (rawSocketOutputStream_ != null) { try { rawSocketOutputStream_.close(); } catch (java.io.IOException e) { // note when {6} = 0 it indicates the socket was closed. // this should be ok since we are going to go an close the socket // immediately following this call. // changing {4} to e.getMessage() may require pub changes SqlException latestException = new SqlException(logWriter_, e, "A communication error has been detected. " + "Communication protocol being used: {0}. " + "Communication API being used: {1}. " + "Location where the error was detected: {2}. " + "Communication function detecting the error: {3}. " + "Protocol specific error codes(s) {4}, {5}, {6}. " + "TCP/IP " + "SOCKETS " + "Agent.close() " + "OutputStream.close() " + e.getMessage() + " " + "* " + "0"); accumulatedExceptions = Utils.accumulateSQLException(latestException, accumulatedExceptions); } finally { rawSocketOutputStream_ = null; } } if (socket_ != null) { try { socket_.close(); } catch (java.io.IOException e) { // again {6} = 0, indicates the socket was closed. // maybe set {4} to e.getMessage(). // do this for now and but may need to modify or // add this to the message pubs. SqlException latestException = new SqlException(logWriter_, e, "A communication error has been detected. " + "Communication protocol being used: {0}. " + "Communication API being used: {1}. " + "Location where the error was detected: {2}. " + "Communication function detecting the error: {3}. " + "Protocol specific error codes(s) {4}, {5}, {6}. " + "TCP/IP " + "SOCKETS " + "Agent.close() " + "Socket.close() " + e.getMessage() + " " + "* " + "0"); accumulatedExceptions = Utils.accumulateSQLException(latestException, accumulatedExceptions); } finally { socket_ = null; } } if (accumulatedExceptions != null) { throw accumulatedExceptions; } } protected void sendRequest() throws DisconnectException { try { request_.flush(rawSocketOutputStream_); } catch (java.io.IOException e) { throwCommunicationsFailure("NetAgent.sendRequest()", "OutputStream.flush()", e.getMessage(), "*"); } } public java.io.InputStream getInputStream() { return rawSocketInputStream_; } public java.io.OutputStream getOutputStream() { return rawSocketOutputStream_; } void setInputStream(java.io.InputStream inputStream) { rawSocketInputStream_ = inputStream; } void setOutputStream(java.io.OutputStream outputStream) { rawSocketOutputStream_ = outputStream; } public void throwCommunicationsFailure(String location, String function, String rc1, String rc2) throws org.apache.derby.client.am.DisconnectException { //org.apache.derby.client.am.DisconnectException //accumulateReadExceptionAndDisconnect // note when {6} = 0 it indicates the socket was closed. // need to still validate any token values against message publications. accumulateChainBreakingReadExceptionAndThrow(new org.apache.derby.client.am.DisconnectException(this, "A communication error has been detected. " + "Communication protocol being used: " + location + ". " + "Communication API being used: " + function + ". " + "Location where the error was detected: " + rc1 + ". " + "Communication function detecting the error: " + rc2 + ". " + "Protocol specific error codes(s) " + "TCP/IP SOCKETS ")); // hardcode tokens 0 and 1 //"08001")); //derby code -30081, don't send 08001 now either } // ----------------------- call-down methods --------------------------------- public org.apache.derby.client.am.LogWriter newLogWriter_(java.io.PrintWriter printWriter, int traceLevel) { return new NetLogWriter(printWriter, traceLevel); } protected void markChainBreakingException_() { setSvrcod(CodePoint.SVRCOD_ERROR); } public void checkForChainBreakingException_() throws SqlException { int svrcod = getSvrcod(); clearSvrcod(); if (svrcod > CodePoint.SVRCOD_WARNING) // Not for SQL warning, if svrcod > WARNING, then its a chain breaker { super.checkForExceptions(); // throws the accumulated exceptions, we'll always have at least one. } } private void writeDeferredResetConnection() throws SqlException { if (!netConnection_.resetConnectionAtFirstSql_) { return; } try { netConnection_.writeDeferredReset(); } catch (SqlException sqle) { DisconnectException de = new DisconnectException(this, "An error occurred during a deferred connect reset and the connection has been terminated. See chained exceptions for details."); de.setNextException(sqle); throw de; } } public void beginWriteChainOutsideUOW() throws SqlException { request_.initialize(); writeDeferredResetConnection(); super.beginWriteChainOutsideUOW(); } public void beginWriteChain(org.apache.derby.client.am.Statement statement) throws SqlException { request_.initialize(); writeDeferredResetConnection(); super.beginWriteChain(statement); } protected void endWriteChain() { super.endWriteChain(); } private void readDeferredResetConnection() throws SqlException { if (!netConnection_.resetConnectionAtFirstSql_) { return; } try { netConnection_.readDeferredReset(); checkForExceptions(); } catch (SqlException sqle) { DisconnectException de = new DisconnectException(this, "An error occurred during a deferred connect reset and the connection has been terminated. See chained exceptions for details."); de.setNextException(sqle); throw de; } } protected void beginReadChain(org.apache.derby.client.am.Statement statement) throws SqlException { readDeferredResetConnection(); super.beginReadChain(statement); } protected void beginReadChainOutsideUOW() throws SqlException { readDeferredResetConnection(); super.beginReadChainOutsideUOW(); } public void endReadChain() throws SqlException { super.endReadChain(); } public String convertToStringTcpIpAddress(int tcpIpAddress) { StringBuffer ipAddrBytes = new StringBuffer(); ipAddrBytes.append((tcpIpAddress >> 24) & 0xff); ipAddrBytes.append("."); ipAddrBytes.append((tcpIpAddress >> 16) & 0xff); ipAddrBytes.append("."); ipAddrBytes.append((tcpIpAddress >> 8) & 0xff); ipAddrBytes.append("."); ipAddrBytes.append((tcpIpAddress) & 0xff); return ipAddrBytes.toString(); } protected int getPort() { return port_; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -