コード例 #1
0
 private void Start()
 {
     try
     {
         var configuredListeners = InstantiateConfiguredListenerObjects();
         LifecycleService.Start(configuredListeners);
         InvocationService.Start();
         ClusterService.Start(configuredListeners);
         ConnectionManager.Start();
         ClusterService.WaitInitialMemberListFetched();
         ConnectionManager.ConnectToAllClusterMembers();
         ListenerService.Start();
         ProxyManager.Init(ClientConfig);
         LoadBalancer.Init(((IHazelcastInstance)this).Cluster, ClientConfig);
         // Statistics.Start();
         AddClientConfigAddedListeners(configuredListeners);
     }
     catch (Exception e)
     {
         try
         {
             LifecycleService.Terminate();
         }
         catch (Exception)
         {
             //ignore
         }
         throw ExceptionUtil.Rethrow(e);
     }
 }
コード例 #2
0
 internal void DoShutdown()
 {
     Clients.TryRemove(_instanceName, out _);
     DisposeAll(_onClientShutdownDisposables);
     // Statistics.Destroy();
     ExecutionService.Shutdown();
     ConnectionManager.Shutdown();
     ProxyManager.Destroy();
     InvocationService.Shutdown();
     NearCacheManager.Shutdown();
     ListenerService.Dispose();
     SerializationService.Destroy();
     CredentialsFactory.Dispose();
 }
コード例 #3
0
 private HazelcastClient(Configuration config)
 {
     Configuration       = config;
     HazelcastProperties = new HazelcastProperties(config.Properties);
     if (config.InstanceName != null)
     {
         _instanceName = config.InstanceName;
     }
     else
     {
         _instanceName = "hz.client_" + _id;
     }
     LifecycleService = new LifecycleService(this);
     try
     {
         //TODO make partition strategy parametric
         var partitioningStrategy = new DefaultPartitioningStrategy();
         SerializationService = new SerializationServiceBuilder().SetConfig(config.SerializationConfig)
                                .SetPartitioningStrategy(partitioningStrategy)
                                .SetVersion(IO.Serialization.SerializationService.SerializerVersion).Build();
     }
     catch (Exception e)
     {
         throw ExceptionUtil.Rethrow(e);
     }
     ProxyManager = new ProxyManager(this);
     //TODO EXECUTION SERVICE
     ExecutionService         = new ExecutionService(_instanceName);
     LoadBalancer             = config.LoadBalancer ?? new RoundRobinLB();
     PartitionService         = new PartitionService(this);
     AddressProvider          = new AddressProvider(Configuration.NetworkConfig, HazelcastProperties);
     ConnectionManager        = new ConnectionManager(this);
     InvocationService        = new InvocationService(this);
     ListenerService          = new ListenerService(this);
     ClusterService           = new ClusterService(this);
     LockReferenceIdGenerator = new ClientLockReferenceIdGenerator();
     // Statistics = new Statistics(this);
     NearCacheManager   = new NearCacheManager(this);
     CredentialsFactory = config.SecurityConfig.AsCredentialsFactory() ??
                          new StaticCredentialsFactory(new UsernamePasswordCredentials());
 }
コード例 #4
0
 private HazelcastClient(ClientConfig config)
 {
     ClientConfig = config;
     if (config.InstanceName != null)
     {
         _instanceName = config.InstanceName;
     }
     else
     {
         _instanceName = "hz.client_" + _id;
     }
     LifecycleService = new LifecycleService(this);
     try
     {
         //TODO make partition strategy parametric
         var partitioningStrategy = new DefaultPartitioningStrategy();
         SerializationService = new SerializationServiceBuilder().SetConfig(config.GetSerializationConfig())
                                .SetPartitioningStrategy(partitioningStrategy)
                                .SetVersion(IO.Serialization.SerializationService.SerializerVersion).Build();
     }
     catch (Exception e)
     {
         throw ExceptionUtil.Rethrow(e);
     }
     ProxyManager = new ProxyManager(this);
     //TODO EXECUTION SERVICE
     ExecutionService         = new ExecutionService(_instanceName, config.GetExecutorPoolSize());
     LoadBalancer             = config.GetLoadBalancer() ?? new RoundRobinLB();
     PartitionService         = new PartitionService(this);
     AddressProvider          = new AddressProvider(ClientConfig);
     ConnectionManager        = new ConnectionManager(this);
     InvocationService        = new InvocationService(this);
     ListenerService          = new ListenerService(this);
     ClusterService           = new ClusterService(this);
     LockReferenceIdGenerator = new ClientLockReferenceIdGenerator();
     // Statistics = new Statistics(this);
     NearCacheManager   = new NearCacheManager(this);
     CredentialsFactory = InitCredentialsFactory(config);
 }
