Java Code Examples for org.apache.catalina.tribes.Member#getPort()

The following examples show how to use org.apache.catalina.tribes.Member#getPort() . 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: NonBlockingCoordinator.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
protected boolean memberAlive(Member mbr, long conTimeout) {
    //could be a shutdown notification
    if ( Arrays.equals(mbr.getCommand(),Member.SHUTDOWN_PAYLOAD) ) return false;

    try (Socket socket = new Socket()) {
        InetAddress ia = InetAddress.getByAddress(mbr.getHost());
        InetSocketAddress addr = new InetSocketAddress(ia, mbr.getPort());
        socket.connect(addr, (int) conTimeout);
        return true;
    } catch (SocketTimeoutException sx) {
        //do nothing, we couldn't connect
    } catch (ConnectException cx) {
        //do nothing, we couldn't connect
    } catch (Exception x) {
        log.error(sm.getString("nonBlockingCoordinator.memberAlive.failed"),x);
    }
    return false;
}
 
Example 2
Source File: TcpFailureDetector.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected boolean memberAlive(Member mbr, byte[] msgData,
                                     boolean sendTest, boolean readTest,
                                     long readTimeout, long conTimeout,
                                     int optionFlag) {
    //could be a shutdown notification
    if ( Arrays.equals(mbr.getCommand(),Member.SHUTDOWN_PAYLOAD) ) return false;

    try (Socket socket = new Socket()) {
        InetAddress ia = InetAddress.getByAddress(mbr.getHost());
        InetSocketAddress addr = new InetSocketAddress(ia, mbr.getPort());
        socket.setSoTimeout((int)readTimeout);
        socket.connect(addr, (int) conTimeout);
        if ( sendTest ) {
            ChannelData data = new ChannelData(true);
            data.setAddress(getLocalMember(false));
            data.setMessage(new XByteBuffer(msgData,false));
            data.setTimestamp(System.currentTimeMillis());
            int options = optionFlag | Channel.SEND_OPTIONS_BYTE_MESSAGE;
            if ( readTest ) options = (options | Channel.SEND_OPTIONS_USE_ACK);
            else options = (options & (~Channel.SEND_OPTIONS_USE_ACK));
            data.setOptions(options);
            byte[] message = XByteBuffer.createDataPackage(data);
            socket.getOutputStream().write(message);
            if ( readTest ) {
                int length = socket.getInputStream().read(message);
                return length > 0;
            }
        }//end if
        return true;
    } catch (SocketTimeoutException | ConnectException | NoRouteToHostException noop) {
        //do nothing, we couldn't connect
    } catch (Exception x) {
        log.error(sm.getString("tcpFailureDetector.failureDetection.failed", mbr),x);
    }
    return false;
}
 
Example 3
Source File: AbstractSender.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public void setDestination(Member destination) throws UnknownHostException {
    this.destination = destination;
    this.address = InetAddress.getByAddress(destination.getHost());
    this.port = destination.getPort();
    this.udpPort = destination.getUdpPort();

}
 
Example 4
Source File: TestMemberImplSerialization.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public boolean compareMembers(Member impl1, Member impl2) {
    boolean result = true;
    result = result && Arrays.equals(impl1.getHost(),impl2.getHost());
    result = result && Arrays.equals(impl1.getPayload(),impl2.getPayload());
    result = result && Arrays.equals(impl1.getUniqueId(),impl2.getUniqueId());
    result = result && impl1.getPort() == impl2.getPort();
    return result;
}
 
Example 5
Source File: AbstractSender.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void setDestination(Member destination) throws UnknownHostException {
    this.destination = destination;
    this.address = InetAddress.getByAddress(destination.getHost());
    this.port = destination.getPort();
    this.udpPort = destination.getUdpPort();

}
 
Example 6
Source File: AbstractSender.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void setDestination(Member destination) throws UnknownHostException {
    this.destination = destination;
    this.address = InetAddress.getByAddress(destination.getHost());
    this.port = destination.getPort();
    this.udpPort = destination.getUdpPort();

}
 
Example 7
Source File: TcpFailureDetector.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
protected static boolean memberAlive(Member mbr, byte[] msgData,
                                     boolean sendTest, boolean readTest,
                                     long readTimeout, long conTimeout,
                                     int optionFlag) {
    //could be a shutdown notification
    if ( Arrays.equals(mbr.getCommand(),Member.SHUTDOWN_PAYLOAD) ) return false;

    Socket socket = new Socket();
    try {
        InetAddress ia = InetAddress.getByAddress(mbr.getHost());
        InetSocketAddress addr = new InetSocketAddress(ia, mbr.getPort());
        socket.setSoTimeout((int)readTimeout);
        socket.connect(addr, (int) conTimeout);
        if ( sendTest ) {
            ChannelData data = new ChannelData(true);
            data.setAddress(mbr);
            data.setMessage(new XByteBuffer(msgData,false));
            data.setTimestamp(System.currentTimeMillis());
            int options = optionFlag | Channel.SEND_OPTIONS_BYTE_MESSAGE;
            if ( readTest ) options = (options | Channel.SEND_OPTIONS_USE_ACK);
            else options = (options & (~Channel.SEND_OPTIONS_USE_ACK));
            data.setOptions(options);
            byte[] message = XByteBuffer.createDataPackage(data);
            socket.getOutputStream().write(message);
            if ( readTest ) {
                int length = socket.getInputStream().read(message);
                return length > 0;
            }
        }//end if
        return true;
    } catch ( SocketTimeoutException sx) {
        //do nothing, we couldn't connect
    } catch ( ConnectException cx) {
        //do nothing, we couldn't connect
    }catch (Exception x ) {
        log.error("Unable to perform failure detection check, assuming member down.",x);
    } finally {
        try {socket.close(); } catch ( Exception ignore ){}
    }
    return false;
}
 
Example 8
Source File: TcpFailureDetector.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
protected static boolean memberAlive(Member mbr, byte[] msgData,
                                     boolean sendTest, boolean readTest,
                                     long readTimeout, long conTimeout,
                                     int optionFlag) {
    //could be a shutdown notification
    if ( Arrays.equals(mbr.getCommand(),Member.SHUTDOWN_PAYLOAD) ) return false;

    Socket socket = new Socket();
    try {
        InetAddress ia = InetAddress.getByAddress(mbr.getHost());
        InetSocketAddress addr = new InetSocketAddress(ia, mbr.getPort());
        socket.setSoTimeout((int)readTimeout);
        socket.connect(addr, (int) conTimeout);
        if ( sendTest ) {
            ChannelData data = new ChannelData(true);
            data.setAddress(mbr);
            data.setMessage(new XByteBuffer(msgData,false));
            data.setTimestamp(System.currentTimeMillis());
            int options = optionFlag | Channel.SEND_OPTIONS_BYTE_MESSAGE;
            if ( readTest ) options = (options | Channel.SEND_OPTIONS_USE_ACK);
            else options = (options & (~Channel.SEND_OPTIONS_USE_ACK));
            data.setOptions(options);
            byte[] message = XByteBuffer.createDataPackage(data);
            socket.getOutputStream().write(message);
            if ( readTest ) {
                int length = socket.getInputStream().read(message);
                return length > 0;
            }
        }//end if
        return true;
    } catch ( SocketTimeoutException sx) {
        //do nothing, we couldn't connect
    } catch ( ConnectException cx) {
        //do nothing, we couldn't connect
    }catch (Exception x ) {
        log.error("Unable to perform failure detection check, assuming member down.",x);
    } finally {
        try {socket.close(); } catch ( Exception ignore ){}
    }
    return false;
}