You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@reef.apache.org by "Dudoladov, Sergey" <se...@tu-berlin.de> on 2015/08/17 13:53:01 UTC

DriverMessageHandler for hierarchies of Tasks.

Hi,

I have the following code:
1) The class "AbstractSuperTask"  implements "Task" interface and behavior common for subtasks.
2) Classes "Subtask A" and "Subtask B" inherit from  "AbstractSuperTask".

I'd like to define a DriverMessageHandler common to all subtasks, so it is logical to place it into "Supertask".
I do not override the handler.

When I do so, I get a runtime error:
 "java.lang.RuntimeException: org.apache.reef.tang.exceptions.InjectionException: Could not invoke constructor: new AbstractSuperTask". 

The source of the error is obvious, but I didn't find a way to configure tasks properly.

What is the correct approach to implement this in REEF ?

I currently hack the issue around by maintaining separate identical DriverMessageHandlers in each subtask, 
but that's inconvenient. 

Best,
Sergey.

Re: DriverMessageHandler for hierarchies of Tasks.

Posted by Markus Weimer <ma...@weimo.de>.
On 2015-08-26 04:59, Gyewon Lee wrote:
> Sorry for the late reply but I couldn't find REEF has no feature of
> sharing instances between REEF Tasks.

I'm not sure I follow. However, REEF can in fact share instances between
subsequent tasks. If by instance you mean objects, that is. Just bind
their Configuration to the Context and make sure they get instantiated
by the context start handler.

Background: The Evaluator instantiates Tasks using an injector forked
off of the Context injector. A forked injector shares all instances
created up to this point with the parent injector. This allows multiple
subsequent tasks to share objects.

Markus

Re: DriverMessageHandler for hierarchies of Tasks.

Posted by Gyewon Lee <st...@gmail.com>.
Hi, Sergey.

Sorry for the late reply but I couldn't find REEF has no feature of sharing
instances between REEF Tasks. So it's impossible for two subtasks share one
DriverMessageHandler right now.

Folks, can you confirm this? If there is no feature about this, how about
adding a feature of sharing instances between Task? From the Tang
perspective, it'd be enough if we can submit multiple Tasks at once with a
one single Configuration.

Thanks!

Best,
Gyewon

2015-08-19 23:37 GMT+08:00 Markus Weimer <ma...@weimo.de>:

> On 2015-08-19 06:56, Dudoladov, Sergey wrote:
> > As an inner class:
> >
> > [...]
> >
> > This evidently won't work, but I need something along these lines.
>
> There is no requirement for the `DriverMessageHandler` to be an inner
> class. You could make it its own class all by itself. That should work.
>
> Markus
>

Re: DriverMessageHandler for hierarchies of Tasks.

Posted by Markus Weimer <ma...@weimo.de>.
On 2015-08-19 06:56, Dudoladov, Sergey wrote:
> As an inner class:
> 
> [...]
> 
> This evidently won't work, but I need something along these lines.

There is no requirement for the `DriverMessageHandler` to be an inner
class. You could make it its own class all by itself. That should work.

Markus

Re: DriverMessageHandler for hierarchies of Tasks.

Posted by Gyewon Lee <st...@gmail.com>.
Hi, Sergey.

I still don't understand your question enough because I don't have an idea
of how you can inject both SubTaskA and SubTaskB. I guess that you are
using a two different configurations and submit SubTaskA and B separately,
right?

In that case, you cannot share a same handler between SubTaskA and B
statically. It's because each injector for SubTaskA and SubTaskB will
create a new instance for the handler, so putting DriverMessageHandler in
the shared abstract task does nothing on handler sharing.

One way for working around it is first making a SubTaskA and get a handler
instance from this. Then configure SubTaskB without DriverHandlerBinding
and bind the handler instance directly to the injector using
bindVolatile(). However, I'm not sure that currently REEF Task can be
configured dyamically, so I'll check if there is a way to dynamically
configure Tasks.

The other way is submit SubTaskA and B simultaneosly with just one
configuration. In that case, injector will be created only once so no two
DriverMessageHandler will be created. I will also check if there is a way
for it in current REEF.

For your last question, you may need cycle injection because handler and
Task should reference each other to see the Task's state from the handler.
In that case, you may use InjectionFuture for the constructor for handler.
You can do like,

@Inject
SubTaskA(DriverMessageHandler handler) {
  ...
}

@Inject
DriverMessageHandler(InjectionFuture<Task> injFuture, ...) {
  Task parentTask = injFuture.get()
}

Then I think you can check the status of Tasks by using parentTask instance.

Best,
Gyewon

2015-08-19 21:56 GMT+08:00 Dudoladov, Sergey <se...@tu-berlin.de>
:

