public Connector(SlaveServer server, Client client) { this._server = server; this._client = client; client.MessageReceived += ProcessMessage; }
public Connector(SlaveServer server, Client client) { _server = server ?? throw new ArgumentNullException(nameof(server)); _client = client ?? throw new ArgumentNullException(nameof(client)); client.MessageReceived += ProcessMessageAsync; }
public ReconnectManager(SlaveServer server, Client client, IViewerClient host, HumanAccount human, GameRole role, string credentials, bool upgrade) { _server = server; _client = client; _host = host; _human = human; _role = role; _credentials = credentials; _upgrade = upgrade; }
protected void InitServerAndClient(string address, int port) { if (_server != null) { _server.Dispose(); _server = null; } _server = new TcpSlaveServer(port, address, ServerConfiguration.Default, new NetworkLocalizer(Thread.CurrentThread.CurrentUICulture.Name)); _client = new Client(""); _client.ConnectTo(_server); }
public void Initialize() { Ros.MasterUri = new Uri("http://localhost:11311/"); Ros.HostName = "localhost"; var topicContainer = new TopicContainer(); topicContainer.AddPublisher(new Publisher <std_msgs.String>("/test_topic", "test")); var tcpListener = new TcpRosListener(0); _slaveServer = new SlaveServer("test", 0, topicContainer); _slaveServer.AddListener("/test_topic", tcpListener); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") private SwitchToSlaveCopyThenBranch newSwitchToSlaveSpy(org.neo4j.io.pagecache.PageCache pageCacheMock, org.neo4j.com.storecopy.StoreCopyClient storeCopyClient) private SwitchToSlaveCopyThenBranch NewSwitchToSlaveSpy(PageCache pageCacheMock, StoreCopyClient storeCopyClient) { ClusterMembers clusterMembers = mock(typeof(ClusterMembers)); ClusterMember master = mock(typeof(ClusterMember)); when(master.StoreId).thenReturn(_storeId); when(master.HARole).thenReturn(HighAvailabilityModeSwitcher.MASTER); when(master.HasRole(eq(HighAvailabilityModeSwitcher.MASTER))).thenReturn(true); when(master.InstanceId).thenReturn(new InstanceId(1)); when(clusterMembers.Members).thenReturn(asList(master)); Dependencies resolver = new Dependencies(); DatabaseAvailability databaseAvailability = mock(typeof(DatabaseAvailability)); when(databaseAvailability.Started).thenReturn(true); resolver.SatisfyDependencies(_requestContextFactory, clusterMembers, mock(typeof(TransactionObligationFulfiller)), mock(typeof(OnlineBackupKernelExtension)), mock(typeof(IndexConfigStore)), mock(typeof(TransactionCommittingResponseUnpacker)), mock(typeof(DataSourceManager)), mock(typeof(StoreLockerLifecycleAdapter)), mock(typeof(FileSystemWatcherService)), databaseAvailability); NeoStoreDataSource dataSource = mock(typeof(NeoStoreDataSource)); when(dataSource.StoreId).thenReturn(_storeId); when(dataSource.DependencyResolver).thenReturn(resolver); DatabaseTransactionStats transactionCounters = mock(typeof(DatabaseTransactionStats)); when(transactionCounters.NumberOfActiveTransactions).thenReturn(0L); Response <HandshakeResult> response = mock(typeof(Response)); when(response.ResponseConflict()).thenReturn(new HandshakeResult(42, 2)); when(_masterClient.handshake(anyLong(), any(typeof(StoreId)))).thenReturn(response); when(_masterClient.ProtocolVersion).thenReturn(Org.Neo4j.Kernel.ha.com.slave.MasterClient_Fields.Current); TransactionIdStore transactionIdStoreMock = mock(typeof(TransactionIdStore)); // note that the checksum (the second member of the array) is the same as the one in the handshake mock above when(transactionIdStoreMock.LastCommittedTransaction).thenReturn(new TransactionId(42, 42, 42)); MasterClientResolver masterClientResolver = mock(typeof(MasterClientResolver)); when(masterClientResolver.Instantiate(anyString(), anyInt(), anyString(), any(typeof(Monitors)), argThat(_storeId => true), any(typeof(LifeSupport)))).thenReturn(_masterClient); return(spy(new SwitchToSlaveCopyThenBranch(TestDirectory.databaseLayout(), NullLogService.Instance, ConfigMock(), mock(typeof(HaIdGeneratorFactory)), mock(typeof(DelegateInvocationHandler)), mock(typeof(ClusterMemberAvailability)), _requestContextFactory, _pullerFactory, masterClientResolver, mock(typeof(SwitchToSlave.Monitor)), storeCopyClient, Suppliers.singleton(dataSource), Suppliers.singleton(transactionIdStoreMock), slave => { SlaveServer server = mock(typeof(SlaveServer)); InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved("localhost", 42); when(server.SocketAddress).thenReturn(inetSocketAddress); return server; }, _updatePuller, pageCacheMock, mock(typeof(Monitors)), () => transactionCounters))); }
public void Initialize() { Ros.MasterUri = new Uri("http://localhost:11311/"); Ros.HostName = "localhost"; Ros.TopicTimeout = 3000; Ros.XmlRpcTimeout = 3000; _container = new TopicContainer(); var listener = new TcpRosListener(0); _slaveServer = new SlaveServer("test", 0, _container); _slaveServer.AddListener("test", listener); _slaveClient = new SlaveClient(_slaveServer.SlaveUri); }
public virtual async ValueTask DisposeAsync() { await ClearConnection(); if (_connector != null) { _connector.Dispose(); _connector = null; } if (_releaseServer && _server != null) { _server.Dispose(); _server = null; } }
public void SubscribeBeforeSetParam() { var server = new ParameterServer(new Uri("http://localhost")); var slave = new SlaveServer("test", 0, new TopicContainer()); var observer = new ReplaySubject <KeyValuePair <string, object> >(); slave.ParameterUpdated += (key, value) => observer.OnNext(new KeyValuePair <string, object>(key, value)); server.SubscribeParam("test", slave.SlaveUri.ToString(), "test_param"); server.SetParam("test", "test_param", 5678); observer.First().Key.Is("test_param"); observer.First().Value.Is(5678); }
public Node(string nodeId) { _disposed = false; NodeId = nodeId; _logger = RosOutLogManager.GetCurrentNodeLogger(NodeId); if (_logger.IsDebugEnabled) { LogLevel = Log.DEBUG; } else if (_logger.IsInfoEnabled) { LogLevel = Log.INFO; } else if (_logger.IsWarnEnabled) { LogLevel = Log.WARN; } else if (_logger.IsErrorEnabled) { LogLevel = Log.ERROR; } else if (_logger.IsFatalEnabled) { LogLevel = Log.FATAL; } _masterClient = new MasterClient(Ros.MasterUri); _parameterServerClient = new ParameterServerClient(Ros.MasterUri); _serviceProxyFactory = new ServiceProxyFactory(NodeId); _topicContainer = new TopicContainer(); _slaveServer = new SlaveServer(NodeId, 0, _topicContainer); _slaveServer.ParameterUpdated += SlaveServerOnParameterUpdated; _logger.InfoFormat("Create Node: {0}", nodeId); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private java.net.URI startHaCommunication(org.neo4j.kernel.lifecycle.LifeSupport haCommunicationLife, org.neo4j.kernel.NeoStoreDataSource neoDataSource, java.net.URI me, java.net.URI masterUri, org.neo4j.storageengine.api.StoreId storeId, org.neo4j.helpers.CancellationRequest cancellationRequest) throws IllegalArgumentException, InterruptedException private URI StartHaCommunication(LifeSupport haCommunicationLife, NeoStoreDataSource neoDataSource, URI me, URI masterUri, StoreId storeId, CancellationRequest cancellationRequest) { MasterClient master = NewMasterClient(masterUri, me, neoDataSource.StoreId, haCommunicationLife); TransactionObligationFulfiller obligationFulfiller = ResolveDatabaseDependency(typeof(TransactionObligationFulfiller)); UpdatePullerScheduler updatePullerScheduler = _updatePullerFactory.createUpdatePullerScheduler(UpdatePuller); Slave slaveImpl = new SlaveImpl(obligationFulfiller); SlaveServer server = _slaveServerFactory.apply(slaveImpl); if (cancellationRequest.CancellationRequested()) { MsgLog.info("Switch to slave cancelled, unable to start HA-communication"); return(null); } _masterDelegateHandler.Delegate = master; haCommunicationLife.Add(updatePullerScheduler); haCommunicationLife.Add(server); haCommunicationLife.Start(); /* * Take the opportunity to catch up with master, now that we're alone here, right before we * drop the availability guard, so that other transactions might start. */ if (!CatchUpWithMaster(UpdatePuller)) { return(null); } URI slaveHaURI = CreateHaURI(me, server); _clusterMemberAvailability.memberIsAvailable(HighAvailabilityModeSwitcher.SLAVE, slaveHaURI, storeId); return(slaveHaURI); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void whenHAModeSwitcherSwitchesToSlaveTheOtherModeSwitcherDoNotGetTheOldMasterClient() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void WhenHAModeSwitcherSwitchesToSlaveTheOtherModeSwitcherDoNotGetTheOldMasterClient() { InstanceId me = new InstanceId(1); StoreId storeId = newStoreIdForCurrentVersion(); HighAvailabilityMemberContext context = mock(typeof(HighAvailabilityMemberContext)); when(context.MyId).thenReturn(me); AvailabilityGuard guard = mock(typeof(DatabaseAvailabilityGuard)); ObservedClusterMembers members = mock(typeof(ObservedClusterMembers)); ClusterMember masterMember = mock(typeof(ClusterMember)); when(masterMember.HARole).thenReturn("master"); when(masterMember.HasRole("master")).thenReturn(true); when(masterMember.InstanceId).thenReturn(new InstanceId(2)); when(masterMember.StoreId).thenReturn(storeId); ClusterMember self = new ClusterMember(me); when(members.Members).thenReturn(Arrays.asList(self, masterMember)); when(members.CurrentMember).thenReturn(self); DependencyResolver dependencyResolver = mock(typeof(DependencyResolver)); FileSystemAbstraction fs = mock(typeof(FileSystemAbstraction)); when(fs.FileExists(any(typeof(File)))).thenReturn(true); when(dependencyResolver.ResolveDependency(typeof(FileSystemAbstraction))).thenReturn(fs); when(dependencyResolver.ResolveDependency(typeof(Monitors))).thenReturn(new Monitors()); NeoStoreDataSource dataSource = mock(typeof(NeoStoreDataSource)); when(dataSource.DependencyResolver).thenReturn(dependencyResolver); when(dataSource.StoreId).thenReturn(storeId); when(dependencyResolver.ResolveDependency(typeof(NeoStoreDataSource))).thenReturn(dataSource); when(dependencyResolver.ResolveDependency(typeof(TransactionIdStore))).thenReturn(new SimpleTransactionIdStore()); when(dependencyResolver.ResolveDependency(typeof(ObservedClusterMembers))).thenReturn(members); UpdatePuller updatePuller = mock(typeof(UpdatePuller)); when(updatePuller.TryPullUpdates()).thenReturn(true); when(dependencyResolver.ResolveDependency(typeof(UpdatePuller))).thenReturn(updatePuller); ClusterMemberAvailability clusterMemberAvailability = mock(typeof(ClusterMemberAvailability)); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TriggerableClusterMemberEvents events = new TriggerableClusterMemberEvents(); TriggerableClusterMemberEvents events = new TriggerableClusterMemberEvents(); Election election = mock(typeof(Election)); HighAvailabilityMemberStateMachine stateMachine = new HighAvailabilityMemberStateMachine(context, guard, members, events, election, NullLogProvider.Instance); ClusterMembers clusterMembers = new ClusterMembers(members, stateMachine); when(dependencyResolver.ResolveDependency(typeof(ClusterMembers))).thenReturn(clusterMembers); stateMachine.Init(); stateMachine.Start(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.ha.DelegateInvocationHandler<org.neo4j.kernel.ha.com.master.Master> handler = new org.neo4j.kernel.ha.DelegateInvocationHandler<>(org.neo4j.kernel.ha.com.master.Master.class); DelegateInvocationHandler <Master> handler = new DelegateInvocationHandler <Master>(typeof(Master)); MasterClientResolver masterClientResolver = mock(typeof(MasterClientResolver)); MasterClient masterClient = mock(typeof(MasterClient)); when(masterClient.ProtocolVersion).thenReturn(MasterClient214.PROTOCOL_VERSION); when(masterClient.Handshake(anyLong(), any(typeof(StoreId)))).thenReturn(new ResponseAnonymousInnerClass(this, storeId, mock(typeof(ResourceReleaser)), handler)); when(masterClient.ToString()).thenReturn("TheExpectedMasterClient!"); when(masterClientResolver.Instantiate(anyString(), anyInt(), anyString(), any(typeof(Monitors)), any(typeof(StoreId)), any(typeof(LifeSupport)))).thenReturn(masterClient); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch(2); System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(2); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean switchedSuccessfully = new java.util.concurrent.atomic.AtomicBoolean(); AtomicBoolean switchedSuccessfully = new AtomicBoolean(); SwitchToSlave.Monitor monitor = new MonitorAnonymousInnerClass(this, latch, switchedSuccessfully); Config config = Config.defaults(ClusterSettings.server_id, me.ToString()); DatabaseTransactionStats transactionCounters = mock(typeof(DatabaseTransactionStats)); when(transactionCounters.NumberOfActiveTransactions).thenReturn(0L); PageCache pageCacheMock = mock(typeof(PageCache)); PagedFile pagedFileMock = mock(typeof(PagedFile)); when(pagedFileMock.LastPageId).thenReturn(1L); when(pageCacheMock.Map(any(typeof(File)), anyInt())).thenReturn(pagedFileMock); TransactionIdStore transactionIdStoreMock = mock(typeof(TransactionIdStore)); when(transactionIdStoreMock.LastCommittedTransaction).thenReturn(new TransactionId(0, 0, 0)); SwitchToSlaveCopyThenBranch switchToSlave = new SwitchToSlaveCopyThenBranch(DatabaseLayout.of(new File("")), NullLogService.Instance, mock(typeof(FileSystemAbstraction)), config, mock(typeof(HaIdGeneratorFactory)), handler, mock(typeof(ClusterMemberAvailability)), mock(typeof(RequestContextFactory)), mock(typeof(PullerFactory), RETURNS_MOCKS), Iterables.empty(), masterClientResolver, monitor, new Org.Neo4j.com.storecopy.StoreCopyClientMonitor_Adapter(), Suppliers.singleton(dataSource), Suppliers.singleton(transactionIdStoreMock), slave => { SlaveServer mock = mock(typeof(SlaveServer)); when(mock.SocketAddress).thenReturn(new InetSocketAddress("localhost", 123)); return(mock); }, updatePuller, pageCacheMock, mock(typeof(Monitors)), () => transactionCounters); ComponentSwitcherContainer switcherContainer = new ComponentSwitcherContainer(); HighAvailabilityModeSwitcher haModeSwitcher = new HighAvailabilityModeSwitcher(switchToSlave, mock(typeof(SwitchToMaster)), election, clusterMemberAvailability, mock(typeof(ClusterClient)), storeSupplierMock(), me, switcherContainer, NeoStoreDataSourceSupplierMock(), NullLogService.Instance); haModeSwitcher.Init(); haModeSwitcher.Start(); haModeSwitcher.ListeningAt(URI.create("http://localhost:12345")); stateMachine.AddHighAvailabilityMemberListener(haModeSwitcher); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReference<org.neo4j.kernel.ha.com.master.Master> ref = new java.util.concurrent.atomic.AtomicReference<>(null); AtomicReference <Master> @ref = new AtomicReference <Master>(null); //noinspection unchecked AbstractComponentSwitcher <object> otherModeSwitcher = new AbstractComponentSwitcherAnonymousInnerClass(this, mock(typeof(DelegateInvocationHandler)), handler, latch, @ref); switcherContainer.Add(otherModeSwitcher); // When events.SwitchToSlave(me); // Then latch.await(); assertTrue("mode switch failed", switchedSuccessfully.get()); Master actual = @ref.get(); // let's test the toString()s since there are too many wrappers of proxies assertEquals(masterClient.ToString(), actual.ToString()); stateMachine.Stop(); stateMachine.Shutdown(); haModeSwitcher.Stop(); haModeSwitcher.Shutdown(); }