All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.servicefabric.cluster.fdetector.FailureDetectorQualifiers Maven / Gradle / Ivy

There is a newer version: 0.0.4
Show newest version
package io.servicefabric.cluster.fdetector;

import rx.functions.Func1;

import io.servicefabric.cluster.ClusterEndpoint;
import io.servicefabric.transport.TransportMessage;

public final class FailureDetectorQualifiers {
	public static final String PING = "pt.openapi.core.cluster/fdetector/ping";
	public static final String PING_REQ = "pt.openapi.core.cluster/fdetector/pingReq";
	public static final String ACK = "pt.openapi.core.cluster/fdetector/ack";

	private static class QFilter implements Func1 {
		final String qualifier;
		final String correlationId;

		QFilter(String qualifier) {
			this(qualifier, null);
		}

		QFilter(String qualifier, String correlationId) {
			this.qualifier = qualifier;
			this.correlationId = correlationId;
		}

		@Override
		public Boolean call(TransportMessage transportMessage) {
			boolean q0 = qualifier.equals(transportMessage.message().qualifier());
			boolean q1 = correlationId == null || correlationId.equals(transportMessage.message().correlationId());
			return q0 && q1;
		}
	}

	private FailureDetectorQualifiers() {
	}

	static Func1 ackFilter() {
		return new QFilter(ACK);
	}

	static Func1 ackFilter(String correlationId) {
		return new QFilter(ACK, correlationId);
	}

	static Func1 pingFilter() {
		return new QFilter(PING);
	}

	static Func1 pingReqFilter() {
		return new QFilter(PING_REQ);
	}

	static Func1 targetFilter(final ClusterEndpoint endpoint) {
		return new Func1() {
			@Override
			public Boolean call(TransportMessage transportMessage) {
				return ((FailureDetectorData) transportMessage.message().data()).getTo().equals(endpoint);
			}
		};
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy