internal static bool HasPersistantStateProvider(Type serviceType) { bool hasPersistentprovider = false; StatePersistenceAttribute persistenceMode = serviceType.GetCustomAttribute <StatePersistenceAttribute>(); if (persistenceMode != null) { hasPersistentprovider = persistenceMode.StatePersistence == StatePersistence.Persisted; } return(hasPersistentprovider); }
void EnforceStatefulActorBehaviorPolicy(ServiceDescription serviceDescription) { ServiceBehaviorAttribute serviceBehavior = serviceDescription.Behaviors.Find <ServiceBehaviorAttribute>(); if (serviceBehavior != null) { Debug.Assert(serviceBehavior.InstanceContextMode == InstanceContextMode.PerSession); Debug.Assert(serviceBehavior.ConcurrencyMode == ConcurrencyMode.Single); serviceBehavior.InstanceContextMode = InstanceContextMode.PerSession; serviceBehavior.ConcurrencyMode = ConcurrencyMode.Single; serviceBehavior.MaxItemsInObjectGraph = int.MaxValue; serviceBehavior.UseSynchronizationContext = false; } DurableServiceAttribute durableService = new DurableServiceAttribute(); durableService.SaveStateInOperationTransaction = true; serviceDescription.Behaviors.Add(durableService); if (serviceDescription.Behaviors.Any(behavior => behavior is ActorStateProviderAttribute) == false) { StatePersistenceAttribute persistenceMode = serviceDescription.ServiceType.GetCustomAttribute <StatePersistenceAttribute>(); if (persistenceMode == null) { throw new InvalidOperationException("Validation failed. Actor " + serviceDescription.ServiceType.Name + " is missing a StatePersistenceAttribute."); } else { if (persistenceMode.StatePersistence != StatePersistence.Persisted) { serviceDescription.Behaviors.Add(new VolatileActorStateProviderAttribute()); } else { serviceDescription.Behaviors.Add(new KvsActorStateProviderAttribute()); } } } serviceDescription.SetThrottle(); ServiceThrottlingBehavior throttle = serviceDescription.Behaviors.Find <ServiceThrottlingBehavior>(); if (throttle != null) { throttle.MaxConcurrentInstances = int.MaxValue; } }
internal static I Create <I>(ActorId actorId, string applicationName, string serviceName, ProxyRemotingInvoker invoker, ProxyRemotingInterceptor remotingInterceptor) where I : class, IActor { Debug.Assert(FabricRuntime.Actors.ContainsKey(applicationName), "Invalid application name '" + applicationName + "' in service Uri."); Type actorType = FabricRuntime.Actors[applicationName].SingleOrDefault(type => type.GetInterfaces().Where(interfaceType => ((IsInfrastructureEndpoint(interfaceType) == false) && (interfaceType == typeof(I)))).Any()); Debug.Assert(actorType != null); Debug.Assert(actorType.BaseType != null); bool actorExists = actorType.GetCustomAttributes <ApplicationManifestAttribute>().Where(attribute => attribute.ApplicationName.Equals(applicationName)).Any(attribute => attribute.ServiceName.Equals(serviceName)); Debug.Assert(actorExists, "Invalid actor name '" + serviceName + "' in service Uri."); if (!actorExists) { throw new InvalidOperationException("Service does not exist."); } IServiceBehavior actorBehavior = null; StatePersistenceAttribute persistenceMode = actorType.GetCustomAttribute <StatePersistenceAttribute>(); if (persistenceMode == null) { throw new InvalidOperationException("Validation failed. Actor " + actorType.Name + " is missing a StatePersistenceAttribute."); } else { actorBehavior = new StatefulActorBehavior(); } if (actorBehavior == null) { throw new InvalidOperationException("Validation failed."); } if ((ServiceTestBase.ActorMocks != null) && (ServiceTestBase.ActorMocks.ContainsKey(actorType)) && (ServiceTestBase.ActorMocks[actorType] != null)) { I mock = null; if (ServiceTestBase.ActorMocks[actorType] is Moq.Mock) { mock = ((Moq.Mock)ServiceTestBase.ActorMocks[actorType]).Object as I; } else { mock = ServiceTestBase.ActorMocks[actorType] as I; } if (mock != null) { return(mock); } } try { actorId.ApplicationName = applicationName; actorId.ActorInterfaceName = typeof(I).FullName; actorId.ActorServiceName = serviceName; ServiceContext context = new ServiceContext { ServiceName = new Uri("fabric:/" + applicationName + "/" + serviceName) }; MethodInfo initializeInstance = m_InitializeInstanceDefinition.MakeGenericMethod(actorType, typeof(I)); ChannelFactory <I> factory = initializeInstance.Invoke(null, new object[] { actorBehavior, new ProxyMessageInterceptor(actorId, context, remotingInterceptor), m_ProxyBinding, m_ActorBinding }) as ChannelFactory <I>; I channel = new ActorChannelInvoker <I>().Install(factory, actorId, invoker); channel.ActivateAsync().Wait(); return(channel); } catch (TargetInvocationException exception) { throw exception.InnerException; } }