Skip to content

Instantly share code, notes, and snippets.

@jonbartels
Created March 17, 2022 16:18
Show Gist options
  • Save jonbartels/c91a8965788b80029812d32b45acc58d to your computer and use it in GitHub Desktop.
Save jonbartels/c91a8965788b80029812d32b45acc58d to your computer and use it in GitHub Desktop.
Timetsampped Maps in Mirth Connect
jonb 11:31
I would do many dirty deeds if globalMap and globalChannelMap and configMap had a lastUpdated flag. I have a use case with a large-ish object in the map and don’t want to re-load or re-parse it if it hasn’t changed. (edited)
pacmano 11:39
We manually put that in there. That would be really nice.
chris 11:51
lastUpdated flag, or timestamp-of-last-update?
11:51
And do you want that per-key, or per-map?
jonb 11:52
timestamp-of-last-update and per-key
11:52
Arguably for my use case not storing big things in maps is best.
chris 11:53
No, you are fine, especially since Mirth provides stewardship for those maps for you.
11:53
It's actually easy and when I explain how to do it you'll say "why didn't I think of that".
11:53
Oh.
11:54
But it will require some syntactic sugar in some places where it might be awkward.
11:54
Like all that $c('foo') stuff you guys like so much.
11:54
Write yourself a new class in Java like this:
11:55
public class TimedObject<T> { private final T o; private final long timestamp=System.currentTimeMillis(); public TimedObject<T>(T o) { this.o = o; } public T get() { return o; } public long getTimestamp() { return timestamp; } }
11:56
Then when you insert into the map:
11:56
globalMap.put('foo', new TimedObject(myObj));
11:56
And when you want it back:
11:56
var wrapper = globalMap.get('foo');
11:57
if(wrapper.getTimestamp() < System.currentTimeMillis() - 10000) {
// do whatever 10-seconds old means
}
11:58
If you instead write your code in javascript, you could do virtually the same thing, but instead have the object willing to give you back the wrapped object normally, but after e.g. 10 seconds, run a lambda (function) that re-freshes the object from wherever it needs to come from.
11:58
That seems like a very javascript-y solution.
11:59
Like:
11:59
globalMap.put('foo', new MagicThing(currentValue, function unwrapper(rawData) { ... }));
12:00
Then globalMap.get('foo') returns an object whose get method will either return currentValue or execute unwrapper and return that value after some time.
chris 12:00
You can really go crazy with this stuff if you want. But if course the more complicated it is, the less readable it will become.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment