hazelcast - How to write client proxy for SPI and what the difference between client and server proxies? -
i have developed own idgenerator based on hazelcast idgenerator class (with storing each last_used_id db). want run hazelcast cluster single java application , web-application other app (web-application restart shouldn't move id values next block). move myidgeneratorproxy , myidgeneratorservice new application, run it, run web-application hazelcast-client ,
illegalargumentexception: no factory registered service: ecs:impl:idgeneratorservice it okay when client , server same application.
it seems it's unable process without clientproxy. have compared idgeneratorproxy , clientidgeneratorproxy , looks same. idea? how write client proxy services? have found no documentation yet. direction of investigations correct? thought possible divide hazelcast inner services (like id generator service) , business-processes. should store custom clientproxy (for custom spi) in web-application?
this demo how create client proxy, missing part customclientproxy function call, quit complicated(more server proxy,here called readrequest, server called operation), can find how atomiclong implement.for every client proxy method have make request.
@test public void client() throws interruptedexception, ioexception { clientconfig cfg = new xmlclientconfigbuilder("hazelcast-client.xml").build(); serviceconfig serviceconfig = new serviceconfig(); serviceconfig.setname(connectorservice.name) .setclassname(connectorservice.class.getcanonicalname()) .setenabled(true); proxyfactoryconfig proxyfactoryconfig = new proxyfactoryconfig(); proxyfactoryconfig.setservice(connectorservice.name); proxyfactoryconfig.setclassname(customproxyfactory.class.getname()); cfg.addproxyfactoryconfig(proxyfactoryconfig); hazelcastinstance hz = hazelcastclient.newhazelcastclient(cfg); thread.sleep(1000); (int = 0; < 10; i++) { connector c = hz.getdistributedobject(connectorservice.name, "connector:" + threadlocalrandom.current() .nextint(10000)); system.out.println(c.snapshot()); } } private static class customproxyfactory implements clientproxyfactory { @override public clientproxy create(string id) { return new customclientproxy(connectorservice.name, id); } } private static class customclientproxy extends clientproxy implements connector { protected customclientproxy(string servicename, string objectname) { super(servicename, objectname); } @override public connectorstate snapshot() { return null; } @override public void loadstate(connectorstate state) { } @override public boolean reconnect(hostnode node) { return false; } @override public boolean connect() { return false; } } edit
in hazelcast idgenerate implemented wrapper atomiclong, should implement idgenerate own, instead of extend idgenerate.
so have implement these(more todo list xd):
api interface myidgenerate server myidgenerateservice myidgenerateproxy myidgeneratexxxoperation client clientmyidgeneratefactory clientmyidgenerateproxy myidgeneratexxxrequest i made sequence(same idgenerate) here, backed zookeeper or redis,also it's easy add db backend,too.i integrate hazelcast if got time.
Comments
Post a Comment