> Thank you for the responses.
>
> >> How did you place the
> common DriverMessageHandler into SuperTask?
>
> As an inner class:
>
> @TaskSide
> @Unit
> public abstract  class SuperTask implements Task {
>
>    ...
>
>    public final class DriverMessageHandler
>             implements EventHandler<DriverMessage>{
>         ...
>     }
>
> }
>
> >> Could you please show me the
> >> code of your Tang configuration?
>
> taskConf = TaskConfiguration.CONF
>                   .set(TaskConfiguration.IDENTIFIER, newTaskID)
>                   .set(TaskConfiguration.TASK, taskClass)
>                   .set(TaskConfiguration.ON_MESSAGE,
>                           SuperTask.DriverMessageHandler.class)
>                   .build();
>
> This evidently won't work, but I need something along these lines.
>
> >> the common solution for the problem is to put
> DriverMessageHandler typed parameter to constructors of both SubTaskA and
> B.
>
> Then how would I access the internal state of Tasks in the handler
> onNext() method ?
> _________________________
> From: Gyewon Lee <st...@gmail.com>
> Sent: Monday, August 17, 2015 4:43 PM
> To: REEF Developers Mailinglist
> Subject: Re: DriverMessageHandler for hierarchies of Tasks.
>
> Hi, Sergey.
>
> I think I don't quite understand your question. How did you place the
> common DriverMessageHandler into SuperTask? Could you please show me the
> code of your Tang configuration?
>
> Anyway, I think the common solution for the problem is to put
> DriverMessageHandler typed parameter to constructors of both SubTaskA and
> B. Like,
>
> AbstractSuperTask(DriverMessageHandler handler, ...) {
>   ...
>   this.handler = handler;
> }
>
> SubTaskA(DriverMessageHandler handler, ...) {
>   ...
>   super(handler);
> }
>
> SubTaskB(DriverMessageHandler handler, ...) {
>   ...
>   super(handler);
> }
>
> ...
>
> cb.bindImplementation(DriverMessageHandler.class,
> DriverMessageHandlerImpl.class);
> cb.bindSetEntry(TaskSet.class, SubTaskA.class);
> cb.bindSetEntry(TaskSet.class, SubTaskB.class);
> ...
>
> By doing that, SubTaskA and SubTaskB would share a same instance of
> DriverMessageHandlerImpl so you don't have to make two identical handlers.
>
> If I understood wrong, please let me know and give me more hints like your
> configuration code.
>
> Best,
> Gyewon
>
>
> 2015-08-17 19:53 GMT+08:00 Dudoladov, Sergey <
> sergey.dudoladov@tu-berlin.de>
> :
>
> > Hi,
> >
> > I have the following code:
> > 1) The class "AbstractSuperTask"  implements "Task" interface and
> behavior
> > common for subtasks.
> > 2) Classes "Subtask A" and "Subtask B" inherit from  "AbstractSuperTask".
> >
> > I'd like to define a DriverMessageHandler common to all subtasks, so it
> is
> > logical to place it into "Supertask".
> > I do not override the handler.
> >
> > When I do so, I get a runtime error:
> >  "java.lang.RuntimeException:
> > org.apache.reef.tang.exceptions.InjectionException: Could not invoke
> > constructor: new AbstractSuperTask".
> >
> > The source of the error is obvious, but I didn't find a way to configure
> > tasks properly.
> >
> > What is the correct approach to implement this in REEF ?
> >
> > I currently hack the issue around by maintaining separate identical
> > DriverMessageHandlers in each subtask,
> > but that's inconvenient.
> >
> > Best,
> > Sergey.
>

Re: DriverMessageHandler for hierarchies of Tasks.

Posted by "Dudoladov, Sergey" <se...@tu-berlin.de>.
Thank you for the responses.

>> How did you place the
common DriverMessageHandler into SuperTask? 

As an inner class:

@TaskSide
@Unit
public abstract  class SuperTask implements Task {

   ...

   public final class DriverMessageHandler
            implements EventHandler<DriverMessage>{
        ...
    }
  
}

>> Could you please show me the
>> code of your Tang configuration?

taskConf = TaskConfiguration.CONF
                  .set(TaskConfiguration.IDENTIFIER, newTaskID)
                  .set(TaskConfiguration.TASK, taskClass)      
                  .set(TaskConfiguration.ON_MESSAGE,
                          SuperTask.DriverMessageHandler.class)
                  .build();

This evidently won't work, but I need something along these lines.

>> the common solution for the problem is to put
DriverMessageHandler typed parameter to constructors of both SubTaskA and
B. 

Then how would I access the internal state of Tasks in the handler onNext() method ?
_________________________
From: Gyewon Lee <st...@gmail.com>
Sent: Monday, August 17, 2015 4:43 PM
To: REEF Developers Mailinglist
Subject: Re: DriverMessageHandler for hierarchies of Tasks.

Hi, Sergey.

