Last active
August 29, 2015 13:56
-
-
Save ngerakines/9085570 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface CalcService extends RespondingService { | |
void add(final CallbackMessageController<CalcProto.Results> messageController, final CalcProto.Add add); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DefaultCalcService implements CalcService { | |
public void add(final CallbackMessageController<CalcProto.Results> messageController, final CalcProto.Add add) { | |
if (add.hasFirst() && add.hasSecond()) { | |
messageController.complete(CalcProto.Results.newBuilder().setValue(add.getFirst() + add.getSecond()).build()); | |
return; | |
} | |
messageController.fail(ServiceProto.Error.newBuilder().setCode(CalcErrors.MISSING_PARAMETERS.code()).build()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FooThingDoer { | |
public void stuff(final ServiceRef serviceRef) { | |
final CalcService calcService = serviceRegistry.getService(serviceRef); | |
final Callback<CalcProto.Results> callback = createCallback(); | |
final CallbackMessageController<CalcProto.Results> messageController = createMessageController(); | |
calcService.add(messageController, CalcProto.Add.newBuilder().setFirst(1).setSecond(1).build()); | |
try { | |
if (messageController.isFinished() && messageController.hasCallbackValue()) { | |
final CalcProto.Results results = messageController.getValue(); | |
// ... do stuff with results | |
} | |
} catch (final Exception e) { | |
// ... | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface RespondingService { | |
ServiceProto.ServiceRef getServiceRef(); | |
List<Integer> getFlags(); | |
void setFlag(final int flag); | |
void removeFlag(final int flag); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment