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

The following examples show how to use org.apache.flink.runtime.akka.AkkaUtils#getAkkaURL() . 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 5 votes vote down vote up
private Tuple2<String, String> extractAddressHostname(ActorRef actorRef) {
	final String actorAddress = AkkaUtils.getAkkaURL(actorSystem, actorRef);
	final String hostname;
	Option<String> host = actorRef.path().address().host();
	if (host.isEmpty()) {
		hostname = "localhost";
	} else {
		hostname = host.get();
	}

	return Tuple2.of(actorAddress, hostname);
}
 
Example 2
Source File: MetricRegistryImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the MetricQueryService.
 *
 * @param actorSystem ActorSystem to create the MetricQueryService on
 * @param resourceID resource ID used to disambiguate the actor name
    */
public void startQueryService(ActorSystem actorSystem, ResourceID resourceID) {
	synchronized (lock) {
		Preconditions.checkState(!isShutdown(), "The metric registry has already been shut down.");

		try {
			queryService = MetricQueryService.startMetricQueryService(actorSystem, resourceID, maximumFramesize);
			metricQueryServicePath = AkkaUtils.getAkkaURL(actorSystem, queryService);
		} catch (Exception e) {
			LOG.warn("Could not start MetricDumpActor. No metrics will be submitted to the WebInterface.", e);
		}
	}
}
 
Example 3
Source File: AkkaRpcService.java    From flink with Apache License 2.0 5 votes vote down vote up
private Tuple2<String, String> extractAddressHostname(ActorRef actorRef) {
	final String actorAddress = AkkaUtils.getAkkaURL(actorSystem, actorRef);
	final String hostname;
	Option<String> host = actorRef.path().address().host();
	if (host.isEmpty()) {
		hostname = "localhost";
	} else {
		hostname = host.get();
	}

	return Tuple2.of(actorAddress, hostname);
}
 
Example 4
Source File: AkkaRpcService.java    From flink with Apache License 2.0 5 votes vote down vote up
private Tuple2<String, String> extractAddressHostname(ActorRef actorRef) {
	final String actorAddress = AkkaUtils.getAkkaURL(actorSystem, actorRef);
	final String hostname;
	Option<String> host = actorRef.path().address().host();
	if (host.isEmpty()) {
		hostname = "localhost";
	} else {
		hostname = host.get();
	}

	return Tuple2.of(actorAddress, hostname);
}
 
Example 5
Source File: AkkaRpcService.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public <C extends RpcEndpoint & RpcGateway> RpcServer startServer(C rpcEndpoint) {
	checkNotNull(rpcEndpoint, "rpc endpoint");

	CompletableFuture<Void> terminationFuture = new CompletableFuture<>();
	final Props akkaRpcActorProps;

	if (rpcEndpoint instanceof FencedRpcEndpoint) {
		akkaRpcActorProps = Props.create(
			FencedAkkaRpcActor.class,
			rpcEndpoint,
			terminationFuture,
			getVersion(),
			configuration.getMaximumFramesize());
	} else {
		akkaRpcActorProps = Props.create(
			AkkaRpcActor.class,
			rpcEndpoint,
			terminationFuture,
			getVersion(),
			configuration.getMaximumFramesize());
	}

	ActorRef actorRef;

	synchronized (lock) {
		checkState(!stopped, "RpcService is stopped");
		actorRef = actorSystem.actorOf(akkaRpcActorProps, rpcEndpoint.getEndpointId());
		actors.put(actorRef, rpcEndpoint);
	}

	LOG.info("Starting RPC endpoint for {} at {} .", rpcEndpoint.getClass().getName(), actorRef.path());

	final String akkaAddress = AkkaUtils.getAkkaURL(actorSystem, actorRef);
	final String hostname;
	Option<String> host = actorRef.path().address().host();
	if (host.isEmpty()) {
		hostname = "localhost";
	} else {
		hostname = host.get();
	}

	Set<Class<?>> implementedRpcGateways = new HashSet<>(RpcUtils.extractImplementedRpcGateways(rpcEndpoint.getClass()));

	implementedRpcGateways.add(RpcServer.class);
	implementedRpcGateways.add(AkkaBasedEndpoint.class);

	final InvocationHandler akkaInvocationHandler;

	if (rpcEndpoint instanceof FencedRpcEndpoint) {
		// a FencedRpcEndpoint needs a FencedAkkaInvocationHandler
		akkaInvocationHandler = new FencedAkkaInvocationHandler<>(
			akkaAddress,
			hostname,
			actorRef,
			configuration.getTimeout(),
			configuration.getMaximumFramesize(),
			terminationFuture,
			((FencedRpcEndpoint<?>) rpcEndpoint)::getFencingToken);

		implementedRpcGateways.add(FencedMainThreadExecutable.class);
	} else {
		akkaInvocationHandler = new AkkaInvocationHandler(
			akkaAddress,
			hostname,
			actorRef,
			configuration.getTimeout(),
			configuration.getMaximumFramesize(),
			terminationFuture);
	}

	// Rather than using the System ClassLoader directly, we derive the ClassLoader
	// from this class . That works better in cases where Flink runs embedded and all Flink
	// code is loaded dynamically (for example from an OSGI bundle) through a custom ClassLoader
	ClassLoader classLoader = getClass().getClassLoader();

	@SuppressWarnings("unchecked")
	RpcServer server = (RpcServer) Proxy.newProxyInstance(
		classLoader,
		implementedRpcGateways.toArray(new Class<?>[implementedRpcGateways.size()]),
		akkaInvocationHandler);

	return server;
}
 
