{"action":"created","comment":{"url":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/comments/173470943","pull_request_review_id":102671958,"id":173470943,"diff_hunk":"@@ -209,4 +215,52 @@ public Boolean call(Object emission) {\n             }\n         };\n     }\n+\n+    private static Func1<Observable<? extends Throwable>, Observable<?>> errorIsRetryableAndAccordingTo(\n+            final WriteOperationRetryStrategy writeOperationRetryStrategy,\n+            final ByteBuffer byteBuffer,\n+            final int batchSize) {\n+        return new Func1<Observable<? extends Throwable>, Observable<?>>() {\n+            @Override\n+            public Observable<?> call(Observable<? extends Throwable> emittedOnWriteFailure) {\n+                return emittedOnWriteFailure\n+                        .flatMap(toLongWriteFailureOrError())\n+                        .doOnNext(repositionByteBufferForRetry())\n+                        .compose(writeOperationRetryStrategy);\n+            }\n+\n+            @NonNull\n+            private Func1<Throwable, Observable<WriteOperationRetryStrategy.LongWriteFailure>> toLongWriteFailureOrError() {\n+                return new Func1<Throwable, Observable<WriteOperationRetryStrategy.LongWriteFailure>>() {\n+                    @Override\n+                    public Observable<WriteOperationRetryStrategy.LongWriteFailure> call(Throwable throwable) {\n+                        if (!(throwable instanceof BleGattCharacteristicException || throwable instanceof BleGattCannotStartException)) {\n+                            return Observable.error(throwable);\n+                        }\n+                        final int failedBatchNumber = calculateFailedBatchNumber(byteBuffer, batchSize);\n+                        WriteOperationRetryStrategy.LongWriteFailure longWriteFailure = new WriteOperationRetryStrategy.LongWriteFailure(\n+                                failedBatchNumber,\n+                                (BleGattException) throwable\n+                        );\n+                        return Observable.just(longWriteFailure);\n+                    }\n+                };\n+            }\n+\n+            @NonNull\n+            private Action1<WriteOperationRetryStrategy.LongWriteFailure> repositionByteBufferForRetry() {\n+                return new Action1<WriteOperationRetryStrategy.LongWriteFailure>() {\n+                    @Override\n+                    public void call(WriteOperationRetryStrategy.LongWriteFailure longWriteFailure) {\n+                        final int newBufferPosition = longWriteFailure.getBatchNumber() * batchSize - batchSize;\n+                        byteBuffer.position(newBufferPosition);\n+                    }\n+                };\n+            }\n+\n+            private int calculateFailedBatchNumber(ByteBuffer byteBuffer, int batchSize) {\n+                return (int) Math.ceil(byteBuffer.position() / (float) batchSize);","path":"rxandroidble/src/main/java/com/polidea/rxandroidble/internal/operations/CharacteristicLongWriteOperation.java","position":109,"original_position":109,"commit_id":"b9c0ba2c4438d548a10b024644fef8aa51baad81","original_commit_id":"b9c0ba2c4438d548a10b024644fef8aa51baad81","user":{"login":"dariuszseweryn","id":1412475,"avatar_url":"https://avatars0.githubusercontent.com/u/1412475?v=4","gravatar_id":"","url":"https://api.github.com/users/dariuszseweryn","html_url":"https://github.com/dariuszseweryn","followers_url":"https://api.github.com/users/dariuszseweryn/followers","following_url":"https://api.github.com/users/dariuszseweryn/following{/other_user}","gists_url":"https://api.github.com/users/dariuszseweryn/gists{/gist_id}","starred_url":"https://api.github.com/users/dariuszseweryn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dariuszseweryn/subscriptions","organizations_url":"https://api.github.com/users/dariuszseweryn/orgs","repos_url":"https://api.github.com/users/dariuszseweryn/repos","events_url":"https://api.github.com/users/dariuszseweryn/events{/privacy}","received_events_url":"https://api.github.com/users/dariuszseweryn/received_events","type":"User","site_admin":false},"body":"doesn't it return a failed batch number + 1?","created_at":"2018-03-09T14:54:03Z","updated_at":"2018-03-09T14:54:03Z","html_url":"https://github.com/Polidea/RxAndroidBle/pull/357#discussion_r173470943","pull_request_url":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/357","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/comments/173470943"},"html":{"href":"https://github.com/Polidea/RxAndroidBle/pull/357#discussion_r173470943"},"pull_request":{"href":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/357"}}},"pull_request":{"url":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/357","id":163785165,"html_url":"https://github.com/Polidea/RxAndroidBle/pull/357","diff_url":"https://github.com/Polidea/RxAndroidBle/pull/357.diff","patch_url":"https://github.com/Polidea/RxAndroidBle/pull/357.patch","issue_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/357","number":357,"state":"open","locked":false,"title":"Added retry mechanism parameter for LongWriteOperation","user":{"login":"martiwi","id":18901891,"avatar_url":"https://avatars1.githubusercontent.com/u/18901891?v=4","gravatar_id":"","url":"https://api.github.com/users/martiwi","html_url":"https://github.com/martiwi","followers_url":"https://api.github.com/users/martiwi/followers","following_url":"https://api.github.com/users/martiwi/following{/other_user}","gists_url":"https://api.github.com/users/martiwi/gists{/gist_id}","starred_url":"https://api.github.com/users/martiwi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martiwi/subscriptions","organizations_url":"https://api.github.com/users/martiwi/orgs","repos_url":"https://api.github.com/users/martiwi/repos","events_url":"https://api.github.com/users/martiwi/events{/privacy}","received_events_url":"https://api.github.com/users/martiwi/received_events","type":"User","site_admin":false},"body":"PR for issue https://github.com/Polidea/RxAndroidBle/issues/352","created_at":"2018-01-18T18:16:57Z","updated_at":"2018-03-09T14:54:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"71d8ebd12dc857cbf5dcad2e17c069ad4140560f","assignee":{"login":"uKL","id":2377962,"avatar_url":"https://avatars3.githubusercontent.com/u/2377962?v=4","gravatar_id":"","url":"https://api.github.com/users/uKL","html_url":"https://github.com/uKL","followers_url":"https://api.github.com/users/uKL/followers","following_url":"https://api.github.com/users/uKL/following{/other_user}","gists_url":"https://api.github.com/users/uKL/gists{/gist_id}","starred_url":"https://api.github.com/users/uKL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uKL/subscriptions","organizations_url":"https://api.github.com/users/uKL/orgs","repos_url":"https://api.github.com/users/uKL/repos","events_url":"https://api.github.com/users/uKL/events{/privacy}","received_events_url":"https://api.github.com/users/uKL/received_events","type":"User","site_admin":false},"assignees":[{"login":"uKL","id":2377962,"avatar_url":"https://avatars3.githubusercontent.com/u/2377962?v=4","gravatar_id":"","url":"https://api.github.com/users/uKL","html_url":"https://github.com/uKL","followers_url":"https://api.github.com/users/uKL/followers","following_url":"https://api.github.com/users/uKL/following{/other_user}","gists_url":"https://api.github.com/users/uKL/gists{/gist_id}","starred_url":"https://api.github.com/users/uKL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uKL/subscriptions","organizations_url":"https://api.github.com/users/uKL/orgs","repos_url":"https://api.github.com/users/uKL/repos","events_url":"https://api.github.com/users/uKL/events{/privacy}","received_events_url":"https://api.github.com/users/uKL/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/357/commits","review_comments_url":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/357/comments","review_comment_url":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/357/comments","statuses_url":"https://api.github.com/repos/Polidea/RxAndroidBle/statuses/b9c0ba2c4438d548a10b024644fef8aa51baad81","head":{"label":"martiwi:feature/issue_352_retry_mechanism","ref":"feature/issue_352_retry_mechanism","sha":"b9c0ba2c4438d548a10b024644fef8aa51baad81","user":{"login":"martiwi","id":18901891,"avatar_url":"https://avatars1.githubusercontent.com/u/18901891?v=4","gravatar_id":"","url":"https://api.github.com/users/martiwi","html_url":"https://github.com/martiwi","followers_url":"https://api.github.com/users/martiwi/followers","following_url":"https://api.github.com/users/martiwi/following{/other_user}","gists_url":"https://api.github.com/users/martiwi/gists{/gist_id}","starred_url":"https://api.github.com/users/martiwi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martiwi/subscriptions","organizations_url":"https://api.github.com/users/martiwi/orgs","repos_url":"https://api.github.com/users/martiwi/repos","events_url":"https://api.github.com/users/martiwi/events{/privacy}","received_events_url":"https://api.github.com/users/martiwi/received_events","type":"User","site_admin":false},"repo":{"id":116370783,"name":"RxAndroidBle","full_name":"martiwi/RxAndroidBle","owner":{"login":"martiwi","id":18901891,"avatar_url":"https://avatars1.githubusercontent.com/u/18901891?v=4","gravatar_id":"","url":"https://api.github.com/users/martiwi","html_url":"https://github.com/martiwi","followers_url":"https://api.github.com/users/martiwi/followers","following_url":"https://api.github.com/users/martiwi/following{/other_user}","gists_url":"https://api.github.com/users/martiwi/gists{/gist_id}","starred_url":"https://api.github.com/users/martiwi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martiwi/subscriptions","organizations_url":"https://api.github.com/users/martiwi/orgs","repos_url":"https://api.github.com/users/martiwi/repos","events_url":"https://api.github.com/users/martiwi/events{/privacy}","received_events_url":"https://api.github.com/users/martiwi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/martiwi/RxAndroidBle","description":"An Android library for Bluetooth Low Energy (BLE) interactions backed with RxJava","fork":true,"url":"https://api.github.com/repos/martiwi/RxAndroidBle","forks_url":"https://api.github.com/repos/martiwi/RxAndroidBle/forks","keys_url":"https://api.github.com/repos/martiwi/RxAndroidBle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/martiwi/RxAndroidBle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/martiwi/RxAndroidBle/teams","hooks_url":"https://api.github.com/repos/martiwi/RxAndroidBle/hooks","issue_events_url":"https://api.github.com/repos/martiwi/RxAndroidBle/issues/events{/number}","events_url":"https://api.github.com/repos/martiwi/RxAndroidBle/events","assignees_url":"https://api.github.com/repos/martiwi/RxAndroidBle/assignees{/user}","branches_url":"https://api.github.com/repos/martiwi/RxAndroidBle/branches{/branch}","tags_url":"https://api.github.com/repos/martiwi/RxAndroidBle/tags","blobs_url":"https://api.github.com/repos/martiwi/RxAndroidBle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/martiwi/RxAndroidBle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/martiwi/RxAndroidBle/git/refs{/sha}","trees_url":"https://api.github.com/repos/martiwi/RxAndroidBle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/martiwi/RxAndroidBle/statuses/{sha}","languages_url":"https://api.github.com/repos/martiwi/RxAndroidBle/languages","stargazers_url":"https://api.github.com/repos/martiwi/RxAndroidBle/stargazers","contributors_url":"https://api.github.com/repos/martiwi/RxAndroidBle/contributors","subscribers_url":"https://api.github.com/repos/martiwi/RxAndroidBle/subscribers","subscription_url":"https://api.github.com/repos/martiwi/RxAndroidBle/subscription","commits_url":"https://api.github.com/repos/martiwi/RxAndroidBle/commits{/sha}","git_commits_url":"https://api.github.com/repos/martiwi/RxAndroidBle/git/commits{/sha}","comments_url":"https://api.github.com/repos/martiwi/RxAndroidBle/comments{/number}","issue_comment_url":"https://api.github.com/repos/martiwi/RxAndroidBle/issues/comments{/number}","contents_url":"https://api.github.com/repos/martiwi/RxAndroidBle/contents/{+path}","compare_url":"https://api.github.com/repos/martiwi/RxAndroidBle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/martiwi/RxAndroidBle/merges","archive_url":"https://api.github.com/repos/martiwi/RxAndroidBle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/martiwi/RxAndroidBle/downloads","issues_url":"https://api.github.com/repos/martiwi/RxAndroidBle/issues{/number}","pulls_url":"https://api.github.com/repos/martiwi/RxAndroidBle/pulls{/number}","milestones_url":"https://api.github.com/repos/martiwi/RxAndroidBle/milestones{/number}","notifications_url":"https://api.github.com/repos/martiwi/RxAndroidBle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/martiwi/RxAndroidBle/labels{/name}","releases_url":"https://api.github.com/repos/martiwi/RxAndroidBle/releases{/id}","deployments_url":"https://api.github.com/repos/martiwi/RxAndroidBle/deployments","created_at":"2018-01-05T10:02:59Z","updated_at":"2018-01-05T10:03:01Z","pushed_at":"2018-03-09T14:42:41Z","git_url":"git://github.com/martiwi/RxAndroidBle.git","ssh_url":"git@github.com:martiwi/RxAndroidBle.git","clone_url":"https://github.com/martiwi/RxAndroidBle.git","svn_url":"https://github.com/martiwi/RxAndroidBle","homepage":"http://polidea.github.io/RxAndroidBle/","size":1756,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Polidea:master","ref":"master","sha":"8c6315db58784870f34cef46ef1e0c3c46c3e114","user":{"login":"Polidea","id":1611150,"avatar_url":"https://avatars2.githubusercontent.com/u/1611150?v=4","gravatar_id":"","url":"https://api.github.com/users/Polidea","html_url":"https://github.com/Polidea","followers_url":"https://api.github.com/users/Polidea/followers","following_url":"https://api.github.com/users/Polidea/following{/other_user}","gists_url":"https://api.github.com/users/Polidea/gists{/gist_id}","starred_url":"https://api.github.com/users/Polidea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Polidea/subscriptions","organizations_url":"https://api.github.com/users/Polidea/orgs","repos_url":"https://api.github.com/users/Polidea/repos","events_url":"https://api.github.com/users/Polidea/events{/privacy}","received_events_url":"https://api.github.com/users/Polidea/received_events","type":"Organization","site_admin":false},"repo":{"id":51078408,"name":"RxAndroidBle","full_name":"Polidea/RxAndroidBle","owner":{"login":"Polidea","id":1611150,"avatar_url":"https://avatars2.githubusercontent.com/u/1611150?v=4","gravatar_id":"","url":"https://api.github.com/users/Polidea","html_url":"https://github.com/Polidea","followers_url":"https://api.github.com/users/Polidea/followers","following_url":"https://api.github.com/users/Polidea/following{/other_user}","gists_url":"https://api.github.com/users/Polidea/gists{/gist_id}","starred_url":"https://api.github.com/users/Polidea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Polidea/subscriptions","organizations_url":"https://api.github.com/users/Polidea/orgs","repos_url":"https://api.github.com/users/Polidea/repos","events_url":"https://api.github.com/users/Polidea/events{/privacy}","received_events_url":"https://api.github.com/users/Polidea/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Polidea/RxAndroidBle","description":"An Android library for Bluetooth Low Energy (BLE) interactions backed with RxJava","fork":false,"url":"https://api.github.com/repos/Polidea/RxAndroidBle","forks_url":"https://api.github.com/repos/Polidea/RxAndroidBle/forks","keys_url":"https://api.github.com/repos/Polidea/RxAndroidBle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Polidea/RxAndroidBle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Polidea/RxAndroidBle/teams","hooks_url":"https://api.github.com/repos/Polidea/RxAndroidBle/hooks","issue_events_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/events{/number}","events_url":"https://api.github.com/repos/Polidea/RxAndroidBle/events","assignees_url":"https://api.github.com/repos/Polidea/RxAndroidBle/assignees{/user}","branches_url":"https://api.github.com/repos/Polidea/RxAndroidBle/branches{/branch}","tags_url":"https://api.github.com/repos/Polidea/RxAndroidBle/tags","blobs_url":"https://api.github.com/repos/Polidea/RxAndroidBle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Polidea/RxAndroidBle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Polidea/RxAndroidBle/git/refs{/sha}","trees_url":"https://api.github.com/repos/Polidea/RxAndroidBle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Polidea/RxAndroidBle/statuses/{sha}","languages_url":"https://api.github.com/repos/Polidea/RxAndroidBle/languages","stargazers_url":"https://api.github.com/repos/Polidea/RxAndroidBle/stargazers","contributors_url":"https://api.github.com/repos/Polidea/RxAndroidBle/contributors","subscribers_url":"https://api.github.com/repos/Polidea/RxAndroidBle/subscribers","subscription_url":"https://api.github.com/repos/Polidea/RxAndroidBle/subscription","commits_url":"https://api.github.com/repos/Polidea/RxAndroidBle/commits{/sha}","git_commits_url":"https://api.github.com/repos/Polidea/RxAndroidBle/git/commits{/sha}","comments_url":"https://api.github.com/repos/Polidea/RxAndroidBle/comments{/number}","issue_comment_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/comments{/number}","contents_url":"https://api.github.com/repos/Polidea/RxAndroidBle/contents/{+path}","compare_url":"https://api.github.com/repos/Polidea/RxAndroidBle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Polidea/RxAndroidBle/merges","archive_url":"https://api.github.com/repos/Polidea/RxAndroidBle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Polidea/RxAndroidBle/downloads","issues_url":"https://api.github.com/repos/Polidea/RxAndroidBle/issues{/number}","pulls_url":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls{/number}","milestones_url":"https://api.github.com/repos/Polidea/RxAndroidBle/milestones{/number}","notifications_url":"https://api.github.com/repos/Polidea/RxAndroidBle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Polidea/RxAndroidBle/labels{/name}","releases_url":"https://api.github.com/repos/Polidea/RxAndroidBle/releases{/id}","deployments_url":"https://api.github.com/repos/Polidea/RxAndroidBle/deployments","created_at":"2016-02-04T13:42:02Z","updated_at":"2018-03-09T12:22:45Z","pushed_at":"2018-03-09T14:42:43Z","git_url":"git://github.com/Polidea/RxAndroidBle.git","ssh_url":"git@github.com:Polidea/RxAndroidBle.git","clone_url":"https://github.com/Polidea/RxAndroidBle.git","svn_url":"https://github.com/Polidea/RxAndroidBle","homepage":"http://polidea.github.io/RxAndroidBle/","size":1885,"stargazers_count":1529,"watchers_count":1529,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":275,"mirror_url":null,"archived":false,"open_issues_count":38,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":275,"open_issues":38,"watchers":1529,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/357"},"html":{"href":"https://github.com/Polidea/RxAndroidBle/pull/357"},"issue":{"href":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/357"},"comments":{"href":"https://api.github.com/repos/Polidea/RxAndroidBle/issues/357/comments"},"review_comments":{"href":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/357/comments"},"review_comment":{"href":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Polidea/RxAndroidBle/pulls/357/commits"},"statuses":{"href":"https://api.github.com/repos/Polidea/RxAndroidBle/statuses/b9c0ba2c4438d548a10b024644fef8aa51baad81"}},"author_association":"NONE"}}
{"actor":{"display_login":"dariuszseweryn"}}