NebulaGraph Java Client  release-3.8
SessionWrapper.java
1 /* Copyright (c) 2021 vesoft inc. All rights reserved.
2  *
3  * This source code is licensed under Apache 2.0 License.
4  */
5 
6 package com.vesoft.nebula.client.graph.net;
7 
8 import com.vesoft.nebula.client.graph.data.ResultSet;
9 import com.vesoft.nebula.client.graph.exception.IOErrorException;
10 import com.vesoft.nebula.client.graph.exception.InvalidSessionException;
11 import java.io.Serializable;
12 import java.util.concurrent.atomic.AtomicBoolean;
13 
14 public class SessionWrapper implements Serializable {
15 
16  private static final long serialVersionUID = -8128331485649098264L;
17 
18  private final Session session;
19  private final long sessionID;
20  private final AtomicBoolean available = new AtomicBoolean(true);
21 
22  public SessionWrapper(Session session) {
23  this.session = session;
24  this.sessionID = session.getSessionID();
25  }
26 
33  public ResultSet execute(String stmt)
34  throws IOErrorException {
35  if (!available()) {
36  throw new InvalidSessionException();
37  }
38  return session.execute(stmt);
39  }
40 
41  public boolean ping() {
42  return session.pingSession();
43  }
44 
45  void setNoAvailable() {
46  this.available.set(false);
47  }
48 
49  boolean available() {
50  return available.get();
51  }
52 
53  void release() {
54  session.release();
55  setNoAvailable();
56  }
57 
58  Session getSession() {
59  return session;
60  }
61 }
ResultSet execute(String stmt)
Execute the query sentence.
The Session is an object that operates with nebula-graph.
Definition: Session.java:53
synchronized boolean pingSession()
check current session is ok
Definition: Session.java:333
synchronized ResultSet execute(String stmt)
Execute the nGql sentence.
Definition: Session.java:91
synchronized void release()
Notifies the server that the session is no longer needed and returns the connection to the pool,...
Definition: Session.java:346