Thank you Manu. This is really helpful.
On 24 October 2016 at 20:07, Manu <[email protected]> wrote:
> If you use ignite jdbc driver, to ensure that you always get a valid ignite
> instance before call a ignite operation I recommend to use a datasource
> implementation that validates connection before calls and create new ones
> otherwise.
>
> For common operations with a ignite instance, I use this method to ensure a
> *good* ignite instance and don“t waits or control reconnection... maybe
> there are some other mechanisms... but who cares? ;)
>
> public Ignite getIgnite() {
> if (this.ignite!=null){
> try{
> //ensure this ignite instance is STARTED
> and connected
> this.ignite.getOrCreateCache("default");
> }catch (IllegalStateException e){
> this.ignite=null;
> }catch (IgniteClientDisconnectedException cause) {
> this.ignite=null;
> }catch (CacheException e) {
> if (e.getCause() instanceof
> IgniteClientDisconnectedException) {
> this.ignite=null;
> }else if (e.getCause() instanceof
> IgniteClientDisconnectedCheckedException) {
> this.ignite=null;
> }else{
> throw e;
> }
> }
> }
> if (this.ignite==null){
> this.createIgniteInstance();
> }
> return ignite;
> }
>
> also you can wait for reconnection using this catch block instead of
> above... but as I said... who cares?... sometimes reconnection waits are
> not
> desirable...
> [...]
> try{
> //ensure this ignite instance is STARTED
> and connected
> this.ignite.getOrCreateCache("default");
> }catch (IllegalStateException e){
> this.ignite=null;
> }catch (IgniteClientDisconnectedException cause) {
> LOG.warn("Client disconnected from cluster.
> Waiting for reconnect...");
> cause.reconnectFuture().get(); // Wait for
> reconnect.
> }catch (CacheException e) {
> if (e.getCause() instanceof
> IgniteClientDisconnectedException) {
> LOG.warn("Client disconnected from
> cluster. Waiting for reconnect...");
> IgniteClientDisconnectedException cause =
> (IgniteClientDisconnectedException)e.getCause();
> cause.reconnectFuture().get(); // Wait for
> reconnect.
> }else if (e.getCause() instanceof
> IgniteClientDisconnectedCheckedException) {
> LOG.warn("Client disconnected from
> cluster. Waiting for reconnect...");
> IgniteClientDisconnectedCheckedException
> cause =
> (IgniteClientDisconnectedCheckedException)e.getCause();
> cause.reconnectFuture().get(); // Wait for
> reconnect.
> }else{
> throw e;
> }
> }
> [...]
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Ignite-Jdbc-connection-tp8431p8441.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>