Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNEMONIC-835: Annotated Durable Entity #395

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,88 @@
import org.apache.mnemonic.OutOfHybridMemory;
import org.apache.mnemonic.RetrieveDurableEntityError;

/**
* The Product class represents a durable entity that can be persisted
* and restored from non-volatile memory. It implements the Durable interface,
* indicating it supports mnemonic protocol features.
*/
@DurableEntity
public abstract class Product implements Durable {

/**
* This method is called after the entity is created. It can be used to perform
* any initialization logic required after creation. Currently, it is empty.
*/
@Override
public void initializeAfterCreate() {
}

/**
* This method is called after the entity is restored. It can be used to perform
* any initialization logic required after restoration. Currently, it is empty.
*/
@Override
public void initializeAfterRestore() {
}

/**
* This method sets up the generic information for the entity. It is used to
* associate entity factory proxies and durable types with the entity.
*
* @param efproxies Array of entity factory proxies
* @param gftypes Array of durable types
*/
@Override
public void setupGenericInfo(EntityFactoryProxy[] efproxies, DurableType[] gftypes) {

// Setup logic for generic information can be added here if needed
}

/**
* Retrieves the name of the product.
*
* @return the name of the product
* @throws RetrieveDurableEntityError if an error occurs while retrieving the entity
*/
@DurableGetter
public abstract String getName() throws RetrieveDurableEntityError;

/**
* Sets the name of the product.
*
* @param name the name to set
* @param destroy whether to destroy the previous value
* @throws OutOfHybridMemory if there is insufficient memory to store the new value
* @throws RetrieveDurableEntityError if an error occurs while retrieving the entity
*/
@DurableSetter
public abstract void setName(String name, boolean destroy)
throws OutOfHybridMemory, RetrieveDurableEntityError;

/**
* Retrieves the price of the product.
*
* @return the price of the product
* @throws RetrieveDurableEntityError if an error occurs while retrieving the entity
*/
@DurableGetter
public abstract Double getPrice() throws RetrieveDurableEntityError;

/**
* Sets the price of the product.
*
* @param price the price to set
* @param destroy whether to destroy the previous value
* @throws OutOfHybridMemory if there is insufficient memory to store the new value
* @throws RetrieveDurableEntityError if an error occurs while retrieving the entity
*/
@DurableSetter
public abstract void setPrice(Double price, boolean destroy)
throws OutOfHybridMemory, RetrieveDurableEntityError;

/**
* Displays the product's name and price in a formatted string.
* This method is for demonstration purposes.
*/
public void show() {
System.out.printf("%s $%.2f \n", getName(), getPrice());
}
Expand Down
Loading