コード例 #5
0
ファイル: EndToEndFixture.cs プロジェクト: 21robin12/wcfpad
        private dynamic InvokeMethod(object parameters, string methodName)
        {
            var parameterTypeFactory      = new ParameterTypeFactory();
            var endpointFactory           = new EndpointFactory(parameterTypeFactory);
            var pathHelper                = new PathHelper();
            var configHelper              = new ConfigHelper();
            var wcfClientBuilder          = new WcfClientBuilder(pathHelper);
            var endpointCache             = new EndpointCache(pathHelper);
            var endpointDefinitionFactory = new EndpointDefinitionFactory(pathHelper, wcfClientBuilder, configHelper);
            var analysisService           = new AnalysisService(endpointFactory, endpointDefinitionFactory, endpointCache);
            var invocationService         = new InvocationService(endpointCache, configHelper);

            var port    = 3030;
            var address = $"http://localhost:{port}/Services/DummyService.svc";

            IList <Endpoint> endpoints = null;

            try
            {
                endpoints = analysisService.AnalyzeAddress(address);
            }
            catch (Exception e)
            {
                throw new Exception($"Could not analyze service at address {address}. " +
                                    "This may be because the service is not running in IIS. To add the service " +
                                    "in IIS, add a new website with the following parameters: path=C:\\inetpub\\wwwroot, " +
                                    $"binding=http, port={port}, hostname=<blank>. Then right-click this website " +
                                    "and select Add Application, using the following parameters: alias=Services, " +
                                    "path=<path to WcfPad.DummyWcfService project>. You may also need to give the " +
                                    "users IIS_IUSRS and IUSR full access to the WcfPad.DummyWcfService folder. " +
                                    $"EXCEPTION MESSAGE: {e.Message}");
            }

            var     serializedParameters = JsonConvert.SerializeObject(parameters);
            dynamic response             = invocationService.InvokeMethod(endpoints.FirstOrDefault().Id, methodName, serializedParameters);

            return(response);
        }
コード例 #6
0
        public Connection(ConnectionManager connectionManager, InvocationService invocationService, int id, Address address,
                          NetworkConfig clientNetworkConfig)
        {
            _connectionManager = connectionManager;
            _id = id;

            var isa           = address.GetInetSocketAddress();
            var socketOptions = clientNetworkConfig.SocketOptions;

            try
            {
                _clientSocket = new Socket(isa.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                _clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                if (socketOptions.LingerSeconds > 0)
                {
                    var lingerOption = new LingerOption(true, socketOptions.LingerSeconds);
                    _clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);
                }
                else
                {
                    var lingerOption = new LingerOption(true, 0);
                    _clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, lingerOption);
                }
                _clientSocket.NoDelay = socketOptions.TcpNoDelay;

                var bufferSize = socketOptions.BufferSize * 1024;
                if (bufferSize < 0)
                {
                    bufferSize = BufferSize;
                }

                _clientSocket.SendBufferSize    = bufferSize;
                _clientSocket.ReceiveBufferSize = bufferSize;

                var connectionTimeout = clientNetworkConfig.ConnectionTimeout > -1
                    ? clientNetworkConfig.ConnectionTimeout
                    : ConnectionTimeout;
                var socketResult = _clientSocket.BeginConnect(address.GetInetAddress(), address.Port, null, null);

                if (!socketResult.AsyncWaitHandle.WaitOne(connectionTimeout, true) || !_clientSocket.Connected)
                {
                    // NOTE, MUST CLOSE THE SOCKET
                    _clientSocket.Close();
                    throw new IOException("Failed to connect to " + address);
                }
                _sendBuffer    = ByteBuffer.Allocate(BufferSize);
                _receiveBuffer = ByteBuffer.Allocate(BufferSize);

                _decoder = new ClientMessageDecoder(invocationService.HandleClientMessage);

                var networkStream = new NetworkStream(_clientSocket, false);
                var sslConfig     = clientNetworkConfig.SslConfig;
                if (sslConfig.Enabled)
                {
                    var sslStream = new SslStream(networkStream, false,
                                                  (sender, certificate, chain, sslPolicyErrors) =>
                                                  RemoteCertificateValidationCallback(sender, certificate, chain, sslPolicyErrors, clientNetworkConfig),
                                                  null);
                    var certificateName            = sslConfig.CertificateName ?? "";
                    var cerPath                    = sslConfig.CertificateFilePath;
                    var enabledSslProtocols        = sslConfig.SslProtocol;
                    var checkCertificateRevocation = sslConfig.CheckCertificateRevocation;
                    var clientCertificates         = GetClientCertificatesOrDefault(cerPath, sslConfig);
                    sslStream.AuthenticateAsClient(certificateName, clientCertificates, enabledSslProtocols,
                                                   checkCertificateRevocation);

                    Logger.Info(
                        $"Client connection ready. Encrypted:{sslStream.IsEncrypted}, MutualAuthenticated:{sslStream.IsMutuallyAuthenticated} using ssl protocol:{sslStream.SslProtocol}");

                    _stream = sslStream;
                }
                else
                {
                    _stream = networkStream;
                }
                _live = new AtomicBoolean(true);
                _connectionStartTime = Clock.CurrentTimeMillis();
            }
            catch (Exception e)
            {
                _clientSocket.Close();
                if (_stream != null)
                {
                    _stream.Close();
                }
                throw new IOException("Cannot init connection.", e);
            }
        }