Skip to content
Browse files

Review activation policies:

- Explicitly activate to depth 1 where no activation was done before
because it was assumed that the default depth would be >= 1. A default
depth of 0 is now possible and might make sense to speed up queries
where the result set is only needed for .size().
- Use depth 1 when trying to obtain non-primitive members. I falsely
assumed that depth 2 was needed for that.
- Critical bugfix: Also activate in setters to ensure that activation
after a setter was called does not overwrite the changed values.
- Optimize activation: When we want the members of a single member
variable we currently activated the whole parent to depth 2 or above
This commit changes the behavior to only activate the parent to depth
1 so the members of the parent are non-null but their members are null
and then activate the needed member to depth 1 or above so its members
are non-null.
  • Loading branch information...
1 parent 38e1eb9 commit 891f73db51483adb03c3301b1676704e76a2290c @xor-freenet xor-freenet committed May 6, 2011
View
4 src/plugins/WebOfTrust/Configuration.java
@@ -69,12 +69,12 @@ public synchronized void storeAndCommit() {
}
public int getDatabaseFormatVersion() {
- // checkedActivate(depth) is not needed, int is a db4o primitive type
+ checkedActivate(1); // int is a db4o primitive type so 1 is enough
return mDatabaseFormatVersion;
}
protected void setDatabaseFormatVersion(int newVersion) {
- // checkedActivate(depth) is not needed, int is a db4o primitive type
+ checkedActivate(1); // int is a db4o primitive type so 1 is enough
if(newVersion <= mDatabaseFormatVersion)
throw new RuntimeException("mDatabaseFormatVersion==" + mDatabaseFormatVersion + "; newVersion==" + newVersion);
View
82 src/plugins/WebOfTrust/Identity.java
@@ -142,7 +142,7 @@ public Identity(String newRequestURI, String newNickname, boolean doesPublishTru
* @return A unique identifier for this Identity.
*/
public final String getID() {
- // checkedActivate(depth) is not needed, Strings are native to db4o
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
return mID;
}
@@ -162,7 +162,8 @@ public static final String getIDFromURI(FreenetURI uri) {
* @return The requestURI ({@link FreenetURI}) to fetch this Identity
*/
public final FreenetURI getRequestURI() {
- checkedActivate(3);
+ checkedActivate(1);
+ checkedActivate(mRequestURI, 2);
return mRequestURI;
}
@@ -175,7 +176,7 @@ public final long getEdition() {
}
public final FetchState getCurrentEditionFetchState() {
- checkedActivate(2); // TODO: Optimization: Do we really need to activate for enums?
+ checkedActivate(1);
return mCurrentEditionFetchState;
}
@@ -187,7 +188,10 @@ public final FetchState getCurrentEditionFetchState() {
* @throws InvalidParameterException If the new edition is less than the current one.
*/
protected void setEdition(long newEdition) throws InvalidParameterException {
- checkedActivate(3);
+ checkedActivate(1);
+ checkedActivate(mRequestURI, 2);
+ // checkedActivate(mCurrentEditionFetchState, 1); is not needed, has no members
+ // checkedActivate(mLatestEditionHint, 1); is not needed, long is a db4o primitive type
long currentEdition = mRequestURI.getEdition();
@@ -207,7 +211,7 @@ protected void setEdition(long newEdition) throws InvalidParameterException {
}
public final long getLatestEditionHint() {
- // checkedActivate(depth) is not needed, long is a db4o primitive type
+ checkedActivate(1); // long is a db4o primitive type so 1 is enough
return mLatestEditionHint;
}
@@ -220,7 +224,7 @@ public final long getLatestEditionHint() {
* @return True, if the given hint was newer than the already stored one. You have to tell the {@link IdentityFetcher} about that then.
*/
protected final boolean setNewEditionHint(long newLatestEditionHint) {
- // checkedActivate(depth) is not needed, long is a db4o primitive type
+ checkedActivate(1); // long is a db4o primitive type so 1 is enough
if (newLatestEditionHint > mLatestEditionHint) {
mLatestEditionHint = newLatestEditionHint;
@@ -235,8 +239,9 @@ protected final boolean setNewEditionHint(long newLatestEditionHint) {
* Decrease the current edition by one. Used by {@link #markForRefetch()}.
*/
private final void decreaseEdition() {
- checkedActivate(3);
- mRequestURI = mRequestURI.setSuggestedEdition(Math.max(getEdition() - 1, 0));
+ checkedActivate(1);
+ checkedActivate(mRequestURI, 2);
+ mRequestURI = mRequestURI.setSuggestedEdition(Math.max(mRequestURI.getEdition() - 1, 0));
// TODO: I decided that we should not decrease the edition hint here. Think about that again.
}
@@ -248,7 +253,8 @@ private final void decreaseEdition() {
* current trust list. This is necessary because we do not create the trusted identities of someone if he has a negative score.
*/
protected void markForRefetch() {
- checkedActivate(2); // TODO: Optimization: Do we really need to activate for enums?
+ checkedActivate(1);
+ // checkedActivate(mCurrentEditionFetchState, 1); not needed, it has no members
if (mCurrentEditionFetchState == FetchState.Fetched) {
mCurrentEditionFetchState = FetchState.NotFetched;
@@ -268,22 +274,23 @@ public final Date getAddedDate() {
* @return The date of this Identity's last modification.
*/
public final Date getLastFetchedDate() {
- // checkedActivate(depth) is not needed, Date is a db4o primitive type
+ checkedActivate(1); // long is a db4o primitive type so 1 is enough
return (Date)mLastFetchedDate.clone();
}
/**
* @return The date of this Identity's last modification.
*/
public final Date getLastChangeDate() {
- // checkedActivate(depth) is not needed, Date is a db4o primitive type
+ checkedActivate(1); // long is a db4o primitive type so 1 is enough
return (Date)mLastChangedDate.clone();
}
/**
* Has to be called when the identity was fetched and parsed successfully. Must not be called before setEdition!
*/
protected final void onFetched() {
+ checkedActivate(1);
mCurrentEditionFetchState = FetchState.Fetched;
mLastFetchedDate = CurrentTimeUTC.get();
updated();
@@ -293,6 +300,7 @@ protected final void onFetched() {
* Has to be called when the identity was fetched and parsing failed. Must not be called before setEdition!
*/
protected final void onParsingFailed() {
+ checkedActivate(1);
mCurrentEditionFetchState = FetchState.ParsingFailed;
mLastFetchedDate = CurrentTimeUTC.get();
updated();
@@ -302,7 +310,7 @@ protected final void onParsingFailed() {
* @return The Identity's nickName
*/
public final String getNickname() {
- // checkedActivate(depth) is not needed, String is a db4o primitive type
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
return mNickname;
}
@@ -343,7 +351,7 @@ public final void setNickname(String newNickname) throws InvalidParameterExcepti
throw new InvalidParameterException("Nickname contains illegal characters.");
}
- // checkedActivate(depth) is not needed, String is a db4o primitive type
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
if (mNickname != null && !mNickname.equals(newNickname)) {
throw new InvalidParameterException("Changing the nickname of an identity is not allowed.");
@@ -359,15 +367,15 @@ public final void setNickname(String newNickname) throws InvalidParameterExcepti
* @return Whether this Identity publishes its trustList or not.
*/
public final boolean doesPublishTrustList() {
- // checkedActivate(depth) is not needed, boolean is a db4o primitive type
+ checkedActivate(1); // boolean is a db4o primitive type so 1 is enough
return mDoesPublishTrustList;
}
/**
* Sets if this Identity publishes its trust list or not.
*/
public final void setPublishTrustList(boolean doesPublishTrustList) {
- // checkedActivate(depth) is not needed, boolean is a db4o primitive type
+ checkedActivate(1); // boolean is a db4o primitive type so 1 is enough
if (mDoesPublishTrustList == doesPublishTrustList) {
return;
@@ -384,7 +392,8 @@ public final void setPublishTrustList(boolean doesPublishTrustList) {
* @return Whether this Identity has that context or not
*/
public final boolean hasContext(String context) {
- checkedActivate(3);
+ checkedActivate(1);
+ checkedActivate(mContexts, 2);
return mContexts.contains(context.trim());
}
@@ -397,7 +406,8 @@ public final boolean hasContext(String context) {
public final ArrayList<String> getContexts() {
/* TODO: If this is used often - which it probably is, we might verify that no code corrupts the HashMap and return the original one
* instead of a copy */
- checkedActivate(3);
+ checkedActivate(1);
+ checkedActivate(mContexts, 2);
return (ArrayList<String>)mContexts.clone();
}
@@ -429,7 +439,8 @@ public final void addContext(String newContext) throws InvalidParameterException
throw new InvalidParameterException("Context names must be latin letters and numbers only");
}
- checkedActivate(3);
+ checkedActivate(1);
+ checkedActivate(mContexts, 2);
if (!mContexts.contains(newContext)) {
if (mContexts.size() >= MAX_CONTEXT_AMOUNT) {
@@ -449,7 +460,8 @@ public final void addContext(String newContext) throws InvalidParameterException
* a re-insert even if nothing was changed.
*/
protected final void setContexts(List<String> newContexts) {
- checkedActivate(3);
+ checkedActivate(1);
+ checkedActivate(mContexts, 2);
mContexts.clear();
@@ -473,7 +485,8 @@ protected final void setContexts(List<String> newContexts) {
public final void removeContext(String context) throws InvalidParameterException {
context = context.trim();
- checkedActivate(3);
+ checkedActivate(1);
+ checkedActivate(mContexts, 2);
if (mContexts.contains(context)) {
mContexts.remove(context);
@@ -483,15 +496,17 @@ public final void removeContext(String context) throws InvalidParameterException
@SuppressWarnings("unchecked")
private final void activateProperties() {
- // TODO: As soon as the db4o bug with hashmaps is fixed, remove this workaround function & replace with plain checkedActivate(4)
- if(mProperties != null) {
- if(mDB.isStored(mProperties)) {
- Query q = mDB.query();
- q.constrain(mProperties).identity();
- mProperties = (HashMap<String,String>)q.execute().next();
- }
- } else
- checkedActivate(4);
+ // TODO: As soon as the db4o bug with hashmaps is fixed, remove this workaround function & replace with:
+ // checkedActivate(1);
+ // checkedActivate(mProperties, 3);
+ checkedActivate(1);
+
+ if(mDB.isStored(mProperties)) {
+ Query q = mDB.query();
+ q.constrain(mProperties).identity();
+ mProperties = (HashMap<String,String>)q.execute().next();
+ checkedActivate(mProperties, 3);
+ }
}
/**
@@ -592,9 +607,7 @@ public final void setProperty(String key, String value) throws InvalidParameterE
* a re-insert even if nothing was changed.
*/
protected final void setProperties(HashMap<String, String> newProperties) {
- // TODO: Optimization: Figure out whether anything breaks if we do not activate since mProperties is set to a new HashMap anyway
activateProperties();
-
checkedDelete(mProperties);
mProperties = new HashMap<String, String>(newProperties.size() * 2);
@@ -627,12 +640,12 @@ public final void removeProperty(String key) throws InvalidParameterException {
* Updated OwnIdentities will be reinserted by the IdentityInserter automatically.
*/
public final void updated() {
- // checkedActivate(depth) is not needed, Date is a db4o primitive type
+ checkedActivate(1); // Date is a db4o primitive type so 1 is enough
mLastChangedDate = CurrentTimeUTC.get();
}
public final String toString() {
- // checkedActivate(depth) is not needed, String is a db4o primitive type
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
return mNickname + "(" + mID + ")";
}
@@ -694,8 +707,7 @@ public boolean equals(Object obj) {
}
public int hashCode() {
- // checkedActivate(depth) is not needed, String is a db4o primitive type
- return mID.hashCode();
+ return getID().hashCode();
}
/**
View
5 src/plugins/WebOfTrust/IdentityFetcher.java
@@ -106,11 +106,14 @@ protected IdentityFetcherCommand(String myIdentityID) {
}
protected String getIdentityID() {
- return mIdentityID; // checkedActivate(depth) is not needed, String is a db4o primitive type
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
+ return mIdentityID;
}
@Override
public void startupDatabaseIntegrityTest() throws Exception {
+ checkedActivate(1); // int is a db4o primitive type so 1 is enough
+
if(mIdentityID == null)
throw new RuntimeException("mIdentityID==null");
View
12 src/plugins/WebOfTrust/OwnIdentity.java
@@ -91,7 +91,8 @@ public final boolean needsInsert() {
* @return This OwnIdentity's insertURI
*/
public final FreenetURI getInsertURI() {
- checkedActivate(3);
+ checkedActivate(1);
+ checkedActivate(mInsertURI, 2);
return mInsertURI;
}
@@ -100,9 +101,11 @@ public final FreenetURI getInsertURI() {
protected final void setEdition(long edition) throws InvalidParameterException {
super.setEdition(edition);
+ checkedActivate(1);
+
mCurrentEditionFetchState = FetchState.Fetched;
- checkedActivate(3);
+ checkedActivate(mInsertURI, 2);
if(edition > mInsertURI.getEdition()) {
mInsertURI = mInsertURI.setSuggestedEdition(edition);
@@ -124,22 +127,23 @@ protected final void markForRefetch() {
*/
protected final void restoreEdition(long edition) throws InvalidParameterException {
setEdition(edition);
+ checkedActivate(1);
mCurrentEditionFetchState = FetchState.NotFetched;
}
/**
* Get the Date of last insertion of this OwnIdentity, in UTC, null if it was not inserted yet.
*/
public final Date getLastInsertDate() {
- // checkedActivate(depth) is not needed, Date is a db4o primitive type
+ checkedActivate(1); // Date is a db4o primitive type so 1 is enough
return (Date)mLastInsertDate.clone();
}
/**
* Sets the last insertion date of this OwnIdentity to current time in UTC.
*/
protected final void updateLastInsertDate() {
- // checkedActivate(depth) is not needed, Date is a db4o primitive type
+ checkedActivate(1); // Date is a db4o primitive type so 1 is enough
mLastInsertDate = CurrentTimeUTC.get();
}
View
1 src/plugins/WebOfTrust/Persistent.java
@@ -344,6 +344,7 @@ protected void checkedCommit(final Object loggingObject) {
* This date is stored in the database so it is constant for a given persistent object.
*/
public final Date getCreationDate() {
+ checkedActivate(1); // Date is a db4o primitive type so 1 is enough
return mCreationDate;
}
View
27 src/plugins/WebOfTrust/Score.java
@@ -6,7 +6,6 @@
import java.util.Date;
import freenet.support.CurrentTimeUTC;
-import freenet.support.Logger;
/**
@@ -86,7 +85,7 @@ public synchronized String toString() {
* @return in which OwnIdentity's trust tree this score is
*/
public OwnIdentity getTruster() {
- checkedActivate(2);
+ checkedActivate(1);
mTruster.initializeTransient(mWebOfTrust);
return mTruster;
}
@@ -95,7 +94,7 @@ public OwnIdentity getTruster() {
* @return Identity that has this Score
*/
public Identity getTrustee() {
- checkedActivate(2);
+ checkedActivate(1);
mTrustee.initializeTransient(mWebOfTrust);
return mTrustee;
}
@@ -105,15 +104,15 @@ public Identity getTrustee() {
*/
/* XXX: Rename to getValue */
public synchronized int getScore() {
- // checkedActivate(depth) is not needed, int is a db4o primitive type
+ checkedActivate(1); // int is a db4o primitive type so 1 is enough
return mValue;
}
/**
* Sets the numeric value of this Score.
*/
protected synchronized void setValue(int newValue) {
- // checkedActivate(depth) is not needed, int is a db4o primitive type
+ checkedActivate(1); // int/Date is a db4o primitive type so 1 is enough
if(mValue == newValue)
return;
@@ -126,7 +125,7 @@ protected synchronized void setValue(int newValue) {
* @return The minimal distance in steps of {@link Trust} values from the truster to the trustee
*/
public synchronized int getRank() {
- // checkedActivate(depth) is not needed, int is a db4o primitive type
+ checkedActivate(1); // int is a db4o primitive type so 1 is enough
return mRank;
}
@@ -137,7 +136,7 @@ protected synchronized void setRank(int newRank) {
if(newRank < -1)
throw new IllegalArgumentException("Illegal rank.");
- // checkedActivate(depth) is not needed, int is a db4o primitive type
+ checkedActivate(1); // int is a db4o primitive type so 1 is enough
if(newRank == mRank)
return;
@@ -150,7 +149,7 @@ protected synchronized void setRank(int newRank) {
* @return how much points the trusted Identity can add to its trustees score
*/
public synchronized int getCapacity() {
- // checkedActivate(depth) is not needed, int is a db4o primitive type
+ checkedActivate(1); // int is a db4o primitive type so 1 is enough
return mCapacity;
}
@@ -161,7 +160,7 @@ protected synchronized void setCapacity(int newCapacity) {
if(newCapacity < 0)
throw new IllegalArgumentException("Negative capacities are not allowed.");
- // checkedActivate(depth) is not needed, int is a db4o primitive type
+ checkedActivate(1); // int/Date is a db4o primitive type so 1 is enough
if(newCapacity == mCapacity)
return;
@@ -175,23 +174,23 @@ protected synchronized void setCapacity(int newCapacity) {
* or capacity of a score changes then its date of creation stays constant.
*/
public synchronized Date getDateOfCreation() {
- // checkedActivate(depth) is not needed, Date is a db4o primitive type
+ checkedActivate(1); // Date is a db4o primitive type so 1 is enough
return mCreationDate;
}
/**
* Gets the {@link Date} when the value, capacity or rank of this score was last changed.
*/
public synchronized Date getDateOfLastChange() {
- // checkedActivate(depth) is not needed, Date is a db4o primitive type
+ checkedActivate(1); // Date is a db4o primitive type so 1 is enough
return mLastChangedDate;
}
@Override
protected void storeWithoutCommit() {
try {
- // 2 is the maximal depth of all getter functions. You have to adjust this when introducing new member variables.
- checkedActivate(2);
+ // 1 is the maximal depth of all getter functions. You have to adjust this when introducing new member variables.
+ checkedActivate(1);
throwIfNotStored(mTruster);
throwIfNotStored(mTrustee);
checkedStore();
@@ -243,7 +242,7 @@ public Score clone() {
@Override
public void startupDatabaseIntegrityTest() throws Exception {
- checkedActivate(2);
+ checkedActivate(1);
if(mTruster == null)
throw new NullPointerException("mTruster==null");
View
28 src/plugins/WebOfTrust/Trust.java
@@ -98,21 +98,21 @@ public synchronized String toString() {
/** @return The Identity that gives this trust. */
public Identity getTruster() {
- checkedActivate(2);
+ checkedActivate(1);
mTruster.initializeTransient(mWebOfTrust);
return mTruster;
}
/** @return The Identity that receives this trust. */
public Identity getTrustee() {
- checkedActivate(2);
+ checkedActivate(1);
mTrustee.initializeTransient(mWebOfTrust);
return mTrustee;
}
/** @return value Numeric value of this trust relationship. The allowed range is -100 to +100, including both limits. 0 counts as positive. */
public synchronized byte getValue() {
- // checkedActivate(depth) is not needed, byte is a db4o primitive type
+ checkedActivate(1); // byte is a db4o primitive type so 1 is enough
return mValue;
}
@@ -125,7 +125,7 @@ protected synchronized void setValue(byte newValue) throws InvalidParameterExcep
if(newValue < -100 || newValue > 100)
throw new InvalidParameterException("Invalid trust value ("+ newValue +"). Trust values must be in range of -100 to +100.");
- // checkedActivate(depth) is not needed, byte is a db4o primitive type
+ checkedActivate(1); // byte is a db4o primitive type so 1 is enough
if(mValue != newValue) {
mValue = newValue;
@@ -135,7 +135,7 @@ protected synchronized void setValue(byte newValue) throws InvalidParameterExcep
/** @return The comment associated to this Trust relationship. */
public synchronized String getComment() {
- // checkedActivate(depth) is not needed, String is a db4o primitive type
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
return mComment;
}
@@ -156,7 +156,7 @@ protected synchronized void setComment(String newComment) throws InvalidParamete
|| !StringValidityChecker.containsNoInvalidFormatting(newComment))
throw new InvalidParameterException("Comment contains illegal characters.");
- // checkedActivate(depth) is not needed, String is a db4o primitive type
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
if(!mComment.equals(newComment)) {
mComment = newComment;
@@ -165,12 +165,12 @@ protected synchronized void setComment(String newComment) throws InvalidParamete
}
public synchronized Date getDateOfCreation() {
- // checkedActivate(depth) is not needed, Date is a db4o primitive type
+ checkedActivate(1); // Date is a db4o primitive type so 1 is enough
return mCreationDate;
}
public synchronized Date getDateOfLastChange() {
- // checkedActivate(depth) is not needed, Date is a db4o primitive type
+ checkedActivate(1); // Date is a db4o primitive type so 1 is enough
return mLastChangedDate;
}
@@ -179,18 +179,19 @@ public synchronized Date getDateOfLastChange() {
* For an explanation for what this is needed please read the description of {@link #mTrusterTrustListEdition}.
*/
protected synchronized void trusterEditionUpdated() {
+ checkedActivate(1); // long is a db4o primitive type so 1 is enough
mTrusterTrustListEdition = getTruster().getEdition();
}
protected synchronized long getTrusterEdition() {
- // checkedActivate(depth) is not needed, long is a db4o primitive type
+ checkedActivate(1); // long is a db4o primitive type so 1 is enough
return mTrusterTrustListEdition;
}
protected void storeWithoutCommit() {
try {
- // 2 is the maximal depth of all getter functions. You have to adjust this when introducing new member variables.
- checkedActivate(2);
+ // 1 is the maximal depth of all getter functions. You have to adjust this when introducing new member variables.
+ checkedActivate(1);
throwIfNotStored(mTruster);
throwIfNotStored(mTrustee);
checkedStore();
@@ -237,8 +238,7 @@ public boolean equals(final Object obj) {
public Trust clone() {
try {
Trust clone = new Trust(getTruster(), getTrustee(), getValue(), getComment());
- // checkedActivate(depth) is not needed, long is a db4o primitive type
- clone.mTrusterTrustListEdition = this.mTrusterTrustListEdition;
+ clone.mTrusterTrustListEdition = getTrusterEdition();
clone.initializeTransient(mWebOfTrust);
return clone;
} catch (InvalidParameterException e) {
@@ -248,7 +248,7 @@ public Trust clone() {
@Override
public void startupDatabaseIntegrityTest() throws Exception {
- checkedActivate(2);
+ checkedActivate(1);
if(mTruster == null)
throw new NullPointerException("mTruster==null");
View
51 src/plugins/WebOfTrust/introduction/IntroductionPuzzle.java
@@ -218,43 +218,43 @@ public static String getIDFromSolutionURI(FreenetURI uri) {
}
public String getID() {
- // checkedActivate(depth) is not needed, String is a db4o primitive type
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
return mID;
}
public PuzzleType getType() {
- checkedActivate(2); // TODO: Optimization: Do we really need to activate for enums?
+ checkedActivate(1);
return mType;
}
public String getMimeType() {
- // checkedActivate(depth) is not needed, String is a db4o primitive type
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
return mMimeType;
}
public byte[] getData() {
- // checkedActivate(depth) is not needed, byte[] is a db4o primitive type
+ checkedActivate(1); // byte[] is a db4o primitive type so 1 is enough
return mData;
}
public Identity getInserter() {
- checkedActivate(2);
+ checkedActivate(1);
mInserter.initializeTransient(mWebOfTrust);
return mInserter;
}
public Date getDateOfInsertion() {
- // checkedActivate(depth) is not needed, Date is a db4o primitive type
+ checkedActivate(1); // Date is a db4o primitive type so 1 is enough
return new Date(mDayOfInsertion);
}
public Date getValidUntilDate() {
- // checkedActivate(depth) is not needed, long is a db4o primitive type
+ checkedActivate(1); // Date is a db4o primitive type so 1 is enough
return mValidUntilDate;
}
public int getIndex() {
- // checkedActivate(depth) is not needed, int is a db4o primitive type
+ checkedActivate(1); // int is a db4o primitive type so 1 is enough
return mIndex;
}
@@ -266,7 +266,9 @@ public int getIndex() {
* @throws InvalidParameterException If the puzzle was already solved.
*/
public synchronized void setSolved(OwnIdentity solver, String solution) {
- if(wasSolved())
+ checkedActivate(1);
+
+ if(mWasSolved)
throw new IllegalStateException("Puzzle is already solved!");
mWasSolved = true;
@@ -275,18 +277,23 @@ public synchronized void setSolved(OwnIdentity solver, String solution) {
}
public synchronized boolean wasSolved() {
- // checkedActivate(depth) is not needed, boolean is a db4o primitive type
+ checkedActivate(1); // boolean is a db4o primitive type so 1 is enough
return mWasSolved;
}
+
+ protected synchronized String getSolution() {
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
+ return mSolution;
+ }
/**
* Get the Identity which solved this puzzle. Used by the IntroductionClient for inserting identity introductions.
*/
public synchronized Identity getSolver() {
- if(!wasSolved())
- throw new IllegalStateException("The puzzle is not solved");
+ checkedActivate(1);
- checkedActivate(2);
+ if(!mWasSolved)
+ throw new IllegalStateException("The puzzle is not solved");
if(mSolver == null)
return null;
@@ -304,7 +311,7 @@ public synchronized Identity getSolver() {
* guessOfSolution = the guess of the solution which is passed to the function.
*/
public synchronized FreenetURI getSolutionURI() {
- // checkedActivate(depth) is not needed, String is a db4o primitive type
+ checkedActivate(1); // String is a db4o primitive type so 1 is enough
if(mSolution == null)
throw new IllegalStateException("The puzzle is not solved.");
@@ -316,23 +323,25 @@ public synchronized FreenetURI getSolutionURI() {
}
public synchronized boolean wasInserted() {
- // checkedActivate(depth) is not needed, boolean is a db4o primitive type
+ checkedActivate(1); // boolean is a db4o primitive type so 1 is enough
return mWasInserted;
}
public synchronized void setInserted() {
Logger.debug(this, "Marking puzzle as inserted: " + this);
- if(wasInserted())
+ checkedActivate(1); // boolean is a db4o primitive type so 1 is enough
+
+ if(mWasInserted)
throw new RuntimeException("The puzzle was already inserted.");
mWasInserted = true;
}
protected void storeWithoutCommit() {
try {
- // 2 is the maximal depth of all getter functions. You have to adjust this when introducing new member variables.
- checkedActivate(2);
+ // 1 is the maximal depth of all getter functions. You have to adjust this when introducing new member variables.
+ checkedActivate(1);
throwIfNotStored(mInserter);
if(wasSolved() && mSolver != null) // Solver is null if parsing of his introduction XML failed.
throwIfNotStored(mSolver);
@@ -349,7 +358,7 @@ protected void deleteWithoutCommit() {
@Override
public void startupDatabaseIntegrityTest() throws Exception {
- checkedActivate(2);
+ checkedActivate(1);
if(mInserter == null)
throw new NullPointerException("mInserter==null");
@@ -414,7 +423,7 @@ public String toString() {
public IntroductionPuzzle clone() {
// TODO: Optimization: If this is used often, make it use the member variables instead of the getters - do proper activation before.
final IntroductionPuzzle copy = new IntroductionPuzzle(getInserter(), getID(), getType(), getMimeType(), getData(), getDateOfInsertion(), getValidUntilDate(), getIndex());
- if(wasSolved()) copy.setSolved((OwnIdentity)getSolver(), mSolution); // checkedActivate(depth) is not needed, String is a db4o primitive type
+ if(wasSolved()) copy.setSolved((OwnIdentity)getSolver(), getSolution());
if(wasInserted()) copy.setInserted();
copy.initializeTransient(mWebOfTrust);
return copy;
@@ -451,6 +460,6 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
- return mID.hashCode(); // checkedActivate(depth) is not needed, String is a db4o primitive type
+ return getID().hashCode();
}
}
View
13 src/plugins/WebOfTrust/introduction/OwnIntroductionPuzzle.java
@@ -45,6 +45,7 @@ private OwnIntroductionPuzzle(OwnIdentity newInserter, String newID, PuzzleType
* # = index of the puzzle.
*/
public FreenetURI getInsertURI() {
+ checkedActivate(1); // Needed for the getters below anyway so we can do it here for the assert()
assert(mWasInserted == false); // checkedActivate(depth) is not needed, boolean is a db4o primitive type
assert(mWasSolved == false);
@@ -63,9 +64,9 @@ public FreenetURI getInsertURI() {
* Sets the solver to null.
*/
public synchronized void setSolved() {
- checkedActivate(2); // For mSolver
+ checkedActivate(1);
- if(wasSolved())
+ if(mWasSolved)
throw new RuntimeException("The puzzle was already solved by " + mSolver);
if(mSolver != null)
@@ -79,9 +80,9 @@ public synchronized void setSolved() {
* Used by the IntroductionServer to mark a puzzle as solved when importing an identity introduction.
*/
public synchronized void setSolved(Identity solver) {
- checkedActivate(2); // For mSolver
+ checkedActivate(1);
- if(wasSolved())
+ if(mWasSolved)
throw new RuntimeException("The puzzle was already solved by " + mSolver);
if(mSolver != null)
@@ -101,7 +102,7 @@ public Identity getSolver() {
@Override
public void startupDatabaseIntegrityTest() throws Exception {
- checkedActivate(2);
+ checkedActivate(1);
super.startupDatabaseIntegrityTest();
if(mSolution==null)
@@ -117,7 +118,7 @@ public void startupDatabaseIntegrityTest() throws Exception {
public OwnIntroductionPuzzle clone() {
// TODO: Optimization: If this is used often, make it use the member variables instead of the getters - do proper activation before.
// checkedActivate(depth) for mSolution is not needed, String is a db4o primitive type
- final OwnIntroductionPuzzle copy = new OwnIntroductionPuzzle((OwnIdentity)getInserter(), getID(), getType(), getMimeType(), getData(), mSolution, getDateOfInsertion(), getIndex());
+ final OwnIntroductionPuzzle copy = new OwnIntroductionPuzzle((OwnIdentity)getInserter(), getID(), getType(), getMimeType(), getData(), getSolution(), getDateOfInsertion(), getIndex());
if(wasSolved()) {
if(getSolver() != null)

0 comments on commit 891f73d

Please sign in to comment.
Something went wrong with that request. Please try again.