Java Code Examples for org.apache.qpid.proton.Proton#reactor()

The following examples show how to use org.apache.qpid.proton.Proton#reactor() . 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: ReactorLogger.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {

        // You can pass multiple handlers to a reactor when you construct it.
        // Each of these handlers will see every event the reactor sees. By
        // combining this with on_unhandled, you can log each event that goes
        // to the reactor.
        Reactor reactor = Proton.reactor(new ReactorLogger(), new Logger());
        reactor.run();

        // Note that if you wanted to add the logger later, you could also
        // write the above as below. All arguments to the reactor are just
        // added to the default handler for the reactor.
        reactor = Proton.reactor(new ReactorLogger());
        if (loggingEnabled)
            reactor.getHandler().add(new Logger());
        reactor.run();
    }
 
Example 2
Source File: Send.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    int port = 5672;
    String host = "localhost";
    if (args.length > 0) {
        String[] parts = args[0].split(":", 2);
        host = parts[0];
        if (parts.length > 1) {
            port = Integer.parseInt(parts[1]);
        }
    }
    String content = args.length > 1 ? args[1] : "Hello World!";

    Reactor r = Proton.reactor(new Send(host, port, content));
    r.run();
}
 
Example 3
Source File: CountRandomly.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    // In HelloWorld.java we said the reactor exits when there are no more
    // events to process. While this is true, it's not actually complete.
    // The reactor exits when there are no more events to process and no
    // possibility of future events arising. For that reason the reactor
    // will keep running until there are no more scheduled events and then
    // exit.
    Reactor reactor = Proton.reactor(new CountRandomly());
    reactor.run();
}
 
Example 4
Source File: GlobalLogger.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    Reactor reactor = Proton.reactor(new GlobalLogger());

    // In addition to having a regular handler, the reactor also has a
    // global handler that sees every event. By adding the Logger to the
    // global handler instead of the regular handler, we can log every
    // single event that occurs in the system regardless of whether or not
    // there are specific handlers associated with the objects that are the
    // target of those events.
    reactor.getGlobalHandler().add(new Logger());
    reactor.run();
}
 
Example 5
Source File: Counter.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    // In HelloWorld.java we said the reactor exits when there are no more
    // events to process. While this is true, it's not actually complete.
    // The reactor exits when there are no more events to process and no
    // possibility of future events arising. For that reason the reactor
    // will keep running until there are no more scheduled events and then
    // exit.
    Reactor reactor = Proton.reactor(new Counter());
    reactor.run();
}
 
Example 6
Source File: Cat.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.err.println("Specify a file name as an argument.");
        System.exit(1);
    }
    FileInputStream inFile = new FileInputStream(args[0]);
    SourceChannel inChannel = EchoInputStreamWrapper.wrap(inFile);
    Reactor reactor = Proton.reactor(new Cat(inChannel));
    reactor.run();
}
 
Example 7
Source File: HelloWorld.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {

        // When you construct a reactor, you can give it a handler that
        // is used, by default, to receive events generated by the reactor.
        Reactor reactor = Proton.reactor(new HelloWorld());

        // When you call run, the reactor will process events. The reactor init
        // event is what kicks off everything else. When the reactor has no
        // more events to process, it exits.
        reactor.run();
    }
 
Example 8
Source File: ReactorTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Parameters
public static Collection<ReactorFactory[]> data() throws IOException {
    ReactorFactory classicReactor = new ReactorFactory() {
        @Override public Reactor newReactor() throws IOException {
            return Proton.reactor();
        }
    };
    ReactorFactory newLeakDetection = new ReactorFactory() {
        @Override public Reactor newReactor() throws IOException {
            return new LeakTestReactor();
        }
    };
    return Arrays.asList(new ReactorFactory[][]{{classicReactor}, {newLeakDetection}});
}
 
Example 9
Source File: Echo.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    SourceChannel inChannel = EchoInputStreamWrapper.wrap(System.in);
    Reactor reactor = Proton.reactor(new Echo(inChannel));
    reactor.run();
}
 
Example 10
Source File: GoodbyeWorld.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    Reactor reactor = Proton.reactor(new GoodbyeWorld());
    reactor.run();
}
 
Example 11
Source File: Delegates.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    Reactor reactor = Proton.reactor(new Delegates(new Hello(), new Goodbye()));
    reactor.run();
}
 
Example 12
Source File: Scheduling.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    Reactor reactor = Proton.reactor(new Scheduling());
    reactor.run();
}
 
Example 13
Source File: Recv.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    Reactor r = Proton.reactor(new Recv());
    r.run();
}
 
Example 14
Source File: Unhandled.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    Reactor reactor = Proton.reactor(new Unhandled());
    reactor.run();
}