io.vlingo.common.Tuple2 Java Examples
The following examples show how to use
io.vlingo.common.Tuple2.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GridNodeBootstrap.java From vlingo-lattice with Mozilla Public License 2.0 | 6 votes |
public static GridNodeBootstrap boot(final GridRuntime grid, final String nodeName, final io.vlingo.cluster.model.Properties properties, final boolean embedded) throws Exception { properties.validateRequired(nodeName); final Tuple2<ClusterSnapshotControl, Logger> control = Cluster.controlFor( grid.world(), new GridNodeInstantiator(grid), properties, nodeName); final GridNodeBootstrap instance = new GridNodeBootstrap(control, nodeName); control._2.info("Successfully started cluster node: '" + nodeName + "'"); if (!embedded) { control._2.info("=========="); } return instance; }
Example #2
Source File: ArgumentLock.java From vlingo-actors with Mozilla Public License 2.0 | 6 votes |
public static Lock acquire(Object param) { Object intern = null; synchronized (locks) { Tuple2<WeakReference<Object>, Lock> pair = locks.get(param); if (pair != null) { intern = pair._1.get(); } if (intern == null) { intern = param; pair = Tuple2.from(new WeakReference<>(intern), new ReentrantLock()); locks.put(intern, pair); } } return new ArgumentLock(intern, locks.get(intern)._2); }
Example #3
Source File: ProxyGenerator.java From vlingo-actors with Mozilla Public License 2.0 | 6 votes |
private String proxyClassSource(final Class<?> protocolInterface) { final Method[] methods = protocolInterface.getMethods(); final StringBuilder builder = new StringBuilder(); final Tuple2<List<InvalidProtocolException.Failure>, String> methodDefs = methodDefinitions(protocolInterface, methods); if (methodDefs._1 != null) { throw new InvalidProtocolException(protocolInterface.getCanonicalName(), methodDefs._1); } builder .append(packageStatement(protocolInterface)).append("\n\n") .append(importStatements(protocolInterface)).append("\n") .append(classStatement(protocolInterface)).append("\n") .append(representationStatements(methods)).append("\n") .append(instanceVariables(protocolInterface)).append("\n") .append(constructor(protocolInterface)).append("\n") .append(emptyConstructor(protocolInterface)).append("\n") .append(methodDefs._2) .append("}").append("\n"); return builder.toString(); }
Example #4
Source File: ProxyGenerator.java From vlingo-actors with Mozilla Public License 2.0 | 6 votes |
private Tuple2<List<InvalidProtocolException.Failure>, String> methodDefinitions(final Class<?> protocolInterface, final Method[] methods) { final StringBuilder builder = new StringBuilder(); final List<InvalidProtocolException.Failure> failures = new ArrayList<>(); int count = 0; for (final Method method : methods) { if (!Modifier.isStatic(method.getModifiers())) { final Tuple2<InvalidProtocolException.Failure, String> result = methodDefinition(protocolInterface, method, ++count); if (result._1 == null) { builder.append(result._2); } else { failures.add(result._1); } } } if (failures.isEmpty()) { return Tuple2.from(null, builder.toString()); } else { return Tuple2.from(failures, null); } }
Example #5
Source File: DiscussionTest.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatDiscussionPosts() throws Exception { System.out.println("=========== testThatDiscussionPosts ==========="); final Tuple2<DiscussionId, Discussion> discussionPair = fixtures.discussionFixture(world); // System.out.println("4b"); journalDispatcher.afterCompleting(1); // System.out.println("4c"); final Author author = Author.unique(); final String subject = "Within the discussion a post"; final String bodyText = "This is the body of the post which is document text."; // System.out.println("4c.1"); Tuple2<PostId,Post> postPair = discussionPair._2.postFor(author, subject, bodyText).await(2000); // System.out.println("4c.2"); assertNotNull(postPair._1); assertNotNull(postPair._2); // System.out.println("4d=" + journalDispatcher.confirmedCount()); final int count = journalDispatcher.confirmedCount(3); // System.out.println("4e"); assertEquals(3, count); final PostedToDiscussion event2 = postAdapter().asSource(journalDispatcher.entry(2)); assertEquals(PostedToDiscussion.class, event2.getClass()); assertEquals(author.value, event2.authorId); assertEquals(subject, event2.subject); assertEquals(bodyText, event2.bodyText); }
Example #6
Source File: PostTest.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatPostModerated() { journalDispatcher.afterCompleting(3); final Tuple2<PostId, Post> postPair = fixtures.postFixture(world); final int count3 = journalDispatcher.confirmedCount(3); assertEquals(3, count3); journalDispatcher.afterCompleting(1); final Moderator moderator = Moderator.unique(); final String subject = "A Moderated Subject"; final String bodyText = "A moderated body text document."; assertNotNull(postPair); assertNotNull(postPair._1); assertNotNull(postPair._2); postPair._2.moderate(moderator, subject, bodyText); final int count4 = journalDispatcher.confirmedCount(4); assertEquals(4, count4); final PostModerated event3 = adapter().asSource(journalDispatcher.entry(3)); assertEquals(PostModerated.class, event3.getClass()); assertEquals(moderator.value, event3.moderatorId); assertEquals(subject, event3.subject); assertEquals(bodyText, event3.bodyText); }
Example #7
Source File: ForumTest.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatForumStartsDiscussion() { journalDispatcher.afterCompleting(2); final Tuple2<ForumId,Forum> forumPair = Forum.startWith(world.stage(), Tenant.unique(), fixtures.forumDescriptionFixture()); final Author author = Author.unique(); final String topic = "At Topic That Is of Great Interest"; final String ownerId = UUID.randomUUID().toString(); forumPair._2.discussFor(author, topic, ownerId) .andThenConsume(discussionPair -> { assertNotNull(discussionPair); assertNotNull(discussionPair._1); UUID.fromString(discussionPair._1.value); // throws if not correct format assertNotNull(discussionPair._2); }); final int count = journalDispatcher.confirmedCount(); assertEquals(2, count); final ForumStarted event0 = adapter().asSource(journalDispatcher.entry(0)); assertEquals(ForumStarted.class, event0.getClass()); final DiscussionStarted event1 = discussionAdapter().asSource(journalDispatcher.entry(1)); assertEquals(DiscussionStarted.class, event1.getClass()); assertEquals(author.value, event1.authorId); assertEquals(topic, event1.topic); }
Example #8
Source File: ForumTest.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatForumReopened() { journalDispatcher.afterCompleting(1); final Tuple2<ForumId,Forum> forumPair = Forum.startWith(world.stage(), Tenant.unique(), fixtures.forumDescriptionFixture()); final int count = journalDispatcher.confirmedCount(); assertEquals(1, count); journalDispatcher.afterCompleting(1); forumPair._2.close(); final int count2 = journalDispatcher.confirmedCount(); assertEquals(2, count2); journalDispatcher.afterCompleting(1); forumPair._2.reopen(); final int count3 = journalDispatcher.confirmedCount(); assertEquals(3, count3); final ForumStarted event0 = adapter().asSource(journalDispatcher.entry(0)); assertEquals(ForumStarted.class, event0.getClass()); final ForumClosed event1 = adapter().asSource(journalDispatcher.entry(1)); assertEquals(ForumClosed.class, event1.getClass()); final ForumReopened event2 = adapter().asSource(journalDispatcher.entry(2)); assertEquals(ForumReopened.class, event2.getClass()); }
Example #9
Source File: ForumTest.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
@Test public void testThatForumStarted() { journalDispatcher.afterCompleting(1); final ForumDescription description = fixtures.forumDescriptionFixture(); final Tuple2<ForumId,Forum> forumPair = Forum.startWith(world.stage(), Tenant.unique(), description); assertNotNull(forumPair); assertNotNull(forumPair._1); UUID.fromString(forumPair._1.value); // throws if not correct format assertNotNull(forumPair._2); final int count = journalDispatcher.confirmedCount(); assertEquals(1, count); final ForumStarted event = adapter().asSource(journalDispatcher.entry(0)); assertEquals(ForumStarted.class, event.getClass()); assertEquals(description.creator.value, event.creatorId); assertEquals(description.description, event.description); assertEquals(description.exclusiveOwner, event.exclusiveOwner); assertEquals(description.forumId.value, event.forumId); assertEquals(description.moderator.value, event.moderatorId); assertEquals(description.topic, event.topic); }
Example #10
Source File: ProductResource.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
public Completes<Response> defineWith(final ProductDefinition productDefinition) { try { final Tuple2<ProductId, Product> product = Product.defineWith( stage, Tenant.fromExisting(productDefinition.tenantId), ProductOwner.fromExisting(productDefinition.tenantId, productDefinition.ownerId), productDefinition.name, productDefinition.description, productDefinition.hasDiscussion); return Completes.withSuccess(Response.of(Created, JsonSerialization.serialized(product._1))); } catch (Throwable t) { this.stage.world().defaultLogger().error("Failed to create the product", t); return Completes.withSuccess(Response.of(InternalServerError)); } }
Example #11
Source File: Product.java From vlingo-examples with Mozilla Public License 2.0 | 6 votes |
static Tuple2<ProductId, Product> defineWith( final Stage stage, final Tenant tenant, final ProductOwner productOwner, final String name, final String description, final boolean hasDiscussion) { assert (tenant != null && tenant.id != null); assert (productOwner != null && productOwner.id != null); assert (name != null); assert (description != null); Address address = stage.addressFactory().unique(); final ProductId productId = ProductId.fromExisting(address.idString()); final Definition definition = Definition.has(ProductEntity.class, Definition.parameters(tenant, productId), productId.id); final Product product = stage.actorFor(Product.class, definition); product.define(productOwner, name, description, hasDiscussion); return Tuple2.from(productId, product); }
Example #12
Source File: ForumEntity.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Override public Completes<Tuple2<DiscussionId, Discussion>> discussFor(final Author author, final String topic, final String ownerId) { final DiscussionId discussionId = DiscussionId.unique(); final Discussion discussion = stage().actorFor(Discussion.class, DiscussionEntity.class, state.tenant, state.forumId, discussionId); discussion.startWith(author, topic, ownerId); return completes().with(Tuple2.from(discussionId, discussion)); }
Example #13
Source File: DiscussionTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatDiscussionCloses() { System.out.println("=========== testThatDiscussionClosed ==========="); final Tuple2<DiscussionId, Discussion> discussionPair = fixtures.discussionFixture(world); journalDispatcher.afterCompleting(1); discussionPair._2.close(); final int count = journalDispatcher.confirmedCount(3); assertEquals(3, count); final DiscussionClosed event2 = adapter().asSource(journalDispatcher.entry(2)); assertEquals(DiscussionClosed.class, event2.getClass()); }
Example #14
Source File: HashRingPropertyTest.java From vlingo-lattice with Mozilla Public License 2.0 | 5 votes |
private static Map<String, Set<UUID>> assignments(Collection<UUID> sample, HashRing<String> ring) { Map<String, List<Tuple2<UUID, String>>> map = sample.stream() .map((uuid) -> Tuple2.from(uuid, ring.nodeOf(uuid))) .collect(Collectors.groupingBy((tuple) -> tuple._2)); Map<String, Set<UUID>> finalMap = new HashMap<>(map.size()); map.forEach((key, value) -> finalMap.put(key, value.stream().map(t -> t._1) .collect(Collectors.toSet()))); return finalMap; }
Example #15
Source File: DiscussionTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatDiscussionReopened() { System.out.println("=========== testThatDiscussionReopened ==========="); final Tuple2<DiscussionId, Discussion> discussionPair = fixtures.discussionFixture(world); journalDispatcher.afterCompleting(2); discussionPair._2.close(); discussionPair._2.reopen(); final int count = journalDispatcher.confirmedCount(4); assertEquals(4, count); final DiscussionClosed event2 = adapter().asSource(journalDispatcher.entry(2)); assertEquals(DiscussionClosed.class, event2.getClass()); final DiscussionReopened event3 = adapter().asSource(journalDispatcher.entry(3)); assertEquals(DiscussionReopened.class, event3.getClass()); }
Example #16
Source File: ForumTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatForumTopicChanged() { journalDispatcher.afterCompleting(2); final Tuple2<ForumId,Forum> forumPair = Forum.startWith(world.stage(), Tenant.unique(), fixtures.forumDescriptionFixture()); final String topic = "Even More Than All Things vlingo/platform"; forumPair._2.topicIs(topic); final int count = journalDispatcher.confirmedCount(); assertEquals(2, count); final ForumStarted event0 = adapter().asSource(journalDispatcher.entry(0)); assertEquals(ForumStarted.class, event0.getClass()); final ForumTopicChanged event1 = adapter().asSource(journalDispatcher.entry(1)); assertEquals(ForumTopicChanged.class, event1.getClass()); assertEquals(topic, event1.topic); }
Example #17
Source File: DiscussionTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatDiscussionTopicChanged() { System.out.println("=========== testThatDiscussionTopicChanged ==========="); final Tuple2<DiscussionId, Discussion> discussionPair = fixtures.discussionFixture(world); journalDispatcher.afterCompleting(1); final String topic = "By Way, Way, Way of Discussion"; discussionPair._2.topicTo(topic); final int count = journalDispatcher.confirmedCount(3); assertEquals(3, count); final DiscussionTopicChanged event2 = adapter().asSource(journalDispatcher.entry(2)); assertEquals(DiscussionTopicChanged.class, event2.getClass()); assertEquals(topic, event2.topic); }
Example #18
Source File: ForumTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatForumDescribed() { journalDispatcher.afterCompleting(2); final Tuple2<ForumId,Forum> forumPair = Forum.startWith(world.stage(), Tenant.unique(), fixtures.forumDescriptionFixture()); final String description = "Let's discuss the vlingo/platform"; forumPair._2.describeAs(description); final int count = journalDispatcher.confirmedCount(); assertEquals(2, count); final ForumStarted event0 = adapter().asSource(journalDispatcher.entry(0)); assertEquals(ForumStarted.class, event0.getClass()); final ForumDescribed event1 = adapter().asSource(journalDispatcher.entry(1)); assertEquals(ForumDescribed.class, event1.getClass()); assertEquals(description, event1.description); }
Example #19
Source File: ForumTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatForumClosed() { journalDispatcher.afterCompleting(2); final Tuple2<ForumId,Forum> forumPair = Forum.startWith(world.stage(), Tenant.unique(), fixtures.forumDescriptionFixture()); forumPair._2.close(); final int count = journalDispatcher.confirmedCount(); assertEquals(2, count); final ForumStarted event0 = adapter().asSource(journalDispatcher.entry(0)); assertEquals(ForumStarted.class, event0.getClass()); final ForumClosed event1 = adapter().asSource(journalDispatcher.entry(1)); assertEquals(ForumClosed.class, event1.getClass()); }
Example #20
Source File: ForumTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Test public void testThatForumModeratorAssigned() { journalDispatcher.afterCompleting(2); final Tuple2<ForumId,Forum> forumPair = Forum.startWith(world.stage(), Tenant.unique(), fixtures.forumDescriptionFixture()); final Moderator moderator = Moderator.unique(); forumPair._2.assign(moderator); final int count = journalDispatcher.confirmedCount(); assertEquals(2, count); final ForumStarted event0 = adapter().asSource(journalDispatcher.entry(0)); assertEquals(ForumStarted.class, event0.getClass()); final ForumModeratorAssigned event1 = adapter().asSource(journalDispatcher.entry(1)); assertEquals(ForumModeratorAssigned.class, event1.getClass()); assertEquals(moderator.value, event1.moderatorId); }
Example #21
Source File: Action.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
private Tuple2<String, List<MethodParameter>> parse(final String to) { final String bad = "Invalid to declaration: " + to; final int openParen = to.indexOf("("); final int closeParen = to.lastIndexOf(")"); if (openParen < 0 || closeParen < 0) { throw new IllegalStateException(bad); } final String methodName = to.substring(0, openParen); final String[] rawParameters = to.substring(openParen + 1, closeParen).split(","); final List<MethodParameter> parameters = new ArrayList<>(rawParameters.length); for (String rawParameter : rawParameters) { rawParameter = rawParameter.trim(); if (!rawParameter.isEmpty()) { if (rawParameter.startsWith("body:")) { final String[] body = typeAndName(rawParameter.substring(5)); parameters.add(new MethodParameter(body[0], body[1], load(qualifiedType(body[0])))); } else { final String[] other = typeAndName(rawParameter); parameters.add(new MethodParameter(other[0], other[1])); } } } return Tuple2.from(methodName, parameters); }
Example #22
Source File: Fixtures.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
public Tuple2<PostId,Post> postFixture(final World world) { final Tuple2<DiscussionId, Discussion> discussionPair = discussionFixture(world); final Author author = Author.unique(); final String subject = "Within the discussion a post"; final String bodyText = "This is the body of the post which is document text."; postPair = discussionPair._2.postFor(author, subject, bodyText).await(); return postPair; }
Example #23
Source File: Fixtures.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
public Tuple2<DiscussionId, Discussion> discussionFixture(final World world) { final Tuple2<ForumId,Forum> forumPair = Forum.startWith(world.stage(), Tenant.unique(), forumDescriptionFixture()); final String ownerId = UUID.randomUUID().toString(); discussionPair = forumPair._2.discussFor(Author.unique(), "By Way of Discussion", ownerId).await(); return discussionPair; }
Example #24
Source File: ProductDiscussionRequestedEventReceiver.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Override public void receive(ProductDiscussionRequested event) { final Forum.ForumDescription description = new Forum.ForumDescription(Creator.fromExisting(event.productOwnerId), Moderator.fromExisting(event.productOwnerId), event.name, event.description); final Tuple2<ForumId, Forum> tuple = Forum.startWith(this.stage, Tenant.fromExisting(event.tenantId), description); final Forum forum = tuple._2; forum.discussFor(Author.fromExisting(event.productOwnerId), event.name, event.ownerId); }
Example #25
Source File: Forum.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
static Tuple2<ForumId, Forum> startWith( final Stage stage, final Tenant tenant, final ForumDescription description) { final Forum forum = stage.actorFor(Forum.class, Definition.has(ForumEntity.class, Definition.parameters(tenant, description.forumId))); forum.startWith(description.creator, description.moderator, description.topic, description.description, description.exclusiveOwner); return Tuple2.from(description.forumId, forum); }
Example #26
Source File: FileProcessorTest.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
private Tuple2<File,String> generateFile() throws Exception { final String prefix = "data" + random.nextLong(); final String suffix = ".dat"; final File file = File.createTempFile(prefix, suffix); return Tuple2.from(file, file.getAbsolutePath()); }
Example #27
Source File: DiscussionEntity.java From vlingo-examples with Mozilla Public License 2.0 | 5 votes |
@Override public Completes<Tuple2<PostId,Post>> postFor(final Author author, final String subject, final String bodyText) { final PostId postId = PostId.unique(); final Post post = stage().actorFor(Post.class, PostEntity.class, state.tenant, state.forumId, state.discussionId, postId); post.submitWith(author, subject, bodyText); return completes().with(Tuple2.from(postId, post)); }
Example #28
Source File: Filters.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
/** * Answer the {@code Request} resulting from any filtering. * @param request the Request incoming from the client * @return Request */ public Request process(final Request request) { if (stopped) return request; Request current = request; for (final RequestFilter filter : requestFilters) { final Tuple2<Request, Boolean> answer = filter.filter(current); if (!answer._2) { return answer._1; } current = answer._1; } return current; }
Example #29
Source File: Filters.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
/** * Answer the {@code Response} resulting from any filtering. * @param response the Response outgoing from a ResourceHandler * @return Response */ public Response process(final Response response) { if (stopped) return response; Response current = response; for (final ResponseFilter filter : responseFilters) { final Tuple2<Response, Boolean> answer = filter.filter(current); if (!answer._2) { return answer._1; } current = answer._1; } return current; }
Example #30
Source File: AllSseFeedActor.java From vlingo-http with Mozilla Public License 2.0 | 5 votes |
private Tuple2<List<SseEvent>, Integer> readSubStream(final int startId, final int endId, final int retry) { final List<SseEvent> substream = new ArrayList<>(); int type = 0; int id = startId; for ( ; id <= endId; ++id) { substream.add(builder.clear().event("mimeType-" + ('A' + type)).id(id).data("data-" + id).retry(retry).toEvent()); type = type > 26 ? 0 : type + 1; } return Tuple2.from(substream, id + 1); }