public async Task <ILogConsistencyProtocolMessage> SendMessage(ILogConsistencyProtocolMessage payload, string clusterId) { log?.Trace("SendMessage {0}->{1}: {2}", this.siloOptions.ClusterId, clusterId, payload); // send the message to ourself if we are the destination cluster if (this.siloOptions.ClusterId == clusterId) { var g = (ILogConsistencyProtocolParticipant)grain; // we are on the same scheduler, so we can call the method directly return(await g.OnProtocolMessageReceived(payload)); } // cannot send to remote instance if there is only one instance if (RegistrationStrategy.Equals(GlobalSingleInstanceRegistration.Singleton)) { throw new ProtocolTransportException("cannot send protocol message to remote instance because there is only one global instance"); } if (!this.MultiClusterEnabled) { throw new ProtocolTransportException("no such cluster"); } if (log != null && log.IsEnabled(LogLevel.Trace)) { var gws = this.multiClusterOracle.GetGateways(); log.Trace("Available Gateways:\n{0}", string.Join("\n", gws.Select((gw) => gw.ToString()))); } var clusterGateway = this.multiClusterOracle.GetRandomClusterGateway(clusterId); if (clusterGateway == null) { throw new ProtocolTransportException("no active gateways found for cluster"); } var repAgent = this.grainFactory.GetSystemTarget <ILogConsistencyProtocolGateway>(Constants.ProtocolGatewayId, clusterGateway); // test hook var filter = (this.multiClusterOracle as MultiClusterOracle)?.ProtocolMessageFilterForTesting; if (filter != null && !filter(payload)) { return(null); } try { var retMessage = await repAgent.RelayMessage(GrainReference.GrainId, payload); return(retMessage); } catch (Exception e) { throw new ProtocolTransportException("failed sending message to cluster", e); } }
/// <inheritdoc/> protected override Task <ILogConsistencyProtocolMessage> OnMessageReceived(ILogConsistencyProtocolMessage payload) { var request = (ReadRequest)payload; var response = new ReadResponse <TLogView>() { Version = version }; // optimization: include value only if version is newer if (version > request.KnownVersion) { response.Value = cached; } return(Task.FromResult <ILogConsistencyProtocolMessage>(response)); }
/// <summary> /// Called from network /// </summary> /// <param name="payLoad"></param> /// <returns></returns> public async Task <ILogConsistencyProtocolMessage> OnProtocolMessageReceived(ILogConsistencyProtocolMessage payLoad) { var notificationMessage = payLoad as INotificationMessage; if (notificationMessage != null) { Services.Log(LogLevel.Debug, "NotificationReceived v{0}", notificationMessage.Version); OnNotificationReceived(notificationMessage); // poke worker so it will process the notifications worker.Notify(); return(null); } else { //it's a protocol message return(await OnMessageReceived(payLoad)); } }
/// <inheritdoc/> protected override Task <ILogConsistencyProtocolMessage> OnMessageReceived(ILogConsistencyProtocolMessage payload) { var request = (ReadRequest)payload; if (!MayAccessStorage()) { throw new ProtocolTransportException("message destined for primary cluster ended up elsewhere (inconsistent configurations?)"); } var response = new ReadResponse <TLogView>() { Version = version }; // optimization: include value only if version is newer if (version > request.KnownVersion) { response.Value = cached; } return(Task.FromResult <ILogConsistencyProtocolMessage>(response)); }
public async Task <ILogConsistencyProtocolMessage> RelayMessage(GrainId id, ILogConsistencyProtocolMessage payload) { var g = this.RuntimeClient.InternalGrainFactory.GetGrain <ILogConsistencyProtocolParticipant>(id); return(await g.OnProtocolMessageReceived(payload)); }
/// <summary> /// Handle protocol messages. /// </summary> protected virtual Task <ILogConsistencyProtocolMessage> OnMessageReceived(ILogConsistencyProtocolMessage payload) { // subclasses that define custom protocol messages must override this throw new NotImplementedException(); }
public async Task <ILogConsistencyProtocolMessage> RelayMessage(GrainId id, ILogConsistencyProtocolMessage payload) { var g = InsideRuntimeClient.Current.InternalGrainFactory.Cast <ILogConsistencyProtocolParticipant>(GrainReference.FromGrainId(id)); return(await g.OnProtocolMessageReceived(payload)); }
public async Task <ILogConsistencyProtocolMessage> SendMessage(ILogConsistencyProtocolMessage payload, string clusterId) { var silo = Silo.CurrentSilo; var mycluster = silo.ClusterId; var oracle = silo.LocalMultiClusterOracle; log?.Verbose3("SendMessage {0}->{1}: {2}", mycluster, clusterId, payload); // send the message to ourself if we are the destination cluster if (mycluster == clusterId) { var g = (ILogConsistencyProtocolParticipant)grain; // we are on the same scheduler, so we can call the method directly return(await g.OnProtocolMessageReceived(payload)); } // cannot send to remote instance if there is only one instance if (RegistrationStrategy.Equals(GlobalSingleInstanceRegistration.Singleton)) { throw new ProtocolTransportException("cannot send protocol message to remote instance because there is only one global instance"); } if (PseudoMultiClusterConfiguration != null) { throw new ProtocolTransportException("no such cluster"); } if (log != null && log.IsVerbose3) { var gws = oracle.GetGateways(); log.Verbose3("Available Gateways:\n{0}", string.Join("\n", gws.Select((gw) => gw.ToString()))); } var clusterGateway = oracle.GetRandomClusterGateway(clusterId); if (clusterGateway == null) { throw new ProtocolTransportException("no active gateways found for cluster"); } var repAgent = InsideRuntimeClient.Current.InternalGrainFactory.GetSystemTarget <ILogConsistencyProtocolGateway>(Constants.ProtocolGatewayId, clusterGateway); // test hook var filter = (oracle as MultiClusterNetwork.MultiClusterOracle).ProtocolMessageFilterForTesting; if (filter != null && !filter(payload)) { return(null); } try { var retMessage = await repAgent.RelayMessage(GrainReference.GrainId, payload); return(retMessage); } catch (Exception e) { throw new ProtocolTransportException("failed sending message to cluster", e); } }