Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change RequestResponseProtocol to use a Message type parameter in anticipation of Functions #108

Merged
merged 11 commits into from
Aug 3, 2018

Conversation

srfc
Copy link
Collaborator

@srfc srfc commented Aug 2, 2018

Proposed Changes

  • Change RequestResponseProtocol to be compatible with envisioned MultiDactorFunctions, specifically the SequentialFunction
  • Add Message types to Request, Response, and the subtypes (Success and Failure)

Message definitions will change from:

object GetCustomerGroupId {
  case class Request() extends RequestResponseProtocol.Request
  case class Success(result: Relation) extends RequestResponseProtocol.Success
  case class Failure(e: Throwable) extends RequestResponseProtocol.Failure
}

to

object GetCustomerGroupId {
  sealed trait GetCustomerGroupId extends Message
  case class Request() extends RequestResponseProtocol.Request[GetCustomerGroupId]
  case class Success(result: Relation) extends RequestResponseProtocol.Response[GetCustomerGroupId]
  case class Failure(e: Throwable) extends RequestResponseProtocol.Failure[GetCustomerGroupId]
}

Related

@srfc srfc added the WIP Work In Progress label Aug 2, 2018
@srfc srfc changed the title Feature/req res message change Change RequestResponseProtocol to use a Message type parameter in anticipation of Functions Aug 2, 2018
@srfc srfc force-pushed the feature/req-res-message-change branch from cb33192 to e4e078b Compare August 2, 2018 10:39
@srfc srfc added Needs Review and removed WIP Work In Progress labels Aug 2, 2018
@srfc srfc requested a review from SebastianSchmidl August 2, 2018 11:45
@srfc srfc mentioned this pull request Aug 2, 2018
Copy link
Owner

@SebastianSchmidl SebastianSchmidl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but a small clarification needed in the scaladoc for RequestResponseProtocol

@@ -4,28 +4,44 @@ import de.up.hpi.informationsystems.adbms.relation.Relation

object RequestResponseProtocol {

/** Message type to be subclassed and used as [[Request]] and [[Response]] type information
*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could explain a little bit more, how this works and why it is needed. I think that's not obvious.
You can add an example usage.

Use the word marker trait, as all descendants will never be implemented, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right it's a little thin there.

There is a slight problem with the system we want at the moment though which relates to the trait Message explanation, though:

In how I am currently implementing SequentialFunction (in the experimental script), I lose the Message type information of the Response being passed back to the initial caller of the function. I am unsure if this is due to type erasure and has been that way regardless or if it is because of the following:

When I send messages to multiple recipients in a start or next step, I wait for them, collect all individual responses and then have to:

  1. unpack the Responses to get the Relation to union them
  2. re-pack into the appropriate Responses to pass on to the next next or end step

I am currently doing this like this:

// Receive
case message: Success[Message] =>
  // are we still waiting for messages? if so, become current state with the received message remembered
  // if not:
  val constructor = message.getClass.getConstructors()(0) // get constr to be able to repack as (hopefully) the correct `Response` subtype
  val unionResponse = (previouslyReceivedResponses :+ message)
    .foldLeft(constructor.newInstance(Relation.empty).asInstanceOf[Success[Message]])((a: Success[Message], b: Success[Message]) =>
      constructor.newInstance(a.result.unionAll(b.result)).asInstanceOf[Success[Message]])
  // use unionResponse to continue with next steps

Due to me losing the specific Response (or rather Success) subtype I can then not match for a specific answer anymore.

If this persists we don't get anything from the current Message type parameter, right?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed in skype

@srfc srfc added the question Further information is requested label Aug 2, 2018
Copy link
Owner

@SebastianSchmidl SebastianSchmidl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example can follow later, when functors are implemented

@SebastianSchmidl SebastianSchmidl added Merge This PR can be merged and removed Changes Requested question Further information is requested labels Aug 2, 2018
@srfc srfc merged commit 0901485 into master Aug 3, 2018
@srfc srfc deleted the feature/req-res-message-change branch August 3, 2018 11:01
@srfc srfc mentioned this pull request Aug 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merge This PR can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants