static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Setup logger and MethodInvocationRemoting objects using (FileApplicationLogger remoteSenderLog = new FileApplicationLogger(LogLevel.Debug, '|', " ", @"C:\Temp\C#Sender.log")) using (TcpRemoteSender tcpSender = new TcpRemoteSender(System.Net.IPAddress.Loopback, 55000, 10, 1000, 30000, 25, remoteSenderLog)) using (TcpRemoteReceiver tcpReceiver = new TcpRemoteReceiver(55001, 10, 1000, 25, remoteSenderLog)) { RemoteReceiverDecompressor decompressorReceiver = new RemoteReceiverDecompressor(tcpReceiver, remoteSenderLog); MethodInvocationSerializer serializer = new MethodInvocationSerializer(new SerializerOperationMap(), remoteSenderLog); MethodInvocationRemoteSender methodInvocationRemoteSender = new MethodInvocationRemoteSender(serializer, tcpSender, decompressorReceiver, remoteSenderLog); // Connect to the MethodInvocationRemoteReceiver tcpSender.Connect(); tcpReceiver.Connect(); // Setup the layers of the application MVP model MainView mainView = new MainView(); Model model = new Model(methodInvocationRemoteSender); Presenter presenter = new Presenter(mainView, model); mainView.Presenter = presenter; // Start the application Application.Run(mainView); // Disconnect from the MethodInvocationRemoteReceiver tcpReceiver.Disconnect(); tcpSender.Disconnect(); } }
//------------------------------------------------------------------------------ // // Method: MainViewRemoteAdapterActiveMQ (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the SampleApplication2.MainViewRemoteAdapterActiveMQ class. /// </summary> /// <param name="connectUriName">The uniform resource name of the ActiveMq broker to connect to.</param> /// <param name="outgoingQueueName">The name of the ActiveMq queue to use for outgoing method calls.</param> /// <param name="incomingQueueName">The name of the ActiveMq queue to use for incoming method calls.</param> /// <param name="requestFilter">The message filter to use for method invocation requests (i.e. calls).</param> /// <param name="responseFilter">The message file to use for method invocation responses (i.e. return values).</param> public MainViewRemoteAdapterActiveMQ(string connectUriName, string outgoingQueueName, string incomingQueueName, string requestFilter, string responseFilter) { // Setup objects for sending method invocations outgoingMethodSerializer = new MethodInvocationSerializer(new SerializerOperationMap()); outgoingSender = new ActiveMqRemoteSender(connectUriName, outgoingQueueName, requestFilter); outgoingReceiver = new ActiveMqRemoteReceiver(connectUriName, outgoingQueueName, responseFilter, 200); methodInvocationSender = new MethodInvocationRemoteSender(outgoingMethodSerializer, outgoingSender, outgoingReceiver); // Setup objects for receiving method invocations incomingMethodSerializer = new MethodInvocationSerializer(new SerializerOperationMap()); incomingSender = new ActiveMqRemoteSender(connectUriName, incomingQueueName, responseFilter); incomingReceiver = new ActiveMqRemoteReceiver(connectUriName, incomingQueueName, requestFilter, 200); methodInvocationReceiver = new MethodInvocationRemoteReceiver(incomingMethodSerializer, incomingSender, incomingReceiver); // Hook the 'MethodInvocationReceived' event on the receiver up to the local method which handles recieving method invocations methodInvocationReceiver.MethodInvocationReceived += new MethodInvocationReceivedEventHandler(ReceiveMethodInvocation); }
//------------------------------------------------------------------------------ // // Method: MainViewRemoteAdapterFile (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the SampleApplication2.MainViewRemoteAdapterFile class. /// </summary> /// <param name="outgoingRequestFilePath">The full path of the file to use for outgoing method invocation requests (i.e. calls).</param> /// <param name="outgoingRequestLockPath">The full path of the lock file to use for outgoing method invocation requests (i.e. calls).</param> /// <param name="outgoingResponseFilePath">The full path of the file to use for outgoing method invocation responses (i.e. return values).</param> /// <param name="outgoingResponseLockPath">The full path of the lock file to use for outgoing method invocation responses (i.e. return values).</param> /// <param name="incomingResponseFilePath">The full path of the file to use for incoming method invocation responses (i.e. return values).</param> /// <param name="incomingResponseLockPath">The full path of the lock file to use for incoming method invocation responses (i.e. return values).</param> /// <param name="incomingRequestFilePath">The full path of the file to use for incoming method invocation requests (i.e. calls).</param> /// <param name="incomingRequestLockPath">The full path of the lock file to use for incoming method invocation requests (i.e. calls).</param> public MainViewRemoteAdapterFile(string outgoingRequestFilePath, string outgoingRequestLockPath, string outgoingResponseFilePath, string outgoingResponseLockPath, string incomingResponseFilePath, string incomingResponseLockPath, string incomingRequestFilePath, string incomingRequestLockPath) { // Setup objects for sending method invocations outgoingMethodSerializer = new MethodInvocationSerializer(new SerializerOperationMap()); outgoingSender = new FileRemoteSender(outgoingRequestFilePath, outgoingRequestLockPath); outgoingReceiver = new FileRemoteReceiver(outgoingResponseFilePath, outgoingResponseLockPath, 200); methodInvocationSender = new MethodInvocationRemoteSender(outgoingMethodSerializer, outgoingSender, outgoingReceiver); // Setup objects for receiving method invocations incomingMethodSerializer = new MethodInvocationSerializer(new SerializerOperationMap()); incomingSender = new FileRemoteSender(incomingResponseFilePath, incomingResponseLockPath); incomingReceiver = new FileRemoteReceiver(incomingRequestFilePath, incomingRequestLockPath, 200); methodInvocationReceiver = new MethodInvocationRemoteReceiver(incomingMethodSerializer, incomingSender, incomingReceiver); // Hook the 'MethodInvocationReceived' event on the receiver up to the local method which handles recieving method invocations methodInvocationReceiver.MethodInvocationReceived += new MethodInvocationReceivedEventHandler(ReceiveMethodInvocation); }
//------------------------------------------------------------------------------ // // Method: MainViewRemoteAdapterTcp (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the SampleApplication2.MainViewRemoteAdapterTcp class. /// </summary> /// <param name="remoteIpAddress">The IP address of the machine where the ContactListPresenterRemoteAdapterTcp object is located.</param> /// <param name="outgoingSenderPort">The TCP port on which to send outgoing method invocation requests (i.e. calls).</param> /// <param name="outgoingReceiverPort">The TCP port on which to receive outgoing method invocation responses (i.e. return values).</param> /// <param name="incomingSenderPort">The TCP port on which to send incoming method invocation responses (i.e. return values).</param> /// <param name="incomingReceiverPort">The TCP port on which to receive incoming method invocation requests (i.e. calls).</param> /// <param name="connectRetryCount">The number of times to retry when initially connecting, or attempting to reconnect the underlying TcpRemoteSender and TcpRemoteReceiver objects.</param> /// <param name="connectRetryInterval">The interval between retries to connect or reconnect in milliseconds.</param> /// <param name="acknowledgementReceiveTimeout">The maximum time the TcpRemoteSender should wait for an acknowledgement of a message in milliseconds.</param> /// <param name="acknowledgementReceiveRetryInterval">The time the TcpRemoteSender should wait between retries to check for an acknowledgement in milliseconds.</param> /// <param name="receiveRetryInterval">The time the TcpRemoteReceiver should wait between attempts to receive a message in milliseconds.</param> public MainViewRemoteAdapterTcp(System.Net.IPAddress remoteIpAddress, int outgoingSenderPort, int outgoingReceiverPort, int incomingSenderPort, int incomingReceiverPort, int connectRetryCount, int connectRetryInterval, int acknowledgementReceiveTimeout, int acknowledgementReceiveRetryInterval, int receiveRetryInterval) { // Setup objects for sending method invocations outgoingMethodSerializer = new MethodInvocationSerializer(new SerializerOperationMap()); outgoingSender = new TcpRemoteSender(remoteIpAddress, outgoingSenderPort, connectRetryCount, connectRetryInterval, acknowledgementReceiveTimeout, acknowledgementReceiveRetryInterval); outgoingReceiver = new TcpRemoteReceiver(outgoingReceiverPort, connectRetryCount, connectRetryInterval, receiveRetryInterval); methodInvocationSender = new MethodInvocationRemoteSender(outgoingMethodSerializer, outgoingSender, outgoingReceiver); // Setup objects for receiving method invocations incomingMethodSerializer = new MethodInvocationSerializer(new SerializerOperationMap()); incomingSender = new TcpRemoteSender(remoteIpAddress, incomingSenderPort, connectRetryCount, connectRetryInterval, acknowledgementReceiveTimeout, acknowledgementReceiveRetryInterval); incomingReceiver = new TcpRemoteReceiver(incomingReceiverPort, connectRetryCount, connectRetryInterval, receiveRetryInterval); methodInvocationReceiver = new MethodInvocationRemoteReceiver(incomingMethodSerializer, incomingSender, incomingReceiver); // Hook the 'MethodInvocationReceived' event on the receiver up to the local method which handles recieving method invocations methodInvocationReceiver.MethodInvocationReceived += new MethodInvocationReceivedEventHandler(ReceiveMethodInvocation); }
static void Main(string[] args) { // Setup connection parameters for ActiveMQ const string connectUri = "activemq:tcp://localhost:61616?wireFormat.maxInactivityDuration=0"; const string queueName = "FromJava"; const string requestQueueFilter = "Request"; const string responseQueueFilter = "Response"; const int receiverConnectLoopTimeout = 200; // Setup method invocation receiver ActiveMqRemoteSender activeMqSender = new ActiveMqRemoteSender(connectUri, queueName, responseQueueFilter); ActiveMqRemoteReceiver activeMqReceiver = new ActiveMqRemoteReceiver(connectUri, queueName, requestQueueFilter, receiverConnectLoopTimeout); MethodInvocationSerializer methodSerializer = new MethodInvocationSerializer(new SerializerOperationMap()); MethodInvocationRemoteReceiver methodInvocationReceiver = new MethodInvocationRemoteReceiver(methodSerializer, activeMqSender, activeMqReceiver); methodInvocationReceiver.MethodInvocationReceived += new MethodInvocationReceivedEventHandler(ReceiveMethodInvocation); try { // Connect to ActiveMQ activeMqSender.Connect(); activeMqReceiver.Connect(); // Start receiving method invocations methodInvocationReceiver.Receive(); Console.WriteLine("Waiting for incoming method calls..."); Console.WriteLine("Press [ENTER] to cancel."); Console.ReadLine(); } catch (Exception e) { Console.WriteLine("An exception occurred"); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } finally { // Stop receiving, disconnect, and dispose methodInvocationReceiver.CancelReceive(); activeMqReceiver.CancelReceive(); activeMqReceiver.Disconnect(); activeMqSender.Disconnect(); activeMqReceiver.Dispose(); activeMqSender.Dispose(); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Setup metric logger and MethodInvocationRemoting objects MetricLoggerDistributor distributor = new MetricLoggerDistributor(); ConsoleMetricLogger consoleMetricLogger = new ConsoleMetricLogger(5000, true); using (FileApplicationLogger logger = new FileApplicationLogger(LogLevel.Information, '|', " ", @"C:\Temp\C#Sender.log")) using (SizeLimitedBufferProcessor fileMetricLoggerBufferProcessor = new SizeLimitedBufferProcessor(50)) using (FileMetricLogger fileMetricLogger = new FileMetricLogger('|', @"C:\Temp\C#Metrics.log", fileMetricLoggerBufferProcessor, true)) using (SizeLimitedBufferProcessor accessMetricLoggerBufferProcessor = new SizeLimitedBufferProcessor(50)) using (MicrosoftAccessMetricLogger accessMetricLogger = new MicrosoftAccessMetricLogger(@"C:\Temp\MetricLogger.mdb", "SampleApplication5-C#", accessMetricLoggerBufferProcessor, true)) using (PerformanceCounterMetricLogger perfmonMetricLogger = new PerformanceCounterMetricLogger("SampleApplication5Metrics", "Metrics produced by MethodInvocationRemoting sample application 5", 1000, true)) using (TcpRemoteSender tcpSender = new TcpRemoteSender(System.Net.IPAddress.Loopback, 55000, 10, 1000, 30000, 25, logger, distributor)) using (TcpRemoteReceiver tcpReceiver = new TcpRemoteReceiver(55001, 10, 1000, 25, logger, distributor)) { RemoteReceiverDecompressor decompressorReceiver = new RemoteReceiverDecompressor(tcpReceiver, logger, distributor); MethodInvocationSerializer serializer = new MethodInvocationSerializer(new SerializerOperationMap(), logger, distributor); MethodInvocationRemoteSender methodInvocationRemoteSender = new MethodInvocationRemoteSender(serializer, tcpSender, decompressorReceiver, logger, distributor); // Define metric aggregates for the console logger DefineMetricAggregates(consoleMetricLogger); // Register base metrics and aggregates with the performance monitor logger perfmonMetricLogger.RegisterMetric(new RemoteMethodSendTime()); perfmonMetricLogger.RegisterMetric(new RemoteMethodSent()); perfmonMetricLogger.RegisterMetric(new MethodInvocationSerializeTime()); perfmonMetricLogger.RegisterMetric(new MethodInvocationSerialized()); perfmonMetricLogger.RegisterMetric(new SerializedMethodInvocationSize(0)); perfmonMetricLogger.RegisterMetric(new ReturnValueDeserializeTime()); perfmonMetricLogger.RegisterMetric(new ReturnValueDeserialized()); perfmonMetricLogger.RegisterMetric(new StringDecompressTime()); perfmonMetricLogger.RegisterMetric(new RemoteReceiverDecompressorReadBufferCreated()); perfmonMetricLogger.RegisterMetric(new StringDecompressed()); perfmonMetricLogger.RegisterMetric(new TcpRemoteReceiverReconnected()); perfmonMetricLogger.RegisterMetric(new MessageReceiveTime()); perfmonMetricLogger.RegisterMetric(new MessageReceived()); perfmonMetricLogger.RegisterMetric(new ReceivedMessageSize(0)); perfmonMetricLogger.RegisterMetric(new TcpRemoteReceiverDuplicateSequenceNumber()); perfmonMetricLogger.RegisterMetric(new MessageSendTime()); perfmonMetricLogger.RegisterMetric(new MessageSent()); perfmonMetricLogger.RegisterMetric(new TcpRemoteSenderReconnected()); DefineMetricAggregates(perfmonMetricLogger); // Create performance monitor counters in the operating system perfmonMetricLogger.CreatePerformanceCounters(); distributor.AddLogger(consoleMetricLogger); distributor.AddLogger(fileMetricLogger); distributor.AddLogger(accessMetricLogger); distributor.AddLogger(perfmonMetricLogger); consoleMetricLogger.Start(); fileMetricLoggerBufferProcessor.Start(); accessMetricLoggerBufferProcessor.Start(); accessMetricLogger.Connect(); perfmonMetricLogger.Start(); // Connect to the MethodInvocationRemoteReceiver tcpSender.Connect(); tcpReceiver.Connect(); // Setup the layers of the application MVP model MainView mainView = new MainView(); Model model = new Model(methodInvocationRemoteSender); Presenter presenter = new Presenter(mainView, model); mainView.Presenter = presenter; // Start the application Application.Run(mainView); // Disconnect from the MethodInvocationRemoteReceiver tcpReceiver.Disconnect(); tcpSender.Disconnect(); // Stop the metric loggers consoleMetricLogger.Stop(); fileMetricLoggerBufferProcessor.Stop(); accessMetricLoggerBufferProcessor.Stop(); accessMetricLogger.Disconnect(); perfmonMetricLogger.Stop(); } }
protected void SetUp() { mocks = new Mockery(); mockApplicationLogger = mocks.NewMock <IApplicationLogger>(); testMethodInvocationSerializer = new MethodInvocationSerializer(new SerializerOperationMap(), mockApplicationLogger); }
protected void SetUp() { mocks = new Mockery(); mockMetricLogger = mocks.NewMock <IMetricLogger>(); testMethodInvocationSerializer = new MethodInvocationSerializer(new SerializerOperationMap(), new ConsoleApplicationLogger(LogLevel.Critical, '|', " "), mockMetricLogger); }