Skip to content
This repository
Browse code

Add AbstractPE.expire()

  • Loading branch information...
commit b11da4f4ebf242d99626a8395f344ae41520ba70 1 parent 737fa28
Bruce Robbins authored
4 s4-core/src/main/java/io/s4/persist/ConMapPersister.java
@@ -110,6 +110,10 @@ public void setAsynch(String key, Object value, int period) {
110 110 }
111 111
112 112 public void set(String key, Object value, int period) {
  113 + if (value == null) {
  114 + cache.remove(key);
  115 + return;
  116 + }
113 117 persistCount.getAndIncrement();
114 118 CacheEntry ce = new CacheEntry();
115 119 ce.value = value;
5 s4-core/src/main/java/io/s4/persist/HashMapPersister.java
@@ -108,6 +108,11 @@ public void setAsynch(String key, Object value, int period) {
108 108 }
109 109
110 110 public void set(String key, Object value, int period) {
  111 + if (value == null) {
  112 + cache.remove(key);
  113 + return;
  114 + }
  115 +
111 116 synchronized (this) {
112 117 persistCount++;
113 118 }
12 s4-core/src/main/java/io/s4/processor/AbstractPE.java
@@ -102,6 +102,7 @@ public String getName() {
102 102 transient private boolean logPauses = false;
103 103 private String id;
104 104 transient protected SchemaContainer schemaContainer = new SchemaContainer();
  105 + transient private PrototypeWrapper prototypeWrapper;
105 106
106 107 transient private boolean recoveryAttempted = false;
107 108 // true if state may have changed
@@ -172,6 +173,10 @@ public Clock getClock() {
172 173 return clock;
173 174 }
174 175
  176 + public void setPrototypeWrapper(PrototypeWrapper prototypeWrapper) {
  177 + this.prototypeWrapper = prototypeWrapper;
  178 + }
  179 +
175 180 public AbstractPE() {
176 181 OverloadDispatcherGenerator oldg = new OverloadDispatcherGenerator(this.getClass());
177 182 Class<?> overloadDispatcherClass = oldg.generate();
@@ -649,6 +654,13 @@ public void processEvent(RecoveryEvent recoveryEvent) {
649 654 isCheckpointingEvent = true;
650 655 recover();
651 656 }
  657 +
  658 + /**
  659 + * This method expires the current PE.
  660 + **/
  661 + protected void expire() {
  662 + this.prototypeWrapper.expire(this.keyValueString);
  663 + }
652 664
653 665 class PeriodicInvoker implements Runnable {
654 666
17 s4-core/src/main/java/io/s4/processor/PrototypeWrapper.java
@@ -20,7 +20,6 @@
20 20 import io.s4.persist.Persister;
21 21 import io.s4.util.clock.Clock;
22 22
23   -import java.lang.reflect.Method;
24 23 import java.util.List;
25 24
26 25 import org.apache.log4j.Logger;
@@ -47,11 +46,8 @@ public PrototypeWrapper(AbstractPE prototype, Clock s4Clock) {
47 46 ((ConMapPersister) lookupTable).setSelfClean(true);
48 47 ((ConMapPersister) lookupTable).init();
49 48 // set the persister in prototype
50   - Method method = prototype.getClass().getMethod("setLookupTable",
51   - Persister.class);
52   - method.invoke(prototype, lookupTable);
53   - } catch (NoSuchMethodException e) {
54   - // this is expected
  49 + prototype.setLookupTable(lookupTable);
  50 + prototype.setPrototypeWrapper(this);
55 51 } catch (Exception e) {
56 52 // this is not expected
57 53 Logger.getLogger("s4")
@@ -109,6 +105,15 @@ public AbstractPE lookupPE(String keyValue) {
109 105
110 106 return pe;
111 107 }
  108 +
  109 + public void expire(String keyValue) {
  110 + try {
  111 + lookupTable.set(keyValue, null, 0);
  112 + } catch (Exception e) {
  113 + logger.error("exception when removing pe for key:" + keyValue, e);
  114 + }
  115 +
  116 + }
112 117
113 118 public int getPECount() {
114 119 return lookupTable.keySet().size();

0 comments on commit b11da4f

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