public static ActorRemotingProviderAttribute GetProvider(IEnumerable <Type> types = null) { if (types != null) { foreach (Type type in types) { ActorRemotingProviderAttribute customAttribute = type.GetTypeInfo().Assembly.GetCustomAttribute <ActorRemotingProviderAttribute>(); if (customAttribute != null) { return(customAttribute); } } } Assembly entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly != (Assembly)null) { ActorRemotingProviderAttribute customAttribute = entryAssembly.GetCustomAttribute <ActorRemotingProviderAttribute>(); if (customAttribute != null) { return(customAttribute); } } return((ActorRemotingProviderAttribute) new FabricTransportActorRemotingProviderAttribute()); }
private IServiceRemotingClientFactory CreateServiceRemotingClientFactory(Type actorInterfaceType) { var factory = this.CreateServiceRemotingClientFactory(ActorEventSubscriberManager.Singleton); if (factory == null) { var provider = ActorRemotingProviderAttribute.GetProvider(new[] { actorInterfaceType }); factory = provider.CreateServiceRemotingClientFactory(ActorEventSubscriberManager.Singleton); } return(factory); }
public static ICommunicationListener CreateActorServiceRemotingListener( ActorService actorService) { var types = new List <Type> { actorService.ActorTypeInformation.ImplementationType }; types.AddRange(actorService.ActorTypeInformation.InterfaceTypes); var provider = ActorRemotingProviderAttribute.GetProvider(types); return(provider.CreateServiceRemotingListener(actorService)); }
protected override IEnumerable <ServiceReplicaListener> CreateServiceReplicaListeners() { //collect base types where actor attribute can be defined var typeList = new List <Type> { ActorTypeInformation.ImplementationType }; typeList.AddRange(ActorTypeInformation.InterfaceTypes); //get provider attribute that can override listener endpoints ActorRemotingProviderAttribute provider = ActorHelper.GetProvider(typeList); //create service remoting listeners the correct way var replicaListeners = new List <ServiceReplicaListener>(); if (Helper.IsEitherRemotingV2(provider.RemotingListenerVersion)) { foreach (KeyValuePair <string, Func <ActorService, IServiceRemotingListener> > remotingListener in provider.CreateServiceRemotingListeners()) { //create our own correlating message handler var handler = new CorrelatingRemotingMessageHandler( L.G(GetType()), //the most upstream type's log this); string listenerName = remotingListener.Key; Func <ActorService, IServiceRemotingListener> createCommunicationListener = remotingListener.Value; /*Func<ActorService, IServiceRemotingListener> debug = a => * { * IServiceRemotingListener result = createCommunicationListener(a); * * return result; * };*/ var listener = new ServiceReplicaListener( c => new FabricTransportActorServiceRemotingListener(c, handler), listenerName, false); /*var listener = new ServiceReplicaListener( * //context => createCommunicationListener(this), * context => debug(this), * listenerName, * false);*/ replicaListeners.Add(listener); } } return(replicaListeners); }
/// <summary> /// Overrides <see cref="Microsoft.ServiceFabric.Services.Runtime.StatefulServiceBase.CreateServiceReplicaListeners()"/>. /// </summary> /// <returns>Endpoint string pairs like /// {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}</returns> protected override IEnumerable <ServiceReplicaListener> CreateServiceReplicaListeners() { var types = new List <Type> { this.ActorTypeInformation.ImplementationType }; types.AddRange(this.ActorTypeInformation.InterfaceTypes); var provider = ActorRemotingProviderAttribute.GetProvider(types); #if !DotNetCoreClr if (provider.RemotingListener.Equals(RemotingListener.V2Listener)) { return(new[] { new ServiceReplicaListener((t) => { return provider.CreateServiceRemotingListenerV2(this); }, ServiceRemotingProviderAttribute.DefaultV2listenerName ) }); } if (provider.RemotingListener.Equals(RemotingListener.CompatListener)) { return(new[] { new ServiceReplicaListener((t) => { return provider.CreateServiceRemotingListener(this); }, "" ), new ServiceReplicaListener((t) => { return provider.CreateServiceRemotingListenerV2(this); }, ServiceRemotingProviderAttribute.DefaultV2listenerName ) }); } else { return(new[] { new ServiceReplicaListener((t) => { return provider.CreateServiceRemotingListener(this); }, "" ) }); } #else return(new[] { new ServiceReplicaListener((t) => { return provider.CreateServiceRemotingListenerV2(this); }, ServiceRemotingProviderAttribute.DefaultV2listenerName ) }); #endif }
public static string GetDefaultListenerName <TActorInterface>(out ActorRemotingProviderAttribute providerAttribute) where TActorInterface : IActor { providerAttribute = GetProvider(new[] { typeof(TActorInterface) }); if (Helper.IsEitherRemotingV2(providerAttribute.RemotingClientVersion)) { if (Helper.IsRemotingV2_1(providerAttribute.RemotingClientVersion)) { return("V2_1Listener"); } return("V2Listener"); } return(null); }
private ActorRemotingProviderAttribute GetProviderAttribute(Type actorInterfaceType) { return(ActorRemotingProviderAttribute.GetProvider(new[] { actorInterfaceType })); }
/// <summary> /// Creates an <see cref="ActorTypeInformation"/> from actorType. /// </summary> /// <param name="actorType">The type of class implementing the actor to create ActorTypeInforamtion for.</param> /// <returns><see cref="ActorTypeInformation"/> created from actorType.</returns> /// <exception cref="System.ArgumentException"> /// <para>When <see cref="System.Type.BaseType"/> for actorType is not of type <see cref="Actor"/>.</para> /// <para>When actorType does not implement an interface deriving from <see cref="IActor"/> /// and is not marked as abstract.</para> /// <para>When actorType implements more than one interface which derives from <see cref="IActor"/> /// but doesn't have <see cref="ActorServiceAttribute"/>.</para> /// </exception> public static ActorTypeInformation Get(Type actorType) { if (!actorType.IsActor()) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, SR.ErrorNotAnActor, actorType.FullName, typeof(Actor).FullName), "actorType"); } string actorServiceName = null; var actorServiceAttr = ActorServiceAttribute.Get(actorType); if (actorServiceAttr != null) { actorServiceName = actorServiceAttr.Name; } // get all actor interfaces var actorInterfaces = actorType.GetActorInterfaces(); // ensure that the if the actor type is not abstract it implements at least one actor interface if ((actorInterfaces.Length == 0) && (!actorType.GetTypeInfo().IsAbstract)) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, SR.ErrorNoActorInterfaceFound, actorType.FullName, typeof(IActor).FullName), "actorType"); } // ensure that all actor interfaces can be remoted foreach (var actorInterface in actorInterfaces) { ActorInterfaceDescription.Create(actorInterface); } // if the actor implements more than one actor interfaces make sure that it has actorServiceName if ((actorInterfaces.Length > 1) && string.IsNullOrEmpty(actorServiceName) && (!actorType.GetTypeInfo().IsAbstract)) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, SR.ErrorNoActorServiceNameMultipleInterfaces, actorType.FullName, typeof(ActorServiceAttribute).FullName), "actorType"); } // get actor event interfaces var eventInterfaces = actorType.GetActorEventInterfaces(); // ensure that all of the event interfaces can be remoted if (eventInterfaces != null) { foreach (var eventInterface in eventInterfaces) { ActorEventInterfaceDescription.Create(eventInterface); } } var types = new List <Type> { actorType }; types.AddRange(actorInterfaces); #if !DotNetCoreClr var remotingserver = Services.Remoting.RemotingListener.V1Listener; #else var remotingserver = Services.Remoting.RemotingListener.V2Listener; #endif var remotingserverAttribuite = ActorRemotingProviderAttribute.GetProvider(types); if (remotingserverAttribuite != null) { remotingserver = remotingserverAttribuite.RemotingListener; } return(new ActorTypeInformation() { InterfaceTypes = actorInterfaces, ImplementationType = actorType, ServiceName = actorServiceName, IsAbstract = actorType.GetTypeInfo().IsAbstract, IsRemindable = actorType.IsRemindableActor(), EventInterfaceTypes = eventInterfaces, StatePersistence = StatePersistenceAttribute.Get(actorType).StatePersistence, RemotingListener = remotingserver }); }