File: BusConstruction.java

package info (click to toggle)
libmbassador-java 1.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 788 kB
  • sloc: java: 5,488; xml: 274; sh: 12; makefile: 5
file content (45 lines) | stat: -rw-r--r-- 1,973 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import net.engio.mbassy.bus.MBassador;
import net.engio.mbassy.bus.SyncMessageBus;
import net.engio.mbassy.bus.config.BusConfiguration;
import net.engio.mbassy.bus.config.Feature;
import net.engio.mbassy.bus.config.IBusConfiguration;
import net.engio.mbassy.bus.error.IPublicationErrorHandler;
import net.engio.mbassy.bus.error.PublicationError;

/**
 * These examples show how to create instances of a message bus using its different constructors.
 *
 */
public class BusConstruction {



    public static void main(String[] args){

        // Create a bus instance configured with reasonable defaults
        // NOTE: Since there is no publication error handler provided, the bus will fall back to
        // ConsoleLogger and print a hint about how to add publication error handlers
        MBassador unboundBus = new MBassador();

        // Create a bus bound to handle messages of type String.class only
        // with a custom publication error handler
        MBassador<String> stringOnlyBus = new MBassador<String>(new IPublicationErrorHandler() {
            @Override
            public void handleError(PublicationError error) {
                // custom error handling logic here
            }
        });


        // Use feature driven configuration to have more control over the configuration details
        MBassador featureDrivenBus = new MBassador(new BusConfiguration()
                .addFeature(Feature.SyncPubSub.Default())
                .addFeature(Feature.AsynchronousHandlerInvocation.Default())
                .addFeature(Feature.AsynchronousMessageDispatch.Default())
                .addPublicationErrorHandler(new IPublicationErrorHandler.ConsoleLogger())
                .setProperty(IBusConfiguration.Properties.BusId, "global bus")); // this is used for identification in #toString

        // The same construction patterns work for the synchronous message bus
        SyncMessageBus synchronousOnly = new SyncMessageBus();
    }
}