Search in sources :

Example 6 with Action1

use of rx.functions.Action1 in project Hystrix by Netflix.

the class HystrixConcurrencyStrategyTest method testThreadContextOnTimeout.

@Test
public void testThreadContextOnTimeout() {
    final AtomicBoolean isInitialized = new AtomicBoolean();
    new TimeoutCommand().toObservable().doOnError(new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            isInitialized.set(HystrixRequestContext.isCurrentThreadInitialized());
        }
    }).materialize().toBlocking().single();
    System.out.println("initialized = " + HystrixRequestContext.isCurrentThreadInitialized());
    System.out.println("initialized inside onError = " + isInitialized.get());
    assertEquals(true, isInitialized.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) Test(org.junit.Test)

Example 7 with Action1

use of rx.functions.Action1 in project Reader by TheKeeperOfPie.

the class TableLink method storeLink.

public Action1<SQLiteDatabase> storeLink(final Link link) {
    return new Action1<SQLiteDatabase>() {

        @Override
        public void call(SQLiteDatabase sqLiteDatabase) {
            sqLiteDatabase.beginTransaction();
            if (link.getComments().getChildren().isEmpty()) {
                TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMN_TITLE, COLUMN_AUTHOR, COLUMN_JSON);
                transaction.insertOrReplace(link.getId(), System.currentTimeMillis(), link.getCreatedUtc(), link.getTitle(), link.getAuthor(), link.getJson());
            } else {
                TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMN_TITLE, COLUMN_AUTHOR, COLUMN_JSON, COLUMN_COMMENTS);
                transaction.insertOrReplace(link.getId(), System.currentTimeMillis(), link.getCreatedUtc(), link.getTitle(), link.getAuthor(), link.getJson(), link.getJsonComments());
            }
            sqLiteDatabase.setTransactionSuccessful();
            sqLiteDatabase.endTransaction();
        }
    };
}
Also used : Action1(rx.functions.Action1) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) TransactionInsertOrReplace(com.winsonchiu.reader.data.database.TransactionInsertOrReplace)

Example 8 with Action1

use of rx.functions.Action1 in project Reader by TheKeeperOfPie.

the class TableSubredditPage method appendPage.

public Action1<SQLiteDatabase> appendPage(final Subreddit subreddit, final List<String> ids, Sort sort, Time time) {
    return new Action1<SQLiteDatabase>() {

        @Override
        public void call(SQLiteDatabase sqLiteDatabase) {
            Cursor query = sqLiteDatabase.query(NAME, COLUMNS, _ID + " = ? LIMIT 1", new String[] { subreddit.getUrl() }, null, null, null);
            if (query != null) {
                if (query.moveToFirst()) {
                    String json = query.getString(query.getColumnIndex(COLUMN_LINKS));
                    try {
                        LinkedHashSet<String> idsCurrent = new LinkedHashSet<>(Arrays.asList(ComponentStatic.getObjectMapper().readValue(json, String[].class)));
                        idsCurrent.addAll(ids);
                        ids.clear();
                        ids.addAll(idsCurrent);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                query.close();
            }
            sqLiteDatabase.beginTransaction();
            try {
                String json = ComponentStatic.getObjectMapper().writeValueAsString(ids);
                TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMNS);
                transaction.insertOrReplace(subreddit.getUrl(), System.currentTimeMillis(), subreddit.getCreatedUtc(), subreddit.getDisplayName(), json);
                sqLiteDatabase.setTransactionSuccessful();
            } catch (IOException e) {
                e.printStackTrace();
            }
            sqLiteDatabase.endTransaction();
        }
    };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Action1(rx.functions.Action1) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) TransactionInsertOrReplace(com.winsonchiu.reader.data.database.TransactionInsertOrReplace) IOException(java.io.IOException) Cursor(android.database.Cursor)

Example 9 with Action1

use of rx.functions.Action1 in project Reader by TheKeeperOfPie.

the class TableSubredditPage method storePage.

public Action1<SQLiteDatabase> storePage(final Subreddit subreddit, final List<String> ids, Sort sort, Time time) {
    return new Action1<SQLiteDatabase>() {

        @Override
        public void call(SQLiteDatabase sqLiteDatabase) {
            sqLiteDatabase.beginTransaction();
            try {
                String json = ComponentStatic.getObjectMapper().writeValueAsString(ids);
                TransactionInsertOrReplace transaction = getInsertOrReplace(sqLiteDatabase, COLUMNS);
                transaction.insertOrReplace(subreddit.getUrl(), System.currentTimeMillis(), subreddit.getCreatedUtc(), subreddit.getDisplayName(), json);
                sqLiteDatabase.setTransactionSuccessful();
            } catch (IOException e) {
                e.printStackTrace();
            }
            sqLiteDatabase.endTransaction();
        }
    };
}
Also used : Action1(rx.functions.Action1) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) TransactionInsertOrReplace(com.winsonchiu.reader.data.database.TransactionInsertOrReplace) IOException(java.io.IOException)

Example 10 with Action1

use of rx.functions.Action1 in project ribbon by Netflix.

the class SimpleGet method main.

@edu.umd.cs.findbugs.annotations.SuppressWarnings
public static void main(String[] args) throws Exception {
    LoadBalancingHttpClient<ByteBuf, ByteBuf> client = RibbonTransport.newHttpClient();
    HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("http://www.google.com/");
    final CountDownLatch latch = new CountDownLatch(1);
    client.submit(request).toBlocking().forEach(new Action1<HttpClientResponse<ByteBuf>>() {

        @Override
        public void call(HttpClientResponse<ByteBuf> t1) {
            System.out.println("Status code: " + t1.getStatus());
            t1.getContent().subscribe(new Action1<ByteBuf>() {

                @Override
                public void call(ByteBuf content) {
                    System.out.println("Response content: " + content.toString(Charset.defaultCharset()));
                    latch.countDown();
                }
            });
        }
    });
    latch.await(2, TimeUnit.SECONDS);
}
Also used : Action1(rx.functions.Action1) HttpClientResponse(io.reactivex.netty.protocol.http.client.HttpClientResponse) ByteBuf(io.netty.buffer.ByteBuf) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

Action1 (rx.functions.Action1)108 Test (org.junit.Test)33 Action0 (rx.functions.Action0)28 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 UiThreadTest (android.support.test.annotation.UiThreadTest)20 Observable (rx.Observable)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 HystrixRuntimeException (com.netflix.hystrix.exception.HystrixRuntimeException)11 ArrayList (java.util.ArrayList)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 TestSubscriber (rx.observers.TestSubscriber)10 AllTypes (io.realm.entities.AllTypes)9 List (java.util.List)9 TestCircuitBreaker (com.netflix.hystrix.HystrixCircuitBreakerTest.TestCircuitBreaker)7 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)6 IOException (java.io.IOException)6 Func1 (rx.functions.Func1)6 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)5 Method (java.lang.reflect.Method)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5