public ServiceClient Construct(ClusteringConfiguration clusteringConfiguration) { if (clusteringConfiguration.ClusteringRole == ClusteringRole.HostOnly && !IPAddress.IsLoopback(clusteringConfiguration.Address)) { throw new InvalidOperationException("It is impossible host a Dargon Service cluster located at a remote address!"); } LocalServiceContainer localServiceContainer = new LocalServiceContainerImpl(collectionFactory); ClusteringPhaseManager clusteringPhaseManager = new ClusteringPhaseManagerImpl(); PortableObjectBoxConverter portableObjectBoxConverter = new PortableObjectBoxConverter(streamFactory, pofSerializer); HostSessionFactory hostSessionFactory = new HostSessionFactoryImpl(threadingProxy, collectionFactory, pofSerializer, pofStreamsFactory, portableObjectBoxConverter); ClusteringPhaseFactory clusteringPhaseFactory = new ClusteringPhaseFactoryImpl(collectionFactory, threadingProxy, networkingProxy, pofStreamsFactory, hostSessionFactory, clusteringConfiguration, portableObjectBoxConverter, clusteringPhaseManager); ClusteringPhase initialClusteringPhase = clusteringPhaseFactory.CreateIndeterminatePhase(localServiceContainer); clusteringPhaseManager.Transition(initialClusteringPhase); RemoteServiceInvocationValidatorFactory validatorFactory = new RemoteServiceInvocationValidatorFactoryImpl(collectionFactory); RemoteServiceProxyFactory remoteServiceProxyFactory = new RemoteServiceProxyFactoryImpl(proxyGenerator, portableObjectBoxConverter, validatorFactory, clusteringPhaseManager); InvokableServiceContextFactory invokableServiceContextFactory = new InvokableServiceContextFactoryImpl(collectionFactory, portableObjectBoxConverter); IConcurrentDictionary <Guid, InvokableServiceContext> serviceContextsById = new ConcurrentDictionary <Guid, InvokableServiceContext>(); LocalServiceRegistry localServiceRegistry = new LocalServiceRegistryImpl(localServiceContainer, clusteringPhaseManager, invokableServiceContextFactory, serviceContextsById); IConcurrentDictionary <Type, object> serviceProxiesByInterface = new ConcurrentDictionary <Type, object>(); RemoteServiceProxyContainer remoteServiceProxyContainer = new RemoteServiceProxyContainerImpl(remoteServiceProxyFactory, serviceProxiesByInterface); return(new ServiceClientProxyImpl(localServiceRegistry, remoteServiceProxyContainer)); }
public void Transition(ClusteringPhase nextClusteringPhase) { nextClusteringPhase.ThrowIfNull("nextClusteringPhase"); synchronization.EnterWriteLock(); try { ThrowIfDisposed(); logger.Info("Transition from phase " + (currentClusteringPhase?.ToString() ?? "null") + " to " + (nextClusteringPhase?.ToString() ?? "null")); currentClusteringPhase = nextClusteringPhase; currentClusteringPhase.HandleEnter(); } finally { synchronization.ExitWriteLock(); } }