Skip to content

Commit

Permalink
Merge pull request #395 from katarinaking/835
Browse files Browse the repository at this point in the history
MNEMONIC-835: Annotated Durable Entity
  • Loading branch information
katarinaking committed Jun 19, 2024
2 parents 7b984f9 + 9324b47 commit d521a5d
Showing 1 changed file with 53 additions and 1 deletion.
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

0 comments on commit d521a5d

Please sign in to comment.