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

com.amazonaws.services.kinesis.leases.interfaces.ILeaseSerializer Maven / Gradle / Ivy

/*
 * Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Amazon Software License (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/asl/
 *
 * 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.kinesis.leases.interfaces;

import java.util.Collection;
import java.util.Map;

import com.amazonaws.services.dynamodbv2.model.AttributeDefinition;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate;
import com.amazonaws.services.dynamodbv2.model.ExpectedAttributeValue;
import com.amazonaws.services.dynamodbv2.model.KeySchemaElement;
import com.amazonaws.services.kinesis.leases.impl.Lease;

/**
 * Utility class that manages the mapping of Lease objects/operations to records in DynamoDB.
 * 
 * @param  Lease subclass, possibly Lease itself
 */
public interface ILeaseSerializer {

    /**
     * Construct a DynamoDB record out of a Lease object
     * 
     * @param lease lease object to serialize
     * @return an attribute value map representing the lease object
     */
    public Map toDynamoRecord(T lease);

    /**
     * Construct a Lease object out of a DynamoDB record.
     * 
     * @param dynamoRecord attribute value map from DynamoDB
     * @return a deserialized lease object representing the attribute value map
     */
    public T fromDynamoRecord(Map dynamoRecord);

    /**
     * @param lease
     * @return the attribute value map representing a Lease's hash key given a Lease object.
     */
    public Map getDynamoHashKey(T lease);

    /**
     * Special getDynamoHashKey implementation used by ILeaseManager.getLease().
     * 
     * @param leaseKey
     * @return the attribute value map representing a Lease's hash key given a string.
     */
    public Map getDynamoHashKey(String leaseKey);

    /**
     * @param lease
     * @return the attribute value map asserting that a lease counter is what we expect.
     */
    public Map getDynamoLeaseCounterExpectation(T lease);

    /**
     * @param lease
     * @return the attribute value map asserting that the lease owner is what we expect.
     */
    public Map getDynamoLeaseOwnerExpectation(T lease);

    /**
     * @return the attribute value map asserting that a lease does not exist.
     */
    public Map getDynamoNonexistantExpectation();

    /**
     * @param lease
     * @return the attribute value map that increments a lease counter
     */
    public Map getDynamoLeaseCounterUpdate(T lease);

    /**
     * @param lease
     * @param newOwner
     * @return the attribute value map that takes a lease for a new owner
     */
    public Map getDynamoTakeLeaseUpdate(T lease, String newOwner);

    /**
     * @param lease
     * @return the attribute value map that voids a lease
     */
    public Map getDynamoEvictLeaseUpdate(T lease);

    /**
     * @param lease
     * @return the attribute value map that updates application-specific data for a lease and increments the lease
     *         counter
     */
    public Map getDynamoUpdateLeaseUpdate(T lease);

    /**
     * @return the key schema for creating a DynamoDB table to store leases
     */
    public Collection getKeySchema();

    /**
     * @return attribute definitions for creating a DynamoDB table to store leases
     */
    public Collection getAttributeDefinitions();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy