Пример #1
0
 /// <summary>Reads a single document</summary>
 /// <seealso><a href="https://docs.arangodb.com/current/HTTP/Document/WorkingWithDocuments.html#read-document">API
 /// *      Documentation</a></seealso>
 /// <param name="key">The key of the document</param>
 /// <param name="type">The type of the document (POJO class, VPackSlice or String for Json)
 ///     </param>
 /// <returns>the document identified by the key</returns>
 /// <exception cref="ArangoDBException"/>
 public virtual T getDocument <T>(string key)
 {
     System.Type type = typeof(T);
     this.executor.validateDocumentKey(key);
     try
     {
         return(this.executor.execute(this.getDocumentRequest(key, new DocumentReadOptions
                                                                  ()), type));
     }
     catch (ArangoDBException e)
     {
         if (LOGGER.isDebugEnabled())
         {
             LOGGER.debug(e.Message, e);
         }
         return(null);
     }
 }
Пример #2
0
 /// <exception cref="System.IO.IOException"/>
 private Message send(Message
                      message)
 {
     if (LOGGER.isDebugEnabled())
     {
         LOGGER.debug(string.format("Send Message (id=%s, head=%s, body=%s)", message.getId
                                        (), message.getHead(), message.getBody() != null ? message.getBody() : "{}"));
     }
     return(this.connection.write(message, this.buildChunks(message)));
 }
Пример #3
0
 /// <exception cref="ArangoDBException"/>
 public virtual Message write(Message
                              message, System.Collections.Generic.ICollection <Chunk
                                                                               > chunks)
 {
     lock (this)
     {
         base.writeIntern(message, chunks);
         byte[] chunkBuffer = null;
         int    off         = 0;
         while (chunkBuffer == null || off < chunkBuffer.Length)
         {
             if (!this.isOpen())
             {
                 this.close();
                 throw new ArangoDBException(new System.IO.IOException("The socket is closed."
                                                                       ));
             }
             try
             {
                 Chunk chunk         = this.readChunk();
                 int   contentLength = chunk.getContentLength();
                 if (chunkBuffer == null)
                 {
                     if (!chunk.isFirstChunk())
                     {
                         throw new ArangoDBException("Wrong Chunk recieved! Expected first Chunk."
                                                     );
                     }
                     int length = (int)(chunk.getMessageLength() > 0 ? chunk.getMessageLength() : contentLength
                                        );
                     chunkBuffer = new byte[length];
                 }
                 this.readBytesIntoBuffer(chunkBuffer, off, contentLength);
                 off += contentLength;
             }
             catch (System.Exception e)
             {
                 this.close();
                 throw new ArangoDBException(e);
             }
         }
         Message responseMessage = new Message
                                       (message.getId(), chunkBuffer);
         if (LOGGER.isDebugEnabled())
         {
             LOGGER.debug(string.format("Received Message (id=%s, head=%s, body=%s)", responseMessage
                                        .getId(), responseMessage.getHead(), responseMessage.getBody() != null ? responseMessage
                                        .getBody() : "{}"));
         }
         return(responseMessage);
     }
 }
Пример #4
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void open()
 {
     lock (this)
     {
         if (this.isOpen())
         {
             return;
         }
         if (this.useSsl != null && this.useSsl)
         {
             if (this.sslContext != null)
             {
                 this.socket = this.sslContext.getSocketFactory().createSocket();
             }
             else
             {
                 this.socket = javax.net.ssl.SSLSocketFactory.getDefault().createSocket();
             }
         }
         else
         {
             this.socket = javax.net.SocketFactory.getDefault().createSocket();
         }
         string host = this.host != null ? this.host : ArangoDBConstants
                       .DEFAULT_HOST;
         int port = this.port != null ? this.port : ArangoDBConstants
                    .DEFAULT_PORT;
         if (LOGGER.isDebugEnabled())
         {
             LOGGER.debug(string.format("Open connection to addr=%s,port=%s", host, port));
         }
         this.socket.connect(new java.net.InetSocketAddress(host, port), this.timeout != null ? this.timeout
              : ArangoDBConstants.DEFAULT_TIMEOUT);
         this.socket.setKeepAlive(true);
         this.socket.setTcpNoDelay(true);
         if (LOGGER.isDebugEnabled())
         {
             LOGGER.debug(string.format("Connected to %s", this.socket));
         }
         this.outputStream = new java.io.BufferedOutputStream(this.socket.getOutputStream());
         this.inputStream  = this.socket.getInputStream();
         if (this.useSsl != null && this.useSsl)
         {
             if (LOGGER.isDebugEnabled())
             {
                 LOGGER.debug(string.format("Start Handshake on %s", this.socket));
             }
             ((javax.net.ssl.SSLSocket) this.socket).startHandshake();
         }
         this.sendProtocolHeader();
     }
 }