reef-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Julia Wang (QIUHE)" <Qiuhe.W...@microsoft.com.INVALID>
Subject RE: Tang problem
Date Thu, 13 Apr 2017 17:17:14 GMT
I am not sure why you have a parameter like this:
            [Parameter(typeof(NetworkOptions.NetService))] INetworkService<string> networkService,
INetworkService is an interface, you don't need to define named parameter for it. You can
directly put the following line as a parameter in the constructor. 

If you really want to use named parameter for this case, then NetService must be defined as
a named parameter. But in your code, it is defined as a RequiredParameter
            public static readonly RequiredParameter<INetworkService<string>>
NetService = new RequiredParameter<INetworkService<string>>();

You should not bind an interface into a required parameter in configuration module. It should
be opposite. 
.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class, GenericType<INetworkService<string>>.Class)

To fix it, 
1. put this line in the constructor instead of [parameter...]
	INetworkService<string> networkService

2. Define the following in the ModuleBuilder
	 public static readonly RequiredImpl<INetworkService <string>> NetService = new
RequiredImpl<INetworkService<string>>();
and 
  	.BindImplementation(GenericType<INetworkService <string>>.Class, NetworkOptions
.NetService)

3. When you create clientNetworkConfig, 
	.Set(NetworkOptions.NetService, GenericType<NetworkService<string>>.Class)

Hope that helps.

Julia

-----Original Message-----
From: Douglas Service [mailto:dsopsrc@gmail.com] 
Sent: Wednesday, April 12, 2017 3:58 PM
To: dev@reef.apache.org
Subject: Tang problem

Given the following constructor.


        [Inject]
        private ClientNetworkService(
            [Parameter(typeof(NetworkOptions.NetService))]
INetworkService<string> networkService,
            [Parameter(typeof(NetworkOptions.ServiceIdentifier))] string serviceIdentifier,
            [Parameter(typeof(NetworkOptions.ServicePort))] int servicePort,
            [Parameter(typeof(NetworkOptions.RemoteServiceIdentifier))]
string remoteServiceIdentifier)

with the following module builder


        public sealed class ModuleBuilder : ConfigurationModuleBuilder
        {
            public static readonly RequiredParameter<INetworkService<string>>
NetService = new RequiredParameter<INetworkService<string>>();
            public static readonly RequiredParameter<string> ServiceIdentifier = new
RequiredParameter<string>();
            public static readonly RequiredParameter<int> ServicePort = new RequiredParameter<int>();
            public static readonly RequiredParameter<string> RemoteServiceIdentifier
= new RequiredParameter<string>();

            // public static readonly
RequiredParameter<IObserver<NsMessage<string>>>
ClientMessageHandler
            //  = new RequiredParameter<IObserver<NsMessage<string>>>();
            // .BindNamedParameter(GenericType<NetworkOptions.kService>.Class,
NetworkService)
            public static readonly ConfigurationModule Config = new
ModuleBuilder()
                .BindImplementation(GenericType<INetworkService<string>>.Class,
GenericType<NetworkService<string>>.Class)

.BindNamedParameter(GenericType<NetworkOptions.NetService>.Class,
GenericType<INetworkService<string>>.Class)

.BindNamedParameter(GenericType<NetworkOptions.ServiceIdentifier>.Class,
ServiceIdentifier)

.BindNamedParameter(GenericType<NetworkOptions.ServicePort>.Class,
ServicePort)
                .BindNamedParameter(GenericType<NetworkOptions.
RemoteServiceIdentifier>.Class, RemoteServiceIdentifier)
                .Build();

                //
.BindNamedParameter(GenericType<DistRNetworkOptions.MessageHandler>.Class,
MessageHandler)
        }

When I try to inject,

           IConfiguration nameClientConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindNamedParameter<NamingConfigurationOptions.NameServerPort,
int>(
                    GenericType<NamingConfigurationOptions.
NameServerPort>.Class,
                    endpoint.Port.ToString(CultureInfo.CurrentCulture))

.BindNamedParameter<NamingConfigurationOptions.NameServerAddress,
string>(

GenericType<NamingConfigurationOptions.NameServerAddress>.Class,
endpoint.Address.ToString())
                .BindImplementation(GenericType<INameClient>.Class,
GenericType<NameClient>.Class)
                .Build();

            IConfiguration networkServiceConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindIntNamedParam<NetworkServiceOptions.
NetworkServicePort>(servicePort.ToString())
                .Build();

            IConfiguration handlerConf = TangFactory.GetTang().
NewConfigurationBuilder()
                .BindImplementation<IObserver<NsMessage<string>>,
ClientMessageHandler>()
                .Build();

            !!!!!!!!!!!THROWS!!!!!!!!!!!!
            IConfiguration clientNetworkConfig = NetworkOptions.ModuleBuilder.Config
                .Set(NetworkOptions.ModuleBuilder.NetService,
GenericType<INetworkService<string>>.Class)
                .Set(NetworkOptions.ModuleBuilder.ServiceIdentifier,
clientId)
                .Set(NetworkOptions.ModuleBuilder.ServicePort,
servicePort.ToString())
                .Set(NetworkOptions.ModuleBuilder.RemoteServiceIdentifier,
driverId)
                .Build();

            TangFactory.GetTang().NewInjector(GetRuntimeConfiguration(args.Length
> 0 ? args[0] : Local),
                nameClientConf, networkServiceConf, handlerConf, clientNetworkConfig).GetInstance<DistributedRClient>().Run();

the line with "!!!!!!!!!!!THROWS!!!!!!!!!!!!"  throws this exception


System.TypeInitializationException occurred
  HResult=0x80131534
  Message=The type initializer for 'ModuleBuilder' threw an exception.
  Source=Org.Apache.REEF.DistributedR
  StackTrace:
   at Org.Apache.REEF.DistributedR.DistributedRClient.Main(String[] args) in E:\reef\lang\cs\Org.Apache.REEF.DistributedR\DistributedRClient.cs:line
184

Inner Exception 1:
ClassHierarchyException: Found declared options that were not used in
binds: { NetService }


However when I remove it and the corresponding code in the ModuleBuilder, I also get an exception
about not being able to RDistributedR class.

What am i missing?

Doug
Mime
View raw message