use of rx.functions.Action1 in project jocean-http by isdom.
the class DefaultHttpServerBuilder method awaitInboundRequest.
private void awaitInboundRequest(final Channel channel, final Subscriber<? super HttpTrade> subscriber, final List<Channel> awaitChannels) {
awaitChannels.add(channel);
Nettys.applyHandler(channel.pipeline(), HttpHandlers.ON_CHANNEL_READ, new Action0() {
@Override
public void call() {
awaitChannels.remove(channel);
if (!subscriber.isUnsubscribed()) {
final HttpTrade trade = httpTradeOf(channel, doRecycleChannel(channel, subscriber, awaitChannels), new Action1<HttpTrade>() {
@Override
public void call(HttpTrade t) {
_numCompletedTrades.incrementAndGet();
}
});
if (trade.isActive()) {
subscriber.onNext(trade);
} else {
LOG.info("HttpTrade({}) has unactived, so ignore.", trade);
}
} else {
LOG.warn("HttpTrade Subscriber {} has unsubscribed, so close channel({})", subscriber, channel);
channel.close();
}
}
});
channel.read();
}
use of rx.functions.Action1 in project xDrip by NightscoutFoundation.
the class ReadDataShare method readSerialNumber.
public void readSerialNumber(final Action1<String> serialNumberListener) {
final Action1<byte[]> manufacturingDataListener = new Action1<byte[]>() {
@Override
public void call(byte[] s) {
Element el = ParsePage(s, Constants.RECORD_TYPES.MANUFACTURING_DATA.ordinal());
Observable.just(el.getAttribute("SerialNumber")).subscribe(serialNumberListener);
}
};
readDataBasePage(Constants.RECORD_TYPES.MANUFACTURING_DATA.ordinal(), 0, manufacturingDataListener);
}
use of rx.functions.Action1 in project xDrip by NightscoutFoundation.
the class ReadDataShare method readDisplayTime.
public void readDisplayTime(final Action1<Date> displayTimeListener) {
Action1<Long> tempSystemTimeListener = new Action1<Long>() {
@Override
public void call(Long s) {
final long systemTime = s;
Action1<Long> tempSystemTimeListener = new Action1<Long>() {
@Override
public void call(Long s) {
Date dateDisplayTime = Utils.receiverTimeToDate(systemTime + s);
Observable.just(dateDisplayTime).subscribe(displayTimeListener);
}
};
readDisplayTimeOffset(tempSystemTimeListener);
}
};
readSystemTime(tempSystemTimeListener);
}
use of rx.functions.Action1 in project xDrip-plus by jamorham.
the class DexShareCollectionService method attemptRead.
public void attemptRead() {
PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
final PowerManager.WakeLock wakeLock1 = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ReadingShareData");
wakeLock1.acquire(60000);
requestHighPriority();
Log.d(TAG, "Attempting to read data");
final Action1<Long> systemTimeListener = new Action1<Long>() {
@Override
public void call(Long s) {
if (s != null) {
Log.d(TAG, "Made the full round trip, got " + s + " as the system time");
final long additiveSystemTimeOffset = new Date().getTime() - s;
final Action1<Long> dislpayTimeListener = new Action1<Long>() {
@Override
public void call(Long s) {
if (s != null) {
Log.d(TAG, "Made the full round trip, got " + s + " as the display time offset");
final long addativeDisplayTimeOffset = additiveSystemTimeOffset - (s * 1000);
Log.d(TAG, "Making " + addativeDisplayTimeOffset + " the the total time offset");
final Action1<EGVRecord[]> evgRecordListener = new Action1<EGVRecord[]>() {
@Override
public void call(EGVRecord[] egvRecords) {
if (egvRecords != null) {
Log.d(TAG, "Made the full round trip, got " + egvRecords.length + " EVG Records");
BgReading.create(egvRecords, additiveSystemTimeOffset, getApplicationContext());
statusErrors = 0;
{
Log.d(TAG, "Releasing wl in egv");
requestLowPriority();
if (wakeLock1 != null && wakeLock1.isHeld())
wakeLock1.release();
Log.d(TAG, "released");
}
if (shouldDisconnect) {
stopSelf();
} else {
setRetryTimer();
}
}
}
};
final Action1<SensorRecord[]> sensorRecordListener = new Action1<SensorRecord[]>() {
@Override
public void call(SensorRecord[] sensorRecords) {
if (sensorRecords != null) {
Log.d(TAG, "Made the full round trip, got " + sensorRecords.length + " Sensor Records");
BgReading.create(sensorRecords, additiveSystemTimeOffset, getApplicationContext());
statusErrors = 0;
readData.getRecentEGVs(evgRecordListener);
}
}
};
final Action1<CalRecord[]> calRecordListener = new Action1<CalRecord[]>() {
@Override
public void call(CalRecord[] calRecords) {
if (calRecords != null) {
Log.d(TAG, "Made the full round trip, got " + calRecords.length + " Cal Records");
Calibration.create(calRecords, addativeDisplayTimeOffset, getApplicationContext());
statusErrors = 0;
readData.getRecentSensorRecords(sensorRecordListener);
}
}
};
readData.getRecentCalRecords(calRecordListener);
} else if (wakeLock1 != null && wakeLock1.isHeld())
wakeLock1.release();
}
};
readData.readDisplayTimeOffset(dislpayTimeListener);
} else if (wakeLock1 != null && wakeLock1.isHeld())
wakeLock1.release();
}
};
readData.readSystemTime(systemTimeListener);
}
use of rx.functions.Action1 in project xDrip-plus by jamorham.
the class ShareTest method attemptRead.
public void attemptRead() {
final ReadDataShare readData = new ReadDataShare(this);
final Action1<Long> systemTimeListener = new Action1<Long>() {
@Override
public void call(Long s) {
Log.d(TAG, "Made the full round trip, got " + s + " as the system time");
Log.d("SYSTTIME", "Made the full round trip, got " + s + " as the system time");
final long addativeSystemTimeOffset = new Date().getTime() - s;
Log.d(TAG, "Made the full round trip, got " + addativeSystemTimeOffset + " offset");
Log.d("SYSTTIME", "Made the full round trip, got " + addativeSystemTimeOffset + " offset");
final Action1<CalRecord[]> calRecordListener = new Action1<CalRecord[]>() {
@Override
public void call(CalRecord[] calRecords) {
Log.d(TAG, "Made the full round trip, got " + calRecords.length + " Cal Records");
Calibration.create(calRecords, addativeSystemTimeOffset, getApplicationContext());
final Action1<SensorRecord[]> sensorRecordListener = new Action1<SensorRecord[]>() {
@Override
public void call(SensorRecord[] sensorRecords) {
Log.d(TAG, "Made the full round trip, got " + sensorRecords.length + " Sensor Records");
BgReading.create(sensorRecords, addativeSystemTimeOffset, getApplicationContext());
final Action1<EGVRecord[]> evgRecordListener = new Action1<EGVRecord[]>() {
@Override
public void call(EGVRecord[] egvRecords) {
Log.d(TAG, "Made the full round trip, got " + egvRecords.length + " EVG Records");
BgReading.create(egvRecords, addativeSystemTimeOffset, getApplicationContext());
}
};
readData.getRecentEGVs(evgRecordListener);
}
};
readData.getRecentSensorRecords(sensorRecordListener);
}
};
readData.getRecentCalRecords(calRecordListener);
}
};
readData.readSystemTime(systemTimeListener);
}
Aggregations