@@ -50,6 +50,7 @@ public static class Builder {
5050 private Boolean useSsl ;
5151 private SSLContext sslContext ;
5252 private Integer chunksize ;
53+ private Integer maxConnections ;
5354
5455 public Builder (final HostHandler hostHandler ) {
5556 super ();
@@ -86,26 +87,38 @@ public Builder chunksize(final Integer chunksize) {
8687 return this ;
8788 }
8889
90+ public Builder maxConnections (final Integer maxConnections ) {
91+ this .maxConnections = maxConnections ;
92+ return this ;
93+ }
94+
8995 public Communication <Response , ConnectionSync > build (final VPack vpack , final CollectionCache collectionCache ) {
9096 return new CommunicationSync (hostHandler , timeout , user , password , useSsl , sslContext , vpack ,
91- collectionCache , chunksize );
97+ collectionCache , chunksize , maxConnections );
9298 }
9399 }
94100
95101 protected CommunicationSync (final HostHandler hostHandler , final Integer timeout , final String user ,
96102 final String password , final Boolean useSsl , final SSLContext sslContext , final VPack vpack ,
97- final CollectionCache collectionCache , final Integer chunksize ) {
103+ final CollectionCache collectionCache , final Integer chunksize , final Integer maxConnections ) {
98104 super (timeout , user , password , useSsl , sslContext , vpack , collectionCache , chunksize ,
99- new ConnectionSync .Builder (hostHandler , new MessageStore ()).timeout (timeout ).useSsl (useSsl )
100- .sslContext (sslContext ).build ());
105+ new ConnectionPool <ConnectionSync >(maxConnections ) {
106+ private final ConnectionSync .Builder builder = new ConnectionSync .Builder (hostHandler ,
107+ new MessageStore ()).timeout (timeout ).useSsl (useSsl ).sslContext (sslContext );
108+
109+ @ Override
110+ public ConnectionSync createConnection () {
111+ return builder .build ();
112+ }
113+ });
101114 }
102115
103116 @ Override
104- public Response execute (final Request request ) throws ArangoDBException {
117+ public Response execute (final Request request , final ConnectionSync connection ) throws ArangoDBException {
105118 connect (connection );
106119 try {
107120 final Message requestMessage = createMessage (request );
108- final Message responseMessage = send (requestMessage );
121+ final Message responseMessage = send (requestMessage , connection );
109122 collectionCache .setDb (request .getDatabase ());
110123 final Response response = createResponse (responseMessage );
111124 checkError (response );
@@ -116,7 +129,7 @@ public Response execute(final Request request) throws ArangoDBException {
116129
117130 }
118131
119- private Message send (final Message message ) throws ArangoDBException {
132+ private Message send (final Message message , final ConnectionSync connection ) throws ArangoDBException {
120133 if (LOGGER .isDebugEnabled ()) {
121134 LOGGER .debug (String .format ("Send Message (id=%s, head=%s, body=%s)" , message .getId (), message .getHead (),
122135 message .getBody () != null ? message .getBody () : "{}" ));
@@ -125,9 +138,10 @@ private Message send(final Message message) throws ArangoDBException {
125138 }
126139
127140 @ Override
128- protected void authenticate () {
141+ protected void authenticate (final ConnectionSync connection ) {
129142 final Response response = execute (
130- new AuthenticationRequest (user , password != null ? password : "" , ArangoDBConstants .ENCRYPTION_PLAIN ));
143+ new AuthenticationRequest (user , password != null ? password : "" , ArangoDBConstants .ENCRYPTION_PLAIN ),
144+ connection );
131145 checkError (response );
132146 }
133147
0 commit comments