本文整理汇总了C#中IInjector.ForkInjector方法的典型用法代码示例。如果您正苦于以下问题:C# IInjector.ForkInjector方法的具体用法?C# IInjector.ForkInjector怎么用?C# IInjector.ForkInjector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IInjector
的用法示例。
在下文中一共展示了IInjector.ForkInjector方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContextRuntime
/// <summary>
/// Create a new ContextRuntime.
/// </summary>
/// <param name="serviceInjector"></param>
/// <param name="contextConfiguration">the Configuration for this context.</param>
/// <param name="parentContext"></param>
public ContextRuntime(
IInjector serviceInjector,
IConfiguration contextConfiguration,
Optional<ContextRuntime> parentContext)
{
ContextConfiguration config = contextConfiguration as ContextConfiguration;
if (config == null)
{
var e = new ArgumentException("contextConfiguration is not of type ContextConfiguration");
Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER);
}
_contextLifeCycle = new ContextLifeCycle(config.Id);
_serviceInjector = serviceInjector;
_parentContext = parentContext;
try
{
_contextInjector = serviceInjector.ForkInjector();
}
catch (Exception e)
{
Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Error, LOGGER);
Optional<string> parentId = ParentContext.IsPresent() ?
Optional<string>.Of(ParentContext.Value.Id) :
Optional<string>.Empty();
ContextClientCodeException ex = new ContextClientCodeException(ContextClientCodeException.GetId(contextConfiguration), parentId, "Unable to spawn context", e);
Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(ex, LOGGER);
}
// Trigger the context start events on contextInjector.
_contextLifeCycle.Start();
}
示例2: GroupCommClient
public GroupCommClient(
[Parameter(typeof(GroupCommConfigurationOptions.SerializedGroupConfigs))] ISet<string> groupConfigs,
[Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId,
StreamingNetworkService<GeneralGroupCommunicationMessage> networkService,
AvroConfigurationSerializer configSerializer,
IInjector injector)
{
_commGroups = new Dictionary<string, ICommunicationGroupClientInternal>();
_networkService = networkService;
foreach (string serializedGroupConfig in groupConfigs)
{
IConfiguration groupConfig = configSerializer.FromString(serializedGroupConfig);
IInjector groupInjector = injector.ForkInjector(groupConfig);
var commGroupClient = (ICommunicationGroupClientInternal)groupInjector.GetInstance<ICommunicationGroupClient>();
_commGroups[commGroupClient.GroupName] = commGroupClient;
}
networkService.Register(new StringIdentifier(taskId));
foreach (var group in _commGroups.Values)
{
group.WaitingForRegistration();
}
}
示例3: ContextRuntime
/// <summary>
/// Create a new ContextRuntime.
/// </summary>
/// <param name="serviceInjector"></param>
/// <param name="contextConfiguration">the Configuration for this context.</param>
/// <param name="parentContext"></param>
public ContextRuntime(
IInjector serviceInjector,
IConfiguration contextConfiguration,
Optional<ContextRuntime> parentContext)
{
_serviceInjector = serviceInjector;
_contextInjector = serviceInjector.ForkInjector(contextConfiguration);
_contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
_parentContext = parentContext;
_contextLifeCycle.Start();
}
示例4: ContextRuntime
/// <summary>
/// Create a new ContextRuntime.
/// </summary>
/// <param name="serviceInjector"></param>
/// <param name="contextConfiguration">the Configuration for this context.</param>
/// <param name="parentContext"></param>
public ContextRuntime(
IInjector serviceInjector,
IConfiguration contextConfiguration,
Optional<ContextRuntime> parentContext)
{
_serviceInjector = serviceInjector;
_injectedServices = Optional<ISet<object>>.Of(serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>());
_contextInjector = serviceInjector.ForkInjector(contextConfiguration);
_contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
_parentContext = parentContext;
_contextLifeCycle.Start();
}
示例5: RootContextLauncher
private RootContextLauncher(
IConfiguration contextConfiguration,
IConfiguration rootServiceConfig,
Optional<IConfiguration> rootTaskConfig,
IInjector injector)
{
_rootContextConfiguration = contextConfiguration;
_rootServiceInjector = injector.ForkInjector(rootServiceConfig);
Id = _rootServiceInjector
.ForkInjector(contextConfiguration)
.GetNamedInstance<ContextConfigurationOptions.ContextIdentifier, string>();
_services = _rootServiceInjector.GetNamedInstance<ServicesSet, ISet<object>>();
Logger.Log(Level.Verbose, string.Format(CultureInfo.InvariantCulture, "injected service(s)"));
RootTaskConfig = rootTaskConfig;
}
示例6: GroupCommClient
private GroupCommClient(
[Parameter(typeof(GroupCommConfigurationOptions.SerializedGroupConfigs))] ISet<string> groupConfigs,
[Parameter(typeof(TaskConfigurationOptions.Identifier))] string taskId,
NetworkService<GroupCommunicationMessage> networkService,
AvroConfigurationSerializer configSerializer,
IInjector injector)
{
_commGroups = new Dictionary<string, ICommunicationGroupClient>();
_networkService = networkService;
networkService.Register(new StringIdentifier(taskId));
foreach (string serializedGroupConfig in groupConfigs)
{
IConfiguration groupConfig = configSerializer.FromString(serializedGroupConfig);
IInjector groupInjector = injector.ForkInjector(groupConfig);
ICommunicationGroupClient commGroupClient = groupInjector.GetInstance<ICommunicationGroupClient>();
_commGroups[commGroupClient.GroupName] = commGroupClient;
}
}
示例7: ForksInjectorInConstructor
public ForksInjectorInConstructor(IInjector i)
{
ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(new string[] { @"Org.Apache.REEF.Tang.Examples" });
//cb.BindImplementation(Number.class, typeof(Int32));
i.ForkInjector(cb.Build());
}
示例8: EvaluatorSettings
private EvaluatorSettings(
[Parameter(typeof(ApplicationIdentifier))] string applicationId,
[Parameter(typeof(EvaluatorIdentifier))] string evaluatorId,
[Parameter(typeof(EvaluatorHeartbeatPeriodInMs))] int heartbeatPeriodInMs,
[Parameter(typeof(HeartbeatMaxRetry))] int maxHeartbeatRetries,
[Parameter(typeof(RootContextConfiguration))] string rootContextConfigString,
AvroConfigurationSerializer serializer,
RuntimeClock clock,
IRemoteManagerFactory remoteManagerFactory,
REEFMessageCodec reefMessageCodec,
IInjector injector,
INameClient nameClient)
{
_serializer = serializer;
_injector = injector;
_applicationId = applicationId;
_evaluatorId = evaluatorId;
_heartBeatPeriodInMs = heartbeatPeriodInMs;
_maxHeartbeatRetries = maxHeartbeatRetries;
_clock = clock;
if (string.IsNullOrWhiteSpace(rootContextConfigString))
{
Utilities.Diagnostics.Exceptions.Throw(
new ArgumentException("empty or null rootContextConfigString"), Logger);
}
_rootContextConfig = _serializer.FromString(rootContextConfigString);
try
{
_rootContextId = injector.ForkInjector(_rootContextConfig).GetNamedInstance<ContextConfigurationOptions.ContextIdentifier, string>();
}
catch (InjectionException)
{
Logger.Log(Level.Info, "Using deprecated ContextConfiguration.");
// TODO[JIRA REEF-1167]: Remove this catch.
var deprecatedContextConfig = new Context.ContextConfiguration(rootContextConfigString);
_rootContextConfig = deprecatedContextConfig;
_rootContextId = deprecatedContextConfig.Id;
}
_rootTaskConfiguration = CreateTaskConfiguration();
_rootServiceConfiguration = CreateRootServiceConfiguration();
_remoteManager = remoteManagerFactory.GetInstance(reefMessageCodec);
_operationState = EvaluatorOperationState.OPERATIONAL;
_nameClient = nameClient;
}
示例9: ForksInjectorInConstructor
public ForksInjectorInConstructor(IInjector i)
{
ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(new string[] { @"Com.Microsoft.Tang.Examples" });
//cb.BindImplementation(Number.class, typeof(Int32));
i.ForkInjector(new IConfiguration[] { cb.Build() });
}
示例10: ContextRuntime
/// <summary>
/// Create a new ContextRuntime.
/// </summary>
/// <param name="serviceInjector"></param>
/// <param name="contextConfiguration">the Configuration for this context.</param>
/// <param name="parentContext"></param>
public ContextRuntime(
IInjector serviceInjector,
IConfiguration contextConfiguration,
Optional<ContextRuntime> parentContext)
{
_serviceInjector = serviceInjector;
// Note that for Service objects and handlers, we are not merging them into a separate
// class (e.g. ServiceContainer) due to the inability to allow service stacking if an instance
// of such a class were to be materialized. i.e. if a ServiceContainer object were initialized
// and a child ServiceConfiguration is submitted, when the child service injector tries to
// get the relevant handlers and services set, it will get the same set of handlers as
// previously instantiated by the parent injector, and thus will not allow the stacking
// of ServiceConfigurations.
_injectedServices = serviceInjector.GetNamedInstance<ServicesSet, ISet<object>>();
_serviceContextStartHandlers =
serviceInjector.GetNamedInstance<ContextConfigurationOptions.StartHandlers, ISet<IObserver<IContextStart>>>();
_serviceContextStopHandlers =
serviceInjector.GetNamedInstance<ContextConfigurationOptions.StopHandlers, ISet<IObserver<IContextStop>>>();
_serviceTaskStartHandlers =
serviceInjector.GetNamedInstance<TaskConfigurationOptions.StartHandlers, ISet<IObserver<ITaskStart>>>();
_serviceTaskStopHandlers =
serviceInjector.GetNamedInstance<TaskConfigurationOptions.StopHandlers, ISet<IObserver<ITaskStop>>>();
_contextInjector = serviceInjector.ForkInjector(contextConfiguration);
_contextLifeCycle = _contextInjector.GetInstance<ContextLifeCycle>();
_parentContext = parentContext;
try
{
_contextLifeCycle.Start();
}
catch (Exception e)
{
const string message = "Encountered Exception in ContextStartHandler.";
if (ParentContext.IsPresent())
{
throw new ContextStartHandlerException(
Id, Optional<string>.Of(ParentContext.Value.Id), message, e);
}
throw new ContextStartHandlerException(Id, Optional<string>.Empty(), message, e);
}
}