From 17905b9934a32bfc1e66c55c222e72c989db0d3a Mon Sep 17 00:00:00 2001 From: Arnaud Simon Date: Fri, 26 Sep 2008 13:13:40 +0000 Subject: qpid-1277: simplified message interface git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@699304 13f79535-47bb-0310-9956-ffa450edef68 --- .../client-010/client/client/ClientInterface.cs | 1 - .../client-010/client/client/ClientSession.cs | 24 +++- .../client/client/ClientSessionDelegate.cs | 6 +- qpid/dotnet/client-010/client/client/IMessage.cs | 46 ++++++++ qpid/dotnet/client-010/client/client/Message.cs | 121 +++++++++++++++++++++ .../client/client/MessageListenerInterface.cs | 8 +- qpid/dotnet/client-010/client/transport/Session.cs | 2 - 7 files changed, 193 insertions(+), 15 deletions(-) create mode 100644 qpid/dotnet/client-010/client/client/IMessage.cs create mode 100644 qpid/dotnet/client-010/client/client/Message.cs diff --git a/qpid/dotnet/client-010/client/client/ClientInterface.cs b/qpid/dotnet/client-010/client/client/ClientInterface.cs index ed95933799..85be5886c6 100644 --- a/qpid/dotnet/client-010/client/client/ClientInterface.cs +++ b/qpid/dotnet/client-010/client/client/ClientInterface.cs @@ -18,7 +18,6 @@ */ using System; -using client.client; namespace org.apache.qpid.client { diff --git a/qpid/dotnet/client-010/client/client/ClientSession.cs b/qpid/dotnet/client-010/client/client/ClientSession.cs index 10f1109031..2f107dc0b2 100644 --- a/qpid/dotnet/client-010/client/client/ClientSession.cs +++ b/qpid/dotnet/client-010/client/client/ClientSession.cs @@ -2,8 +2,10 @@ using System; using System.Collections.Generic; -using client.client; +using System.IO; +using System.Text; using org.apache.qpid.transport; +using org.apache.qpid.transport.util; namespace org.apache.qpid.client { @@ -24,20 +26,34 @@ namespace org.apache.qpid.client public static short MESSAGE_ACQUIRE_ANY_AVAILABLE_MESSAGE = 0; public static short MESSAGE_ACQUIRE_MESSAGES_IF_ALL_ARE_AVAILABLE = 1; - private Dictionary _listeners = new Dictionary(); + private Dictionary _listeners = new Dictionary(); public ClientSession(byte[] name) : base(name) { } - public void attachMessageListener(MessageListener listener, string Destination) + public void attachMessageListener(IMessageListener listener, string Destination) { _listeners.Add(Destination, listener); } - public Dictionary MessageListeners + public Dictionary MessageListeners { get { return _listeners; } } + + public void messageTransfer(String destination, string routingkey, IMessage message) + { + byte[] body = new byte[message.Body.Position]; + message.Body.Seek(0, SeekOrigin.Begin); + message.Body.Read(body, 0, body.Length); + message.MessageProperties.setMessageId(UUID.randomUUID()); + message.DeliveryProperties.setRoutingKey(routingkey); + messageTransfer(destination, + MessageAcceptMode.NONE, + MessageAcquireMode.PRE_ACQUIRED, + message.Header, + body); + } } } \ No newline at end of file diff --git a/qpid/dotnet/client-010/client/client/ClientSessionDelegate.cs b/qpid/dotnet/client-010/client/client/ClientSessionDelegate.cs index 087f2d2006..1b40e2ba45 100644 --- a/qpid/dotnet/client-010/client/client/ClientSessionDelegate.cs +++ b/qpid/dotnet/client-010/client/client/ClientSessionDelegate.cs @@ -16,8 +16,6 @@ * specific language governing permissions and limitations * under the License. */ -using System; -using client.client; using org.apache.qpid.transport; using org.apache.qpid.transport.util; @@ -34,8 +32,8 @@ namespace org.apache.qpid.client { if (((ClientSession) session).MessageListeners.ContainsKey(xfr.getDestination())) { - MessageListener listener = ((ClientSession) session).MessageListeners[xfr.getDestination()]; - listener.messageTransfer(xfr); + IMessageListener listener = ((ClientSession)session).MessageListeners[xfr.getDestination()]; + listener.messageTransfer( new Message(xfr)); } else { diff --git a/qpid/dotnet/client-010/client/client/IMessage.cs b/qpid/dotnet/client-010/client/client/IMessage.cs new file mode 100644 index 0000000000..b669867ebb --- /dev/null +++ b/qpid/dotnet/client-010/client/client/IMessage.cs @@ -0,0 +1,46 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you 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. +* +*/ +using System; +using System.Collections.Generic; +using System.IO; +using org.apache.qpid.transport; + +namespace org.apache.qpid.client +{ + public interface IMessage + { + int Id { get; } + + Header Header { get; set; } + + MessageProperties MessageProperties { get; set; } + + DeliveryProperties DeliveryProperties { get; set; } + + Dictionary ApplicationHeaders { get; set; } + + void appendData(byte[] bytes); + + MemoryStream Body { get; } + + void clearData(); + } +} diff --git a/qpid/dotnet/client-010/client/client/Message.cs b/qpid/dotnet/client-010/client/client/Message.cs new file mode 100644 index 0000000000..934ce60e68 --- /dev/null +++ b/qpid/dotnet/client-010/client/client/Message.cs @@ -0,0 +1,121 @@ +/* +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you 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. +* +*/ +using System.Collections.Generic; +using System.IO; +using org.apache.qpid.transport; + +namespace org.apache.qpid.client +{ + public class Message : IMessage + { + private readonly MessageTransfer _message; + + public Message(MessageTransfer m) + { + _message = m; + } + + public Message() + { + _message = new MessageTransfer(); + _message.Header = new Header( new MessageProperties(), new DeliveryProperties()); + ((MessageProperties) _message.Header.Structs[0]).setApplicationHeaders(new Dictionary()); + } + + public MessageProperties MessageProperties + { + get + { + if (_message.Header != null) + return (MessageProperties) Header.Structs[0]; + return null; + } + set + { + if (_message.Header != null) + { + Header.Structs[0] = value; + } + } + } + + public DeliveryProperties DeliveryProperties + { + get + { + if (Header != null) + return (DeliveryProperties) Header.Structs[1]; + return null; + } + set + { + if (Header != null) + { + Header.Structs[1] = value; + } + } + } + + public Dictionary ApplicationHeaders + { + get + { + if (Header != null) + return ((MessageProperties) Header.Structs[0]).getApplicationHeaders(); + return null; + } + set + { + if (Header != null) + { + ((MessageProperties) Header.Structs[0]).setApplicationHeaders(value); + } + } + } + + public void appendData(byte[] bytes) + { + Body.Write(bytes, 0, bytes.Length); + } + + public void clearData() + { + Body.Seek(0, SeekOrigin.Begin); + } + + public Header Header + { + get{ return _message.Header;} + set{ _message.Header = value;} + } + + public MemoryStream Body + { + get { return _message.Body; } + set { _message.Body = value; } + } + + public int Id + { + get { return _message.Id; } + } + } +} diff --git a/qpid/dotnet/client-010/client/client/MessageListenerInterface.cs b/qpid/dotnet/client-010/client/client/MessageListenerInterface.cs index ac56ff8c99..978248e04c 100644 --- a/qpid/dotnet/client-010/client/client/MessageListenerInterface.cs +++ b/qpid/dotnet/client-010/client/client/MessageListenerInterface.cs @@ -16,16 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -using org.apache.qpid.transport; -namespace client.client + +namespace org.apache.qpid.client { - public interface MessageListener + public interface IMessageListener { /// /// Inform the listener of the message transfer /// /// The message transfer object - void messageTransfer(MessageTransfer xfr); + void messageTransfer(IMessage xfr); } } diff --git a/qpid/dotnet/client-010/client/transport/Session.cs b/qpid/dotnet/client-010/client/transport/Session.cs index f97fb44568..69afb68046 100644 --- a/qpid/dotnet/client-010/client/transport/Session.cs +++ b/qpid/dotnet/client-010/client/transport/Session.cs @@ -22,8 +22,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Threading; -using common.org.apache.qpid.transport.util; -using org.apache.qpid.transport; using org.apache.qpid.transport.util; using Frame = org.apache.qpid.transport.network.Frame; using Logger = org.apache.qpid.transport.util.Logger; -- cgit v1.2.1