Java Code Examples for org.apache.flink.runtime.akka.AkkaUtils#getAkkaConfig()

The following examples show how to use org.apache.flink.runtime.akka.AkkaUtils#getAkkaConfig() . 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: MiniCluster.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Factory method to instantiate the RPC service.
 *
 * @param akkaRpcServiceConfig
 *            The default RPC timeout for asynchronous "ask" requests.
 * @param remoteEnabled
 *            True, if the RPC service should be reachable from other (remote) RPC services.
 * @param bindAddress
 *            The address to bind the RPC service to. Only relevant when "remoteEnabled" is true.
 *
 * @return The instantiated RPC service
 */
protected RpcService createRpcService(
		AkkaRpcServiceConfiguration akkaRpcServiceConfig,
		boolean remoteEnabled,
		String bindAddress) {

	final Config akkaConfig;

	if (remoteEnabled) {
		akkaConfig = AkkaUtils.getAkkaConfig(akkaRpcServiceConfig.getConfiguration(), bindAddress, 0);
	} else {
		akkaConfig = AkkaUtils.getAkkaConfig(akkaRpcServiceConfig.getConfiguration());
	}

	final Config effectiveAkkaConfig = AkkaUtils.testDispatcherConfig().withFallback(akkaConfig);

	final ActorSystem actorSystem = AkkaUtils.createActorSystem(effectiveAkkaConfig);

	return new AkkaRpcService(actorSystem, akkaRpcServiceConfig);
}
 
Example 2
Source File: MiniCluster.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Factory method to instantiate the RPC service.
 *
 * @param akkaRpcServiceConfig
 *            The default RPC timeout for asynchronous "ask" requests.
 * @param remoteEnabled
 *            True, if the RPC service should be reachable from other (remote) RPC services.
 * @param bindAddress
 *            The address to bind the RPC service to. Only relevant when "remoteEnabled" is true.
 *
 * @return The instantiated RPC service
 */
protected RpcService createRpcService(
		AkkaRpcServiceConfiguration akkaRpcServiceConfig,
		boolean remoteEnabled,
		String bindAddress) {

	final Config akkaConfig;

	if (remoteEnabled) {
		akkaConfig = AkkaUtils.getAkkaConfig(akkaRpcServiceConfig.getConfiguration(), bindAddress, 0);
	} else {
		akkaConfig = AkkaUtils.getAkkaConfig(akkaRpcServiceConfig.getConfiguration());
	}

	final Config effectiveAkkaConfig = AkkaUtils.testDispatcherConfig().withFallback(akkaConfig);

	final ActorSystem actorSystem = AkkaUtils.createActorSystem(effectiveAkkaConfig);

	return new AkkaRpcService(actorSystem, akkaRpcServiceConfig);
}
 
Example 3
Source File: QueryableWindowOperator.java    From yahoo-streaming-benchmark with Apache License 2.0 6 votes vote down vote up
private static void initializeActorSystem(String hostname) throws UnknownHostException {
  synchronized (actorSystemLock) {
    if (actorSystem == null) {
      Configuration config = new Configuration();
      Option<scala.Tuple2<String, Object>> remoting = new Some<>(new scala.Tuple2<String, Object>(hostname, 0));

      Config akkaConfig = AkkaUtils.getAkkaConfig(config, remoting);

      LOG.info("Start actory system.");
      actorSystem = ActorSystem.create("queryableWindow", akkaConfig);
      actorSystemUsers = 1;
    } else {
      LOG.info("Actor system has already been started.");
      actorSystemUsers++;
    }
  }
}
 
Example 4
Source File: QueryableWindowOperatorEvicting.java    From yahoo-streaming-benchmark with Apache License 2.0 6 votes vote down vote up
private static void initializeActorSystem(String hostname) throws UnknownHostException {
	synchronized (actorSystemLock) {
		if (actorSystem == null) {
			Configuration config = new Configuration();
			Option<scala.Tuple2<String, Object>> remoting = new Some<>(new scala.Tuple2<String, Object>(hostname, 0));

			Config akkaConfig = AkkaUtils.getAkkaConfig(config, remoting);

			LOG.info("Start actory system.");
			actorSystem = ActorSystem.create("queryableWindow", akkaConfig);
			actorSystemUsers = 1;
		} else {
			LOG.info("Actor system has already been started.");
			actorSystemUsers++;
		}
	}
}
 
