org.apache.flink.runtime.rpc.FencedRpcGateway Java Examples

The following examples show how to use org.apache.flink.runtime.rpc.FencedRpcGateway. 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: AkkaRpcService.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public <F extends Serializable, C extends FencedRpcGateway<F>> CompletableFuture<C> connect(String address, F fencingToken, Class<C> clazz) {
	return connectInternal(
		address,
		clazz,
		(ActorRef actorRef) -> {
			Tuple2<String, String> addressHostname = extractAddressHostname(actorRef);

			return new FencedAkkaInvocationHandler<>(
				addressHostname.f0,
				addressHostname.f1,
				actorRef,
				configuration.getTimeout(),
				configuration.getMaximumFramesize(),
				null,
				() -> fencingToken);
		});
}
 
Example #2
Source File: AkkaInvocationHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	Class<?> declaringClass = method.getDeclaringClass();

	Object result;

	if (declaringClass.equals(AkkaBasedEndpoint.class) ||
		declaringClass.equals(Object.class) ||
		declaringClass.equals(RpcGateway.class) ||
		declaringClass.equals(StartStoppable.class) ||
		declaringClass.equals(MainThreadExecutable.class) ||
		declaringClass.equals(RpcServer.class)) {
		result = method.invoke(this, args);
	} else if (declaringClass.equals(FencedRpcGateway.class)) {
		throw new UnsupportedOperationException("AkkaInvocationHandler does not support the call FencedRpcGateway#" +
			method.getName() + ". This indicates that you retrieved a FencedRpcGateway without specifying a " +
			"fencing token. Please use RpcService#connect(RpcService, F, Time) with F being the fencing token to " +
			"retrieve a properly FencedRpcGateway.");
	} else {
		result = invokeRpc(method, args);
	}

	return result;
}
 
Example #3
Source File: AkkaRpcService.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public <F extends Serializable, C extends FencedRpcGateway<F>> CompletableFuture<C> connect(String address, F fencingToken, Class<C> clazz) {
	return connectInternal(
		address,
		clazz,
		(ActorRef actorRef) -> {
			Tuple2<String, String> addressHostname = extractAddressHostname(actorRef);

			return new FencedAkkaInvocationHandler<>(
				addressHostname.f0,
				addressHostname.f1,
				actorRef,
				configuration.getTimeout(),
				configuration.getMaximumFramesize(),
				null,
				() -> fencingToken);
		});
}
 
Example #4
Source File: AkkaInvocationHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	Class<?> declaringClass = method.getDeclaringClass();

	Object result;

	if (declaringClass.equals(AkkaBasedEndpoint.class) ||
		declaringClass.equals(Object.class) ||
		declaringClass.equals(RpcGateway.class) ||
		declaringClass.equals(StartStoppable.class) ||
		declaringClass.equals(MainThreadExecutable.class) ||
		declaringClass.equals(RpcServer.class)) {
		result = method.invoke(this, args);
	} else if (declaringClass.equals(FencedRpcGateway.class)) {
		throw new UnsupportedOperationException("AkkaInvocationHandler does not support the call FencedRpcGateway#" +
			method.getName() + ". This indicates that you retrieved a FencedRpcGateway without specifying a " +
			"fencing token. Please use RpcService#connect(RpcService, F, Time) with F being the fencing token to " +
			"retrieve a properly FencedRpcGateway.");
	} else {
		result = invokeRpc(method, args);
	}

	return result;
}
 
Example #5
Source File: AkkaRpcService.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public <F extends Serializable, C extends FencedRpcGateway<F>> CompletableFuture<C> connect(String address, F fencingToken, Class<C> clazz) {
	return connectInternal(
		address,
		clazz,
		(ActorRef actorRef) -> {
			Tuple2<String, String> addressHostname = extractAddressHostname(actorRef);

			return new FencedAkkaInvocationHandler<>(
				addressHostname.f0,
				addressHostname.f1,
				actorRef,
				configuration.getTimeout(),
				configuration.getMaximumFramesize(),
				null,
				() -> fencingToken,
				captureAskCallstacks);
		});
}
 
