public GremlinClient(GremlinServer gremlinServer, GraphSONReader graphSONReader, GraphSONWriter graphSONWriter, string mimeType, ConnectionPoolSettings connectionPoolSettings = null, Action <ClientWebSocketOptions> webSocketConfiguration = null, string sessionId = null) { IMessageSerializer messageSerializer; switch (mimeType) { case SerializationTokens.GraphSON3MimeType: VerifyGraphSONArgumentTypeForMimeType <GraphSON3Reader>(graphSONReader, nameof(graphSONReader), mimeType); VerifyGraphSONArgumentTypeForMimeType <GraphSON3Writer>(graphSONWriter, nameof(graphSONWriter), mimeType); messageSerializer = new GraphSON3MessageSerializer( (GraphSON3Reader)graphSONReader ?? new GraphSON3Reader(), (GraphSON3Writer)graphSONWriter ?? new GraphSON3Writer()); break; case SerializationTokens.GraphSON2MimeType: VerifyGraphSONArgumentTypeForMimeType <GraphSON2Reader>(graphSONReader, nameof(graphSONReader), mimeType); VerifyGraphSONArgumentTypeForMimeType <GraphSON2Writer>(graphSONWriter, nameof(graphSONWriter), mimeType); messageSerializer = new GraphSON2MessageSerializer( (GraphSON2Reader)graphSONReader ?? new GraphSON2Reader(), (GraphSON2Writer)graphSONWriter ?? new GraphSON2Writer()); break; default: throw new ArgumentException(nameof(mimeType), $"{mimeType} not supported"); } var connectionFactory = new ConnectionFactory(gremlinServer, messageSerializer, new WebSocketSettings { WebSocketConfigurationCallback = webSocketConfiguration }, sessionId); // make sure one connection in pool as session mode if (!string.IsNullOrEmpty(sessionId)) { if (connectionPoolSettings != null) { if (connectionPoolSettings.PoolSize != 1) { throw new ArgumentOutOfRangeException(nameof(connectionPoolSettings), "PoolSize must be 1 in session mode!"); } } else { connectionPoolSettings = new ConnectionPoolSettings { PoolSize = 1 }; } } _connectionPool = new ConnectionPool(connectionFactory, connectionPoolSettings ?? new ConnectionPoolSettings()); }
/// <summary> /// Initializes a new instance of the <see cref="JanusGraphGraphSONMessageSerializer" /> class. /// </summary> /// <param name="graphSONReader">The <see cref="GraphSON3Reader"/> used to deserialize from GraphSON.</param> /// <param name="graphSONWriter">The <see cref="GraphSON3Writer"/> used to serialize to GraphSON.</param> public JanusGraphGraphSONMessageSerializer(GraphSON3Reader graphSONReader, GraphSON3Writer graphSONWriter) { _serializer = new GraphSON3MessageSerializer(graphSONReader, graphSONWriter); }