diff --git a/Part 1 - Getting Started/1. Why Rx.md b/Part 1 - Getting Started/1. Why Rx.md index 339ee02..25f391f 100644 --- a/Part 1 - Getting Started/1. Why Rx.md +++ b/Part 1 - Getting Started/1. Why Rx.md @@ -1,49 +1,46 @@ # PART 1 - Getting started -## Why Rx +## Rx? -> Users expect real time data. They want their tweets now. Their order confirmed now. They need prices accurate as of now. Their online games need to be responsive. As a developer, you demand fire-and-forget messaging. You don't want to be blocked waiting for a result. You want to have the result pushed to you when it is ready. Even better, when working with result sets, you want to receive individual results as they are ready. You do not want to wait for the entire set to be processed before you see the first row. The world has moved to push; users are waiting for us to catch up. Developers have tools to push data, this is easy. Developers need tools to react to push data +> 사용자는 실시간 데이터를 기대합니다. 그들은 당장 그들의 트윗이 보이길 원하고 명령이 당장 확인되길 원하며, 정확한 가격이 필요합니다. 또한 그들의 온라인 게임은 반응적일 필요가 있습니다. 개발자는 파이어-앤-포겟(발사 후 망각) 메시지를 요구합니다. 당신은 결과를 기다리는것을 막지 않고 준비가 되었을 때 결과를 푸시하고 싶습니다. 여러 개의 결과값을 사용하여 작업 할 때 준비가 되면 각각의 결과를 받기 원합니다. 전체 집합이 처리 될 때까지 기다리지 않으려고합니다. 세상은 밀어 붙이기 시작했습니다. 사용자는 우리가 따라잡길 기다리고 있습니다. 개발자는 데이터를 푸시 할 수 있는 도구를 가지고 있습니다. 개발자는 데이터를 푸시하기 위해 반응하는 도구가 필요합니다. -Welcome to Rx. This book is based on [Rx.NET](http://msdn.microsoft.com/en-us/devlabs/gg577609)'s www.introtorx.com and it introduces beginners to [RxJava](https://github.com/ReactiveX/RxJava), the Netflix implementation of the original Microsoft library. Rx is a powerful tool that enables the solution of problems in an elegant declarative style, familiar to functional programmers. Rx has several benefits: +Rx에 오신 것을 환영합니다. 이 책은 [Rx.NET](http://msdn.microsoft.com/en-us/devlabs/gg577609)의 www.introtorx.com을 기반으로 하며 오리지널 Microsoft 라이브러리의 Netflix 구현인 [RxJava](https://github.com/ReactiveX/RxJava)를 초보자를 위해 소개합니다. Rx는 함수형 프로그래머에게 익숙한 선언적 스타일로 문제를 해결 할 수 있는 강력한 도구입니다. Rx는 다음과 같은 몇 가지 이점이 있습니다. -* Unitive - * Queries in Rx are done in the same style as other libraries inspired by functional programming, such as Java streams. In Rx, one can use functional style transformations on event streams. -* Extensible - * RxJava can be extended with custom operators. Although Java does not allow for this to happen in an elegant way, RxJava offers all the extensibility one can find Rx implementations in other languages. -* Declarative - * Functional transformations are read in a declarative way. -* Composable - * Rx operators can be combined to produce more complicated operations. -* Transformative - * Rx operators can transform one type of data to another, reducing, mapping or expanding streams as needed. +* 통합 + * Rx의 질의는 함수형 프로그래밍에서 영감을 얻은 다른 라이브러리와 동일한 스타일로 수행됩니다.(예: Java 스트림). Rx에서는 이벤트 스트림에서 함수 스타일 변환을 사용 할 수 있습니다. +* 확장 + * RxJava는 커스텀 연산자를 사용하여 확장 할 수 있습니다. Java가 이것이 일어나는 것을 허용하지는 않지만 RxJava는 다른 언어로 Rx구현을 찾을 수 있는 모든 확장성을 제공합니다. +* 선언 + * 기능적 변환은 선언적 방식으로 읽혀집니다. +* 구성 + * Rx 연산자는 더 복잡한 연산을 생성하기 위해 결합 될 수 있습니다. +* 변형 + * Rx 연산자는 한 유형의 데이터를 다른 유형으로 변환하여 필요에 따라 스트림을 축소, 매핑 또는 확장 할 수 있습니다. -## When is Rx appropriate? +## 언제 Rx를 써야할까? -Rx is fit for composing and consuming sequences of events. We present some of the use cases for Rx, according to www.introtorx.com +Rx는 일련의 이벤트를 작성하고 소비하는 데 적합합니다. www.introtorx.com에 따르면 Rx에 대한 몇 가지 사용 사례를 제시합니다. ### Should use Rx -* UI events like mouse move, button click -* Domain events like property changed, collection updated, "Order Filled", "Registration accepted" etc. -* Infrastructure events like from file watcher, system and WMI events -* Integration events like a broadcast from a message bus or a push event from WebSockets API or other low latency middleware like Nirvana -* Integration with a CEP engine like StreamInsight or StreamBase. +* 마우스 이동, 버튼 클릭과 같은 UI 이벤트 +* 속성 변경, Collection 업데이트, "주문 완료","등록 승인"등의 도메인 이벤트 +* 파일 감시자, 시스템 및 WMI 이벤트와 같은 인프라 이벤트 +* 메시지 버스의 브로드캐스트, WebSocket API & Nivana와 같은 대기 시간이 짧은 미들웨어의 푸시 이벤트와 같은 통합 이벤트 +* StreamInsight 또는 StreamBase와 같은 CEP 엔진과의 통합 ### Could use Rx +* '미래'의 결과 또는 동등한 패턴 -* Result of `Future` or equivalent pattern +이러한 패턴은 미지 잘 구현되어있으며 Rx를 도입하면 개발 프로세스가 추가되지 않는 다는 것을 알고 있습니다. -Those patterns are already well adopted and you may find that introducing Rx on top of that does not add to the development process. +### Rx를 사용하지 않는 사례 +* Rx 라이브러리를 통해 작업하기 위해서 iterable을 observable로 변환해야합니다. -### Won't use Rx +##### 계속 읽기 -* Translating iterables to observables, just for the sake of working on them through an Rx library. - - -##### Continue reading - -| Previous | Next | +| 이전 | 다음 | | --- | --- | | | [Key types](/Part 1 - Getting Started/2. Key types.md) | diff --git a/Part 1 - Getting Started/2. Key types.md b/Part 1 - Getting Started/2. Key types.md index 12ac033..906fee4 100644 --- a/Part 1 - Getting Started/2. Key types.md +++ b/Part 1 - Getting Started/2. Key types.md @@ -1,34 +1,33 @@ # Key types -Rx is based around two fundamental types, while several others expand the functionality around the core types. Those two core types are the `Observable` and the `Observer`, which will be introduced in this chapter. We will also introduce `Subject`s, which ease the learning curve. +Rx는 두 가지 근본적인 유형을 기반으로하며, 일부는 핵심 유형을 중심으로 기능을 확장해야합니다. 이 두가지 핵심 유형은 이 문서에서 소개 될 `Observable`와 `Observer`입니다. 또한 러닝 커브를 쉽게 해주는 `Subject`에 대해서도 소개합니다. -Rx builds upon the [Observer](http://en.wikipedia.org/wiki/Observer_pattern) pattern. It is not unique in doing so. Event handling already exists in Java (e.g. JavaFX's EventHandler). Those are simpler approaches, which suffer in comparison to Rx: +Rx는 [Observer](http://en.wikipedia.org/wiki/Observer_pattern) 패턴을 기반으로합니다. 이것은 그렇게 특별하지 않습니다. Java에는 이미 이벤트 핸들링이 있습니다. (JavaFX's EventHandler). 그것들은 더 쉽게 접근 할 수 있지만 Rx와 비교해보면 고통 받을 수 있습니다. -* Events through event handlers are hard to compose. -* They cannot be queried over time -* They can lead to memory leaks -* These is no standard way of signaling completion. -* Require manual handling of concurrency and multithreading. +* 이벤트 핸들러를 통한 이벤트는 작성하기가 어렵습니다. +* 시간이 지남에 따라 쿼리 할 수 없습니다. +* 메모리 누수가 발생할 수 있습니다. +* 시그널 완료의 표준 방법이 아닙니다. +* 동시성 및 다중 쓰레딩의 수동 처리가 필요합니다. ## Observable -[Observable](http://reactivex.io/RxJava/javadoc/rx/Observable) is the first core element that we will see. This class contains a lot of the implementation of Rx, including all of the core operators. We will be examining it step by step throughout this book. For now, we must understand the `Subscribe` method. Here is one key overload of the method: +[Observable](http://reactivex.io/RxJava/javadoc/rx/Observable)은 처음으로 보게 될 핵짐적인 요소입니다. 이 클래스의 모든 핵심 연산자를 포함하여 Rx 구현이 많이 포함되어있습니다. 우리는 이 문서 전체에 걸쳐 단계적으로 배울 것입니다. 지금은 `subscribe` 메소드를 이해해야합니다. 해당 메소드는 다음과 같은 매개변수와 리턴값을 가지고 있습니다. ```java public final Subscription subscribe(Subscriber subscriber) ``` -This is the method that you use to receive the values emitted by the observable. As the values come to be pushed (through policies that we will discuss throughout this book), they are pushed to the subscriber, which is then responsible for the behaviour intended by the consumer. The `Subscriber` here is an implementation of the `Observer` interface. - -An observable pushes 3 kinds of events -* Values -* Completion, which indicates that no more values will be pushed. -* Errors, if something caused the sequence to fail. These events also imply termination. +위 메소드는 observable에 의해 전달된 값을 받는데 사용되는 메소드입니다. 값이 전달되어 질 때, Consumer가 의도한 동작을 한 다음 subscriber으로 전달됩니다. 여기서 `subscriber`는 `Observer` 인터페이스의 구현체입니다. +Observable는 3종류의 이벤트를 전달합니다. +* 값 +* 완료(더 이상 전달 할 값이 없을 경우) +* 에러, 무언가를 처리하다가 실패를 한 경우, 이 이벤트는 종료를 의미하기도 합니다. ## Observer -We already saw one abstract implementation of the [Observer](http://reactivex.io/RxJava/javadoc/rx/Observer.html), `Subscriber`. `Subscriber` implements some extra functionality and should be used as the basis for our implementations of `Observer`. For now, it is simpler to first understand the interface. +[Observer](http://reactivex.io/RxJava/javadoc/rx/Observer.html)의 추상적인 구현체인 `Subscriber`를 보았습니다. `Subscriber`는 몇 가지 추가 기능을 구현하며 `Observer`구현의 기초로 사용하기도 합니다. 지금은 인터페이스를 먼저 이해하는것이 더 좋습니다. ```java interface Observer { @@ -38,30 +37,29 @@ interface Observer { } ``` -Those three methods are the behaviour that is executed every time the observable pushes a value. The observer will have its `onNext` called zero or more times, optionally followed by an `onCompleted` or an `onError`. No calls happen after a call to `onError` or `onCompleted`. - -When developing Rx code, you'll see a lot of `Observable`, but not so much of `Observer`. While it is important to understand the `Observer`, there are shorthands that remove the need to instantiate it yourself. +3개의 메소드는 observable이 값을 전달 할 때 마다 실행되는 메소드입니다. observer는 0번 이상 호출되는 `onNext`를 가지며 선택적으로 `onCompleted`나 `onError`가 뒤 따릅니다. `onError` 또는 `onCompleted`를 호출 한 후에는 더 이상 호출이 일어나지 않습니다. +Rx 코드를 개발 할 때, `Observable`를 많이 볼 순 있지만 `Observer`는 그리 많지가 않습니다. `Observer`를 이해하는 것이 중요하지만, 스스로를 인스턴스화 할 필요성을 제거하는 특징이 있습니다. -## Implementing Observable and Observer +## Observable와 Observer 구현 -You could manually implement `Observer` or extend `Observable`. In reality that will usually be unnecessary, since Rx already provides all the building blocks you need. It is also dangerous, as interaction between parts of Rx includes conventions and internal plumming that are not obvious to a beginner. It is both simpler and safer to use the many tools that Rx gives you for generating the functionality that you need. +직접 `Observer`을 구현하거나 `Observable`을 확장 할 수 있습니다. Rx는 필요한 모든 구성 요소를 제공하기 때문에 실제로는 불필요합니다. 그것은 위험한 방법이기도 한데, Rx의 요소들 간의 상호작용에는 초보자에게는 분명하지 않은 규약이나 내부 연관성이 있습니다. Rx가 필요한 기능을 생성하는데 필요한 여러 도구를 사용하는 것이 더 간단하고 안전합니다. -To subscribe to an observable, it is not necessary to provide instances of `Observer` at all. There are overloads to `subscribe` that simply take the functions to be executed for `onNext`, `onError` and `onSubscribe`, hiding away the instantiation of the corresponding `Observer`. It is not even necessary to provide each of those functions. You can provide a subset of them, i.e. just `onNext` or just `onNext` and `onError`. +observable를 subscribe하려면 `Observer`의 인스턴스를 제공 할 필요가 없습니다. `onNext`,`onError` 및 `onSubscribe`에 대해 실행되는 메소드를 구현하고 해당 `Observer`의 인스턴스 생성을 숨기는 `subscribe`를 오버로드합니다. 각 기능을 제공할 필요도 없으며 부분을 제공 할 수도 있습니다.(예 : `onNext` 또는 `onNext` 및 `onError`). -The introduction of lambda functions in Java 1.8 makes these overloads very convenient for the short examples that exist in this book. +Java 1.8에서 람다 함수를 도입하면서 이 책에 있는 간단한 예제를 매우 편리하게 오버로드 할 수 있게되었습니다. ## Subject -Subjects are an extension of the `Observable` that also implements the `Observer` interface. The idea may sound odd at first, but they make things a lot simpler in some cases. They can have events pushed to them (like observers), which they then push further to their own subscribers (like observables). This makes them ideal entry points into Rx code: when you have values coming in from outside of Rx, you can push them into a `Subject`, turning them into an observable. You can think of them as entry points to an Rx pipeline. +Subject는 `Observer` 인터페이스를 구현하는 `Observable`의 확장입니다. 이 생각은 처음에 이상하게 들릴수도 있는데, 어떠한 경우에는 훨씬 더 간단해집니다. Subject는 Observer와 같이 이벤트를 전달 할 수도 있으며, Observable와 같이 자신의 subscriber에게 값을 전달 할 수 있습니다. 외부에서 값을 가져오는 경우 이 `Subject`를 이용하면 Observable로 변환하는데 있어 Rx코드에 대한 이상적인 진입점이 됩니다. Rx 파이프라인의 진입점이라 생각 할 수도 있습니다. -`Subject` has two parameter types: the input type and the output type. This was designed so for the sake of abstraction and not because the common uses for subjects involve transforming values. There are transformation operators to do that, which we will see later. +`Subject`는 입력과 출력 두 가지의 파라미터 유형을 가지고 있습니다. 이것은 추상적인 목적을 위해서 설계된 것이지 Subject의 일반적인 용도가 값을 변형시키는 것이 아니기 때문입니다. 이를 수행 할 수 있는 변환 연산자가 있는데 나중에 살펴보겠습니다. -There are a few different implementations of `Subject`. We will now examine the most important ones and their differences. +`Subject`는 몇가지 다른 구현체가 있습니다. 가장 중요한 것들과 그 차이점에 대해서 알아보겠습니다. ### PublishSubject -`PublishSubject` is the most straight-forward kind of subject. When a value is pushed into a `PublishSubject`, the subject pushes it to every subscriber that is subscribed to it at that moment. +`PublishSubject` 가장 간단한 종류의 subject입니다. 값이 `PublishSubject`에 전달 될 때 subject는 그 값을 모든 subscriber에 전달합니다. ```java public static void main(String[] args) { @@ -80,17 +78,16 @@ public static void main(String[] args) { 4 ``` -As we can see in the example, `1` isn't printed because we weren't subscribed when it was pushed. After we subscribed, we began receiving the values that were pushed to the subject. +예제를 보면 값이 전달되어 질 때 subscribe가 없기 때문에 `1`이 출력되지 않았습니다. subscribe를 등록 한 후에 subject에 전달된 값을 출력 하기 시작했습니다. -This is the first time we see `subscribe` being used, so it is worth paying attention to how it was used. In this case, we used the overload which expects one [Function](http://reactivex.io/RxJava/javadoc/rx/functions/Function.html) for the case of onNext. That function takes an argument of type `Integer` and returns nothing. Functions without a return type are also called actions. We can provide that function in different ways: -* we can supply an instance of `Action1`, -* implicitly create one using a [lambda expression](http://en.wikipedia.org/wiki/Anonymous_function#Java) or -* pass a reference to an existing method that fits the signature. -In this case, `System.out::println` has an overload that accepts `Object`, so we passed a reference to it. `subscribe` will call `println` with the arriving values as the argument. +우리는 `subscribe`가 사용되는 것을 처음보았기 때문에 이것이 어떻게 사용되었는지를 주목해야합니다. 우리는 onNext의 경우에 대해 하나의 [Function](http://reactivex.io/RxJava/javadoc/rx/functions/Function.html)를 사용했습니다. 이 함수는 `Integer` 형의 인수를 취하고 아무것도 반환하지 않습니다. 반환 유형이 없는 함수를 action이라고도 합니다. 우리는 그 기능을 다른 방법으로 제공 할 수 있습니다. +* `Action1`의 인스턴스를 제공. +* [람다 식](http://en.wikipedia.org/wiki/Anonymous_function#Java)을 사용하여 암시적으로 만듬 +* 매개변수에 맞는 기존 메소드에 대한 참조를 전달. 위 예제에서 `System.out::println`은 `Object`를 받아드리는 오버로드를 가지고 있기 때문에 그것에 대한 참조를 전달. `subscribe`는 전달되는 값을 인수로 하여 `println`을 호출. ### ReplaySubject -`ReplaySubject` has the special feature of caching all the values pushed to it. When a new subscription is made, the event sequence is replayed from the start for the new subscriber. After catching up, every subscriber receives new events as they come. +`ReplaySubject`는 전달된 모든 값을 캐싱하고 있는 특별한 기능을 가지고 있습니다. 새로운 subscription이 만들어지면 새 subscriber의 대한 이벤트 시퀀스가 재생됩니다. 이벤트가 전달되면 저장된 모든 subscriber는 새로운 이벤트를 받습니다. ```java ReplaySubject s = ReplaySubject.create(); @@ -110,16 +107,16 @@ Early:2 Late: 2 ``` -All the values are received by the subscribers, even though one was late. Also notice that the late subscriber had everything replayed to it before proceeding to the next value. +하나의 값이 나중에 전달되더라도 모든 값을 subscriber가 수신합니다. 또 등록이 늦은 subscriber가 다음 값이 진행되기 전에 이전 값을 처리했음을 주목하십시오. -Caching everything isn't always a good idea, as an observable sequence can run for a long time. There are ways to limit the size of the internal buffer. `ReplaySubject.createWithSize` limits the size of the buffer, while `ReplaySubject.createWithTime` limits how long an object can stay cached. +observable 시퀀스는 오랫동안 실행 될 수 있기 때문에 모든 값을 캐싱하는 것은 좋은 생각이 아닙니다. `ReplaySubject.createWithSize`는 버퍼의 크기를 제한하고, `ReplaySubject.createWithTime`는 객체가 캐시 된 기간을 제한합니다. ```java ReplaySubject s = ReplaySubject.createWithSize(2); s.onNext(0); s.onNext(1); s.onNext(2); -s.subscribe(v -> System.out.println("Late: " + v)); +s.subscribe(v -> System.out.println("Late: " + v)); s.onNext(3); ``` [Output](/tests/java/itrx/chapter1/ReplaySubjectExample.java) @@ -129,7 +126,7 @@ Late: 2 Late: 3 ``` -Our late subscriber now missed the first value, which fell off the buffer of size 2. Similarily, old values fall off the buffer as time passes, when the subject is created with `createWithTime` +버퍼 사이즈를 2로 제한했기 때문에 늦게 등록된 subscriber는 첫 번째 값을 놓쳤습니다. subject가 `createWithTime`에 의해서 생성 될 때 지정된 시간이 지나게 된 이후에 버퍼에 등록된 값이 전달됩니다. ```java ReplaySubject s = ReplaySubject.createWithTime(150, TimeUnit.MILLISECONDS, @@ -139,7 +136,7 @@ Thread.sleep(100); s.onNext(1); Thread.sleep(100); s.onNext(2); -s.subscribe(v -> System.out.println("Late: " + v)); +s.subscribe(v -> System.out.println("Late: " + v)); s.onNext(3); ``` [Output](/tests/java/itrx/chapter1/ReplaySubjectExample.java) @@ -149,9 +146,9 @@ Late: 2 Late: 3 ``` -Creating a `ReplaySubject` with time requires a `Scheduler`, which is Rx's way of keeping time. Feel free to ignore this for now, as we will properly introduce schedulers in the chapter about concurrency. +`createWithTime`를 이용하여 `ReplaySubject`를 생성하기 위해서는 `Scheduler`가 필요합니다. Rx가 시간을 처리하는 방식입니다. 동시성에 대한 파트에서 `Scheduler`를 소개 할 것이기 때문에 지금은 이를 무시하세요. -`ReplaySubject.createWithTimeAndSize` limits both, which ever comes first. +`ReplaySubject.createWithTimeAndSize`는 시간과 버퍼 사이즈를 둘 다 제한합니다. ### BehaviorSubject diff --git a/README.md b/README.md index 04a8584..b1392b4 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,20 @@ -# Intro to RxJava +> *이 문서는 [Intro-to-Rxjava](https://github.com/Froussios/Intro-To-RxJava)를 Fork하여 번역한 문서입니다.* -This guide aims to introduce a beginner reactive programmer to the complete power of the [RxJava](https://github.com/ReactiveX/RxJava) implementation of reactive programming for the JVM. It is based on the [IntroToRx](http://www.introtorx.com) guide for Rx.NET. +# RxJava 소개 -No experience with either reactive or functional programming is needed to follow the book. Familiarity with the basics of Java is required. +이 가이드는 리액티브 프로그래머가 [RxJava](https://github.com/ReactiveX/RxJava)를 통해 JVM용 리액티브 프로그래밍을 구현하는 것을 목표로 합니다. Rx.NET의 [IntroToRx](http://www.introtorx.com) 가이드를 기반으로 합니다. -[Begin learning](/Part 1 - Getting Started/1. Why Rx.md) +이 가이드를 읽으려면 리액티브, 함수형 프로그래밍에 대한 경험이 필요 없습니다. 다만 자바에 익숙해야합니다. -### Structure +[학습 시작](/Part 1 - Getting Started/1. Why Rx.md) -The content of this book is meant to be read from start to finish. It is bigger than your average tutorial and smaller than an actual book. It begins with the basics and every subsequent chapter introduces increasingly advanced features and concepts. Sections of the book are intended to be self-containing and to-the-point, so that the book can be referred back to by non-beginners. +### 구조 -The examples used in the book are also [available in compilable java files](/tests/java/itrx) in two formats: -* Examples that print to standard output (recommended for first-time readers) -* Silent, self-checking examples in the form of [JUnit](http://junit.org/) tests. -The readers are invited to study whichever style suits them best. +이 가이드의 내용을 처음부터 끝까지 읽어야하며 평균적인 튜토리얼보다 양이 많지만 실제 책보다는 작습니다. Rx에 대한 기본부터 시작하고 후속으로 갈 수록 점점 더 진보된 기능과 개념을 소개합니다. 이 가이드의 섹션은 초보자가 아닌 사람이 다시 참조 할 수 있도록 자체 포함되고 점으로 구성됩니다. + +이 가이드에서 사용된 예제는 2가지 형식의 [컴파일 가능한 자바 파일](/tests/java/itrx)로 제공됩니다: +* 표준 out으로 출력하는 예제(처음 읽는 사람에게 권장) +* [JUnit](http://junit.org/)으로 체크하는 예제. + +독자들은 자신에게 적합한 스타일로 예제를 볼 수 있습니다.