public static void Initialize(string envPrefix, string configFile, Server serverInfo, NativeLogLevel logLevel, NativeLogKind logKind, Action <string> logFunction, MetricsConfiguration metricsConfig, ServiceDiscoveryListener serviceDiscoveryListener = null) { _serviceDiscoveryListener = serviceDiscoveryListener; _handleRpcCallback = new HandleRpcCallbackFunc(HandleRpcCallback); _clusterNotificationCallback = new ClusterNotificationCallbackFunc(ClusterNotificationCallback); _logFunctionCallback = new LogFunction(LogFunctionCallback); var logCtx = GCHandle.Alloc(logFunction, GCHandleType.Normal); var pitayaMetrics = IntPtr.Zero; if (metricsConfig.IsEnabled) { if (metricsConfig.CustomMetrics == null) { metricsConfig.CustomMetrics = new CustomMetrics(); } metricsConfig.CustomMetrics.AddHistogram( RPC_LATENCY_METRIC, new HistogramBuckets(HistogramBucketKind.Exponential, 0.0005, 2.0, 20) ); _metricsReporter = new MetricsReporter(metricsConfig); pitayaMetrics = _metricsReporter.GetPitayaPtr(); } IntPtr err = pitaya_initialize_with_nats( IntPtr.Zero, envPrefix, configFile, Marshal.GetFunctionPointerForDelegate(_handleRpcCallback), Marshal.GetFunctionPointerForDelegate(_clusterNotificationCallback), logLevel, logKind, Marshal.GetFunctionPointerForDelegate(_logFunctionCallback), GCHandle.ToIntPtr(logCtx), pitayaMetrics, serverInfo.Handle, out pitaya ); if (err != IntPtr.Zero) { var pitayaError = new PitayaError(pitaya_error_code(err), pitaya_error_message(err)); pitaya_error_drop(err); throw new PitayaException($"Initialization failed: code={pitayaError.Code} msg={pitayaError.Message}"); } _rpcClient = new RpcClient(pitaya, _serializer); _metricsReporter?.Start(); }
private static extern IntPtr pitaya_initialize_with_nats( IntPtr context, string envPrefix, string configFile, IntPtr handleRpcCallback, IntPtr clusterNotificationCallback, NativeLogLevel logLevel, NativeLogKind logKind, IntPtr logFunction, IntPtr logCtx, IntPtr rawMetricsReporter, IntPtr serverInfo, out IntPtr pitaya);