org.apache.catalina.tribes.RemoteProcessException Java Examples

The following examples show how to use org.apache.catalina.tribes.RemoteProcessException. 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: ReplicatedMap.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * publish info about a map pair (key/value) to other nodes in the cluster
 * @param key Object
 * @param value Object
 * @return Member - the backup node
 * @throws ChannelException Cluster error
 */
@Override
protected Member[] publishEntryInfo(Object key, Object value) throws ChannelException {
    if  (! (key instanceof Serializable && value instanceof Serializable)  ) return new Member[0];
    //select a backup node
    Member[] backup = getMapMembers();

    if (backup == null || backup.length == 0) return null;

    try {
        //publish the data out to all nodes
        MapMessage msg = new MapMessage(getMapContextName(), MapMessage.MSG_COPY, false,
                (Serializable) key, (Serializable) value, null,channel.getLocalMember(false), backup);

        getChannel().send(backup, msg, getChannelSendOptions());
    } catch (ChannelException e) {
        FaultyMember[] faultyMembers = e.getFaultyMembers();
        if (faultyMembers.length == 0) throw e;
        List<Member> faulty = new ArrayList<>();
        for (FaultyMember faultyMember : faultyMembers) {
            if (!(faultyMember.getCause() instanceof RemoteProcessException)) {
                faulty.add(faultyMember.getMember());
            }
        }
        Member[] realFaultyMembers = faulty.toArray(new Member[faulty.size()]);
        if (realFaultyMembers.length != 0) {
            backup = excludeFromSet(realFaultyMembers, backup);
            if (backup.length == 0) {
                throw e;
            } else {
                if (getLog().isWarnEnabled()) {
                    getLog().warn(sm.getString("replicatedMap.unableReplicate.completely", key,
                            Arrays.toString(backup), Arrays.toString(realFaultyMembers)), e);
                }
            }
        }
    }
    return backup;
}
 
Example #2
Source File: TcpFailureDetector.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    try {
        super.sendMessage(destination, msg, payload);
    }catch ( ChannelException cx ) {
        FaultyMember[] mbrs = cx.getFaultyMembers();
        for ( int i=0; i<mbrs.length; i++ ) {
            if ( mbrs[i].getCause()!=null &&
                 (!(mbrs[i].getCause() instanceof RemoteProcessException)) ) {//RemoteProcessException's are ok
                this.memberDisappeared(mbrs[i].getMember());
            }//end if
        }//for
        throw cx;
    }
}
 
Example #3
Source File: BioSender.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * 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: TcpFailureDetector.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    try {
        super.sendMessage(destination, msg, payload);
    }catch ( ChannelException cx ) {
        FaultyMember[] mbrs = cx.getFaultyMembers();
        for ( int i=0; i<mbrs.length; i++ ) {
            if ( mbrs[i].getCause()!=null &&
                 (!(mbrs[i].getCause() instanceof RemoteProcessException)) ) {//RemoteProcessException's are ok
                this.memberDisappeared(mbrs[i].getMember());
            }//end if
        }//for
        throw cx;
    }
}
 
Example #5
Source File: BioSender.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #6
Source File: TcpFailureDetector.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Override
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException {
    try {
        super.sendMessage(destination, msg, payload);
    }catch ( ChannelException cx ) {
        FaultyMember[] mbrs = cx.getFaultyMembers();
        for ( int i=0; i<mbrs.length; i++ ) {
            if ( mbrs[i].getCause()!=null &&
                 (!(mbrs[i].getCause() instanceof RemoteProcessException)) ) {//RemoteProcessException's are ok
                this.memberDisappeared(mbrs[i].getMember());
            }//end if
        }//for
        throw cx;
    }
}
 
Example #7
Source File: BioSender.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #8
Source File: ReplicatedMap.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * publish info about a map pair (key/value) to other nodes in the cluster
 * @param key Object
 * @param value Object
 * @return Member - the backup node
 * @throws ChannelException
 */
@Override
protected Member[] publishEntryInfo(Object key, Object value) throws ChannelException {
    if  (! (key instanceof Serializable && value instanceof Serializable)  ) return new Member[0];
    //select a backup node
    Member[] backup = getMapMembers();

    if (backup == null || backup.length == 0) return null;

    try {
        
        //publish the data out to all nodes
        MapMessage msg = new MapMessage(getMapContextName(), MapMessage.MSG_COPY, false,
                (Serializable) key, (Serializable) value, null,channel.getLocalMember(false), backup);

        getChannel().send(getMapMembers(), msg, getChannelSendOptions());
    } catch (ChannelException e) {
        FaultyMember[] faultyMembers = e.getFaultyMembers();
        if (faultyMembers.length == 0) throw e;
        ArrayList<Member> faulty = new ArrayList<Member>();
        for (FaultyMember faultyMember : faultyMembers) {
            if (!(faultyMember.getCause() instanceof RemoteProcessException)) {
                faulty.add(faultyMember.getMember());
            }
        }
        Member[] realFaultyMembers = faulty.toArray(new Member[faulty.size()]);
        if (realFaultyMembers.length != 0) {
            backup = excludeFromSet(realFaultyMembers, backup);
            if (backup.length == 0) {
                throw e;
            } else {
                if (log.isWarnEnabled()) {
                    log.warn("Unable to replicate backup key:" + key
                            + ". Success nodes:" + Arrays.toString(backup)
                            + ". Failed nodes:" + Arrays.toString(realFaultyMembers), e);
                }
            }
        }
    }
    return backup;
}
 
Example #9
Source File: ReplicatedMap.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * publish info about a map pair (key/value) to other nodes in the cluster
 * @param key Object
 * @param value Object
 * @return Member - the backup node
 * @throws ChannelException
 */
@Override
protected Member[] publishEntryInfo(Object key, Object value) throws ChannelException {
    if  (! (key instanceof Serializable && value instanceof Serializable)  ) return new Member[0];
    //select a backup node
    Member[] backup = getMapMembers();

    if (backup == null || backup.length == 0) return null;

    try {
        
        //publish the data out to all nodes
        MapMessage msg = new MapMessage(getMapContextName(), MapMessage.MSG_COPY, false,
                (Serializable) key, (Serializable) value, null,channel.getLocalMember(false), backup);

        getChannel().send(backup, msg, getChannelSendOptions());
    } catch (ChannelException e) {
        FaultyMember[] faultyMembers = e.getFaultyMembers();
        if (faultyMembers.length == 0) throw e;
        ArrayList<Member> faulty = new ArrayList<Member>();
        for (FaultyMember faultyMember : faultyMembers) {
            if (!(faultyMember.getCause() instanceof RemoteProcessException)) {
                faulty.add(faultyMember.getMember());
            }
        }
        Member[] realFaultyMembers = faulty.toArray(new Member[faulty.size()]);
        if (realFaultyMembers.length != 0) {
            backup = excludeFromSet(realFaultyMembers, backup);
            if (backup.length == 0) {
                throw e;
            } else {
                if (log.isWarnEnabled()) {
                    log.warn("Unable to replicate backup key:" + key
                            + ". Success nodes:" + Arrays.toString(backup)
                            + ". Failed nodes:" + Arrays.toString(realFaultyMembers), e);
                }
            }
        }
    }
    return backup;
}