Example 5
Source File: RemoteMiniClusterImpl.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
protected RpcService createRpcService(
    AkkaRpcServiceConfiguration akkaRpcServiceConfig, boolean remoteEnabled, String bindAddress) {

  // Enable remote connections to the mini cluster which are disabled by default
  final Config akkaConfig =
      AkkaUtils.getAkkaConfig(akkaRpcServiceConfig.getConfiguration(), bindAddress, 0);

  final Config effectiveAkkaConfig = AkkaUtils.testDispatcherConfig().withFallback(akkaConfig);

  final ActorSystem actorSystem = AkkaUtils.createActorSystem(effectiveAkkaConfig);

  final AkkaRpcService akkaRpcService = new AkkaRpcService(actorSystem, akkaRpcServiceConfig);
  this.port = akkaRpcService.getPort();

  return akkaRpcService;
}
 
Example 6
Source File: BootstrapTools.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Starts an Actor System at a specific port.
 * @param configuration The Flink configuration.
 * @param actorSystemName Name of the started {@link ActorSystem}
 * @param listeningAddress The address to listen at.
 * @param listeningPort The port to listen at.
 * @param logger the logger to output log information.
 * @param actorSystemExecutorConfiguration configuration for the ActorSystem's underlying executor
 * @return The ActorSystem which has been started.
 * @throws Exception
 */
public static ActorSystem startActorSystem(
	Configuration configuration,
	String actorSystemName,
	String listeningAddress,
	int listeningPort,
	Logger logger,
	ActorSystemExecutorConfiguration actorSystemExecutorConfiguration) throws Exception {

	String hostPortUrl = NetUtils.unresolvedHostAndPortToNormalizedString(listeningAddress, listeningPort);
	logger.info("Trying to start actor system at {}", hostPortUrl);

	try {
		Config akkaConfig = AkkaUtils.getAkkaConfig(
			configuration,
			new Some<>(new Tuple2<>(listeningAddress, listeningPort)),
			actorSystemExecutorConfiguration.getAkkaConfig());

		logger.debug("Using akka configuration\n {}", akkaConfig);

		ActorSystem actorSystem = AkkaUtils.createActorSystem(actorSystemName, akkaConfig);

		logger.info("Actor system started at {}", AkkaUtils.getAddress(actorSystem));
		return actorSystem;
	}
	catch (Throwable t) {
		if (t instanceof ChannelException) {
			Throwable cause = t.getCause();
			if (cause != null && t.getCause() instanceof BindException) {
				throw new IOException("Unable to create ActorSystem at address " + hostPortUrl +
					" : " + cause.getMessage(), t);
			}
		}
		throw new Exception("Could not create actor system", t);
	}
}
 
Example 7
Source File: BootstrapTools.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Starts an Actor System at a specific port.
 * @param configuration The Flink configuration.
 * @param actorSystemName Name of the started {@link ActorSystem}
 * @param listeningAddress The address to listen at.
 * @param listeningPort The port to listen at.
 * @param logger the logger to output log information.
 * @param actorSystemExecutorConfiguration configuration for the ActorSystem's underlying executor
 * @return The ActorSystem which has been started.
 * @throws Exception
 */
public static ActorSystem startActorSystem(
	Configuration configuration,
	String actorSystemName,
	String listeningAddress,
	int listeningPort,
	Logger logger,
	ActorSystemExecutorConfiguration actorSystemExecutorConfiguration) throws Exception {

	String hostPortUrl = NetUtils.unresolvedHostAndPortToNormalizedString(listeningAddress, listeningPort);
	logger.info("Trying to start actor system at {}", hostPortUrl);

	try {
		Config akkaConfig = AkkaUtils.getAkkaConfig(
			configuration,
			new Some<>(new Tuple2<>(listeningAddress, listeningPort)),
			actorSystemExecutorConfiguration.getAkkaConfig());

		logger.debug("Using akka configuration\n {}", akkaConfig);

		ActorSystem actorSystem = AkkaUtils.createActorSystem(actorSystemName, akkaConfig);

		logger.info("Actor system started at {}", AkkaUtils.getAddress(actorSystem));
		return actorSystem;
	}
	catch (Throwable t) {
		if (t instanceof ChannelException) {
			Throwable cause = t.getCause();
			if (cause != null && t.getCause() instanceof BindException) {
				throw new IOException("Unable to create ActorSystem at address " + hostPortUrl +
					" : " + cause.getMessage(), t);
			}
		}
		throw new Exception("Could not create actor system", t);
	}
}
 
