Search in sources :

Example 1 with MillisDatabase

use of me.retrodaredevil.solarthing.database.MillisDatabase in project solarthing by wildmountainfarms.

the class SendPacketAction method onStart.

@Override
protected void onStart() {
    super.onStart();
    Instant now = Instant.now();
    MillisDatabase millisDatabase = millisDatabaseSupplier.get();
    PacketCollection packetCollection = packetCollectionCreator.create(now);
    executorService.execute(() -> {
        int retryCounter = 0;
        while (true) {
            boolean success = upload(millisDatabase, packetCollection);
            if (success) {
                nextAction = onSuccessAction;
                break;
            }
            if (retryCounter == maxRetries) {
                nextAction = onMaxRetriesAction;
                LOGGER.info("Reached max retries for packet id: " + packetCollection.getDbId() + " will not try again.");
                break;
            }
            retryCounter++;
            if (retryWaitMillis > 0) {
                try {
                    Thread.sleep(retryWaitMillis);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    LOGGER.info("A SendPacketAction's sleep was interrupted.");
                    // We don't set nextAction to something because we assume someone just called end() on us and won't be using our next action
                    break;
                }
            }
        }
        setDone(true);
    });
}
Also used : MillisDatabase(me.retrodaredevil.solarthing.database.MillisDatabase) PacketCollection(me.retrodaredevil.solarthing.packets.collection.PacketCollection) Instant(java.time.Instant)

Aggregations

Instant (java.time.Instant)1 MillisDatabase (me.retrodaredevil.solarthing.database.MillisDatabase)1 PacketCollection (me.retrodaredevil.solarthing.packets.collection.PacketCollection)1