org.apache.catalina.tribes.transport.SenderState Java Examples
The following examples show how to use
org.apache.catalina.tribes.transport.SenderState.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BioSender.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Send message. * @param data The data to send * @param waitForAck Wait for an ack * @throws IOException An IO error occurred sending the message */ public void sendMessage(byte[] data, boolean waitForAck) throws IOException { IOException exception = null; setAttempt(0); try { // first try with existing connection pushMessage(data,false,waitForAck); } catch (IOException x) { SenderState.getSenderState(getDestination()).setSuspect(); exception = x; if (log.isTraceEnabled()) log.trace(sm.getString("bioSender.send.again", getAddress().getHostAddress(),Integer.valueOf(getPort())),x); while ( getAttempt()<getMaxRetryAttempts() ) { try { setAttempt(getAttempt()+1); // second try with fresh connection pushMessage(data, true,waitForAck); exception = null; } catch (IOException xx) { exception = xx; closeSocket(); } } } finally { setRequestCount(getRequestCount()+1); keepalive(); if ( exception != null ) throw exception; } }
Example #2
Source File: BioSender.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Open real socket and set time out when waitForAck is enabled * is socket open return directly. * @throws IOException Error opening socket */ protected void openSocket() throws IOException { if(isConnected()) return ; try { socket = new Socket(); InetSocketAddress sockaddr = new InetSocketAddress(getAddress(), getPort()); socket.connect(sockaddr,(int)getTimeout()); socket.setSendBufferSize(getTxBufSize()); socket.setReceiveBufferSize(getRxBufSize()); socket.setSoTimeout( (int) getTimeout()); socket.setTcpNoDelay(getTcpNoDelay()); socket.setKeepAlive(getSoKeepAlive()); socket.setReuseAddress(getSoReuseAddress()); socket.setOOBInline(getOoBInline()); socket.setSoLinger(getSoLingerOn(),getSoLingerTime()); socket.setTrafficClass(getSoTrafficClass()); setConnected(true); soOut = socket.getOutputStream(); soIn = socket.getInputStream(); setRequestCount(0); setConnectTime(System.currentTimeMillis()); if (log.isDebugEnabled()) log.debug(sm.getString("bioSender.openSocket", getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0))); } catch (IOException ex1) { SenderState.getSenderState(getDestination()).setSuspect(); if (log.isDebugEnabled()) log.debug(sm.getString("bioSender.openSocket.failure",getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0)), ex1); throw ex1; } }
Example #3
Source File: BioSender.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Wait for Acknowledgement from other server. * FIXME Please, not wait only for three characters, better control that the wait ack message is correct. * @throws IOException An IO error occurred */ protected void waitForAck() throws java.io.IOException { try { boolean ackReceived = false; boolean failAckReceived = false; ackbuf.clear(); int bytesRead = 0; int i = soIn.read(); while ((i != -1) && (bytesRead < Constants.ACK_COMMAND.length)) { bytesRead++; byte d = (byte)i; ackbuf.append(d); if (ackbuf.doesPackageExist() ) { byte[] ackcmd = ackbuf.extractDataPackage(true).getBytes(); ackReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.ACK_DATA); failAckReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA); ackReceived = ackReceived || failAckReceived; break; } i = soIn.read(); } if (!ackReceived) { if (i == -1) throw new IOException(sm.getString("bioSender.ack.eof",getAddress(), Integer.valueOf(socket.getLocalPort()))); else throw new IOException(sm.getString("bioSender.ack.wrong",getAddress(), Integer.valueOf(socket.getLocalPort()))); } else if ( failAckReceived && getThrowOnFailedAck()) { throw new RemoteProcessException(sm.getString("bioSender.fail.AckReceived")); } } catch (IOException x) { String errmsg = sm.getString("bioSender.ack.missing", getAddress(), Integer.valueOf(socket.getLocalPort()), Long.valueOf(getTimeout())); if ( SenderState.getSenderState(getDestination()).isReady() ) { SenderState.getSenderState(getDestination()).setSuspect(); if ( log.isWarnEnabled() ) log.warn(errmsg, x); } else { if ( log.isDebugEnabled() )log.debug(errmsg, x); } throw x; } finally { ackbuf.clear(); } }
Example #4
Source File: BioSender.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Wait for Acknowledgement from other server. * FIXME Please, not wait only for three characters, better control that the wait ack message is correct. * @throws java.io.IOException * @throws java.net.SocketTimeoutException */ protected void waitForAck() throws java.io.IOException { try { boolean ackReceived = false; boolean failAckReceived = false; ackbuf.clear(); int bytesRead = 0; int i = soIn.read(); while ((i != -1) && (bytesRead < Constants.ACK_COMMAND.length)) { bytesRead++; byte d = (byte)i; ackbuf.append(d); if (ackbuf.doesPackageExist() ) { byte[] ackcmd = ackbuf.extractDataPackage(true).getBytes(); ackReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.ACK_DATA); failAckReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA); ackReceived = ackReceived || failAckReceived; break; } i = soIn.read(); } if (!ackReceived) { if (i == -1) throw new IOException(sm.getString("IDataSender.ack.eof",getAddress(), Integer.valueOf(socket.getLocalPort()))); else throw new IOException(sm.getString("IDataSender.ack.wrong",getAddress(), Integer.valueOf(socket.getLocalPort()))); } else if ( failAckReceived && getThrowOnFailedAck()) { throw new RemoteProcessException("Received a failed ack:org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA"); } } catch (IOException x) { String errmsg = sm.getString("IDataSender.ack.missing", getAddress(), Integer.valueOf(socket.getLocalPort()), Long.valueOf(getTimeout())); if ( SenderState.getSenderState(getDestination()).isReady() ) { SenderState.getSenderState(getDestination()).setSuspect(); if ( log.isWarnEnabled() ) log.warn(errmsg, x); } else { if ( log.isDebugEnabled() )log.debug(errmsg, x); } throw x; } finally { ackbuf.clear(); } }
Example #5
Source File: BioSender.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * open real socket and set time out when waitForAck is enabled * is socket open return directly */ protected void openSocket() throws IOException { if(isConnected()) return ; try { socket = new Socket(); InetSocketAddress sockaddr = new InetSocketAddress(getAddress(), getPort()); socket.connect(sockaddr,(int)getTimeout()); socket.setSendBufferSize(getTxBufSize()); socket.setReceiveBufferSize(getRxBufSize()); socket.setSoTimeout( (int) getTimeout()); socket.setTcpNoDelay(getTcpNoDelay()); socket.setKeepAlive(getSoKeepAlive()); socket.setReuseAddress(getSoReuseAddress()); socket.setOOBInline(getOoBInline()); socket.setSoLinger(getSoLingerOn(),getSoLingerTime()); socket.setTrafficClass(getSoTrafficClass()); setConnected(true); soOut = socket.getOutputStream(); soIn = socket.getInputStream(); setRequestCount(0); setConnectTime(System.currentTimeMillis()); if (log.isDebugEnabled()) log.debug(sm.getString("IDataSender.openSocket", getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0))); } catch (IOException ex1) { SenderState.getSenderState(getDestination()).setSuspect(); if (log.isDebugEnabled()) log.debug(sm.getString("IDataSender.openSocket.failure",getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0)), ex1); throw (ex1); } }
Example #6
Source File: BioSender.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Send message. */ public void sendMessage(byte[] data, boolean waitForAck) throws IOException { IOException exception = null; setAttempt(0); try { // first try with existing connection pushMessage(data,false,waitForAck); } catch (IOException x) { SenderState.getSenderState(getDestination()).setSuspect(); exception = x; if (log.isTraceEnabled()) log.trace(sm.getString("IDataSender.send.again", getAddress().getHostAddress(), Integer.valueOf(getPort())),x); while ( getAttempt()<getMaxRetryAttempts() ) { try { setAttempt(getAttempt()+1); // second try with fresh connection pushMessage(data, true,waitForAck); exception = null; } catch (IOException xx) { exception = xx; closeSocket(); } } } finally { setRequestCount(getRequestCount()+1); keepalive(); if ( exception != null ) throw exception; } }
Example #7
Source File: BioSender.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Send message. */ public void sendMessage(byte[] data, boolean waitForAck) throws IOException { IOException exception = null; setAttempt(0); try { // first try with existing connection pushMessage(data,false,waitForAck); } catch (IOException x) { SenderState.getSenderState(getDestination()).setSuspect(); exception = x; if (log.isTraceEnabled()) log.trace(sm.getString("IDataSender.send.again", getAddress().getHostAddress(), Integer.valueOf(getPort())),x); while ( getAttempt()<getMaxRetryAttempts() ) { try { setAttempt(getAttempt()+1); // second try with fresh connection pushMessage(data, true,waitForAck); exception = null; } catch (IOException xx) { exception = xx; closeSocket(); } } } finally { setRequestCount(getRequestCount()+1); keepalive(); if ( exception != null ) throw exception; } }
Example #8
Source File: BioSender.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * open real socket and set time out when waitForAck is enabled * is socket open return directly */ protected void openSocket() throws IOException { if(isConnected()) return ; try { socket = new Socket(); InetSocketAddress sockaddr = new InetSocketAddress(getAddress(), getPort()); socket.connect(sockaddr,(int)getTimeout()); socket.setSendBufferSize(getTxBufSize()); socket.setReceiveBufferSize(getRxBufSize()); socket.setSoTimeout( (int) getTimeout()); socket.setTcpNoDelay(getTcpNoDelay()); socket.setKeepAlive(getSoKeepAlive()); socket.setReuseAddress(getSoReuseAddress()); socket.setOOBInline(getOoBInline()); socket.setSoLinger(getSoLingerOn(),getSoLingerTime()); socket.setTrafficClass(getSoTrafficClass()); setConnected(true); soOut = socket.getOutputStream(); soIn = socket.getInputStream(); setRequestCount(0); setConnectTime(System.currentTimeMillis()); if (log.isDebugEnabled()) log.debug(sm.getString("IDataSender.openSocket", getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0))); } catch (IOException ex1) { SenderState.getSenderState(getDestination()).setSuspect(); if (log.isDebugEnabled()) log.debug(sm.getString("IDataSender.openSocket.failure",getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0)), ex1); throw (ex1); } }
Example #9
Source File: BioSender.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Wait for Acknowledgement from other server. * FIXME Please, not wait only for three characters, better control that the wait ack message is correct. * @throws java.io.IOException * @throws java.net.SocketTimeoutException */ protected void waitForAck() throws java.io.IOException { try { boolean ackReceived = false; boolean failAckReceived = false; ackbuf.clear(); int bytesRead = 0; int i = soIn.read(); while ((i != -1) && (bytesRead < Constants.ACK_COMMAND.length)) { bytesRead++; byte d = (byte)i; ackbuf.append(d); if (ackbuf.doesPackageExist() ) { byte[] ackcmd = ackbuf.extractDataPackage(true).getBytes(); ackReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.ACK_DATA); failAckReceived = Arrays.equals(ackcmd,org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA); ackReceived = ackReceived || failAckReceived; break; } i = soIn.read(); } if (!ackReceived) { if (i == -1) throw new IOException(sm.getString("IDataSender.ack.eof",getAddress(), Integer.valueOf(socket.getLocalPort()))); else throw new IOException(sm.getString("IDataSender.ack.wrong",getAddress(), Integer.valueOf(socket.getLocalPort()))); } else if ( failAckReceived && getThrowOnFailedAck()) { throw new RemoteProcessException("Received a failed ack:org.apache.catalina.tribes.transport.Constants.FAIL_ACK_DATA"); } } catch (IOException x) { String errmsg = sm.getString("IDataSender.ack.missing", getAddress(), Integer.valueOf(socket.getLocalPort()), Long.valueOf(getTimeout())); if ( SenderState.getSenderState(getDestination()).isReady() ) { SenderState.getSenderState(getDestination()).setSuspect(); if ( log.isWarnEnabled() ) log.warn(errmsg, x); } else { if ( log.isDebugEnabled() )log.debug(errmsg, x); } throw x; } finally { ackbuf.clear(); } }
Example #10
Source File: ChannelCoordinator.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public void memberDisappeared(Member member){ SenderState.removeSenderState(member); super.memberDisappeared(member); }
Example #11
Source File: MemberImpl.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public boolean isFailing() { return SenderState.getSenderState(this).isFailing(); }
Example #12
Source File: MemberImpl.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public boolean isSuspect() { return SenderState.getSenderState(this).isSuspect(); }
Example #13
Source File: MemberImpl.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public boolean isReady() { return SenderState.getSenderState(this).isReady(); }
Example #14
Source File: ChannelCoordinator.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void memberDisappeared(Member member){ SenderState.removeSenderState(member); super.memberDisappeared(member); }
Example #15
Source File: ChannelCoordinator.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override public void memberAdded(Member member){ SenderState.getSenderState(member); super.memberAdded(member); }
Example #16
Source File: MemberImpl.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public boolean isFailing() { return SenderState.getSenderState(this).isFailing(); }
Example #17
Source File: MemberImpl.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public boolean isSuspect() { return SenderState.getSenderState(this).isSuspect(); }
Example #18
Source File: MemberImpl.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public boolean isReady() { return SenderState.getSenderState(this).isReady(); }
Example #19
Source File: ChannelCoordinator.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public void memberDisappeared(Member member){ SenderState.removeSenderState(member); super.memberDisappeared(member); }
Example #20
Source File: ChannelCoordinator.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public void memberAdded(Member member){ SenderState.getSenderState(member); super.memberAdded(member); }
Example #21
Source File: MemberImpl.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public boolean isFailing() { return SenderState.getSenderState(this).isFailing(); }
Example #22
Source File: MemberImpl.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public boolean isSuspect() { return SenderState.getSenderState(this).isSuspect(); }
Example #23
Source File: MemberImpl.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public boolean isReady() { return SenderState.getSenderState(this).isReady(); }
Example #24
Source File: ChannelCoordinator.java From Tomcat8-Source-Read with MIT License | 4 votes |
@Override public void memberAdded(Member member){ SenderState.getSenderState(member); super.memberAdded(member); }
Example #25
Source File: BioSender.java From Tomcat7.0.67 with Apache License 2.0 | 3 votes |
/** * Push messages with only one socket at a time * Wait for ack is needed and make auto retry when write message is failed. * After sending error close and reopen socket again. * * After successful sending update stats * * WARNING: Subclasses must be very careful that only one thread call this pushMessage at once!!! * * @see #closeSocket() * @see #openSocket() * @see #sendMessage(byte[], boolean) * * @param data * data to send * @since 5.5.10 */ protected void pushMessage(byte[] data, boolean reconnect, boolean waitForAck) throws IOException { keepalive(); if ( reconnect ) closeSocket(); if (!isConnected()) openSocket(); soOut.write(data); soOut.flush(); if (waitForAck) waitForAck(); SenderState.getSenderState(getDestination()).setReady(); }
Example #26
Source File: BioSender.java From tomcatsrc with Apache License 2.0 | 3 votes |
/** * Push messages with only one socket at a time * Wait for ack is needed and make auto retry when write message is failed. * After sending error close and reopen socket again. * * After successful sending update stats * * WARNING: Subclasses must be very careful that only one thread call this pushMessage at once!!! * * @see #closeSocket() * @see #openSocket() * @see #sendMessage(byte[], boolean) * * @param data * data to send * @since 5.5.10 */ protected void pushMessage(byte[] data, boolean reconnect, boolean waitForAck) throws IOException { keepalive(); if ( reconnect ) closeSocket(); if (!isConnected()) openSocket(); soOut.write(data); soOut.flush(); if (waitForAck) waitForAck(); SenderState.getSenderState(getDestination()).setReady(); }
Example #27
Source File: BioSender.java From Tomcat8-Source-Read with MIT License | 3 votes |
/** * Push messages with only one socket at a time * Wait for ack is needed and make auto retry when write message is failed. * After sending error close and reopen socket again. * * After successful sending update stats * * WARNING: Subclasses must be very careful that only one thread call this pushMessage at once!!! * * @see #closeSocket() * @see #openSocket() * @see #sendMessage(byte[], boolean) * * @param data Data to send * @param reconnect Do a reconnect (close socket then reopen) * @param waitForAck Wait for an acknowledgement * @throws IOException IO error writing data * @since 5.5.10 */ protected void pushMessage(byte[] data, boolean reconnect, boolean waitForAck) throws IOException { keepalive(); if ( reconnect ) closeSocket(); if (!isConnected()) openSocket(); soOut.write(data); soOut.flush(); if (waitForAck) waitForAck(); SenderState.getSenderState(getDestination()).setReady(); }