Example 6
Source File: AkkaRpcService.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <C extends RpcEndpoint & RpcGateway> RpcServer startServer(C rpcEndpoint) {
	checkNotNull(rpcEndpoint, "rpc endpoint");

	CompletableFuture<Void> terminationFuture = new CompletableFuture<>();
	final Props akkaRpcActorProps;

	if (rpcEndpoint instanceof FencedRpcEndpoint) {
		akkaRpcActorProps = Props.create(
			FencedAkkaRpcActor.class,
			rpcEndpoint,
			terminationFuture,
			getVersion(),
			configuration.getMaximumFramesize());
	} else {
		akkaRpcActorProps = Props.create(
			AkkaRpcActor.class,
			rpcEndpoint,
			terminationFuture,
			getVersion(),
			configuration.getMaximumFramesize());
	}

	ActorRef actorRef;

	synchronized (lock) {
		checkState(!stopped, "RpcService is stopped");
		actorRef = actorSystem.actorOf(akkaRpcActorProps, rpcEndpoint.getEndpointId());
		actors.put(actorRef, rpcEndpoint);
	}

	LOG.info("Starting RPC endpoint for {} at {} .", rpcEndpoint.getClass().getName(), actorRef.path());

	final String akkaAddress = AkkaUtils.getAkkaURL(actorSystem, actorRef);
	final String hostname;
	Option<String> host = actorRef.path().address().host();
	if (host.isEmpty()) {
		hostname = "localhost";
	} else {
		hostname = host.get();
	}

	Set<Class<?>> implementedRpcGateways = new HashSet<>(RpcUtils.extractImplementedRpcGateways(rpcEndpoint.getClass()));

	implementedRpcGateways.add(RpcServer.class);
	implementedRpcGateways.add(AkkaBasedEndpoint.class);

	final InvocationHandler akkaInvocationHandler;

	if (rpcEndpoint instanceof FencedRpcEndpoint) {
		// a FencedRpcEndpoint needs a FencedAkkaInvocationHandler
		akkaInvocationHandler = new FencedAkkaInvocationHandler<>(
			akkaAddress,
			hostname,
			actorRef,
			configuration.getTimeout(),
			configuration.getMaximumFramesize(),
			terminationFuture,
			((FencedRpcEndpoint<?>) rpcEndpoint)::getFencingToken);

		implementedRpcGateways.add(FencedMainThreadExecutable.class);
	} else {
		akkaInvocationHandler = new AkkaInvocationHandler(
			akkaAddress,
			hostname,
			actorRef,
			configuration.getTimeout(),
			configuration.getMaximumFramesize(),
			terminationFuture);
	}

	// Rather than using the System ClassLoader directly, we derive the ClassLoader
	// from this class . That works better in cases where Flink runs embedded and all Flink
	// code is loaded dynamically (for example from an OSGI bundle) through a custom ClassLoader
	ClassLoader classLoader = getClass().getClassLoader();

	@SuppressWarnings("unchecked")
	RpcServer server = (RpcServer) Proxy.newProxyInstance(
		classLoader,
		implementedRpcGateways.toArray(new Class<?>[implementedRpcGateways.size()]),
		akkaInvocationHandler);

	return server;
}
 