Example #6
Source File: AkkaInvocationHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	Class<?> declaringClass = method.getDeclaringClass();

	Object result;

	if (declaringClass.equals(AkkaBasedEndpoint.class) ||
		declaringClass.equals(Object.class) ||
		declaringClass.equals(RpcGateway.class) ||
		declaringClass.equals(StartStoppable.class) ||
		declaringClass.equals(MainThreadExecutable.class) ||
		declaringClass.equals(RpcServer.class)) {
		result = method.invoke(this, args);
	} else if (declaringClass.equals(FencedRpcGateway.class)) {
		throw new UnsupportedOperationException("AkkaInvocationHandler does not support the call FencedRpcGateway#" +
			method.getName() + ". This indicates that you retrieved a FencedRpcGateway without specifying a " +
			"fencing token. Please use RpcService#connect(RpcService, F, Time) with F being the fencing token to " +
			"retrieve a properly FencedRpcGateway.");
	} else {
		result = invokeRpc(method, args);
	}

	return result;
}
 
Example #7
Source File: FencedAkkaInvocationHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	Class<?> declaringClass = method.getDeclaringClass();

	if (declaringClass.equals(FencedMainThreadExecutable.class) ||
		declaringClass.equals(FencedRpcGateway.class)) {
		return method.invoke(this, args);
	} else {
		return super.invoke(proxy, method, args);
	}
}
 
Example #8
Source File: FencedAkkaInvocationHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	Class<?> declaringClass = method.getDeclaringClass();

	if (declaringClass.equals(FencedMainThreadExecutable.class) ||
		declaringClass.equals(FencedRpcGateway.class)) {
		return method.invoke(this, args);
	} else {
		return super.invoke(proxy, method, args);
	}
}
 
Example #9
Source File: FencedAkkaInvocationHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
	Class<?> declaringClass = method.getDeclaringClass();

	if (declaringClass.equals(FencedMainThreadExecutable.class) ||
		declaringClass.equals(FencedRpcGateway.class)) {
		return method.invoke(this, args);
	} else {
		return super.invoke(proxy, method, args);
	}
}
 
Example #10
Source File: RetryingRegistration.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * This method resolves the target address to a callable gateway and starts the
 * registration after that.
 */
@SuppressWarnings("unchecked")
public void startRegistration() {
	if (canceled) {
		// we already got canceled
		return;
	}

	try {
		// trigger resolution of the target address to a callable gateway
		final CompletableFuture<G> rpcGatewayFuture;

		if (FencedRpcGateway.class.isAssignableFrom(targetType)) {
			rpcGatewayFuture = (CompletableFuture<G>) rpcService.connect(
				targetAddress,
				fencingToken,
				targetType.asSubclass(FencedRpcGateway.class));
		} else {
			rpcGatewayFuture = rpcService.connect(targetAddress, targetType);
		}

		// upon success, start the registration attempts
		CompletableFuture<Void> rpcGatewayAcceptFuture = rpcGatewayFuture.thenAcceptAsync(
			(G rpcGateway) -> {
				log.info("Resolved {} address, beginning registration", targetName);
				register(rpcGateway, 1, retryingRegistrationConfiguration.getInitialRegistrationTimeoutMillis());
			},
			rpcService.getExecutor());

		// upon failure, retry, unless this is cancelled
		rpcGatewayAcceptFuture.whenCompleteAsync(
			(Void v, Throwable failure) -> {
				if (failure != null && !canceled) {
					final Throwable strippedFailure = ExceptionUtils.stripCompletionException(failure);
					if (log.isDebugEnabled()) {
						log.debug(
							"Could not resolve {} address {}, retrying in {} ms.",
							targetName,
							targetAddress,
							retryingRegistrationConfiguration.getErrorDelayMillis(),
							strippedFailure);
					} else {
						log.info(
							"Could not resolve {} address {}, retrying in {} ms: {}.",
							targetName,
							targetAddress,
							retryingRegistrationConfiguration.getErrorDelayMillis(),
							strippedFailure.getMessage());
					}

					startRegistrationLater(retryingRegistrationConfiguration.getErrorDelayMillis());
				}
			},
			rpcService.getExecutor());
	}
	catch (Throwable t) {
		completionFuture.completeExceptionally(t);
		cancel();
	}
}
 
Example #11
Source File: RetryingRegistration.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * This method resolves the target address to a callable gateway and starts the
 * registration after that.
 */
