Search in sources :

Example 91 with Action1

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();
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1)

Example 92 with Action1

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);
}
Also used : Action1(rx.functions.Action1) Element(org.w3c.dom.Element)

Example 93 with Action1

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);
}
Also used : Action1(rx.functions.Action1) Date(java.util.Date)

Example 94 with Action1

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);
}
Also used : Action1(rx.functions.Action1) EGVRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord) Date(java.util.Date) PowerManager(android.os.PowerManager) SensorRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord) CalRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord)

Example 95 with Action1

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);
}
Also used : Action1(rx.functions.Action1) CalRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.CalRecord) SensorRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.SensorRecord) EGVRecord(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.records.EGVRecord) ReadDataShare(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.ReadDataShare) Date(java.util.Date)

Aggregations

Action1 (rx.functions.Action1)106 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)18 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 OnSubscribe (rx.Observable.OnSubscribe)7 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)6 IOException (java.io.IOException)6 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)5 Method (java.lang.reflect.Method)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5