Example 7
Source File: AkkaRpcService.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public <C extends RpcEndpoint & RpcGateway> RpcServer startServer(C rpcEndpoint) {
	checkNotNull(rpcEndpoint, "rpc endpoint");

	final SupervisorActor.ActorRegistration actorRegistration = registerAkkaRpcActor(rpcEndpoint);
	final ActorRef actorRef = actorRegistration.getActorRef();
	final CompletableFuture<Void> actorTerminationFuture = actorRegistration.getTerminationFuture();

	LOG.info("Starting RPC endpoint for {} at {} .", rpcEndpoint.getClass().getName(), actorRef.path());

	final String akkaAddress = AkkaUtils.getAkkaURL(actorSystem, actorRef);
	final String hostname;
	Option<String> host = actorRef.path().address().host();
	if (host.isEmpty()) {
		hostname = "localhost";
	} else {
		hostname = host.get();
	}

	Set<Class<?>> implementedRpcGateways = new HashSet<>(RpcUtils.extractImplementedRpcGateways(rpcEndpoint.getClass()));

	implementedRpcGateways.add(RpcServer.class);
	implementedRpcGateways.add(AkkaBasedEndpoint.class);

	final InvocationHandler akkaInvocationHandler;

	if (rpcEndpoint instanceof FencedRpcEndpoint) {
		// a FencedRpcEndpoint needs a FencedAkkaInvocationHandler
		akkaInvocationHandler = new FencedAkkaInvocationHandler<>(
			akkaAddress,
			hostname,
			actorRef,
			configuration.getTimeout(),
			configuration.getMaximumFramesize(),
			actorTerminationFuture,
			((FencedRpcEndpoint<?>) rpcEndpoint)::getFencingToken,
			captureAskCallstacks);

		implementedRpcGateways.add(FencedMainThreadExecutable.class);
	} else {
		akkaInvocationHandler = new AkkaInvocationHandler(
			akkaAddress,
			hostname,
			actorRef,
			configuration.getTimeout(),
			configuration.getMaximumFramesize(),
			actorTerminationFuture,
			captureAskCallstacks);
	}

	// Rather than using the System ClassLoader directly, we derive the ClassLoader
	// from this class . That works better in cases where Flink runs embedded and all Flink
	// code is loaded dynamically (for example from an OSGI bundle) through a custom ClassLoader
	ClassLoader classLoader = getClass().getClassLoader();

	@SuppressWarnings("unchecked")
	RpcServer server = (RpcServer) Proxy.newProxyInstance(
		classLoader,
		implementedRpcGateways.toArray(new Class<?>[implementedRpcGateways.size()]),
		akkaInvocationHandler);

	return server;
}
 
Example 8
Source File: QueryableWindowOperator.java    From yahoo-streaming-benchmark with Apache License 2.0 3 votes vote down vote up
@Override
public void open() throws Exception {
  super.open();

  LOG.info("Opening QueryableWindowOperator {}.", this);

  // don't overwrite if this was initialized in restoreState()
  if (windows == null) {
    windows = new HashMap<>();
  }

  // retainedWindows = new HashMap<>();

  if (registrationService != null) {
    registrationService.start();

    String hostname = registrationService.getConnectingHostname();
    String actorName = "responseActor_" + getRuntimeContext().getIndexOfThisSubtask() + System.nanoTime();

    initializeActorSystem(hostname);

    ActorRef responseActor = actorSystem.actorOf(Props.create(ResponseActor.class, this), actorName);

    String akkaURL = AkkaUtils.getAkkaURL(actorSystem, responseActor);

    registrationService.registerActor(getRuntimeContext().getIndexOfThisSubtask(), akkaURL);
  }
}
 
Example 9
Source File: QueryableWindowOperatorEvicting.java    From yahoo-streaming-benchmark with Apache License 2.0 3 votes vote down vote up
@Override
public void open() throws Exception {
	super.open();

	LOG.info("Opening QueryableWindowOperator {}." , this);

	// don't overwrite if this was initialized in restoreState()
	if (windows == null) {
		windows = new HashMap<>();
	}

	// retainedWindows = new HashMap<>();

	if(registrationService != null) {
		registrationService.start();

		String hostname = registrationService.getConnectingHostname();
		String actorName = "responseActor_" + getRuntimeContext().getIndexOfThisSubtask() + System.nanoTime();

		initializeActorSystem(hostname);

		ActorRef responseActor = actorSystem.actorOf(Props.create(ResponseActor.class, this), actorName);

		String akkaURL = AkkaUtils.getAkkaURL(actorSystem, responseActor);

		registrationService.registerActor(getRuntimeContext().getIndexOfThisSubtask(), akkaURL);
	}
}