JAM - examples

Printer-friendly versionPrinter-friendly version
How to use the JAM framework


To give some fancy examples for the fluent API:

.theMessage(new LongMessageId(1000), "One thousend!")

Publishes immediately the message with ID 1000 as INFO under ANY. We can pass different topic types to the on(Topic) operation, including our own implementations of the Topic interface. JAM provides several types out of the box, e.g.

  • RootTopic (root hierarchy of (all) topics)
  • NamedTopic (creates topics from names)
  • TypeTopic (creates topics from types)
  • GenericTopic (creates topics from any objects)
  • WeakGenericTopic (weakly referenced topics)
  • NoTopic (fallback if no topic is provided)


Long long = PublishParallel.as(Long.class)

Returns immediately an instance of type Long.

.within(2, TimeUnit.SECONDS)
.that(new Long(100))

Offers a Long, but requires to finish all processes within 2 seconds (timeout).

Object object = PublishParallel.asFollows()
        .theObject(new Long(100))

Waits 2 seconds, creates for this demand a TypeTopic with the type Long, then returns an object as specified (Long value=100) as soon as all processes are completed. The operation demandingObjectsTimed() returns a ConcurrencyContext which provides many methods to deal with concurrency and scheduling. Here we just got the queue again.

.that(new Long(100))
.sendingResultsTo(new ResultReceiver<Long>() {
    public void receive(Queue<Long> results, Topic topic, Announcement<?> announcement) {
        // here we process the "results"


Here we demand a Long object, processed concurrently, but the results are forwarded to another given receiver (here as anonymous class).


We saw many basic examples of using different API provided by JAM. There is so much more to discover in JAM - for instance Ref with ValueChangeVetoSupplier, Distribute and DistributeParallel with distributors, distribution channels and distributions, also the subscription of anouncement filters, weak subscriptions and we should not forget the numerous possibilities to configure the mediators itself, regarding multi-level concurrency, thread pools, input queue, announcements on demand, and so on - tons of features!