Esempio n. 1
0
        /// <inheritdoc />
        public void DeleteObjectReference(IAddressable obj)
        {
            if (!(obj is GrainReference reference))
            {
                throw new ArgumentException("Argument reference is not a grain reference.");
            }

            if (!ObserverGrainId.TryParse(reference.GrainId, out var observerId))
            {
                throw new ArgumentException($"Reference {reference.GrainId} is not an observer reference");
            }

            if (!invokableObjects.TryDeregister(observerId))
            {
                throw new ArgumentException("Reference is not associated with a local object.", "reference");
            }
        }
Esempio n. 2
0
        /// <summary>Constructs a reference to the grain with the specified Id.</summary>
        /// <param name="grainId">The Id of the grain to refer to.</param>
        /// <param name="genericArgument">Type arguments in case of a generic grain.</param>
        /// <param name="runtime">The runtime which this grain reference is bound to.</param>
        private GrainReference(GrainId grainId, string genericArgument, IGrainReferenceRuntime runtime)
        {
            GrainId = grainId;
            this.genericArguments = genericArgument;
            this.runtime          = runtime;
            if (string.IsNullOrEmpty(genericArgument))
            {
                genericArguments = null; // always keep it null instead of empty.
            }

            // SystemTarget checks
            var isSystemTarget = grainId.IsSystemTarget();

            if (SystemTargetGrainId.TryParse(grainId, out var systemTargetId))
            {
                this.SystemTargetSilo = systemTargetId.GetSiloAddress();
                if (SystemTargetSilo == null)
                {
                    throw new ArgumentNullException("systemTargetSilo", String.Format("Trying to create a GrainReference for SystemTarget grain id {0}, but passing null systemTargetSilo.", grainId));
                }

                if (genericArguments != null)
                {
                    throw new ArgumentException(String.Format("Trying to create a GrainReference for SystemTarget grain id {0}, and also passing non-null genericArguments {1}.", grainId, genericArguments), "genericArgument");
                }
            }

            // ObserverId checks
            var isClient = grainId.IsClient();

            if (isClient)
            {
                // Note: we can probably just remove this check - it serves little purpose.
                if (!ObserverGrainId.TryParse(grainId, out _))
                {
                    throw new ArgumentNullException("observerId", String.Format("Trying to create a GrainReference for Observer with Client grain id {0}, but passing null observerId.", grainId));
                }

                if (genericArguments != null)
                {
                    throw new ArgumentException(String.Format("Trying to create a GrainReference for Client grain id {0}, and also passing non-null genericArguments {1}.", grainId, genericArguments), "genericArgument");
                }
            }
        }
Esempio n. 3
0
        /// <inheritdoc />
        public GrainReference CreateObjectReference(IAddressable obj, IGrainMethodInvoker invoker)
        {
            if (obj is GrainReference)
            {
                throw new ArgumentException("Argument obj is already a grain reference.");
            }

            var observerId     = ObserverGrainId.Create(this.ClientId);
            var grainReference = GrainReference.NewObserverGrainReference(observerId, this.grainReferenceRuntime);

            if (!this.invokableObjects.TryRegister(obj, observerId, invoker))
            {
                throw new ArgumentException(
                          string.Format("Failed to add new observer {0} to localObjects collection.", grainReference),
                          nameof(grainReference));
            }

            return(grainReference);
        }
Esempio n. 4
0
 internal static GrainReference NewObserverGrainReference(ObserverGrainId observerId, IGrainReferenceRuntime runtime)
 {
     return(new GrainReference(observerId.GrainId, null, runtime));
 }