@SuppressWarnings("unchecked")
public void startRegistration() {
	if (canceled) {
		// we already got canceled
		return;
	}

	try {
		// trigger resolution of the target address to a callable gateway
		final CompletableFuture<G> rpcGatewayFuture;

		if (FencedRpcGateway.class.isAssignableFrom(targetType)) {
			rpcGatewayFuture = (CompletableFuture<G>) rpcService.connect(
				targetAddress,
				fencingToken,
				targetType.asSubclass(FencedRpcGateway.class));
		} else {
			rpcGatewayFuture = rpcService.connect(targetAddress, targetType);
		}

		// upon success, start the registration attempts
		CompletableFuture<Void> rpcGatewayAcceptFuture = rpcGatewayFuture.thenAcceptAsync(
			(G rpcGateway) -> {
				log.info("Resolved {} address, beginning registration", targetName);
				register(rpcGateway, 1, retryingRegistrationConfiguration.getInitialRegistrationTimeoutMillis());
			},
			rpcService.getExecutor());

		// upon failure, retry, unless this is cancelled
		rpcGatewayAcceptFuture.whenCompleteAsync(
			(Void v, Throwable failure) -> {
				if (failure != null && !canceled) {
					final Throwable strippedFailure = ExceptionUtils.stripCompletionException(failure);
					if (log.isDebugEnabled()) {
						log.debug(
							"Could not resolve {} address {}, retrying in {} ms.",
							targetName,
							targetAddress,
							retryingRegistrationConfiguration.getErrorDelayMillis(),
							strippedFailure);
					} else {
						log.info(
							"Could not resolve {} address {}, retrying in {} ms: {}.",
							targetName,
							targetAddress,
							retryingRegistrationConfiguration.getErrorDelayMillis(),
							strippedFailure.getMessage());
					}

					startRegistrationLater(retryingRegistrationConfiguration.getErrorDelayMillis());
				}
			},
			rpcService.getExecutor());
	}
	catch (Throwable t) {
		completionFuture.completeExceptionally(t);
		cancel();
	}
}
 
Example #12
Source File: RetryingRegistration.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * This method resolves the target address to a callable gateway and starts the
 * registration after that.
 */
@SuppressWarnings("unchecked")
public void startRegistration() {
	if (canceled) {
		// we already got canceled
		return;
	}

	try {
		// trigger resolution of the target address to a callable gateway
		final CompletableFuture<G> rpcGatewayFuture;

		if (FencedRpcGateway.class.isAssignableFrom(targetType)) {
			rpcGatewayFuture = (CompletableFuture<G>) rpcService.connect(
				targetAddress,
				fencingToken,
				targetType.asSubclass(FencedRpcGateway.class));
		} else {
			rpcGatewayFuture = rpcService.connect(targetAddress, targetType);
		}

		// upon success, start the registration attempts
		CompletableFuture<Void> rpcGatewayAcceptFuture = rpcGatewayFuture.thenAcceptAsync(
			(G rpcGateway) -> {
				log.info("Resolved {} address, beginning registration", targetName);
				register(rpcGateway, 1, retryingRegistrationConfiguration.getInitialRegistrationTimeoutMillis());
			},
			rpcService.getExecutor());

		// upon failure, retry, unless this is cancelled
		rpcGatewayAcceptFuture.whenCompleteAsync(
			(Void v, Throwable failure) -> {
				if (failure != null && !canceled) {
					final Throwable strippedFailure = ExceptionUtils.stripCompletionException(failure);
					if (log.isDebugEnabled()) {
						log.debug(
							"Could not resolve {} address {}, retrying in {} ms.",
							targetName,
							targetAddress,
							retryingRegistrationConfiguration.getErrorDelayMillis(),
							strippedFailure);
					} else {
						log.info(
							"Could not resolve {} address {}, retrying in {} ms: {}",
							targetName,
							targetAddress,
							retryingRegistrationConfiguration.getErrorDelayMillis(),
							strippedFailure.getMessage());
					}

					startRegistrationLater(retryingRegistrationConfiguration.getErrorDelayMillis());
				}
			},
			rpcService.getExecutor());
	}
	catch (Throwable t) {
		completionFuture.completeExceptionally(t);
		cancel();
	}
}