You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/05/08 10:26:14 UTC
[camel] 05/05: Camel-Soroush: Removed useless class
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 08b1b2da5dea38d84a8f288459ee60dfc8857cc4
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed May 8 12:25:27 2019 +0200
Camel-Soroush: Removed useless class
---
.../src/test/java/playground/OkHTTP.java | 110 ---------------------
1 file changed, 110 deletions(-)
diff --git a/components/camel-soroush/src/test/java/playground/OkHTTP.java b/components/camel-soroush/src/test/java/playground/OkHTTP.java
deleted file mode 100644
index 44165b3..0000000
--- a/components/camel-soroush/src/test/java/playground/OkHTTP.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package playground;
-
-import java.time.Duration;
-import java.util.concurrent.TimeUnit;
-
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
-import okhttp3.sse.EventSource;
-import okhttp3.sse.EventSourceListener;
-import okhttp3.sse.EventSources;
-import org.apache.camel.component.soroushbot.utils.ExponentialBackOffStrategy;
-
-public class OkHTTP {
- public static void main(String[] args) throws InterruptedException {
- String url = "https://bot.sapp.ir/NQcJlsDAviBNaUWPQpLZS3UkUbfiY316QpULBvpZze1aJ4r_RkhQaV9pC0IqRfOl4rBG2TbJc1n2jD4zsIrSirDcb1x_i5wsRQFsNE6s_tS7YMX2kyIYycLI2g6mXbyXB4YBaD-dSWSnPUxV/getMessage";
- Request request = new Request.Builder()
- .url(url)
- .build();
- System.out.println(url);
- OkHttpClient client = new OkHttpClient.Builder().writeTimeout(Duration.ZERO).readTimeout(Duration.ZERO).connectTimeout(10,TimeUnit.SECONDS).callTimeout(Duration.ZERO).build();
- ExponentialBackOffStrategy backOffStrategy = new ExponentialBackOffStrategy(1000l,2l,3600_000L);
- ReconnectableEventSourceListener connection = new ReconnectableEventSourceListener(client, request, 10){
- @Override
- public void onEvent(EventSource eventSource, String id, String type, String data) {
- System.out.println(data);
- }
-
- @Override
- protected boolean onBeforeConnect() {
- try {
- backOffStrategy.waitBeforeRetry(connectionRetry);
- return true;
- } catch (InterruptedException e) {
- return false;
- }
- }
- };
- connection.connect();
-
-
- }
- static class ReconnectableEventSourceListener extends EventSourceListener {
- OkHttpClient client;
- final int maxConnectionRetry;
- int connectionRetry=0;
- Request request;
- private final EventSource.Factory factory;
-
- public ReconnectableEventSourceListener(OkHttpClient client,Request request ,int maxConnectionRetry) {
- this.client = client;
- this.maxConnectionRetry = maxConnectionRetry;
- this.request=request;
- factory = EventSources.createFactory(client);
- }
- public void connect(){
- if(!onBeforeConnect()){
- return;
- }
- if(maxConnectionRetry>=connectionRetry || maxConnectionRetry<0){
- System.out.println(connectionRetry);
- factory.newEventSource(request,this);
- }
- }
-
- protected boolean onBeforeConnect() {
- return true;
- }
-
- @Override
- public void onOpen(EventSource eventSource, Response response) {
- System.out.println(Thread.currentThread().toString());
- System.out.println("OPEN");
- connectionRetry=0;
- }
-
- @Override
- public void onClosed(EventSource eventSource) {
- System.out.println("CLOSED");
- connectionRetry++;
- connect();
- }
-
- @Override
- public void onFailure(EventSource eventSource, Throwable t, Response response) {
- System.out.println(Thread.currentThread().toString());
- eventSource.cancel();
- System.out.println("FAILURE "+eventSource.toString());
- connectionRetry++;
- connect();
- }
- }
-}