network programming - Basic Distributed Counter using Java Sockets -
i have java processes(socket programs) running on different servers, on same network , on different networks. these processes have job maintain global counter. client can connect of these processes , issue command increase
, decrease
or get
counter value. global counter should consistent(network partition can occur , can recover it).
the solution have thought of far maintain count of increments , decrements on each node nodes. when increment command issued on node, increments own local copy of counts of increments , broadcasts increment , decrement count. nodes receive broadcast take max of received counts , local copy of sender's counts , stores result latest count. when get
command issued on node gives difference of sums of increments , decrements. assume take care of cases broadcasts received out of order , other unreliabilities. don't want use persistence layer.
is there better way implement this? protocol should use broadcast counts? gossip on udp work? java libraries might help?
you may aware of design pattern, still may inspiring: https://en.wikipedia.org/wiki/observer_pattern
you make of instances of program observe of other instances, notify each other if 1 changes (check out diagram in link).
as far java libraries, check these out, see if of them make life easier:
Comments
Post a Comment