users@hk2.java.net

HK2 now has events!!!

From: John Wells <john.wells_at_oracle.com>
Date: Wed, 26 Mar 2014 07:27:49 -0400

We have promoted a version of HK2 (2.3.0-b03) that contains the latest
hk2 features, events.

With events you can send and receive messages from previously unrelated
components. To publish an event of type Foo you would inject a
Topic<Foo> like this:

@Inject
private Topic<Foo> fooPublisher;

You can then send an event by using the publish method:

fooPublisher.publish(new Foo());

In order to subscribe to events you simply add a method with a field
annotated with @SubscribeTo, like this

private void subscription(@SubscribeTo Foo foo) {...}

This method will get invoked whenever a Foo has been published. There is
much more information on this feature here:

https://hk2.java.net/2.3.0-b03/events.html

Furthermore, if you don't like the quality of service between the
publisher and subscribers (or don't like the subscription mechanism) you
can use our Eventing SPI to replace the default implementation (for
which we have a patent pending). For example, this example changes the
subscriptions to be invoked on a different thread from the publisher:

https://hk2.java.net/2.3.0-b03/threaded-events-example.html

Other than the new eventing feature this version contains various bug
fixes (in particular in the area of caching) as well as a new method in
ServiceLocatorFactory which allows the caller to specify exactly what to
do if a named ServiceLocator already exists when calling create.

We'd be happy to hear your feedback on the new hk2!

John Wells
john.wells_at_oracle.comNOSPAM