01 /*
02 *
03 * Licensed to the Apache Software Foundation (ASF) under one
04 * or more contributor license agreements. See the NOTICE file
05 * distributed with this work for additional information
06 * regarding copyright ownership. The ASF licenses this file
07 * to you under the Apache License, Version 2.0 (the
08 * "License"); you may not use this file except in compliance
09 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21 package org.apache.qpid.codec;
22
23 import org.apache.mina.filter.codec.ProtocolCodecFactory;
24 import org.apache.mina.filter.codec.ProtocolDecoder;
25 import org.apache.mina.filter.codec.ProtocolEncoder;
26
27 /**
28 * AMQCodecFactory is a Mina codec factory. It supplies the encoders and decoders need to read and write the bytes to
29 * the wire.
30 *
31 * <p/><table id="crc"><caption>CRC Card</caption>
32 * <tr><th> Responsibilities <th> Collaborations.
33 * <tr><td> Supply the protocol encoder. <td> {@link AMQEncoder}
34 * <tr><td> Supply the protocol decoder. <td> {@link AMQDecoder}
35 * </table>
36 */
37 public class AMQCodecFactory implements ProtocolCodecFactory
38 {
39 /** Holds the protocol encoder. */
40 private final AMQEncoder _encoder = new AMQEncoder();
41
42 /** Holds the protocol decoder. */
43 private final AMQDecoder _frameDecoder;
44
45 /**
46 * Creates a new codec factory, specifiying whether it is expected that the first frame of data should be an
47 * initiation. This is the case for the broker, which always expects to received the protocol initiation on a newly
48 * connected client.
49 *
50 * @param expectProtocolInitiation <tt>true</tt> if the first frame received is going to be a protocol initiation
51 * frame, <tt>false</tt> if it is going to be a standard AMQ data block.
52 */
53 public AMQCodecFactory(boolean expectProtocolInitiation)
54 {
55 _frameDecoder = new AMQDecoder(expectProtocolInitiation);
56 }
57
58 /**
59 * Gets the AMQP encoder.
60 *
61 * @return The AMQP encoder.
62 */
63 public ProtocolEncoder getEncoder()
64 {
65 return _encoder;
66 }
67
68 /**
69 * Gets the AMQP decoder.
70 *
71 * @return The AMQP decoder.
72 */
73 public ProtocolDecoder getDecoder()
74 {
75 return _frameDecoder;
76 }
77 }
|