Package rx.functions

Examples of rx.functions.Action0


              logger.debug("Connection: "+connection.toString()+" unsubscribed");
            }
            return Observable.empty();
          }
        })
        .doOnCompleted(new Action0(){
          @Override
          public void call() {
            // connection closed, remote slot
            releaseSlot(slottingStrategyReference.getValue(), connection);
            logger.debug("Connection: "+connection.toString()+" closed");
View Full Code Here


                          responseHolder.add(response);
                          return response.getContent();
                      }
                  })
                  .ignoreElements()
                  .finallyDo(new Action0() {
                      @Override
                      public void call() {
                          finishLatch.countDown();
                      }
                  })
View Full Code Here

                            Notification<Void> notification) {
                        return !notification
                                .isOnError();
                    }
                })
                .finallyDo(new Action0() {
                    @Override
                    public void call() {
                        System.out.println(" --> Closing connection and stream");
                    }
                })
View Full Code Here

                                                + "\nCommands => subscribe:, unsubscribe:\n");
                                    }
                                    return Observable.empty();
                                }
                            }
                        }).finallyDo(new Action0() {
                            @Override
                            public void call() {
                                System.out.println("--- Connection Closed ---");
                            }
                        });
View Full Code Here

                });

                // wait for the helloMessage then start the output and receive echo input
                return Observable.concat(helloMessage, Observable.merge(intervalOutput, echo));
            }
        }).take(10).doOnCompleted(new Action0() {
            @Override
            public void call() {
                System.out.println("COMPLETED!");
            }
        }).toBlocking().toIterable();
View Full Code Here

                });

                // wait for the helloMessage then start the output and receive echo input
                return Observable.concat(helloMessage, Observable.merge(intervalOutput, echo));
            }
        }).take(10).doOnCompleted(new Action0() {
            @Override
            public void call() {
                System.out.println("COMPLETED!");
            }
        }).toBlocking().toIterable();
View Full Code Here

                    @Override
                    public Observable<Void> handle(HttpServerRequest<ByteBuf> request,
                                                   HttpServerResponse<ByteBuf> response) {
                        request.getContent().subscribe();
                        response.writeString("Hellooo!!!");
                        return response.close().finallyDo(new Action0() {
                            @Override
                            public void call() {
                                bothClientAndServerDone.countDown();
                            }
                        });
                    }
                }).appendPipelineConfigurator(new PipelineConfigurator<HttpServerRequest<ByteBuf>, HttpServerResponse<ByteBuf>>() {
                    @Override
                    public void configureNewPipeline(ChannelPipeline pipeline) {
                        pipeline.addLast(serverCloseListener);
                    }
                }).enableWireLogging(LogLevel.ERROR).build().start();
        TestableServerMetricsEventListener listener = new TestableServerMetricsEventListener();
        server.subscribe(listener);

        TestableClientMetricsEventListener clientListener = new TestableClientMetricsEventListener();
        final ChannelCloseListener clientCloseListener = new ChannelCloseListener();
        HttpClient<ByteBuf, ByteBuf> client =
                RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder("localhost", server.getServerPort())
                       .enableWireLogging(LogLevel.DEBUG)
                       .appendPipelineConfigurator(new PipelineConfigurator<HttpClientResponse<ByteBuf>, HttpClientRequest<ByteBuf>>() {
                           @Override
                           public void configureNewPipeline(ChannelPipeline pipeline) {
                               pipeline.addLast(clientCloseListener);
                           }
                       })
                       .withNoConnectionPooling().build();
        client.subscribe(clientListener);

        client.submit(HttpClientRequest.createGet("/"))
              .finallyDo(new Action0() {
                  @Override
                  public void call() {
                      bothClientAndServerDone.countDown();
                  }
              }).toBlocking().last();