Example 8
Source File: BootstrapTools.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Starts a remote Actor System at given address and specific port.
 * @param configuration The Flink configuration.
 * @param actorSystemName Name of the started {@link ActorSystem}
 * @param externalAddress The external address to access the ActorSystem.
 * @param externalPort The external port to access the ActorSystem.
 * @param bindAddress The local address to bind to.
 * @param bindPort The local port to bind to.
 * @param logger the logger to output log information.
 * @param actorSystemExecutorConfiguration configuration for the ActorSystem's underlying executor
 * @param customConfig Custom Akka config to be combined with the config derived from Flink configuration.
 * @return The ActorSystem which has been started.
 * @throws Exception
 */
private static ActorSystem startRemoteActorSystem(
	Configuration configuration,
	String actorSystemName,
	String externalAddress,
	int externalPort,
	String bindAddress,
	int bindPort,
	Logger logger,
	ActorSystemExecutorConfiguration actorSystemExecutorConfiguration,
	Config customConfig) throws Exception {

	String externalHostPortUrl = NetUtils.unresolvedHostAndPortToNormalizedString(externalAddress, externalPort);
	String bindHostPortUrl = NetUtils.unresolvedHostAndPortToNormalizedString(bindAddress, bindPort);
	logger.info("Trying to start actor system, external address {}, bind address {}.", externalHostPortUrl, bindHostPortUrl);

	try {
		Config akkaConfig = AkkaUtils.getAkkaConfig(
			configuration,
			new Some<>(new Tuple2<>(externalAddress, externalPort)),
			new Some<>(new Tuple2<>(bindAddress, bindPort)),
			actorSystemExecutorConfiguration.getAkkaConfig());

		if (customConfig != null) {
			akkaConfig = customConfig.withFallback(akkaConfig);
		}

		return startActorSystem(akkaConfig, actorSystemName, logger);
	}
	catch (Throwable t) {
		if (t instanceof ChannelException) {
			Throwable cause = t.getCause();
			if (cause != null && t.getCause() instanceof BindException) {
				throw new IOException("Unable to create ActorSystem at address " + bindHostPortUrl +
					" : " + cause.getMessage(), t);
			}
		}
		throw new Exception("Could not create actor system", t);
	}
}
 
Example 9
Source File: BootstrapTools.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Starts a local Actor System.
 * @param configuration The Flink configuration.
 * @param actorSystemName Name of the started ActorSystem.
 * @param logger The logger to output log information.
 * @param actorSystemExecutorConfiguration Configuration for the ActorSystem's underlying executor.
 * @param customConfig Custom Akka config to be combined with the config derived from Flink configuration.
 * @return The ActorSystem which has been started.
 * @throws Exception
 */
public static ActorSystem startLocalActorSystem(
	Configuration configuration,
	String actorSystemName,
	Logger logger,
	ActorSystemExecutorConfiguration actorSystemExecutorConfiguration,
	Config customConfig) throws Exception {

	logger.info("Trying to start local actor system");

	try {
		Config akkaConfig = AkkaUtils.getAkkaConfig(
			configuration,
			scala.Option.empty(),
			scala.Option.empty(),
			actorSystemExecutorConfiguration.getAkkaConfig());

		if (customConfig != null) {
			akkaConfig = customConfig.withFallback(akkaConfig);
		}

		return startActorSystem(akkaConfig, actorSystemName, logger);
	}
	catch (Throwable t) {
		throw new Exception("Could not create actor system", t);
	}
}