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());
}
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();
}
};
}
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();
}
};
}
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();
}
};
}
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);
}
Aggregations