object GetInstance(MessageHeaders headers, Type actorType) { ActorId id = ActorIdHelper.Get(headers); object instance = Activator.CreateInstance(actorType, new ActorService(), id); return(instance); }
object GetInstance(MessageHeaders headers, Type actorType) { ActorId id = ActorIdHelper.Get(headers); ServiceContext context = ServiceContextHelper.Get(headers); ActorService service = (context == null) ? new ActorService(null, ActorTypeInformation.Get(actorType)) : new ActorService(new StatefulServiceContext(context.ServiceName), ActorTypeInformation.Get(actorType)); object instance = Activator.CreateInstance(actorType, service, id); return(instance); }
public InstanceContext GetExistingInstanceContext(Message message, IContextChannel channel) { //No OperationContext here! try { m_InstanceAccess.WaitOne(); //Remove the instance id context if it exists. Treat each message as an activation request so that we can reassign the InstanceId on the service-side. bool found = RemoveInstanceIdFromMessage(message); ActorId actorId = ActorIdHelper.Get(message.Headers); Guid instanceId = ActorManager.GetInstance(actorId); ActorManager.UpdateIdleTime(actorId); if ((instanceId.Equals(Guid.Empty)) && (message.Headers.Action.Contains("Activate") == false)) { //Message received after actor instance completed. Can only occur when a client improperly caches an ActorProxy after completing the instance. //Clear context and reset InstanceId so that InitializeInstanceContext can handle the message as an initiating request. message.Properties.Remove(ContextMessageProperty.Name); } else if (instanceId.Equals(Guid.Empty) == false) { //Always use the managed InstanceId. It may differ from the InstanceId in the ActorId context after an Actor completion. SetInstanceIdInMessage(message, instanceId.ToString()); } InstanceContext context = m_PreviousProvider.GetExistingInstanceContext(message, channel); if (context != null) { m_InstanceAccess.ReleaseMutex(); } return(context); } catch (Exception exception) { m_InstanceAccess.ReleaseMutex(); throw exception; } }