private Address LocalAddressForRemote( IDictionary<string, HashSet<ProtocolTransportAddressPair>> transportMapping, Address remote) { HashSet<ProtocolTransportAddressPair> transports; if (transportMapping.TryGetValue(remote.Protocol, out transports)) { ProtocolTransportAddressPair[] responsibleTransports = transports.Where(t => t.ProtocolTransport.Transport.IsResponsibleFor(remote)).ToArray(); if (responsibleTransports.Length == 0) { throw new RemoteTransportException( "No transport is responsible for address:[" + remote + "] although protocol [" + remote.Protocol + "] is available." + " Make sure at least one transport is configured to be responsible for the address.", null); } if (responsibleTransports.Length == 1) { return responsibleTransports.First().Address; } throw new RemoteTransportException( "Multiple transports are available for [" + remote + ": " + string.Join(",", responsibleTransports.Select(t => t.ToString())) + "] " + "Remoting cannot decide which transport to use to reach the remote system. Change your configuration " + "so that only one transport is responsible for the address.", null); } throw new RemoteTransportException( "No transport is loaded for protocol: [" + remote.Protocol + "], available protocols: [" + string.Join(",", transportMapping.Keys.Select(t => t.ToString())) + "]", null); }
public RemoteMetricsSpec() : base(@" akka.actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" akka.remote.log-frame-size-exceeding = 200 b akka.remote.helios.tcp = { port = 0 hostname = localhost } akka.loglevel = DEBUG ") { _client = ActorSystem.Create("RemoteMetricsSpec-client", ConfigurationFactory.ParseString(@" akka.actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" akka.remote.helios.tcp = { port = 0 hostname = localhost } ").WithFallback(Sys.Settings.Config)); _address = Sys.AsInstanceOf<ExtendedActorSystem>().Provider.DefaultAddress; _subject = Sys.ActorOf(Props.Create(() => new Subject()).WithDeploy(Deploy.Local), "subject"); var listener = Sys.ActorOf(Props.Create(() => new InfoEventListener(TestActor)).WithDeploy(Deploy.Local), "listener"); Sys.EventStream.Subscribe(listener, typeof (Info)); }
public ConnectionAssociationHandle(IActorRef connection, Address localAddress, Address remoteAddress) : base(localAddress, remoteAddress) { _connection = connection; ReadHandlerSource = new TaskCompletionSource<IHandleEventListener>(); ReadHandlerSource.Task.PipeTo(connection); }
public Watcher(TestLatch exitingLatch, TestLatch removedLatch, Address secondAddress) { _exitingLatch = exitingLatch; _removedLatch = removedLatch; _secondAddress = secondAddress; Receive<ClusterEvent.CurrentClusterState>(state => { if (state.Members.Any(m => m.Address == _secondAddress && m.Status == MemberStatus.Exiting)) _exitingLatch.CountDown(); }); Receive<ClusterEvent.MemberExited>(m => { if (m.Member.Address == secondAddress) { exitingLatch.CountDown(); } }); Receive<ClusterEvent.MemberRemoved>(m => { if (m.Member.Address == secondAddress) { _removedLatch.CountDown(); } }); }
public RemoteDeploySpec() : base(@" akka { loglevel = INFO log-dead-letters-during-shutdown = false // actor.provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" remote.helios.tcp = { hostname = localhost port = 0 } actor.deployment { /router1 { router = round-robin-pool nr-of-instances = 3 } /router2 { router = round-robin-pool nr-of-instances = 3 } /router3 { router = round-robin-pool nr-of-instances = 0 } } } ") { _remoteSystem = ActorSystem.Create("RemoteSystem", Sys.Settings.Config); _remoteAddress = _remoteSystem.AsInstanceOf<ExtendedActorSystem>().Provider.DefaultAddress; var remoteAddressUid = AddressUidExtension.Uid(_remoteSystem); }
public void CreateCorrectToStringWithAddress() { var local = new Address("akka.tcp", "mysys"); var a = new Address("akka.tcp", "mysys", "aaa", 2552); var b = new Address("akka.tcp", "mysys", "bb", 2552); var c = new Address("akka.tcp", "mysys", "cccc" , 2552); var root = new RootActorPath(local); root.ToStringWithAddress(a).ShouldBe("akka.tcp://mysys@aaa:2552/"); (root / "user").ToStringWithAddress(a).ShouldBe("akka.tcp://mysys@aaa:2552/user"); (root / "user" / "foo").ToStringWithAddress(a).ShouldBe("akka.tcp://mysys@aaa:2552/user/foo"); root.ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@bb:2552/"); (root / "user").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@bb:2552/user"); (root / "user" / "foo").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@bb:2552/user/foo"); root.ToStringWithAddress(c).ShouldBe("akka.tcp://mysys@cccc:2552/"); (root / "user").ToStringWithAddress(c).ShouldBe("akka.tcp://mysys@cccc:2552/user"); (root / "user" / "foo").ToStringWithAddress(c).ShouldBe("akka.tcp://mysys@cccc:2552/user/foo"); var rootA = new RootActorPath(a); rootA.ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@aaa:2552/"); (rootA / "user").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@aaa:2552/user"); (rootA / "user" / "foo").ToStringWithAddress(b).ShouldBe("akka.tcp://mysys@aaa:2552/user/foo"); }
private void Ready() { Receive<SendState>(msg => { _cluster.SendCurrentClusterState(Self); }); Receive<ClusterEvent.CurrentClusterState>(state => { //_hub.ClusterState(state, _cluster.SelfAddress); }); Receive<RemoveMe>(msg => { _logger.Warning("[l] Monitor stopping; Issuing a Cluster.Leave() command for following address: {0}", _cluster.SelfAddress); _cluster.Leave(_cluster.SelfAddress); }); Receive<MemberLeave>(msg => { Address add = new Address(msg.Protocol, msg.System, msg.Host, msg.Port); _logger.Warning("[l] Forcing Member to leave cluster: {0}", add.ToString()); _cluster.Leave(add); }); Receive<MemberDown>(msg => { Address add = new Address(msg.Protocol, msg.System, msg.Host, msg.Port); _logger.Warning("[l] Forcing the Member down: {0}", add.ToString()); _cluster.Down(add); }); }
public DisassociatedEvent(Address localAddress, Address remoteAddress, bool inbound) { LocalAddress = localAddress; RemoteAddress = remoteAddress; IsInbound = inbound; EventName = "Disassociated"; }
/// <summary> /// Serializes the specified message. /// </summary> /// <param name="system">The system.</param> /// <param name="address"></param> /// <param name="message">The message.</param> /// <returns>SerializedMessage.</returns> public static SerializedMessage Serialize(ActorSystem system, Address address, object message) { Serializer serializer = system.Serialization.FindSerializerFor(message); SerializedMessage.Builder messageBuilder = new SerializedMessage.Builder() .SetMessage(ByteString.Unsafe.FromBytes(serializer.ToBinaryWithAddress(address, message))) .SetSerializerId(serializer.Identifier); var serializer2 = serializer as SerializerWithStringManifest; if (serializer2 != null) { var manifest = serializer2.Manifest(message); if (!string.IsNullOrEmpty(manifest)) { messageBuilder.SetMessageManifest(ByteString.CopyFromUtf8(manifest)); } } else { if (serializer.IncludeManifest) messageBuilder.SetMessageManifest(ByteString.CopyFromUtf8(message.GetType().AssemblyQualifiedName)); } return messageBuilder.Build(); }
public void RemoteActorRefProvider_should_create_RemoteActorRef_for_nonlocaladdress() { var nonLocalAddress = new Address("akka.trttl.gremlin.tcp", Sys.Name, "localhost", RARP.For(Sys).Provider.DefaultAddress.Port); var nonLocalActorPath = new RootActorPath(nonLocalAddress) / "user" / "foo"; var resolved = RARP.For(Sys).Provider.ResolveActorRefWithLocalAddress(nonLocalActorPath.ToSerializationFormat(), nonLocalAddress); Assert.IsType<RemoteActorRef>(resolved); // should be a remote actorref }
public Message(IInternalActorRef recipient, Address recipientAddress, SerializedMessage serializedMessage, IActorRef senderOptional = null, SeqNo seq = null) { Seq = seq; SenderOptional = senderOptional; SerializedMessage = serializedMessage; RecipientAddress = recipientAddress; Recipient = recipient; }
public void Setup(BenchmarkContext context) { _actorSystem = ActorSystem.Create("MessageDispatcher" + Counter.GetAndIncrement(), RemoteHocon); _systemAddress = RARP.For(_actorSystem).Provider.DefaultAddress; _inboundMessageDispatcherCounter = context.GetCounter(MessageDispatcherThroughputCounterName); _message = SerializedMessage.CreateBuilder().SetSerializerId(0).SetMessage(ByteString.CopyFromUtf8("foo")).Build(); _dispatcher = new DefaultMessageDispatcher(_actorSystem, RARP.For(_actorSystem).Provider, _actorSystem.Log); _targetActorRef = new BenchmarkActorRef(_inboundMessageDispatcherCounter, RARP.For(_actorSystem).Provider); }
public IActorRef ReadOnlyEndpointFor(Address address) { IActorRef tmp; if (addressToReadonly.TryGetValue(address, out tmp)) { return tmp; } return null; }
public void CreateCorrectToStringWithoutAddress() { var a = new Address("akka.tcp", "mysys"); //TODO: there must be a / after system name new RootActorPath(a).ToStringWithoutAddress().ShouldBe("/"); (new RootActorPath(a) / "user").ToStringWithoutAddress().ShouldBe("/user"); (new RootActorPath(a) / "user" / "foo").ToStringWithoutAddress().ShouldBe("/user/foo"); (new RootActorPath(a) / "user" / "foo" / "bar").ToStringWithoutAddress().ShouldBe("/user/foo/bar"); }
public AssociationErrorEvent(Exception cause, Address localAddress, Address remoteAddress, bool inbound, LogLevel level) { LocalAddress = localAddress; RemoteAddress = remoteAddress; IsInbound = inbound; EventName = "AssociationError"; _level = level; Cause = cause; }
public Task <Akka.Actor.Address> GetAddress(Akka.Actor.Address address) { var requestMessage = new RequestMessage { InvokePayload = new ISurrogate_PayloadTable.GetAddress_Invoke { address = address } }; return(SendRequestAndReceive <Akka.Actor.Address>(requestMessage)); }
void ISurrogate_NoReply.GetAddress(Akka.Actor.Address address) { var requestMessage = new RequestMessage { InvokePayload = new ISurrogate_PayloadTable.GetAddress_Invoke { address = address } }; SendRequest(requestMessage); }
public TcpTransport(ActorSystem system, Config config) : base(system, config) { string protocol = "akka." + config.GetString("transport-protocol"); SchemeIdentifier = protocol; string host = config.GetString("hostname"); int port = config.GetInt("port"); Address = new Address(protocol, system.Name, host, port); log = Logging.GetLogger(system, this); server = new TcpServer(system, Address); }
public void MemoryFootprint(BenchmarkContext context) { var actorPaths = new Address[100000]; for (var i = 0; i < 100000;) { actorPaths[i] = new Address("akka", "foo", "localhost", 9091); ++i; _parseThroughput.Increment(); } }
/// <summary> /// Converts a <see cref="ByteString"/> structure into a Helios <see cref="NetworkData"/> structure /// </summary> /// <param name="byteString">The data to send over the network</param> /// <param name="address">The address that we received data from / are sending data to</param> /// <returns>a new <see cref="NetworkData"/> struct</returns> public static NetworkData ToData(ByteString byteString, Address address) { var data = new NetworkData() { Buffer = byteString.ToByteArray(), RemoteHost = HeliosTransport.AddressToNode(address) }; data.Length = data.Buffer.Length; return data; }
/// <summary> /// Initializes a new instance of the <see cref="RemoteActorRef"/> class. /// </summary> /// <param name="remote">The remote.</param> /// <param name="localAddressToUse">The local address to use.</param> /// <param name="path">The path.</param> /// <param name="parent">The parent.</param> /// <param name="props">The props.</param> /// <param name="deploy">The deploy.</param> internal RemoteActorRef(RemoteTransport remote, Address localAddressToUse, ActorPath path, InternalActorRef parent, Props props, Deploy deploy) { Remote = remote; LocalAddressToUse = localAddressToUse; Path = path; _parent = parent; _props = props; _deploy = deploy; }
public override void Down(Address node) { if (_leader) { _probe.Tell(new DownCalled(node)); } else { _probe.Tell("down must only be done by leader"); } }
public ActorRef RegisterWritableEndpoint(Address address, ActorRef endpoint, int? uid = null) { EndpointManager.EndpointPolicy existing; if (addressToWritable.TryGetValue(address, out existing)) { throw new ArgumentException("Attempting to overwrite existing endpoint " + existing + " with " + endpoint); } addressToWritable.Add(address, new EndpointManager.Pass(endpoint, uid)); writableToAddress.Add(endpoint, address); return endpoint; }
/// <summary> /// Serializes the specified message. /// </summary> /// <param name="system">The system.</param> /// <param name="address"></param> /// <param name="message">The message.</param> /// <returns>SerializedMessage.</returns> public static SerializedMessage Serialize(ActorSystem system,Address address, object message) { Serializer serializer = system.Serialization.FindSerializerFor(message); byte[] messageBytes = serializer.ToBinaryWithAddress(address,message); SerializedMessage.Builder messageBuilder = new SerializedMessage.Builder() .SetSerializerId(serializer.Identifier); if (serializer.IncludeManifest) messageBuilder.SetMessageManifest(ByteString.CopyFromUtf8(message.GetType().AssemblyQualifiedName)); messageBuilder.SetMessage(ByteString.Unsafe.FromBytes(messageBytes)); return messageBuilder.Build(); }
public EndpointActor(Address localAddress, Address remoteAddress, Transport.Transport transport, RemoteSettings settings) { this.localAddress = localAddress; this.remoteAddress = remoteAddress; this.transport = transport; this.settings = settings; client = new TcpClient(); client.Connect(remoteAddress.Host, remoteAddress.Port.Value); stream = client.GetStream(); }
public static SurrogateForAddress Convert(Address value) { if (value == null) return null; return new SurrogateForAddress { Protocol = value.Protocol, System = value.System, Host = value.Host, Port = value.Port, }; }
public CurrentClusterState( ImmutableSortedSet<Member> members, ImmutableHashSet<Member> unreachable, ImmutableHashSet<Address> seenBy, Address leader, ImmutableDictionary<string, Address> roleLeaderMap) { _members = members; _unreachable = unreachable; _seenBy = seenBy; _leader = leader; _roleLeaderMap = roleLeaderMap; }
public static Address ParseAddress(EndPoint ep) { bool isIp = ep is IPEndPoint; IPEndPoint ip = ep as IPEndPoint; DnsEndPoint dns = ep as DnsEndPoint; var addr = new Address("akka.tcp", "foo", isIp ? (ip.Address.AddressFamily == AddressFamily.InterNetworkV6 ? // have to explicitly check for IPV6 and bracket it "[" + ip.Address + "]" : ip.Address.ToString()) : dns.Host, isIp ? ip.Port : dns.Port); return addr; }
public IActorRef RegisterWritableEndpoint(Address address, IActorRef endpoint, int? uid = null) { EndpointManager.EndpointPolicy existing; if (addressToWritable.TryGetValue(address, out existing)) { var gated = existing as EndpointManager.Gated; if(gated != null && !gated.TimeOfRelease.IsOverdue) //don't throw if the prune timer didn't get a chance to run first throw new ArgumentException("Attempting to overwrite existing endpoint " + existing + " with " + endpoint); } addressToWritable.AddOrSet(address, new EndpointManager.Pass(endpoint, uid)); writableToAddress.AddOrSet(endpoint, address); return endpoint; }
public static Proto.Msg.Address AddressToProto(Address address) { if (string.IsNullOrEmpty(address.Host) || !address.Port.HasValue) { throw new ArgumentOutOfRangeException( $"Address [{address}] could not be serialized: host or port missing."); } return(new Proto.Msg.Address() { Hostname = address.Host, Port = address.Port.Value }); }
public void RegisterWritableEndpointUid(Address remoteAddress, int uid) { EndpointManager.EndpointPolicy existing; if (_addressToWritable.TryGetValue(remoteAddress, out existing)) { var pass = existing as EndpointManager.Pass; if (pass != null) { _addressToWritable[remoteAddress] = new EndpointManager.Pass(pass.Endpoint, uid, pass.RefuseUid); } // if the policy is not Pass, then the GotUid might have lost the race with some failure } }
public void ClusterMessages_must_be_serializable() { var address = new Address("akka.tcp", "system", "some.host.org", 4711); var uniqueAddress = new UniqueAddress(address, 17); var address2 = new Address("akka.tcp", "system", "other.host.org", 4711); var uniqueAddress2 = new UniqueAddress(address2, 18); CheckSerialization(new InternalClusterAction.Join(uniqueAddress, ImmutableHashSet.Create("foo","bar"))); CheckSerialization(new ClusterUserAction.Leave(address)); CheckSerialization(new ClusterUserAction.Down(address)); CheckSerialization(new InternalClusterAction.InitJoin()); CheckSerialization(new InternalClusterAction.InitJoinAck(address)); CheckSerialization(new InternalClusterAction.InitJoinNack(address)); CheckSerialization(new ClusterHeartbeatSender.Heartbeat(address)); CheckSerialization(new ClusterHeartbeatSender.HeartbeatRsp(uniqueAddress)); var node1 = new VectorClock.Node("node1"); var node2 = new VectorClock.Node("node2"); var node3 = new VectorClock.Node("node3"); var node4 = new VectorClock.Node("node4"); var g1 = new Gossip(ImmutableSortedSet.Create(a1, b1, c1, d1)).Increment(node1) .Increment(node2) .Seen(a1.UniqueAddress) .Seen(b1.UniqueAddress); var g2 = g1.Increment(node3).Increment(node4).Seen(a1.UniqueAddress).Seen(c1.UniqueAddress); var reachability3 = Reachability.Empty.Unreachable(a1.UniqueAddress, e1.UniqueAddress) .Unreachable(b1.UniqueAddress, e1.UniqueAddress); var g3 = g2.Copy(members: ImmutableSortedSet.Create(a1, b1, c1, d1, e1), overview: g2.Overview.Copy(reachability: reachability3)); CheckSerialization(new GossipEnvelope(a1.UniqueAddress, uniqueAddress2, g1)); CheckSerialization(new GossipEnvelope(a1.UniqueAddress, uniqueAddress2, g2)); CheckSerialization(new GossipEnvelope(a1.UniqueAddress, uniqueAddress2, g3)); CheckSerialization(new GossipStatus(a1.UniqueAddress, g1.Version)); CheckSerialization(new GossipStatus(a1.UniqueAddress, g2.Version)); CheckSerialization(new GossipStatus(a1.UniqueAddress, g3.Version)); CheckSerialization(new InternalClusterAction.Welcome(uniqueAddress, g2)); var mg = new MetricsGossip(ImmutableHashSet.Create<NodeMetrics>(new[] { new NodeMetrics(a1.Address, 4711, ImmutableHashSet.Create<Metric>(new Metric("foo", 1.2, null))), new NodeMetrics(b1.Address, 4712, ImmutableHashSet.Create<Metric>(new Metric("foo", 2.1, new EWMA(100.0, 0.18)) , new Metric("bar1", Double.MinValue, null), new Metric("bar2", float.MaxValue, null), new Metric("bar3", int.MaxValue, null), new Metric("bar4", long.MaxValue, null), new Metric("bar5", double.MaxValue, null))) })); CheckSerialization(new MetricsGossipEnvelope(a1.Address, mg, true)); }
public static void ChangeLeader(Akka.Actor.Address address) { foreach (var member in MemberInfos.Values) { member.ClusterLeader = false; } var addressStr = address.ToString(); if (MemberInfos.ContainsKey(addressStr)) { MemberInfos[addressStr].ClusterLeader = true; } }
public void RemoveClusterMember(Address address) { using (var cmd = new SQLiteCommand(@"DELETE FROM cluster_nodes WHERE member_address = @addr", _connectionFactory())) using (var tx = cmd.Connection.BeginTransaction()) { cmd.Transaction = tx; var addr = address.ToString(); cmd.Parameters.Add("@addr", DbType.String); cmd.Parameters["@addr"].Value = addr; cmd.ExecuteNonQuery(); tx.Commit(); } }
public Reply(Address address) { Address = address; }
/// <summary> /// TBD /// </summary> /// <param name="address">TBD</param> /// <returns>TBD</returns> public IActorRef RootGuardianAt(Address address) { return(address == _rootPath.Address ? _rootGuardian : _deadLetters); }
/// <summary> /// TBD /// </summary> /// <param name="address">TBD</param> /// <returns>TBD</returns> public Address GetExternalAddressFor(Address address) { return(address == _rootPath.Address ? address : null); }
public DefaultCollector(Address address) { _address = address; _cpuWatch = new Stopwatch(); }
public AddressTerminated(Address address) { Address = address; }