Refine search
@Override public void onNext(PooledConnection<R, W> conn) { boolean _terminated; Throwable _error; synchronized (this) { onNextArrived = true; _terminated = terminated; _error = error; delegate.onNext(conn); } if (_terminated) { if (null != error) { delegate.onError(_error); } else { delegate.onCompleted(); } } } }
@Override public void call(Subscriber<? super PooledConnection<R, W>> subscriber) { PooledConnection<R, W> idleConnection; while (!subscriber.isUnsubscribed() && (idleConnection = idleConnections.poll()) != null) { subscriber.onNext(idleConnection); } if (!subscriber.isUnsubscribed()) { subscriber.onCompleted(); } } });
private void emitNewConnection(Channel channel) { if (isValidToEmit(newChannelSub)) { try { newChannelSub.onNext(channel); connectionEmitted = true; checkEagerSubscriptionIfConfigured(channel); newChannelSub.onCompleted(); } catch (Exception e) { logger.error("Error emitting a new connection. Closing this channel.", e); channel.close(); } } else { channel.close(); // Closing the connection if not sent to a subscriber. } }
@Override public void call(Subscriber<? super Boolean> s) { try { Thread.sleep(executionSleep); } catch (InterruptedException e) { e.printStackTrace(); } s.onNext(true); s.onCompleted(); }
@Override public void call(Subscriber<? super Boolean> s) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } s.onNext(true); s.onCompleted(); }
@Override public void call(Subscriber<? super Boolean> s) { try { Thread.sleep(500); } catch (InterruptedException e) { System.out.println(">>>> Sleep Interrupted: " + e.getMessage()); // e.printStackTrace(); } s.onNext(true); s.onCompleted(); }
@Override public void call(Subscriber<? super Boolean> s) { try { Thread.sleep(500); } catch (InterruptedException e) { System.out.println(">>>> Sleep Interrupted: " + e.getMessage()); // e.printStackTrace(); } s.onNext(true); s.onCompleted(); }
@Override public void call(final Subscriber<? super T> subscriber) { /** * You would replace this code with your file reading. Instead of emitting from an iterator, * you would create a bean object that represents the entity, and then emit it */ try { while (!subscriber.isUnsubscribed() && input.hasNext()) { //send our input to the next subscriber.onNext((T) input.next()); } //tell the subscriber we don't have any more data subscriber.onCompleted(); } catch (Throwable t) { logger.error("failed on subscriber", t); subscriber.onError(t); } } }
@Override public void call(Subscriber<? super Boolean> s) { //signals caller that run has started startLatch.countDown(); try { // waits for caller to countDown latch waitLatch.await(); s.onNext(true); s.onCompleted(); } catch (InterruptedException e) { e.printStackTrace(); s.onNext(false); s.onCompleted(); } } }).subscribeOn(Schedulers.computation());
@Override public void call(Subscriber<? super Boolean> sub) { latch.countDown(); try { latch.await(); sub.onNext(true); sub.onCompleted(); } catch (InterruptedException e) { sub.onError(e); } } }).subscribeOn(Schedulers.computation()).toBlocking().toFuture());
@Override public void call(Subscriber<? super Boolean> s) { action.call(); s.onNext(true); s.onCompleted(); }
@Override public void call( final Subscriber<? super T> subscriber ) { try { subscriber.onStart(); //get our iterator and push data to the observer final Iterator<T> itr = getIterator(); Preconditions.checkNotNull( itr, "The observable must return an iterator. Null was returned for iterator " + name ); //while we have items to emit and our subscriber is subscribed, we want to keep emitting items while ( itr.hasNext() && !subscriber.isUnsubscribed() ) { final T next = itr.next(); if (logger.isTraceEnabled()) logger.trace( "Iterator '{}' emitting item '{}'", name, next ); subscriber.onNext( next ); } subscriber.onCompleted(); } //if any error occurs, we need to notify the observer so it can perform it's own error handling catch ( Throwable t ) { subscriber.onError( t ); } }
@Override public void call(Subscriber<? super Integer> subscriber) { addLatency(fallbackLatency); if (fallbackResult == AbstractTestHystrixCommand.FallbackResult.SUCCESS) { subscriber.onNext(11); subscriber.onCompleted(); } else if (fallbackResult == FallbackResult.MULTIPLE_EMITS_THEN_SUCCESS) { subscriber.onNext(12); subscriber.onNext(13); subscriber.onNext(14); subscriber.onNext(15); subscriber.onCompleted(); } else if (fallbackResult == FallbackResult.MULTIPLE_EMITS_THEN_FAILURE) { subscriber.onNext(16); subscriber.onNext(17); subscriber.onNext(18); subscriber.onNext(19); subscriber.onError(new RuntimeException("Fallback Async Failure For TestHystrixObservableCommand after 4 emits")); } else if (fallbackResult == AbstractTestHystrixCommand.FallbackResult.ASYNC_FAILURE) { subscriber.onError(new RuntimeException("Fallback Async Failure for TestHystrixCommand after 0 fallback emits")); } else { subscriber.onError(new RuntimeException("You passed in a fallbackResult enum that can't be represented in HystrixObservableCommand: " + fallbackResult)); } } });
@Override public HttpContent processContentChunk(ZuulMessage zuulMessage, HttpContent chunk) { // Only call onNext() after we've received the LastContent of request from client. if (chunk instanceof LastHttpContent) { ResponseState state = (ResponseState) zuulMessage.getContext().get(KEY_FOR_SUBSCRIBER); if (state != null) { state.subscriber.onNext(state.response); state.subscriber.onCompleted(); zuulMessage.getContext().remove(KEY_FOR_SUBSCRIBER); } } return super.processContentChunk(zuulMessage, chunk); }
@Override public Observable<UUID> setStatus( final UUID applicationId, final UUID jobId, final Status status, final Map<String, Object> data) { Preconditions.checkNotNull(applicationId, "app id is null"); Preconditions.checkNotNull(jobId, "job id is null"); Preconditions.checkNotNull(status, "status is null"); final Map<String,Object> dataMap = data != null ? data : new HashMap<String,Object>(); return Observable.create(sub -> { final String jobString = StringUtils.sanitizeUUID(jobId); final Id appId = CpNamingUtils.generateApplicationId(applicationId); final MapManager mapManager = mapManagerFactory.createMapManager(new MapScopeImpl(appId, "status")); try { final String dataString = MAPPER.writeValueAsString(dataMap); mapManager.putString(jobString + dataKey, dataString); mapManager.putString(jobString + statusKey, status.toString()); sub.onNext(jobId); sub.onCompleted(); } catch (Exception e) { logger.error("Failed to serialize map",e); throw new RuntimeException(e); } }); }
@Override public Observable<JobStatus> getStatus(final UUID applicationId, UUID jobId) { Preconditions.checkNotNull(applicationId, "app id is null"); Preconditions.checkNotNull(jobId, "job id is null"); return Observable.create(subscriber -> { final String jobString = StringUtils.sanitizeUUID(jobId); Id appId = CpNamingUtils.generateApplicationId(applicationId); final MapManager mapManager = mapManagerFactory.createMapManager(new MapScopeImpl(appId, "status")); try { String statusVal = mapManager.getString(jobString + statusKey); //nothing to emit if(statusVal==null){ subscriber.onCompleted(); }else { final Map<String, Object> data = MAPPER.readValue(mapManager.getString(jobString + dataKey), Map.class); final Status status = Status.valueOf(statusVal); subscriber.onNext(new JobStatus(jobId,status,data)); } subscriber.onCompleted(); }catch (Exception e){ logger.error("Failed to parse map",e); throw new RuntimeException(e); } }); } }
@Override public void call(Subscriber<? super String> s) { System.out.println(">>> TestCollapserCommand run() ... batch size: " + requests.size()); // simulate a batch request for (CollapsedRequest<String, String> request : requests) { if (request.getArgument() == null) { throw new NullPointerException("Simulated Error"); } if (request.getArgument().equals("TIMEOUT")) { try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } s.onNext(request.getArgument()); } s.onCompleted(); }
addLatency(executionLatency); if (executionResult == AbstractTestHystrixCommand.ExecutionResult.SUCCESS) { subscriber.onNext(1); subscriber.onCompleted(); } else if (executionResult == AbstractTestHystrixCommand.ExecutionResult.MULTIPLE_EMITS_THEN_SUCCESS) { subscriber.onNext(2); subscriber.onNext(3); subscriber.onNext(4); subscriber.onNext(5); subscriber.onCompleted(); } else if (executionResult == AbstractTestHystrixCommand.ExecutionResult.MULTIPLE_EMITS_THEN_FAILURE) { subscriber.onNext(6); subscriber.onNext(7); subscriber.onNext(8); subscriber.onNext(9); subscriber.onError(new RuntimeException("Execution Async Failure For TestHystrixObservableCommand after 4 emits")); } else if (executionResult == AbstractTestHystrixCommand.ExecutionResult.ASYNC_FAILURE) {
@Override public void call(Subscriber<? super String> subscriber) { try { assertNotNull("Executing the Batch command should have a HystrixRequestContext", HystrixRequestContext.getContextForCurrentThread()); Thread.sleep(1); for (Integer arg : args) { int numEmits = emitsPerArg.get(arg.toString()); for (int j = 1; j < numEmits + 1; j++) { subscriber.onNext(arg + ":" + (arg * j)); Thread.sleep(1); } Thread.sleep(1); } subscriber.onCompleted(); } catch (Throwable ex) { ex.printStackTrace(); subscriber.onError(ex); } } });
@Override public void onError(Throwable throwable) { try { subscriber.onNext(Result.<R>error(throwable)); } catch (Throwable t) { try { subscriber.onError(t); } catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) { RxJavaPlugins.getInstance().getErrorHandler().handleError(e); } catch (Throwable inner) { Exceptions.throwIfFatal(inner); CompositeException composite = new CompositeException(t, inner); RxJavaPlugins.getInstance().getErrorHandler().handleError(composite); } return; } subscriber.onCompleted(); }