Mercurial > dive4elements > framework
changeset 84:72e2dd4feb31
Added the time to live of an artifact to the CallContext.
artifacts/trunk@828 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 25 Mar 2010 17:32:54 +0000 |
parents | 8c4638abd518 |
children | 78263e910675 |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java artifacts/src/main/java/de/intevation/artifacts/CallContext.java |
diffstat | 4 files changed, 43 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Mar 22 15:54:06 2010 +0000 +++ b/ChangeLog Thu Mar 25 17:32:54 2010 +0000 @@ -1,3 +1,16 @@ +2010-03-25 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + * artifacts/src/main/java/de/intevation/artifacts/CallContext.java: Added a + method 'getTimeToLive()' which retrieves the current artifact's time to + live. The ttl of an artifact is available where ever a CallContext object + is existing. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java: + Added new field ttl of an artifact to an PersistentArtifact. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java: + Implemented 'getTimeToLive()' in CallContextImpl. + 2010-03-22 Ingo Weinzierl <ingo.weinzierl@intevation.de> * artifact-database/src/main/java/de/intevation/artifactdatabase/App.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Mon Mar 22 15:54:06 2010 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Thu Mar 25 17:32:54 2010 +0000 @@ -131,6 +131,10 @@ return callMeta; } + public Long getTimeToLive() { + return artifact.getTTL(); + } + public void postCall() { switch (action) { case NOTHING: @@ -472,6 +476,7 @@ new Backend.ArtifactLoader() { public Object load( ArtifactFactory factory, + Long ttl, byte [] bytes, int id ) {
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Mon Mar 22 15:54:06 2010 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Thu Mar 25 17:32:54 2010 +0000 @@ -58,15 +58,18 @@ { private Artifact artifact; private ArtifactSerializer serializer; + private Long ttl; public PersistentArtifact( Artifact artifact, ArtifactSerializer serializer, + Long ttl, int id ) { super(id); this.artifact = artifact; this.serializer = serializer; + this.ttl = ttl; } public Artifact getArtifact() { @@ -77,6 +80,10 @@ return serializer; } + public Long getTTL() { + return ttl; + } + public void store() { if (logger.isDebugEnabled()) { logger.debug("storing artifact id = " + getId()); @@ -122,6 +129,7 @@ return new PersistentArtifact( artifact, factory.getSerializer(), + ttl, insertDatabase(artifact, factory, ttl)); } @@ -135,12 +143,13 @@ return new PersistentArtifact( artifact, factory.getSerializer(), + ttl, storeOrReplaceDatabase(artifact, factory, ttl)); } public interface ArtifactLoader { - Object load(ArtifactFactory factory, byte [] bytes, int id); + Object load(ArtifactFactory factory, Long ttl, byte [] bytes, int id); } // interface ArtifactLoader @@ -152,6 +161,7 @@ public Object load( ArtifactFactory factory, + Long ttl, byte [] bytes, int id ) { @@ -161,7 +171,7 @@ return artifact == null ? null - : new PersistentArtifact(artifact, serializer, id); + : new PersistentArtifact(artifact, serializer, ttl, id); } }); } @@ -188,12 +198,14 @@ return null; } - int id = load_result.getInt(1); - long ttl = load_result.getLong(3); + int id = load_result.getInt(1); + long ttlX = load_result.getLong(3); - if (!load_result.wasNull()) { // real time to life + Long ttl = load_result.wasNull() ? null : Long.valueOf(ttlX); + + if (ttl != null) { // real time to life long last_access = load_result.getTimestamp(2).getTime(); - if (last_access + ttl < System.currentTimeMillis()) { + if (last_access + ttlX < System.currentTimeMillis()) { artifactOutdated(id); return null; } @@ -216,7 +228,7 @@ byte [] bytes = load_result.getBytes(5); - return loader.load(factory, bytes, id); + return loader.load(factory, ttl, bytes, id); } catch (SQLException sqle) { logger.error(sqle.getLocalizedMessage(), sqle);
--- a/artifacts/src/main/java/de/intevation/artifacts/CallContext.java Mon Mar 22 15:54:06 2010 +0000 +++ b/artifacts/src/main/java/de/intevation/artifacts/CallContext.java Thu Mar 25 17:32:54 2010 +0000 @@ -83,5 +83,11 @@ * @return The formerly stored value under the given key. */ Object putContextValue(Object key, Object value); + + /** + * Returns the time to live of the current artifact. + * @return The time to live of the current artifact. + */ + Long getTimeToLive(); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: