summaryrefslogtreecommitdiff
path: root/qpid/java/client-api/src/main/java/org/apache/qpid/messaging/cpp/CppMessageFactory.java
blob: 4fddcaa326bfda0371eee01e80726a117af1f5aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/* 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.
 */
package org.apache.qpid.messaging.cpp;

import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;

import org.apache.qpid.messaging.ListMessage;
import org.apache.qpid.messaging.MapMessage;
import org.apache.qpid.messaging.Message;
import org.apache.qpid.messaging.MessageEncodingException;
import org.apache.qpid.messaging.MessageFactory;
import org.apache.qpid.messaging.MessagingException;
import org.apache.qpid.messaging.StringMessage;
import org.apache.qpid.messaging.cpp.jni.Address;
import org.apache.qpid.messaging.cpp.jni.Duration;
import org.apache.qpid.messaging.util.MessageFactory_AMQP_0_10;

/**
 * For the time being 0-10 is assumed.
 */
public class CppMessageFactory extends MessageFactory_AMQP_0_10
{
    @Override
    protected Class<? extends MessageFactory> getFactoryClass()
    {
        return CppMessageFactory.class;
    }

    @Override
    protected Message createFactorySpecificMessageDelegate()
    {
        return new CppMessageDelegate();
    }

    public Message createMessage(org.apache.qpid.messaging.cpp.jni.Message m) throws MessagingException
    {
        return createMessage(new CppMessageDelegate(m), m.getContentAsByteBuffer());
    }

    class CppMessageDelegate implements Message
    {
        private org.apache.qpid.messaging.cpp.jni.Message _cppMessage;

        public CppMessageDelegate()
        {
            this(new org.apache.qpid.messaging.cpp.jni.Message());
        }

        public CppMessageDelegate(org.apache.qpid.messaging.cpp.jni.Message msg)
        {
            _cppMessage = msg;
        }

        @Override
        public String getMessageId()
        {
            return _cppMessage.getMessageId();
        }

        @Override
        public void setMessageId(String messageId)
        {
            _cppMessage.setMessageId(messageId);

        }

        @Override
        public String getSubject()
        {
            return _cppMessage.getSubject();
        }

        @Override
        public void setSubject(String subject)
        {
            _cppMessage.setMessageId(subject);
        }

        @Override
        public String getContentType()
        {
            return _cppMessage.getContentType();
        }

        @Override
        public void setContentType(String contentType)
        {
            _cppMessage.setContentType(contentType);
        }

        @Override
        public String getCorrelationId()
        {
            return _cppMessage.getCorrelationId();
        }

        @Override
        public void setCorrelationId(String correlationId)
        {
            _cppMessage.setCorrelationId(correlationId);
        }

        @Override
        public String getReplyTo()
        {
            return _cppMessage.getReplyTo().toString();
        }

        @Override
        public void setReplyTo(String replyTo)
        {
            _cppMessage.setReplyTo(new Address(replyTo));
        }

        @Override
        public String getUserId()
        {
            return _cppMessage.getUserId();
        }

        @Override
        public void setUserId(String userId)
        {
            _cppMessage.setUserId(userId);
        }

        @Override
        public boolean isDurable()
        {
            return _cppMessage.getDurable();
        }

        @Override
        public void setDurable(boolean durable)
        {
            _cppMessage.setDurable(durable);
        }

        @Override
        public boolean isRedelivered()
        {
            return _cppMessage.getRedelivered();
        }

        @Override
        public void setRedelivered(boolean redelivered)
        {
            _cppMessage.setRedelivered(redelivered);
        }

        @Override
        public int getPriority()
        {
            return _cppMessage.getPriority();
        }

        @Override
        public void setPriority(int priority)
        {
            _cppMessage.setPriority((byte)priority);
        }

        @Override
        public long getTtl()
        {
            return _cppMessage.getTtl().getMilliseconds();
        }

        @Override
        public void setTtl(long ttl)
        {
            _cppMessage.setTtl(new Duration(ttl));
        }

        @Override
        public long getTimestamp()
        {
            return 0;
        }

        @Override
        public void setTimestamp(long timestamp)
        {
            //ignore the c++ client will set it when sending
        }

        @SuppressWarnings("unchecked")
        @Override
        public Map<String, Object> getProperties()
        {
            return _cppMessage.getProperties();
        }

        @Override
        public void setProperty(String key, Object value)
        {
            _cppMessage.setProperty(key, value);
        }

        protected org.apache.qpid.messaging.cpp.jni.Message getCppMessage()
        {
            return _cppMessage;
        }

        @Override
        public String toString()
        {
            return _cppMessage.toString();
        }

        @Override
        public ByteBuffer getContent() throws MessagingException
        {
            return null; // The delegate is only for the headers
        }

        public org.apache.qpid.messaging.cpp.jni.Message getNativeMessage()
        {
            return _cppMessage;
        }
    }

}