View Full Code Here

    @Test
    public void testCompletionWhenNoFuture() throws Exception {
        NoOpChannelHandlerContext context = new NoOpChannelHandlerContext();
        MultipleFutureListener listener = new MultipleFutureListener(context.newPromise());
        final CountDownLatch completionLatch = new CountDownLatch(1);
        listener.asObservable().doOnTerminate(new Action0() {
            @Override
            public void call() {
                completionLatch.countDown();
            }
        }).subscribe();
View Full Code Here

                            // store the command that is being run
                            endCurrentThreadExecutingCommand.set(Hystrix.startCurrentThreadExecutingCommand(getCommandKey()));

                            getRunObservableDecoratedForMetricsAndErrorHandling(performAsyncTimeout)
                                    .doOnTerminate(new Action0() {

                                        @Override
                                        public void call() {
                                            // release the semaphore
                                            // this is done here instead of below so that the acquire/release happens where it is guaranteed
                                            // and not affected by the conditional circuit-breaker checks, timeouts, etc
                                            executionSemaphore.release();

                                        }
                                    }).unsafeSubscribe(observer);
                        } catch (RuntimeException e) {
                            observer.onError(e);
                        }
                    } else {
                        metrics.markSemaphoreRejection();
                        logger.debug("HystrixCommand Execution Rejection by Semaphore."); // debug only since we're throwing the exception and someone higher will do something with it
                        // retrieve a fallback or throw an exception if no fallback available
                        getFallbackOrThrowException(HystrixEventType.SEMAPHORE_REJECTED, FailureType.REJECTED_SEMAPHORE_EXECUTION, "could not acquire a semaphore for execution").unsafeSubscribe(observer);
                    }
                } else {
                    // record that we are returning a short-circuited fallback
                    metrics.markShortCircuited();
                    // short-circuit and go directly to fallback (or throw an exception if no fallback implemented)
                    try {
                        getFallbackOrThrowException(HystrixEventType.SHORT_CIRCUITED, FailureType.SHORTCIRCUIT, "short-circuited").unsafeSubscribe(observer);
                    } catch (Exception e) {
                        observer.onError(e);
                    }
                }
            }
        });

        // error handling at very end (this means fallback didn't exist or failed)
        o = o.onErrorResumeNext(new Func1<Throwable, Observable<R>>() {

            @Override
            public Observable<R> call(Throwable t) {
                // count that we are throwing an exception and re-throw it
                metrics.markExceptionThrown();
                return Observable.error(t);
            }

        });

        // any final cleanup needed
        o = o.doOnTerminate(new Action0() {

            @Override
            public void call() {
                Reference<TimerListener> tl = timeoutTimer.get();
                if (tl != null) {
View Full Code Here

                        // and not increment any of the counters below or other such logic
                        s.onError(new RuntimeException("timed out before executing run()"));
                    } else {
                        // not timed out so execute
                        try {
                            final Action0 endCurrentThread = Hystrix.startCurrentThreadExecutingCommand(getCommandKey());
                            getExecutionObservable().doOnTerminate(new Action0() {

                                @Override
                                public void call() {
                                    // TODO is this actually the end of the thread?
                                    executionHook.onThreadComplete(_self);
                                    endCurrentThread.call();
                                }
                            }).unsafeSubscribe(s);
                        } catch (Throwable t) {
                            // the run() method is a user provided implementation so can throw instead of using Observable.onError
                            // so we catch it here and turn it into Observable.error
                            Observable.<R> error(t).unsafeSubscribe(s);
                        }
                    }
                }

            }).subscribeOn(threadPool.getScheduler());
        } else {
            // semaphore isolated
            executionHook.onRunStart(_self);
            try {
                run = getExecutionObservable();
            } catch (Throwable t) {
                // the run() method is a user provided implementation so can throw instead of using Observable.onError
                // so we catch it here and turn it into Observable.error
                run = Observable.error(t);
            }
        }

        run = run.doOnEach(new Action1<Notification<? super R>>() {

            @Override
            public void call(Notification<? super R> n) {
                setRequestContextIfNeeded(currentRequestContext);
            }

        }).lift(new HystrixObservableTimeoutOperator<R>(_self, performAsyncTimeout)).map(new Func1<R, R>() {

            boolean once = false;

            @Override
            public R call(R t1) {
                System.out.println("map " + t1);
                if (!once) {
                    // report success
                    executionResult = executionResult.addEvents(HystrixEventType.SUCCESS);
                    once = true;
                }

                return executionHook.onRunSuccess(_self, t1);
            }

        }).doOnCompleted(new Action0() {

            @Override
            public void call() {
                long duration = System.currentTimeMillis() - invocationStartTime;
                metrics.addCommandExecutionTime(duration);
View Full Code Here

TOP

Related Classes of rx.functions.Action0

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.