From f7734690f42343f172d96013e6abd379f450de96 Mon Sep 17 00:00:00 2001 From: markpollack Date: Tue, 16 Jun 2009 19:53:15 +0000 Subject: [PATCH] Minor cleanup. Added example of RequestReplyNmsTemplate --- .../Gateways/ISyncStockService.cs | 38 +++++++++++++ .../Gateways/NmsSyncStockServiceGateway.cs | 35 ++++++++++++ .../Gateways/RequestReplyNmsTemplate.cs | 56 +++++++++++++++++++ .../Handlers/StockAppHandler.cs | 18 ++++++ .../Spring.NmsQuickStart.Client/Program.cs | 20 +++++++ .../Spring.NmsQuickStart.Client.csproj | 5 +- .../UI/StockController.cs | 28 ++++++++-- .../UI/StockForm.cs | 27 ++++++++- .../UI/StockForm.designer.cs | 1 + 9 files changed, 222 insertions(+), 6 deletions(-) create mode 100644 examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/ISyncStockService.cs create mode 100644 examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/NmsSyncStockServiceGateway.cs create mode 100644 examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/RequestReplyNmsTemplate.cs diff --git a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/ISyncStockService.cs b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/ISyncStockService.cs new file mode 100644 index 00000000..f5420dc0 --- /dev/null +++ b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/ISyncStockService.cs @@ -0,0 +1,38 @@ + + +#region License + +/* + * Copyright 2002-2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +using Spring.NmsQuickStart.Common.Data; + +namespace Spring.NmsQuickStart.Client.Gateways +{ + /// + /// + /// + /// + /// + /// + /// Mark Pollack + public interface ISyncStockService + { + TradeResponse Send(TradeRequest tradeRequest); + } +} \ No newline at end of file diff --git a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/NmsSyncStockServiceGateway.cs b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/NmsSyncStockServiceGateway.cs new file mode 100644 index 00000000..ccb1b9f8 --- /dev/null +++ b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/NmsSyncStockServiceGateway.cs @@ -0,0 +1,35 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + + +using Spring.Messaging.Nms.Core; +using Spring.NmsQuickStart.Common.Data; + +namespace Spring.NmsQuickStart.Client.Gateways +{ + public class NmsSyncStockServiceGateway : NmsGatewaySupport, ISyncStockService + { + public TradeResponse Send(TradeRequest tradeRequest) + { + RequestReplyNmsTemplate requestReplyNmsTemplate = (RequestReplyNmsTemplate) NmsTemplate; + return (TradeResponse)requestReplyNmsTemplate.ConvertAndSendRequestReply(tradeRequest); + } + } +} \ No newline at end of file diff --git a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/RequestReplyNmsTemplate.cs b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/RequestReplyNmsTemplate.cs new file mode 100644 index 00000000..9d32e9d2 --- /dev/null +++ b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Gateways/RequestReplyNmsTemplate.cs @@ -0,0 +1,56 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +using Apache.NMS; +using Spring.Messaging.Nms.Core; + +namespace Spring.NmsQuickStart.Client.Gateways +{ + /// + /// Not used in the example application but included to show how one could layer on top of + /// NMS a synchronous request reply interaction. This implementation uses temporary queues but + /// another approach would be to use a permanent queue with a message selector unique to the request. + /// + public class RequestReplyNmsTemplate : NmsTemplate + { + public object ConvertAndSendRequestReply(object objectToSend) + { + return Execute(delegate(ISession session, IMessageProducer producer) + { + ITemporaryQueue tempQueue = null; + try + { + tempQueue = session.CreateTemporaryQueue(); + this.ConvertAndSendWithDelegate(objectToSend, delegate(IMessage message) + { + message.NMSReplyTo = + tempQueue; + return message; + }); + return ReceiveAndConvert(tempQueue); + } + finally + { + if (tempQueue != null) session.DeleteDestination(tempQueue); + } + }); + } + } +} \ No newline at end of file diff --git a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Handlers/StockAppHandler.cs b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Handlers/StockAppHandler.cs index 6fac7a06..d6c44096 100644 --- a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Handlers/StockAppHandler.cs +++ b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Handlers/StockAppHandler.cs @@ -1,4 +1,22 @@ +#region License +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion using System.Collections; using Common.Logging; diff --git a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Program.cs b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Program.cs index 48e5e208..9898a0c7 100644 --- a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Program.cs +++ b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Program.cs @@ -1,3 +1,23 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + using System; using System.Threading; using System.Windows.Forms; diff --git a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Spring.NmsQuickStart.Client.csproj b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Spring.NmsQuickStart.Client.csproj index 521f352b..86d4eb7d 100644 --- a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Spring.NmsQuickStart.Client.csproj +++ b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/Spring.NmsQuickStart.Client.csproj @@ -49,7 +49,10 @@ - + + Code + + diff --git a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockController.cs b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockController.cs index e91b978d..e0b11bfe 100644 --- a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockController.cs +++ b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockController.cs @@ -1,3 +1,22 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion using System.Collections; @@ -6,13 +25,15 @@ using Spring.NmsQuickStart.Common.Data; namespace Spring.NmsQuickStart.Client.UI { + /// + /// Handles requests from the UI and forwards them to the remote service. Messages recieved from + /// the service routed through this controller to update the UI. + /// public class StockController { private StockForm stockForm; private IStockService stockService; - - public StockForm StockForm { @@ -38,8 +59,7 @@ namespace Spring.NmsQuickStart.Client.UI tradeRequest.UserName = "Joe Trader"; stockService.Send(tradeRequest); - } - + } public void UpdateMarketData(IDictionary marketDataDict) { diff --git a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockForm.cs b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockForm.cs index cced9c16..e5585521 100644 --- a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockForm.cs +++ b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockForm.cs @@ -1,3 +1,23 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + using System; using System.Collections; using System.Windows.Forms; @@ -34,7 +54,7 @@ namespace Spring.NmsQuickStart.Client.UI //In this simple example no data is collected from the view. //Instead a hardcoded trade request is created in the controller. tradeRequestStatusTextBox.Text = "Request Pending..."; - stockController.SendTradeRequest(); + stockController.SendTradeRequest(); log.Info("Sent trade request."); } @@ -56,6 +76,11 @@ namespace Spring.NmsQuickStart.Client.UI })); } + private void OnPortfolioRequest(object sender, EventArgs e) + { + MessageBox.Show("Get Portfolio operation not yet implemented.", "NmsQuickStart"); + } + } } \ No newline at end of file diff --git a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockForm.designer.cs b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockForm.designer.cs index 79a2960e..9b7d3be5 100644 --- a/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockForm.designer.cs +++ b/examples/Spring/Spring.NmsQuickStart/src/Spring/Spring.NmsQuickStart.Client/UI/StockForm.designer.cs @@ -63,6 +63,7 @@ namespace Spring.NmsQuickStart.Client.UI this.button1.TabIndex = 2; this.button1.Text = "Get Portfolio"; this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.OnPortfolioRequest); // // portfolioListBox //