All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazonaws.services.dynamodbv2.document.internal.PageBasedCollection Maven / Gradle / Ivy

Go to download

The AWS SDK for Java with support for OSGi. The AWS SDK for Java provides Java APIs for building software on AWS' cost-effective, scalable, and reliable infrastructure products. The AWS Java SDK allows developers to code against APIs for all of Amazon's infrastructure web services (Amazon S3, Amazon EC2, Amazon SQS, Amazon Relational Database Service, Amazon AutoScaling, etc).

There is a newer version: 1.11.60
Show newest version
/*
 * Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package com.amazonaws.services.dynamodbv2.document.internal;

import com.amazonaws.services.dynamodbv2.document.LowLevelResultListener;
import com.amazonaws.services.dynamodbv2.document.Page;

/**
 * Abstract base class for all page-based collections.
 *
 * @param  resource type
 * @param  low level outcome/result type
 */
public abstract class PageBasedCollection implements Iterable {
    private volatile R lastLowLevelResult;
    private volatile LowLevelResultListener listener = LowLevelResultListener.none();

    @Override
    public IteratorSupport iterator() {
        PageIterable pageIterable = pages();
        final PageIterator pageIterator = pageIterable.iterator();
        return new IteratorSupport(pageIterator);
    }

    public PageIterable pages() {
        return new PageIterable(this);
    }

    public abstract Page firstPage();
    
    /**
     * Returns the maximum number of resources to be retrieved in this
     * collection; or null if there is no limit.
     */
    public abstract Integer getMaxResultSize();

    /**
     * Returns the low-level result last retrieved (for the current page) from
     * the server side; or null if there has yet no calls to the server.
     */
    public R getLastLowLevelResult() {
        return lastLowLevelResult;
    }

    /**
     * Internal method used by the implementation layer for setting
     * the low level result received from the server side.
     */
    protected void setLastLowLevelResult(R lowLevelResult) {
        this.lastLowLevelResult = lowLevelResult;
        // deliver the event of receiving a low level result from the server side 
        listener.onLowLevelResult(lowLevelResult);
    }

    /**
     * Used to register a listener for the event of receiving a low-level result
     * from the server side.
     * 
     * @param listener
     *            listener to be registered. If null, a "none" listener will be
     *            set.
     * @return the previously registered listener. The return value is never
     *         null.
     */
    public LowLevelResultListener registerLowLevelResultListener(LowLevelResultListener listener) {
        LowLevelResultListener prev = this.listener;
        if (listener == null)
            this.listener = LowLevelResultListener.none();
        else
            this.listener = listener;
        return prev;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy