~ubuntu-branches/ubuntu/trusty/smuxi/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/ServiceStack/src/ServiceStack.Common/Messaging/Rcon/PacketProcessingClient.cs

  • Committer: Package Import Robot
  • Author(s): Mirco Bauer
  • Date: 2013-05-25 22:11:31 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130525221131-nd2mc0kzubuwyx20
Tags: 0.8.11-1
* [22d13d5] Imported Upstream version 0.8.11
* [6d2b95a] Refreshed patches
* [89eb66e] Added ServiceStack libraries to smuxi-engine package
* [848ab10] Enable Campfire engine
* [c6dbdc7] Always build db4o for predictable build result
* [13ec489] Exclude OS X specific libraries from dh_clideps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if !SILVERLIGHT 
 
2
using System;
 
3
using System.Collections.Generic;
 
4
using ServiceStack.Messaging;
 
5
using System.Net.Sockets;
 
6
using System.Text;
 
7
 
 
8
namespace ServiceStack.Messaging.Rcon
 
9
{
 
10
    /// <summary>
 
11
    /// Processing client used to interface with ServiceStack and allow a message to be processed.
 
12
    /// Not an actual client.
 
13
    /// </summary>
 
14
    internal class ProcessingClient : IMessageQueueClient
 
15
    {
 
16
        Packet thePacket;
 
17
        Socket theClient;
 
18
        Server theServer;
 
19
        bool givenPacket = false;
 
20
 
 
21
        public ProcessingClient(Packet packet, Socket client, Server server)
 
22
        {
 
23
            thePacket = packet;
 
24
            theClient = client;
 
25
            theServer = server;
 
26
        }
 
27
 
 
28
        public void Publish<T>(T messageBody)
 
29
        {
 
30
            if (typeof(IMessage).IsAssignableFrom(typeof(T)))
 
31
                Publish((IMessage)messageBody);
 
32
            else
 
33
                Publish<T>(new Message<T>(messageBody));
 
34
        }
 
35
 
 
36
        public void Publish(IMessage message)
 
37
        {
 
38
            var messageBytes = message.ToBytes();
 
39
            Publish(new QueueNames(message.Body.GetType()).In, messageBytes);
 
40
        }
 
41
 
 
42
        public void Publish<T>(IMessage<T> message)
 
43
        {
 
44
            var messageBytes = message.ToBytes();
 
45
            Publish(message.ToInQueueName(), messageBytes);
 
46
        }
 
47
 
 
48
        /// <summary>
 
49
        /// Publish the specified message into the durable queue @queueName
 
50
        /// </summary>
 
51
        /// <param name="queueName"></param>
 
52
        /// <param name="messageBytes"></param>
 
53
        public void Publish(string queueName, byte[] messageBytes)
 
54
        {
 
55
            theServer.Publish(queueName, messageBytes, theClient, thePacket.Sequence);
 
56
        }
 
57
        
 
58
        /// <summary>
 
59
        /// Publish the specified message into the transient queue @queueName
 
60
        /// </summary>
 
61
        /// <param name="queueName"></param>
 
62
        /// <param name="messageBytes"></param>
 
63
        public void Notify(string queueName, byte[] messageBytes)
 
64
        {
 
65
            theServer.Notify(queueName, messageBytes, theClient, thePacket.Sequence);
 
66
        }
 
67
 
 
68
        /// <summary>
 
69
        /// Synchronous blocking get.
 
70
        /// </summary>
 
71
        /// <param name="queueName"></param>
 
72
        /// <param name="timeOut"></param>
 
73
        /// <returns></returns>
 
74
        public byte[] Get(string queueName, TimeSpan? timeOut)
 
75
        {
 
76
            if (givenPacket)
 
77
                return null;
 
78
            var ret = thePacket.Words[1];
 
79
            givenPacket = true;
 
80
            return ret;
 
81
        }
 
82
        
 
83
        /// <summary>
 
84
        /// Non blocking get message
 
85
        /// </summary>
 
86
        /// <param name="queueName"></param>
 
87
        /// <returns></returns>
 
88
        public byte[] GetAsync(string queueName)
 
89
        {
 
90
            return Get(queueName, TimeSpan.MinValue);
 
91
        }
 
92
 
 
93
        /// <summary>
 
94
        /// Blocking wait for notifications on any of the supplied channels
 
95
        /// </summary>
 
96
        /// <param name="channelNames"></param>
 
97
        /// <returns></returns>
 
98
        public string WaitForNotifyOnAny(params string[] channelNames)
 
99
        {
 
100
            return null;
 
101
        }
 
102
 
 
103
        public void Dispose()
 
104
        {
 
105
        }
 
106
    }
 
107
}
 
108
#endif
 
 
b'\\ No newline at end of file'