I think I don't quite understand your question. How did you place the
common DriverMessageHandler into SuperTask? Could you please show me the
code of your Tang configuration?

Anyway, I think the common solution for the problem is to put
DriverMessageHandler typed parameter to constructors of both SubTaskA and
B. Like,

AbstractSuperTask(DriverMessageHandler handler, ...) {
  ...
  this.handler = handler;
}

SubTaskA(DriverMessageHandler handler, ...) {
  ...
  super(handler);
}

SubTaskB(DriverMessageHandler handler, ...) {
  ...
  super(handler);
}

...

cb.bindImplementation(DriverMessageHandler.class,
DriverMessageHandlerImpl.class);
cb.bindSetEntry(TaskSet.class, SubTaskA.class);
cb.bindSetEntry(TaskSet.class, SubTaskB.class);
...

By doing that, SubTaskA and SubTaskB would share a same instance of
DriverMessageHandlerImpl so you don't have to make two identical handlers.

If I understood wrong, please let me know and give me more hints like your
configuration code.

Best,
Gyewon


2015-08-17 19:53 GMT+08:00 Dudoladov, Sergey <se...@tu-berlin.de>
:

> Hi,
>
> I have the following code:
> 1) The class "AbstractSuperTask"  implements "Task" interface and behavior
> common for subtasks.
> 2) Classes "Subtask A" and "Subtask B" inherit from  "AbstractSuperTask".
>
> I'd like to define a DriverMessageHandler common to all subtasks, so it is
> logical to place it into "Supertask".
> I do not override the handler.
>
> When I do so, I get a runtime error:
>  "java.lang.RuntimeException:
> org.apache.reef.tang.exceptions.InjectionException: Could not invoke
> constructor: new AbstractSuperTask".
>
> The source of the error is obvious, but I didn't find a way to configure
> tasks properly.
>
> What is the correct approach to implement this in REEF ?
>
> I currently hack the issue around by maintaining separate identical
> DriverMessageHandlers in each subtask,
> but that's inconvenient.
>
> Best,
> Sergey.

Re: DriverMessageHandler for hierarchies of Tasks.

Posted by Gyewon Lee <st...@gmail.com>.
Hi, Sergey.

I think I don't quite understand your question. How did you place the
common DriverMessageHandler into SuperTask? Could you please show me the
code of your Tang configuration?

Anyway, I think the common solution for the problem is to put
DriverMessageHandler typed parameter to constructors of both SubTaskA and
B. Like,

AbstractSuperTask(DriverMessageHandler handler, ...) {
  ...
  this.handler = handler;
}

SubTaskA(DriverMessageHandler handler, ...) {
  ...
  super(handler);
}

SubTaskB(DriverMessageHandler handler, ...) {
  ...
  super(handler);
}

...

cb.bindImplementation(DriverMessageHandler.class,
DriverMessageHandlerImpl.class);
cb.bindSetEntry(TaskSet.class, SubTaskA.class);
cb.bindSetEntry(TaskSet.class, SubTaskB.class);
...

By doing that, SubTaskA and SubTaskB would share a same instance of
DriverMessageHandlerImpl so you don't have to make two identical handlers.

If I understood wrong, please let me know and give me more hints like your
configuration code.

Best,
Gyewon


2015-08-17 19:53 GMT+08:00 Dudoladov, Sergey <se...@tu-berlin.de>
:

> Hi,
>
> I have the following code:
> 1) The class "AbstractSuperTask"  implements "Task" interface and behavior
> common for subtasks.
> 2) Classes "Subtask A" and "Subtask B" inherit from  "AbstractSuperTask".
>
> I'd like to define a DriverMessageHandler common to all subtasks, so it is
> logical to place it into "Supertask".
> I do not override the handler.
>
> When I do so, I get a runtime error:
>  "java.lang.RuntimeException:
> org.apache.reef.tang.exceptions.InjectionException: Could not invoke
> constructor: new AbstractSuperTask".
>
> The source of the error is obvious, but I didn't find a way to configure
> tasks properly.
>
> What is the correct approach to implement this in REEF ?
>
> I currently hack the issue around by maintaining separate identical
> DriverMessageHandlers in each subtask,
> but that's inconvenient.
>
> Best,
> Sergey.

Re: DriverMessageHandler for hierarchies of Tasks.

Posted by Markus Weimer <ma...@weimo.de>.
On 2015-08-17 04:53, Dudoladov, Sergey wrote:
> When I do so, I get a runtime error: "java.lang.RuntimeException:
> org.apache.reef.tang.exceptions.InjectionException: Could not invoke
> constructor: new AbstractSuperTask".
> 
> What is the correct approach to implement this in REEF ?

Have you tried binding the concrete class as the driver message handler?
It does implement the needed interface and can be instantiated via Tang.
Hence, it might work.

Markus