@Override public void heartbeat() { super.heartbeat(); checkMembers(false); }
public void memberAdded(Member member) { if ( membership == null ) setupMembership(); boolean notify = false; synchronized (membership) { if (removeSuspects.containsKey(member)) { //previously marked suspect, system below picked up the member again removeSuspects.remove(member); } else if (membership.getMember( (MemberImpl) member) == null){ //if we add it here, then add it upwards too //check to see if it is alive if (memberAlive(member)) { membership.memberAlive( (MemberImpl) member); notify = true; } else { addSuspects.put(member, new Long(System.currentTimeMillis())); } } } if ( notify ) super.memberAdded(member); }
public void checkMembers(boolean checkAll) { try { if (membership == null) setupMembership(); synchronized (membership) { if ( !checkAll ) performBasicCheck(); else performForcedCheck(); } }catch ( Exception x ) { log.warn("Unable to perform heartbeat on the TcpFailureDetector.",x); } finally { } }
@Override public Member[] getMembers() { if ( membership == null ) setupMembership(); return membership.getMembers(); }
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;
protected boolean alive(Member mbr) { return TcpFailureDetector.memberAlive(mbr, COORD_ALIVE, false, false, waitForCoordMsgTimeout, waitForCoordMsgTimeout, getOptionFlag()); }
if ( sendTest ) { ChannelData data = new ChannelData(true); data.setAddress(getLocalMember(false)); data.setMessage(new XByteBuffer(msgData,false)); data.setTimestamp(System.currentTimeMillis());
TcpFailureDetector tcpFailureDetector = new TcpFailureDetector(); tcpFailureDetector.setReadTestTimeout(120000); tcpFailureDetector.setConnectTimeout(180000); channel.addInterceptor(tcpFailureDetector); if (log.isDebugEnabled()) {
public void messageReceived(ChannelMessage msg) { //catch incoming boolean process = true; if ( okToProcess(msg.getOptions()) ) { //check to see if it is a testMessage, if so, process = false process = ( (msg.getMessage().getLength() != TCP_FAIL_DETECT.length) || (!Arrays.equals(TCP_FAIL_DETECT,msg.getMessage().getBytes()) ) ); }//end if //ignore the message, it doesnt have the flag set if ( process ) super.messageReceived(msg); else if ( log.isDebugEnabled() ) log.debug("Received a failure detector packet:"+msg); }//messageReceived
@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; } }
TcpFailureDetector tcpFailureDetector = new TcpFailureDetector(); tcpFailureDetector.setConnectTimeout(30000); channel.addInterceptor(tcpFailureDetector); if (log.isDebugEnabled()) {
protected void checkDefaults() { if ( clusterListeners.size() == 0 ) { addClusterListener(new ClusterSessionListener()); } if ( valves.size() == 0 ) { addValve(new JvmRouteBinderValve()); addValve(new ReplicationValve()); } if ( clusterDeployer != null ) clusterDeployer.setCluster(this); if ( channel == null ) channel = new GroupChannel(); if ( channel instanceof GroupChannel && !((GroupChannel)channel).getInterceptors().hasNext()) { channel.addInterceptor(new MessageDispatch15Interceptor()); channel.addInterceptor(new TcpFailureDetector()); } }
@Override public Member getMember(Member mbr) { if ( membership == null ) setupMembership(); return membership.getMember(mbr); }
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;
protected boolean alive(Member mbr) { return TcpFailureDetector.memberAlive(mbr, COORD_ALIVE, false, false, waitForCoordMsgTimeout, waitForCoordMsgTimeout, getOptionFlag()); }
TcpFailureDetector tcpFailureDetector = new TcpFailureDetector(); tcpFailureDetector.setReadTestTimeout(120000); tcpFailureDetector.setConnectTimeout(180000); channel.addInterceptor(tcpFailureDetector); if (log.isDebugEnabled()) {
@Override public void messageReceived(ChannelMessage msg) { //catch incoming boolean process = true; if ( okToProcess(msg.getOptions()) ) { //check to see if it is a testMessage, if so, process = false process = ( (msg.getMessage().getLength() != TCP_FAIL_DETECT.length) || (!Arrays.equals(TCP_FAIL_DETECT,msg.getMessage().getBytes()) ) ); }//end if //ignore the message, it doesnt have the flag set if ( process ) super.messageReceived(msg); else if ( log.isDebugEnabled() ) log.debug("Received a failure detector packet:"+msg); }//messageReceived
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; } }
TcpFailureDetector tcpFailureDetector = new TcpFailureDetector(); tcpFailureDetector.setConnectTimeout(30000); channel.addInterceptor(tcpFailureDetector); if (log.isDebugEnabled()) {
protected void checkDefaults() { if ( clusterListeners.size() == 0 && managerTemplate instanceof DeltaManager ) { addClusterListener(new ClusterSessionListener()); } if ( valves.size() == 0 ) { addValve(new JvmRouteBinderValve()); addValve(new ReplicationValve()); } if ( clusterDeployer != null ) clusterDeployer.setCluster(this); if ( channel == null ) channel = new GroupChannel(); if ( channel instanceof GroupChannel && !((GroupChannel)channel).getInterceptors().hasNext()) { channel.addInterceptor(new MessageDispatchInterceptor()); channel.addInterceptor(new TcpFailureDetector()); } if (heartbeatBackgroundEnabled) channel.setHeartbeat(false); }